def ban(update: Update, context: CallbackContext): if not context.args: ban_list = context.bot_data.get('ban', None) if ban_list: update.message.reply_text('\n'.join(map(str, ban_list))) return if not context.args[0].isdigit: update.message.reply_text('/ban user_id') return user_id = int(context.args[0]) if not context.bot_data.get('ban', None): context.bot_data['ban'] = [user_id] elif user_id not in context.bot_data['ban']: new_ban = copy.deepcopy(context.bot_data['ban']) new_ban.append(user_id) context.bot_data['ban'] = new_ban else: update.message.reply_text('✔️ Already exists on the blacklist.') return context.dispatcher.update_persistence() tasks = thread_pool.get(user_id, None) if tasks: for t in tasks: t.kill() logger.debug( 'Task {} was stopped due to user {} is banned.'.format( t.ident, user_id)) break update.message.reply_text('✅ Added to the blacklist.') logger.info('{} is banned.'.format(user_id)) return
def stop_task(update, context): query = update.callback_query if query.message.chat_id < 0 and \ (not query.message.reply_to_message or query.from_user.id != query.message.reply_to_message.from_user.id): alert_users(context, update.effective_user, 'invalid caller', query.data) query.answer(text='Yo ha', show_alert=True) return if query.data: match = re.search(regex_stop_task, query.data) if match: thread_id = int(match.group(1)) tasks = thread_pool.get(update.effective_user.id, None) if tasks: for t in tasks: if t.ident == thread_id and t.owner == query.from_user.id: t.kill() logger.info('User {} has stopped task {}'.format( query.from_user.id, thread_id)) return alert_users(context, update.effective_user, 'invalid query data', query.data) query.answer(text='Yo ha', show_alert=True) return
def ban(update: Update, context: CallbackContext): if not context.args: ban_list = context.bot_data.get('ban', None) if ban_list: update.message.reply_text('\n'.join(map(str, ban_list))) return if not context.args[0].isdigit: update.message.reply_text('/ban user_id') return user_id = int(context.args[0]) if not context.bot_data.get('ban', None): context.bot_data['ban'] = [user_id] elif user_id not in context.bot_data['ban']: new_ban = copy.deepcopy(context.bot_data['ban']) new_ban.append(user_id) context.bot_data['ban'] = new_ban else: update.message.reply_text('已存在于黑名单。') return context.dispatcher.update_persistence() tasks = thread_pool.get(user_id, None) if tasks: for t in tasks: t.kill() return update.message.reply_text('已添加至黑名单。') return
def save_to_folder(update, context): query = update.callback_query if query.message.chat_id < 0 and \ (not query.message.reply_to_message or query.from_user.id != query.message.reply_to_message.from_user.id): alert_users(context, update.effective_user, 'invalid caller', query.data) query.answer(text='Yo ha', show_alert=True) return match = re.search(r'^save_to_folder(?:_page#[\d]+)?,\s*([\dA-Za-z\-_]+)$', query.data) fav_folders = context.user_data.get(udkey_folders, {}) if not match or match.group(1) not in fav_folders: alert_users(context, update.effective_user, 'invalid query', query.data) query.answer(text='Yo ha', show_alert=True) return message = query.message if message.caption: text = message.caption else: text = message.text folder_ids = parse_entity_for_drive_id(message) if not folder_ids: return dest_folder = fav_folders[match.group(1)] dest_folder['folder_id'] = match.group(1) if not thread_pool.get(update.effective_user.id, None): thread_pool[update.effective_user.id] = [] t = MySaveFileThread(args=(update, context, folder_ids, text, dest_folder)) thread_pool[update.effective_user.id].append(t) t.start() logger.debug('User {} has added task {}.'.format(query.from_user.id, t.ident)) query.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text='It has been executed', callback_data='#') ]]))