コード例 #1
0
ファイル: pipeline.py プロジェクト: shawkinsl/python-rtmbot
def get_pipeline(data):
    outputs.append([data['channel'], "One moment please..."])
    wbdb = WarbotDB()
    pwc = PWClient(USERNAME, PASS, logger=logger)
    notifying_beiges = wbdb.beige_checks.find({"state": "notify"})
    watching_beiges = wbdb.beige_checks.find({"state": "watch"})

    total = notifying_beiges.count() + watching_beiges.count()
    if total > 1:
        outputs.append([data['channel'], "Processing "+str(total)+" records in the pipeline..."])
    else:
        return "The pipeline looks empty from here!"
    output_strings = []
    if notifying_beiges.count() > 0:
        output_strings.append("*Next turn notifications*")
    for record in notifying_beiges:
        user = get_username_from_user_id(record["requesting_user_slack_id"])
        output_strings.append("I am notifying "+user+" next turn about nation "+record["nation_name"] + "("+record["nation_id"]+")")

    if watching_beiges.count() > 0:
        output_strings.append("*Upcoming reminders*")
    for record in watching_beiges:
        try:
            nation = pwc.get_nation_obj_from_ID(record["nation_id"])
            user = get_username_from_user_id(record["requesting_user_slack_id"])
            output_strings.append("I am watching nation "+record["nation_name"] + "("+str(record["nation_id"])+") for "+user+". Has *"+str(nation.beige_turns_left)+"* turns left in beiege.")
        except NationDoesNotExistError as e:
            user = get_username_from_user_id(record["requesting_user_slack_id"])
            output_strings.append("I am watching nation "+record["nation_name"] + "("+str(record["nation_id"])+") for "+user+". However, *_the nation no longer exists!_*")
    return "\n".join(output_strings)
コード例 #2
0
def notify_end_of_beige(slack_uid, slack_username, action):
    pwc = PWClient(USERNAME, PASS, logger=logger)
    wardb = WarbotDB()

    print "enter notify_end_of_beige"
    nation_ids = [int(s) for s in action.split() if s.isdigit()]
    nations_added = []
    nations_already_watched = []
    not_in_beige = []
    for nation_id in nation_ids:
        try:
            nation = pwc.get_nation_obj_from_ID(nation_id)
        except:
            trace = traceback.format_exc()
            print "Skipping this nation, exception below:"
            print trace
            continue
        if nation.beige_turns_left is not None:
            if wardb.create_personal_beige_watch_record(slack_uid, nation_id, nation.name, nation.beige_turns_left):
                nations_added.append(nation.name)
            else:
                nations_already_watched.append(nation.name)
        else:
            not_in_beige.append(nation.name)
    if len(nations_added) > 0:
        text = "OK, " + str(slack_username) + ", I'll notify you when " + ", ".join(nations_added) + " leaves beige"
    else:
        text = "I didn't find any nations to add in your query! Try `warbot help` if you need!"

    if len(nations_already_watched) > 0:
        text += "\nYou're already watching " + ", ".join(nations_already_watched) + ", ya doof!"
    if len(not_in_beige) > 0:
        text += "\nbtw, it looks like " + ", ".join(not_in_beige) + " aren't in beige ya dingus"

    return text
コード例 #3
0
ファイル: register.py プロジェクト: shawkinsl/python-rtmbot
def register_user(slack_uid, slack_username, action):
    pwc = PWClient(USERNAME, PASS, logger=logger)
    wardb = WarbotDB()

    nation_ids = [int(s) for s in action.split() if s.isdigit()]
    if len(nation_ids) != 1:
        return error_message()
    nation_id = nation_ids[0]

    print "Getting nation to register: ", nation_id

    nation_obj = pwc.get_nation_obj_from_ID(nation_id)
    name = nation_obj.name

    wardb.update_user_map(slack_uid, slack_username, nation_id, name)

    return "OK, "+slack_username+", I've registered your nation as "+name