Пример #1
0
    def test_add_no_matches(self, config, bot, update):
        update.set_message("", username="******")
        pinger = Pinger(config)

        pinger.add(bot, update, [])

        assert "Usage" in bot.get_message()
Пример #2
0
    def test_add_not_for_me_not_admin(self, config, bot, update):
        update.set_message("", username="******")
        username = "******"
        match = "тулук"
        pinger = Pinger(config)

        pinger.add(bot, update, [username, match])
Пример #3
0
    def test_delete_own_match(self, config, bot, update):
        match = "первого"
        pinger = Pinger(config)

        pinger.delete(bot, update, [match])

        assert "deleted" in bot.get_message()
Пример #4
0
    def test_show_username(self, config, bot, update):
        expected_message = "второго"
        pinger = Pinger(config)

        pinger.show(bot, update, ["@test_two"])

        assert expected_message in bot.get_message()
Пример #5
0
    def test_drop_false_username(self, config, bot, update):
        username = "******"
        pinger = Pinger(config)

        pinger.drop(bot, update, [username])

        assert "not found" in bot.get_message()
Пример #6
0
    def test_show_no_nickname(self, config, bot, update):
        expected_message = "Usage:"
        pinger = Pinger(config)

        pinger.show(bot, update, ["fail"])

        assert expected_message in bot.get_message()
Пример #7
0
    def test_show_all_admin(self, config, bot, update):
        expected = "первого"
        pinger = Pinger(config)

        pinger.show_all(bot, update)

        assert expected in bot.get_message()
Пример #8
0
    def test_show_empty(self, config, bot, update):
        expected_message = "первого"
        pinger = Pinger(config)

        pinger.show(bot, update, [])

        assert expected_message in bot.get_message()
Пример #9
0
    def test_show_no_exist_username(self, config, bot, update):
        expected_message = "No such user"
        pinger = Pinger(config)

        pinger.show(bot, update, ["@test_none"])

        assert expected_message in bot.get_message()
Пример #10
0
    def test_drop_from_admin(self, config, bot, update):
        username = "******"
        pinger = Pinger(config)

        pinger.drop(bot, update, [username])

        assert "deleted" in bot.get_message()
Пример #11
0
    def test_delete_one_match(self, config, bot, update):
        username = "******"
        match = "нумбер"
        pinger = Pinger(config)

        pinger.delete(bot, update, [username, match])

        assert "deleted" in bot.get_message()
Пример #12
0
    def test_show_all_not_admin(self, config, bot, update):
        update.set_message("", username="******")
        expected = "only allowed"
        pinger = Pinger(config)

        pinger.show_all(bot, update)

        assert expected in bot.get_message()
Пример #13
0
    def test_add_for_me_not_admin(self, config, bot, update):
        update.set_message("", username="******")
        match = "тулук"
        pinger = Pinger(config)

        pinger.add(bot, update, [match])

        assert "added" in bot.get_message()
Пример #14
0
    def test_delete_false_match(self, config, bot, update):
        username = "******"
        match = "failed"
        pinger = Pinger(config)

        pinger.delete(bot, update, [username, match])

        assert "not found" in bot.get_message()
Пример #15
0
    def test_drop_no_admin(self, config, bot, update):
        update.set_message("", username="******")
        username = "******"
        pinger = Pinger(config)

        pinger.drop(bot, update, [username])

        assert "allowed for admins" in bot.get_message()
Пример #16
0
    def test_delete_one_match_from_two_users(self, config, bot, update):
        username = "******"
        username_two = "@user_three"
        match = "абырвалг"
        pinger = Pinger(config)

        pinger.delete(bot, update, [username, username_two, match])

        assert "deleted" in bot.get_message()
Пример #17
0
    def test_add_eleventh_match_admin(self, config, bot, update):
        username = "******"
        match = "eleven"

        pinger = Pinger(config)

        pinger.add(bot, update, [username, match])

        assert "has been added" in bot.get_message()
Пример #18
0
    def test_delete_another_user_no_admin(self, config, bot, update):
        update.set_message("", username="******")
        username = "******"
        match = "первого"
        pinger = Pinger(config)

        pinger.delete(bot, update, [username, match])

        assert "Deleting" in bot.get_message()
