diff --git a/main.py b/main.py index 1cbe697..77d6adc 100755 --- a/main.py +++ b/main.py @@ -77,16 +77,16 @@ def _add_user(bot, uid): return user -def add_user(update: Update, ctx: CallbackContext, groups=(), args=()): +def add_user(update: Update, ctx: CallbackContext): if update.callback_query: update.callback_query.answer() - if groups: + if ctx.match: if update.callback_query.message.chat.id != MANAGEMENT_CHAT: return - uid = groups[0] - elif args: - uid = args[0] + uid = ctx.match.group(1) + elif ctx.args: + uid = ctx.args[0] elif update.message and update.message.reply_to_message and update.message.reply_to_message.forward_from: uid = update.message.reply_to_message.forward_from.id else: @@ -102,7 +102,7 @@ def add_user(update: Update, ctx: CallbackContext, groups=(), args=()): if update.callback_query: update.callback_query.message.edit_reply_markup() ctx.bot.send_message(MANAGEMENT_CHAT, f'{escape(user.name)} был добавлен', - parse_mode='html') + parse_mode='html') ctx.bot.send_message(uid, 'Добро пожаловать. Снова.') except TelegramError as e: ctx.bot.send_message(MANAGEMENT_CHAT, str(e)) @@ -115,16 +115,16 @@ def _remove_user(uid): return user -def remove_user(update: Update, ctx: CallbackContext, groups=(), args=()): +def remove_user(update: Update, ctx: CallbackContext): if update.callback_query: update.callback_query.answer() - if groups: + if ctx.match: if update.callback_query.message.chat.id != MANAGEMENT_CHAT: return - uid = groups[0] - elif args: - uid = args[0] + uid = ctx.match.groups(1) + elif ctx.args: + uid = ctx.args[0] elif update.message and update.message.reply_to_message and update.message.reply_to_message.forward_from: uid = update.message.reply_to_message.forward_from.id else: @@ -138,7 +138,7 @@ def remove_user(update: Update, ctx: CallbackContext, groups=(), args=()): try: user = _remove_user(uid) ctx.bot.send_message(MANAGEMENT_CHAT, f'{escape(user.name)} был удален', - parse_mode='html') + parse_mode='html') if update.callback_query: update.callback_query.message.edit_reply_markup() except KeyError: @@ -393,9 +393,9 @@ def main(): updater.dispatcher.add_handler(CommandHandler('start', welcome, Filters.private)) updater.dispatcher.add_handler(CommandHandler('stop', unsubscribe, Filters.private)) updater.dispatcher.add_handler(CommandHandler('add', add_user, Filters.chat(MANAGEMENT_CHAT), pass_args=True)) - updater.dispatcher.add_handler(CallbackQueryHandler(add_user, pattern=r'^add (\d+)$', pass_groups=True)) + updater.dispatcher.add_handler(CallbackQueryHandler(add_user, pattern=r'^add (\d+)$')) updater.dispatcher.add_handler(CommandHandler('remove', remove_user, Filters.chat(MANAGEMENT_CHAT), pass_args=True)) - updater.dispatcher.add_handler(CallbackQueryHandler(remove_user, pattern=r'^remove (\d+)$', pass_groups=True)) + updater.dispatcher.add_handler(CallbackQueryHandler(remove_user, pattern=r'^remove (\d+)$')) updater.dispatcher.add_handler(CommandHandler('users', users_list, Filters.private)) updater.dispatcher.add_handler(MessageHandler(Filters.private, msg))