async def update_admins_list(_, query): cb_wrapper = MethodWrapper(query) if CACHE[query.from_user.id][0] == "AWAITING_ADMIN": if time.time() - CACHE[ query.from_user.id][1] >= ADMINS_LIST_UPDATE_DELAY: CACHE[query.from_user.id][1] = time.time() queue = LIVE_CHAT_STATUSES for admin_id, admin_name in ADMINS.items(): status = CACHE[admin_id][0] if status != "IN_CHAT": queue += f"- {STATUS_FREE}" else: queue += f"- {STATUS_BUSY}" queue += f"[{admin_name}]({NAME.format(admin_id)})\n" await cb_wrapper.edit_message_text(SUPPORT_REQUEST_SENT.format( queue=queue, date=time.strftime('%d/%m/%Y %T')), reply_markup=BUTTONS) join_chat_button = InlineKeyboardMarkup([[ InlineKeyboardButton(JOIN_CHAT_BUTTON, f"join_{query.from_user.id}") ]]) user = get_user(query.from_user.id) tg_id, tg_uname, date, banned = user text = USER_INFO.format(tg_id=tg_id, tg_uname='@' + tg_uname if tg_uname else 'N/A', date=date, status=YES if banned else NO, admin=YES if tg_id in ADMINS else NO) for admin in ADMINS: status = CACHE[admin][0] if status != "IN_CHAT": if status != "NOTIFICATION_SENT" and CACHE[admin][ 1] != tg_id: message = await wrapper.send_message( admin, SUPPORT_NOTIFICATION.format(uinfo=text), reply_markup=join_chat_button) CACHE[query.from_user.id][-1].append( (message.chat.id, message.message_id)) else: await cb_wrapper.answer(TOO_FAST, show_alert=True) else: await cb_start_handler(_, query)
async def begin_chat(_, query): cb_wrapper = MethodWrapper(query) if query.from_user.id in ADMINS: await cb_wrapper.answer(CANNOT_REQUEST_SUPPORT) else: CACHE[query.from_user.id] = ["AWAITING_ADMIN", time.time()] queue = LIVE_CHAT_STATUSES for admin_id, admin_name in ADMINS.items(): status = CACHE[admin_id][0] if status != "IN_CHAT": queue += f"- {STATUS_FREE}" else: queue += f"- {STATUS_BUSY}" queue += f"[{admin_name}]({NAME.format(admin_id)})\n" msg = await cb_wrapper.edit_message_text(SUPPORT_REQUEST_SENT.format( queue=queue, date=time.strftime('%d/%m/%Y %T')), reply_markup=BUTTONS) join_chat_button = InlineKeyboardMarkup([[ InlineKeyboardButton(JOIN_CHAT_BUTTON, f"join_{query.from_user.id}") ]]) user = get_user(query.from_user.id) tg_id, tg_uname, date, banned = user text = USER_INFO.format(tg_id=tg_id, tg_uname='@' + tg_uname if tg_uname else 'N/A', date=date, status=YES if banned else NO, admin=YES if tg_id in ADMINS else NO) CACHE[query.from_user.id].append([]) for admin in ADMINS: status = CACHE[admin][0] if status != "IN_CHAT": message = await wrapper.send_message( admin, SUPPORT_NOTIFICATION.format(uinfo=text), reply_markup=join_chat_button) CACHE[query.from_user.id][-1].append( (message.chat.id, message.message_id)) CACHE[admin] = ["NOTIFICATION_SENT", query.from_user.id] CACHE[query.from_user.id][-1].append((msg.chat.id, msg.message_id))
from pyrogram import Client, filters from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton from BotBase.config import CACHE, ADMINS, ADMINS_LIST_UPDATE_DELAY, LIVE_CHAT_STATUSES, STATUS_BUSY, STATUS_FREE, \ USER_INFO, ADMIN_MESSAGE, USER_MESSAGE, NAME, bot from BotBase.strings.default_strings import SUPPORT_REQUEST_SENT, SUPPORT_NOTIFICATION, ADMIN_JOINS_CHAT, \ USER_CLOSES_CHAT, JOIN_CHAT_BUTTON, USER_LEAVES_CHAT, TOO_FAST, CHAT_BUSY, LEAVE_CURRENT_CHAT, USER_JOINS_CHAT, \ CANNOT_REQUEST_SUPPORT, YES, NO, CLOSE_CHAT_BUTTON, BACK_BUTTON, UPDATE_BUTTON, ADMIN_ACCEPTED_CHAT from BotBase.methods.custom_filters import callback_regex, admin_is_chatting, user_is_chatting, user_banned from BotBase.database.query import get_user from BotBase.methods import MethodWrapper from BotBase.modules.antiflood import BANNED_USERS from BotBase.modules.start import cb_start_handler ADMINS_FILTER = filters.user(list(ADMINS.keys())) BUTTONS = InlineKeyboardMarkup( [[InlineKeyboardButton(BACK_BUTTON, "back_start")], [InlineKeyboardButton(UPDATE_BUTTON, "update_admins_list")]]) wrapper = MethodWrapper(bot) @Client.on_callback_query( filters.regex("begin_chat") & ~BANNED_USERS & ~user_banned()) async def begin_chat(_, query): cb_wrapper = MethodWrapper(query) if query.from_user.id in ADMINS: await cb_wrapper.answer(CANNOT_REQUEST_SUPPORT) else: CACHE[query.from_user.id] = ["AWAITING_ADMIN", time.time()] queue = LIVE_CHAT_STATUSES
CACHE, DELETE_MESSAGES, FLOOD_PERCENTAGE, MAX_UPDATE_THRESHOLD, PRIVATE_ONLY, bot, plate, ) from BotBase.methods import MethodWrapper from BotBase.methods.custom_filters import user_banned # Some variables for runtime configuration MESSAGES = defaultdict(list) # Internal variable for the antiflood module BANNED_USERS = filters.user() # Filters where the antiflood will put banned users BYPASS_USERS = filters.user(list(ADMINS.keys())) if BYPASS_FLOOD else filters.user() ADMINS = filters.user(list(ADMINS.keys())) FILTER = filters.private if PRIVATE_ONLY else ~filters.user() wrapper = MethodWrapper(bot) def is_flood(updates: list): """ Calculates if a sequence of updates corresponds to a flood """ genexpr = [ i <= ANTIFLOOD_SENSIBILITY for i in ( (updates[i + 1] - timestamp)