Пример #19
0
    def test_add_eleventh_match_no_admin(self, config, bot, update):
        update.set_message("", username="******")
        username = "******"
        match = "eleven"

        pinger = Pinger(config)

        pinger.add(bot, update, [username, match])

        assert "only 10 matches" in bot.get_message()
Пример #20
0
def handler(action, input_config):
    def new_action(bot, update, **kwargs):
        action(input_config, bot, update, **kwargs)

    return new_action


if __name__ == '__main__':
    config = Config()

    logging.basicConfig(
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        level=logging.INFO
    )

    pinger = Pinger(config)

    functions = [database_handler, weather, wset, parser]
    db_handler, weather_handler, wset_handler, parser_handler = \
        (handler(act, config) for act in functions)

    log_print('Started')

    try:
        create_table(config)

        updater = Updater(token=config.telegram_token())
        dispatcher = updater.dispatcher

        [dispatcher.add_handler(i) for i in [
            CommandHandler('bug', bug),
Пример #21
0
def handler(action, input_config):
    def new_action(bot, update, **kwargs):
        action(input_config, bot, update, **kwargs)

    return new_action


if __name__ == '__main__':
    config = Config()
    register(config)

    logging.basicConfig(
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        level=logging.INFO)

    pinger = Pinger()

    functions = [
        database_handler, weather, me, wset, parser, mute, mute_on, mute_off
    ]
    db_handler, weather_handler, me_handler, wset_handler, parser_handler, mute_handler, mute_on_handler, mute_off_handler = \
        (handler(act, config) for act in functions)

    log_print('Started')

    try:
        create_table(config)

        updater = Updater(token=config.telegram_token())
        dispatcher = updater.dispatcher
Пример #22
0
def main():
    config = Config()
    register(config)

    logging.basicConfig(
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        level=logging.INFO)

    tglogger = logging.getLogger("telegram.bot")
    tglogger.setLevel(logging.ERROR)

    pinger = Pinger()

    functions = [
        database_handler, me, parser, clash, clash_start, clash_enable,
        clash_disable, clash_results
    ]

    db_handler,\
    me_handler,\
    parser_handler,\
    clash_handler,\
    clash_start_handler,\
    clash_enable_handler,\
    clash_disable_handler,\
    clash_results_handler = (handler(act, config) for act in functions)

    log_print('Started', level="INFO", command="main")

    try:
        create_table(config)

        updater = Updater(token=config.telegram_token())
        dispatcher = updater.dispatcher

        [
            dispatcher.add_handler(i) for i in [
                CommandHandler(['bug', 'issue'], bug),
                CommandHandler('chatid', chat_id),
                CommandHandler(['start', 'info'], start),
                CommandHandler('NSFW', nsfw),
                CommandHandler('me', me_handler, pass_args=True),
                CommandHandler('db', db_handler, pass_args=True),
                CommandHandler('ping_add_me', pinger.add_me, pass_args=True),
                CommandHandler('ping_show', pinger.show, pass_args=True),
                CommandHandler('ping_show_me', pinger.show_me, pass_args=True),
                CommandHandler('ping_show_all', pinger.show_all),
                CommandHandler('ping_delete', pinger.delete, pass_args=True),
                CommandHandler('ping_drop', pinger.drop, pass_args=True),
                CommandHandler('ping_add', pinger.add, pass_args=True),
                CommandHandler('clash', clash_handler),
                CommandHandler('clash_start', clash_start_handler),
                CommandHandler('clash_enable', clash_enable_handler),
                CommandHandler('clash_disable', clash_disable_handler),
                CommandHandler(
                    'clash_results', clash_results_handler, pass_args=True),
                MessageHandler(Filters.all, parser_handler)
            ]
        ]

        if config.telegram_mode().lower() == 'webhook':
            updater.start_webhook(listen=config.listen_ip(),
                                  port=config.webhook_port(),
                                  url_path=config.telegram_token())
            updater.bot.set_webhook(config.webhook_url())
            updater.idle()
        else:
            updater.start_polling()
    except sqlite3.ProgrammingError:
        pass
Пример #23
0
    def test_delete_no_match(self, config, bot, update):
        pinger = Pinger(config)

        pinger.delete(bot, update, [])

        assert "Usage" in bot.get_message()
Пример #24
0
    def test_drop_empty(self, config, bot, update):
        pinger = Pinger(config)

        pinger.drop(bot, update, [])

        assert "Usage" in bot.get_message()