Example #1
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
Example #2
0
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