fix management

master
bakatrouble 4 years ago
parent 44ef567a82
commit b4513267ca

@ -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'<a href="tg://user?id={uid}">{escape(user.name)}</a> был добавлен',
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'<a href="tg://user?id={uid}">{escape(user.name)}</a> был удален',
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))

Loading…
Cancel
Save