fix management
This commit is contained in:
parent
44ef567a82
commit
b4513267ca
28
main.py
28
main.py
@ -77,16 +77,16 @@ def _add_user(bot, uid):
|
|||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def add_user(update: Update, ctx: CallbackContext, groups=(), args=()):
|
def add_user(update: Update, ctx: CallbackContext):
|
||||||
if update.callback_query:
|
if update.callback_query:
|
||||||
update.callback_query.answer()
|
update.callback_query.answer()
|
||||||
|
|
||||||
if groups:
|
if ctx.match:
|
||||||
if update.callback_query.message.chat.id != MANAGEMENT_CHAT:
|
if update.callback_query.message.chat.id != MANAGEMENT_CHAT:
|
||||||
return
|
return
|
||||||
uid = groups[0]
|
uid = ctx.match.group(1)
|
||||||
elif args:
|
elif ctx.args:
|
||||||
uid = args[0]
|
uid = ctx.args[0]
|
||||||
elif update.message and update.message.reply_to_message and update.message.reply_to_message.forward_from:
|
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
|
uid = update.message.reply_to_message.forward_from.id
|
||||||
else:
|
else:
|
||||||
@ -102,7 +102,7 @@ def add_user(update: Update, ctx: CallbackContext, groups=(), args=()):
|
|||||||
if update.callback_query:
|
if update.callback_query:
|
||||||
update.callback_query.message.edit_reply_markup()
|
update.callback_query.message.edit_reply_markup()
|
||||||
ctx.bot.send_message(MANAGEMENT_CHAT, f'<a href="tg://user?id={uid}">{escape(user.name)}</a> был добавлен',
|
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, 'Добро пожаловать. Снова.')
|
ctx.bot.send_message(uid, 'Добро пожаловать. Снова.')
|
||||||
except TelegramError as e:
|
except TelegramError as e:
|
||||||
ctx.bot.send_message(MANAGEMENT_CHAT, str(e))
|
ctx.bot.send_message(MANAGEMENT_CHAT, str(e))
|
||||||
@ -115,16 +115,16 @@ def _remove_user(uid):
|
|||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def remove_user(update: Update, ctx: CallbackContext, groups=(), args=()):
|
def remove_user(update: Update, ctx: CallbackContext):
|
||||||
if update.callback_query:
|
if update.callback_query:
|
||||||
update.callback_query.answer()
|
update.callback_query.answer()
|
||||||
|
|
||||||
if groups:
|
if ctx.match:
|
||||||
if update.callback_query.message.chat.id != MANAGEMENT_CHAT:
|
if update.callback_query.message.chat.id != MANAGEMENT_CHAT:
|
||||||
return
|
return
|
||||||
uid = groups[0]
|
uid = ctx.match.groups(1)
|
||||||
elif args:
|
elif ctx.args:
|
||||||
uid = args[0]
|
uid = ctx.args[0]
|
||||||
elif update.message and update.message.reply_to_message and update.message.reply_to_message.forward_from:
|
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
|
uid = update.message.reply_to_message.forward_from.id
|
||||||
else:
|
else:
|
||||||
@ -138,7 +138,7 @@ def remove_user(update: Update, ctx: CallbackContext, groups=(), args=()):
|
|||||||
try:
|
try:
|
||||||
user = _remove_user(uid)
|
user = _remove_user(uid)
|
||||||
ctx.bot.send_message(MANAGEMENT_CHAT, f'<a href="tg://user?id={uid}">{escape(user.name)}</a> был удален',
|
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:
|
if update.callback_query:
|
||||||
update.callback_query.message.edit_reply_markup()
|
update.callback_query.message.edit_reply_markup()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -393,9 +393,9 @@ def main():
|
|||||||
updater.dispatcher.add_handler(CommandHandler('start', welcome, Filters.private))
|
updater.dispatcher.add_handler(CommandHandler('start', welcome, Filters.private))
|
||||||
updater.dispatcher.add_handler(CommandHandler('stop', unsubscribe, 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(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(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(CommandHandler('users', users_list, Filters.private))
|
||||||
updater.dispatcher.add_handler(MessageHandler(Filters.private, msg))
|
updater.dispatcher.add_handler(MessageHandler(Filters.private, msg))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user