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()
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])
def test_delete_own_match(self, config, bot, update): match = "первого" pinger = Pinger(config) pinger.delete(bot, update, [match]) assert "deleted" in bot.get_message()
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()
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()
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()
def test_show_all_admin(self, config, bot, update): expected = "первого" pinger = Pinger(config) pinger.show_all(bot, update) assert expected in bot.get_message()
def test_show_empty(self, config, bot, update): expected_message = "первого" pinger = Pinger(config) pinger.show(bot, update, []) assert expected_message in bot.get_message()
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()
def test_drop_from_admin(self, config, bot, update): username = "******" pinger = Pinger(config) pinger.drop(bot, update, [username]) assert "deleted" in bot.get_message()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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),
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
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
def test_delete_no_match(self, config, bot, update): pinger = Pinger(config) pinger.delete(bot, update, []) assert "Usage" in bot.get_message()
def test_drop_empty(self, config, bot, update): pinger = Pinger(config) pinger.drop(bot, update, []) assert "Usage" in bot.get_message()