コード例 #1
0
ファイル: run.py プロジェクト: cloudrainstar/efai_clock
def login(update, context):
    """Command handler: /login <username> <password> - save login to database."""
    logging.info(f"Command: /login triggered by {update.effective_chat.id}")
    if len(context.args) != 2:
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text="Not enough or too many parameters, I need both usernamae and password.",
        )
    else:
        ses = apollodb.UserQuery(apollodb.Session())
        u = ses.get_user(update.effective_chat.id)
        if u:
            context.bot.send_message(
                chat_id=update.effective_chat.id,
                text="Your user already exists, I'm going to delete it and create a new one.",
            )
            ses.delete(update.effective_chat.id)
        new_user = apollodb.User(
            userid=update.effective_chat.id,
            apollo_user=context.args[0],
            apollo_password=context.args[1],
        )
        ses.add_user(new_user)
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text="Your login information is now saved.",
        )
        ses.close()
コード例 #2
0
ファイル: run.py プロジェクト: cloudrainstar/efai_clock
def autolog(update, context):
    """Command handler: /autolog <on/off> - set autolog on or off."""
    logging.info(f"Command: /autolog triggered by {update.effective_chat.id}")
    if len(context.args) != 1:
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text="Not enough or too many parameters, autolog either on or off.",
        )
    else:
        ses = apollodb.UserQuery(apollodb.Session())
        u = ses.get_user(update.effective_chat.id)
        if u:
            if context.args[0] == "on":
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text="I will automatically clock you in and out. Reminder is also enabled.",
                )
                ses.set_reminder(update.effective_chat.id, True)
                ses.set_autolog(update.effective_chat.id, True)
            elif context.args[0] == "off":
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text="I will stop automatically clocking you in and out.",
                )
                ses.set_autolog(update.effective_chat.id, False)
            else:
                context.bot.send_message(
                    chat_id=update.effective_chat.id, text="Sorry, I don't understand."
                )
        else:
            context.bot.send_message(
                chat_id=update.effective_chat.id,
                text="I don't have any information on you. /login first.",
            )
        ses.close()
コード例 #3
0
ファイル: run.py プロジェクト: cloudrainstar/efai_clock
def info(update, context):
    """Command handler: /info - check database info."""
    logging.info(f"Command: /info triggered by {update.effective_chat.id}")
    ses = apollodb.UserQuery(apollodb.Session())
    u = ses.get_user(update.effective_chat.id)
    if u:
        text = "I currently have the following information:"
        text += "\nYour username: "******"\nYour password: "******"\nReminders are: " + ("on" if u.reminder else "off")
        text += "\nAutolog is: " + ("on" if u.autolog else "off")
    else:
        text = "I don't have any information on you."
    context.bot.send_message(chat_id=update.effective_chat.id, text=text)
    ses.close()
コード例 #4
0
ファイル: run.py プロジェクト: cloudrainstar/efai_clock
def delete(update, context):
    """Command handler: /delete - delete all info."""
    logging.info(f"Command: /delete triggered by {update.effective_chat.id}")
    ses = apollodb.UserQuery(apollodb.Session())
    u = ses.get_user(update.effective_chat.id)
    if u:
        ses.delete(update.effective_chat.id)
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text="Your user information has been deleted.",
        )
    else:
        context.bot.send_message(
            chat_id=update.effective_chat.id, text="I couldn't find your information."
        )
    ses.close()
コード例 #5
0
ファイル: run.py プロジェクト: cloudrainstar/efai_clock
def callback_reminder_clock(context: CallbackContext, out: bool = False) -> None:
    """Handle callback: a clock in/out reminder schedule using job queue."""
    ses = apollodb.UserQuery(apollodb.Session())
    us = ses.get_reminder()
    clock_string = "clockin_"
    if out:
        clock_string = "clockout_"
    for u in us:
        max_half_hour_delay = random.randint(0, 60 * 29)
        logging.info(
            f"{clock_string}: Adding a {str(max_half_hour_delay)} second delay for {str(u.userid)}"
        )
        callback_clock_function = partial(callback_clock, out=False)
        if out:
            callback_clock_function = partial(callback_clock, out=True)
        context.job_queue.run_once(
            callback_clock_function,
            max_half_hour_delay,
            context=u,
            name=clock_string + str(u.userid),
        )
コード例 #6
0
ファイル: run.py プロジェクト: cloudrainstar/efai_clock
def clock(update, context):
    """Command handler: /clock <in/out> - clock in or out."""
    logging.info(f"Command: /clock triggered by {update.effective_chat.id}")
    if len(context.args) != 1:
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text="Not enough or too many parameters, clock either in or out.",
        )
    else:
        ses = apollodb.UserQuery(apollodb.Session())
        u = ses.get_user(update.effective_chat.id)
        if u:
            if context.args[0] == "in":
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text="Attempting to clock you in...",
                )
                br = apollo.ApolloSession()
                login_status = br.login(u.apollo_user, u.apollo_password)
                if str(login_status) == "True":
                    context.bot.send_message(
                        chat_id=update.effective_chat.id,
                        text="Login successful, starting clock-in...",
                    )
                    msg = br.clock_in()
                    context.bot.send_message(chat_id=update.effective_chat.id, text=msg)
                else:
                    context.bot.send_message(
                        chat_id=update.effective_chat.id,
                        text="Login unsuccessful, check your username or password...",
                    )
                del br
            elif context.args[0] == "out":
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text="Attempting to clock you out...",
                )
                br = apollo.ApolloSession()
                login_status = br.login(u.apollo_user, u.apollo_password)
                if str(login_status) == "True":
                    context.bot.send_message(
                        chat_id=update.effective_chat.id,
                        text="Login successful, starting clock-out...",
                    )
                    msg = br.clock_out()
                    context.bot.send_message(chat_id=update.effective_chat.id, text=msg)
                else:
                    context.bot.send_message(
                        chat_id=update.effective_chat.id,
                        text="Login unsuccessful, check your username or password...",
                    )
                del br
            else:
                context.bot.send_message(
                    chat_id=update.effective_chat.id, text="Clock either in or out..."
                )
        else:
            context.bot.send_message(
                chat_id=update.effective_chat.id,
                text="I don't have any information on you. /login first.",
            )
        ses.close()