コード例 #1
0
ファイル: tg_bot.py プロジェクト: RHabby/scheduler-bot
def settings(message: types.Message):
    text = "Here is some setting:"
    bot.send_message(chat_id=message.chat.id,
                     text=text,
                     reply_markup=m.settings_markup,
                     disable_notification=True)
    rw.set_state(id=message.from_user.id, value=States.START_STATE.value)
コード例 #2
0
ファイル: tg_bot.py プロジェクト: RHabby/scheduler-bot
def choose_sorting(message: types.Message):
    rw.set_state_value(message.from_user.id, "sorting", message.text)
    bot.send_message(chat_id=message.from_user.id,
                     text="How many posts would you like to see?",
                     reply_markup=m.choose_count_markup,
                     disable_notification=True)
    rw.set_state(id=message.from_user.id,
                 value=config.States.ENTER_COUNT_STATE.value)
コード例 #3
0
ファイル: tg_bot.py プロジェクト: RHabby/scheduler-bot
def choose_channel(message: types.Message):
    rw.set_state_value(message.from_user.id, "subreddit_name", message.text)
    bot.send_message(chat_id=message.from_user.id,
                     text="What sorting would you like?",
                     reply_markup=m.choose_sorting_markup,
                     disable_notification=True)
    rw.set_state(id=message.from_user.id,
                 value=config.States.ENTER_SORTING_STATE.value)
コード例 #4
0
ファイル: tg_bot.py プロジェクト: RHabby/scheduler-bot
def delete_subreddit_button(call: types.CallbackQuery):
    if call.message:
        text = "What subreddit button would you like to delete? Send me a text message."
        bot.send_message(chat_id=call.message.chat.id,
                         text=text,
                         disable_notification=True)

        rw.set_state(id=call.message.chat.id,
                     value=States.DELETE_SUBREDDIT_STATE.value)
コード例 #5
0
ファイル: tg_bot.py プロジェクト: RHabby/scheduler-bot
def deleting_subreddit_button(message: types.Message):
    del_button = m.delete_button(id=message.chat.id,
                                 key="channels",
                                 value=message.text)
    rw.set_state(id=message.chat.id, value=States.START_STATE.value)
    if del_button:
        bot.send_message(chat_id=message.chat.id,
                         text="The button was deleted",
                         disable_notification=True)
コード例 #6
0
ファイル: tg_bot.py プロジェクト: RHabby/scheduler-bot
def adding_subreddit_button(message: types.Message):
    add_button = m.set_kboard(id=message.chat.id,
                              key="channels",
                              value=message.text)
    rw.set_state(id=message.chat.id, value=States.START_STATE.value)
    if add_button:
        bot.send_message(chat_id=message.chat.id,
                         text="The button was added",
                         disable_notification=True)
コード例 #7
0
ファイル: tg_bot.py プロジェクト: RHabby/scheduler-bot
def choose_commands(message: types.Message):
    markup = m.generate_kboard(kboard_type="reply",
                               id=message.chat.id,
                               key="channels")
    bot.send_message(chat_id=message.from_user.id,
                     text="what subreddit would you like?",
                     reply_markup=markup,
                     disable_notification=True)
    rw.set_state(id=message.from_user.id,
                 value=States.ENTER_SUBREDDIT_STATE.value)
コード例 #8
0
ファイル: tg_bot.py プロジェクト: RHabby/scheduler-bot
def start(message: types.Message):
    welcome = f"Hello, {message.from_user.first_name}.\n{cs.welcome_message}"
    bot.send_message(chat_id=message.from_user.id,
                     text=welcome,
                     reply_markup=m.start_markup,
                     parse_mode="markdown",
                     disable_notification=True)

    rw.set_state(id=message.from_user.id, value=States.START_STATE.value)
    logger.info(
        f"Bot was started by user {message.chat.username} with ID: {message.chat.id}"
    )
コード例 #9
0
ファイル: tg_bot.py プロジェクト: RHabby/scheduler-bot
def send_reddit_photo(message: types.Message):
    try:
        args = rw.get_values(message.from_user.id)
        logger.info(f'Command: /reddit. User {message.chat.username}\
 ID: {message.chat.id}.\
 Subreddit name: {args.get(b"subreddit_name").decode("utf-8")},\
 sorting: {args.get(b"sorting").decode("utf-8")},\
 count: {int(args.get(b"count").decode("utf-8"))}')
        send_simple(subreddit_name=args.get(b"subreddit_name").decode("utf-8"),
                    submission_sort=args.get(b"sorting").decode("utf-8"),
                    limit=int(args.get(b"count").decode("utf-8")),
                    where_to_post=message.from_user.id,
                    source="reddit")
        rw.set_state(id=message.from_user.id,
                     value=config.States.START_STATE.value)
        logger.info(f'Command: /reddit. User {message.chat.username}\
 ID: {message.chat.id}. Status: Done')

    except (Redirect, NotFound) as e:
        markup = m.generate_kboard(kboard_type="reply",
                                   id=message.chat.id,
                                   key="channels")
        bot.send_message(
            chat_id=message.from_user.id,
            text="There is no subreddit with that name, try another one",
            reply_markup=markup,
            parse_mode="markdown",
            disable_notification=True)
        logger.info(
            f'{repr(e)}. Command: /reddit. User {message.chat.username}\
 ID: {message.chat.id}.\
 Subreddit name: {args.get(b"subreddit_name").decode("utf-8")},\
 sorting: {args.get(b"sorting").decode("utf-8")},\
 count: {int(args.get(b"count").decode("utf-8"))}')
        rw.set_state(id=message.from_user.id,
                     value=config.States.ENTER_SUBREDDIT_STATE.value)

    rw.clear_fields(message.from_user.id, "subreddit_name", "sorting", "count")