Esempio n. 1
0
def home_page():
    # tells the session the bot is online. Might actually make this useful
    # at some point.
    if NERVES.poll():
        signal = NERVES.recv()
        session["status"] = signal
    elif "status" not in session:
        session["status"] = "OFFLINE"

    if not session.has_key("logged_in") or not session["logged_in"]:
        LOG.debug("Not logged in, displaying standard home page")
        return render_template("HomePage.html", groups=None, listname=None, listview=None, majors=None)

    # if the session has an invalid side,
    if not session.has_key("side") or session["side"] < 0:
        session["side"] = 1

    # get the name of the list being managed, if any
    listname = request.args.get("listview")
    listname = listname if listname is not None else "all"
    if listname:
        LOG.debug("Listname = {}".format(listname))

    # checks if a new list has been created
    if request.args.get("new_name") is not None:

        new_list_name = request.args.get("new_name")
        listname = new_list_name
        memory.create_list(session["side"], listname)
        LOG.debug("Added a new list {} to memory for side {}".format(listname, session["side"]))

    # if a player was removed, deal with that
    if request.args.get("remove") is not None:
        removed_player = request.args.get("remove")
        memory.remove_player(session["side"], listname, removed_player)
        LOG.debug("Removed {} from list {} of side {}".format(removed_player, listname, session["side"]))

    # if a player was added, deal with that
    if request.args.get("add") is not None:
        added_player = request.args.get("add")
        memory.add_player(session["side"], listname, added_player)
        LOG.debug("Added {} to list {} for side {}".format(added_player, listname, session["side"]))

    groups = memory.get_lists_of(session["side"])
    LOG.debug("Groups for side {} are {}".format(session["side"], groups))
    try:
        listview = groups[listname]
        LOG.debug("Users in group {}: {}".format(listname, listview))
    except KeyError:
        listview = ["There's nothing here!"]
    try:
        majors = memory.get_players_with(g.db, side=session["side"], recruited=True)
    except sqlite3.InterfaceError:
        majors = []

    return render_template(
        "HomePage.html", groups=groups, listname=listname, listview=listview, majors=majors, version=CONFIG["VERSION"]
    )
Esempio n. 2
0
def authorize_bot():
    """
    Allow me to authorize a bot
    """

    # make sure no one else can do it
    if session["usertype"] != 2:
        return redirect("/")
    bot_name = request.args.get("bot_name")
    bot_side = int(request.args.get("bot_side"))
    LOG.debug("Attempting to authorize {} bot for side {}".format(bot_name, bot_side))
    if len(memory.get_players_with(g.db, side=bot_side, usertype=-1)) > 0:
        LOG.warning("{} is already registered with side {}!".format(bot_name, bot_side))
        LOG.warning(
            "List returned by memory: {}".format(memory.get_players_with(g.db, side=bot_side, usertype=-1).__str__())
        )
        return redirect("/")
    memory.handle_player_memory(g.db, bot_name, side=bot_side, usertype=-1)
    LOG.info("Authorized {} bot for side {}".format(bot_name, bot_side))
    return redirect(ANTENNA.get_OAuth_URL("bot"))
Esempio n. 3
0
def reset_bots():
    """
    Lets me destroy the bots in the DB so I can reauthorize them.
    """
    # make sure no one else can do it
    if session["usertype"] != 2:
        return redirect("/")
    bot_list = memory.get_players_with(g.db, usertype=-1)
    for bot in bot_list:
        memory.remove_player_from_DB(g.db, bot)
    return redirect("/")
Esempio n. 4
0
def recruit_getter(cfg, db, antenna, side):
    """
    Get all of the new recruits from the proper side's recruitment thread
    and return them in a list. Note that this will only return new
    recruits.

    :param cfg: Global configuration information to be used
    :param db: Database to be used
    :param antenna: Antenna connection to Reddit
    :param side: Side to gather recruits from
    :return: A list of new recruits.
    """
    # retrieve majors from DB
    majors = memory.get_players_with(db, recruited=True)

    # retrieve sign up thread from reddit
    if side == 0:
        signup_thread = antenna.get_submission(
            submission_id=cfg['OR_RECRUIT_THREAD'],
            comment_limit=None,
            comment_sort='new')
    elif side == 1:
        signup_thread = antenna.get_submission(
            submission_id=cfg['PW_RECRUIT_THREAD'],
            comment_limit=None,
            comment_sort='new')
    else:
        raise excs.InvalidSideError(__name__, side)
    LOG.debug('Got signup thread for side {} from {}'.format(
        side,
        signup_thread.id))
    # and replace more comments
    signup_thread.replace_more_comments()
    LOG.debug('Replaced more comments')

    # list comment authors from comment generator
    all_recruits = [cmnt for cmnt in signup_thread.comments]

    # filter out already registered recruits
    new_recruits = [recr for recr in all_recruits if
                    str(recr.author).lower() not in majors]

    return new_recruits