def build_lock_message(chat, chatP, user, chatname): locks = sql.get_locks(chat.id) restr = sql.get_restr(chat.id) if not (locks or restr): res = tld(chatP.id, "There are no current locks in *{}*.".format(chatname)) else: res = tld(chatP.id, "These are the locks in *{}*:".format(chatname)) if locks: res += "\n - sticker = `{}`" \ "\n - audio = `{}`" \ "\n - voice = `{}`" \ "\n - document = `{}`" \ "\n - video = `{}`" \ "\n - videonote = `{}`" \ "\n - contact = `{}`" \ "\n - photo = `{}`" \ "\n - gif = `{}`" \ "\n - url = `{}`" \ "\n - bots = `{}`" \ "\n - forward = `{}`" \ "\n - game = `{}`" \ "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document, locks.video, locks.videonote, locks.contact, locks.photo, locks.gif, locks.url, locks.bots, locks.forward, locks.game, locks.location) if restr: res += "\n - messages = `{}`" \ "\n - media = `{}`" \ "\n - other = `{}`" \ "\n - previews = `{}`" \ "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview, all([restr.messages, restr.media, restr.other, restr.preview])) return res
def new_fed(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message fednam = message.text[len('/newfed '):] if not fednam == '': fed_id = str(uuid.uuid4()) fed_name = fednam LOGGER.info(fed_id) #if fednam == 'Name': # fed_id = "Name" x = sql.new_fed(user.id, fed_name, fed_id) if not x: update.effective_message.reply_text( tld( chat.id, "Big F! There is an error while creating Federations, Kindly get into my support group and ask what is going on!" )) return update.effective_message.reply_text("*You have successfully created a new federation!*"\ "\nName: `{}`"\ "\nID: `{}`" "\n\nUse command below to join the federation:" "\n`/joinfed {}`".format(fed_name, fed_id, fed_id), parse_mode=ParseMode.MARKDOWN) bot.send_message( MESSAGE_DUMP, "Federation <b>{}</b> has been created with ID: <pre>{}</pre>". format(fed_name, fed_id), parse_mode=ParseMode.HTML) else: update.effective_message.reply_text( tld(chat.id, "Please write federation name!"))
def paginate_modules(chat_id, page_n: int, module_dict: Dict, prefix, chat=None) -> List: if not chat: modules = sorted([ EqInlineKeyboardButton(tld(chat_id, x.__mod_name__), callback_data="{}_module({})".format( prefix, x.__mod_name__.lower())) for x in module_dict.values() ]) else: modules = sorted([ EqInlineKeyboardButton(tld(chat_id, x.__mod_name__), callback_data="{}_module({},{})".format( prefix, chat, x.__mod_name__.lower())) for x in module_dict.values() ]) pairs = [ modules[i * 3:(i + 1) * 3] for i in range((len(modules) + 3 - 1) // 3) ] round_num = len(modules) / 3 calc = len(modules) - round(round_num) if calc == 1: pairs.append((modules[-1], )) elif calc == 2: pairs.append((modules[-1], )) return pairs
def fed_admin(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if not fed_id: update.effective_message.reply_text( tld(chat.id, "This group is not in any federation!")) return if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text( tld(chat.id, "Only fed admins can do this!")) return print(fed_id) user = update.effective_user # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] info = sql.get_fed_info(fed_id) text = "\n\n<b>Federation Admins:</b>" user = bot.get_chat(info.owner_id) text += "\n• {} - <code>{}</code> (Creator)".format( mention_html(user.id, user.first_name), user.id) h = sql.all_fed_users(fed_id) for O in h: user = bot.get_chat(O) text += "\n• {} - <code>{}</code>".format( mention_html(user.id, user.first_name), user.id, O) update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def antispam(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) > 0: if args[0].lower() in ["on", "yes"]: sql.enable_antispam(chat.id) update.effective_message.reply_text( tld( chat.id, "I've enabled antispam security in this group. This will help protect you " "from spammers, unsavoury characters, and the biggest trolls." )) elif args[0].lower() in ["off", "no"]: sql.disable_antispam(chat.id) update.effective_message.reply_text( tld( chat.id, "I've disabled antispam security in this group. GBans wont affect your users " "anymore. You'll be less protected from any trolls and spammers " "though! And i am little disappointed too. 😶")) else: update.effective_message.reply_text( tld( chat.id, "Give me some arguments to choose a setting! on/off, yes/no!\n\n" "Your current setting is: {}\n" "When True, any gbans that happen will also happen in your group. " "When False, they won't, leaving you at the possible mercy of " "spammers.").format(sql.does_chat_gban(chat.id)))
def leave_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) administrators = chat.get_administrators() if user.id in SUDO_USERS: pass else: for admin in administrators: status = admin.status if status == "creator": print(admin) if str(admin.user.id) == str(user.id): pass else: update.effective_message.reply_text( tld(chat.id, "Only group creator can do it!")) return if sql.chat_leave_fed(chat.id) == True: update.effective_message.reply_text(tld(chat.id, "Left from fed!")) else: update.effective_message.reply_text( tld(chat.id, "Why you are leaving feds when you have not join any!"))
def enable(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = update.effective_chat if len(args) >= 1: enable_cmd = args[0] if enable_cmd.startswith(CMD_STARTERS): enable_cmd = enable_cmd[1:] if sql.enable_command(chatD.id, enable_cmd): update.effective_message.reply_text( tld(chat.id, "Enabled the use of `{}` in *{}*").format( enable_cmd, chatD.title), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( tld(chat.id, "Is that even disabled?")) else: update.effective_message.reply_text( tld(chat.id, "What should I enable?"))
def commands(bot: Bot, update: Update): chat = update.effective_chat user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = update.effective_chat disabled = sql.get_all_disabled(chatD.id) if not disabled: update.effective_message.reply_text( tld(chat.id, "No commands are disabled! in *{}*!").format(chatD.title)) text = build_curr_disabled(chatD.id, chat.id) update.effective_message.reply_text(tld( chat.id, "The following commands are currently restricted in *{}*:\n{}"). format(chatD.title, text), parse_mode=ParseMode.MARKDOWN)
def disable(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = update.effective_chat if len(args) >= 1: disable_cmd = args[0] if disable_cmd.startswith(CMD_STARTERS): disable_cmd = disable_cmd[1:] if disable_cmd in set(DISABLE_CMDS + DISABLE_OTHER): sql.disable_command(chatD.id, disable_cmd) update.effective_message.reply_text( tld(chat.id, "Disabled the use of `{}` in *{}*").format( disable_cmd, chatD.title), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( tld(chat.id, "That command can't be disabled")) else: update.effective_message.reply_text( tld(chat.id, "What should I disable?"))
def del_lockables(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] for lockable, filter in LOCK_TYPES.items(): if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(chat, bot.id): if lockable == "bots": new_members = update.effective_message.new_chat_members for new_mem in new_members: if new_mem.is_bot: if not is_bot_admin(chat, bot.id): message.reply_text(tld(chat.id, "I see a bot, and I've been told to stop them joining... but I'm not admin!")) return chat.kick_member(new_mem.id) message.reply_text(tld(chat.id, "Only admins are allowed to add bots to this chat! Get outta here.")) else: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") break
def invite(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chatP = dispatcher.bot.getChat(conn) else: chatP = update.effective_chat if chat.type == "private": exit(1) if chatP.username: update.effective_message.reply_text(chatP.username) elif chatP.type == chatP.SUPERGROUP or chatP.type == chatP.CHANNEL: bot_member = chatP.get_member(bot.id) if bot_member.can_invite_users: invitelink = chatP.invite_link #print(invitelink) if not invitelink: invitelink = bot.exportChatInviteLink(chatP.id) update.effective_message.reply_text(invitelink) else: update.effective_message.reply_text( tld( chat.id, "I don't have access to the invite link, try changing my permissions!" )) else: update.effective_message.reply_text( tld( chat.id, "I can only give you invite links for supergroups and channels, sorry!" ))
def promote(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": exit(1) if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text( "I can't promote/demote people here! " "Make sure I'm admin and can appoint new admins.") exit(1) user_id = extract_user(message, args) if not user_id: message.reply_text( tld(chat.id, "You don't seem to be referring to a user.")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text( tld(chat.id, "How am I meant to promote someone that's already an admin?")) return "" if user_id == bot.id: message.reply_text( tld(chat.id, "I can't promote myself! Get an admin to do it for me.")) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chatD.get_member(bot.id) bot.promoteChatMember(chatD.id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, can_invite_users=bot_member.can_invite_users, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages) message.reply_text(tld(chat.id, f"Successfully promoted in *{chatD.title}*!"), parse_mode=ParseMode.MARKDOWN) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#PROMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
def __user_info__(user_id, chat_id): if user_id == dispatcher.bot.id: return tld( chat_id, "I've seen them in... Wow. Are they stalking me? They're in all the same places I am... oh. It's me." ) num_chats = sql.get_user_num_chats(user_id) return tld( chat_id, "I've seen them in <code>{}</code> chats in total.").format(num_chats)
def list_cmds(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] if DISABLE_CMDS + DISABLE_OTHER: result = "" for cmd in set(DISABLE_CMDS + DISABLE_OTHER): result += " • `{}`\n".format(escape_markdown(cmd)) update.effective_message.reply_text(tld( chat.id, "The following commands are toggleable:\n{}").format(result), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( tld(chat.id, "No commands can be disabled."))
def send_start(bot, update): chat = update.effective_chat first_name = update.effective_user.first_name text = PM_START keyboard = [[ InlineKeyboardButton(text=tld(chat.id, "Add me to your group ♥️"), url="t.me/RealAlexaBot?startgroup=true") ]] keyboard += [[ InlineKeyboardButton(text=tld(chat.id, "Join our support chat 🌍"), url="https://t.me/RealAlexaBotSupport") ]] keyboard += [[ InlineKeyboardButton(text="My Commands ⚙️", callback_data="help_back") ]] keyboard += [[ InlineKeyboardButton(text="Check out my website 🌐", url="http://realalexabot.unaux.com/home") ]] try: query = update.callback_query # query.message.delete() bot.edit_message_text(chat_id=query.message.chat_id, message_id=query.message.message_id, text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(keyboard), disable_web_page_preview=False) except Exception: pass if query: try: bot.edit_message_text(chat_id=query.message.chat_id, message_id=query.message.message_id, text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(keyboard), disable_web_page_preview=False) except Exception: return else: update.effective_message.reply_text( text, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=False)
def __user_info__(user_id, chat_id): is_gbanned = sql.is_user_gbanned(user_id) is_gmuted = sql.is_user_gmuted(user_id) if not user_id in SUDO_USERS: text = tld(chat_id, "Globally banned: <b>{}</b>") if is_gbanned: text = text.format(tld(chat_id, "Yes")) user = sql.get_gbanned_user(user_id) if user.reason: text += tld(chat_id, "\nReason: {}").format(html.escape(user.reason)) else: text = text.format(tld(chat_id, "No")) text += tld(chat_id, "\nGlobally muted: <b>{}</b>") if is_gmuted: text = text.format(tld(chat_id, "Yes")) user = sql.get_gmuted_user(user_id) if user.reason: text += tld(chat_id, "\nReason: {}").format(html.escape(user.reason)) else: text = text.format(tld(chat_id, "No")) return text else: return ""
def check_afk(bot, update, user_id, fst_name): chat = update.effective_chat # type: Optional[Chat] if sql.is_afk(user_id): user = sql.check_afk_status(user_id) elapsed_time = time.time() - start_time final = time.strftime("%Hh: %Mm: %Ss", time.gmtime(elapsed_time)) if not user.reason: res = tld(chat.id, f"{fst_name} is AFK !\n\nLast seen {final} ago") else: res = tld( chat.id, f"{fst_name} is AFK !\n\nReason: {user.reason}\n\nLast seen {final} ago" ) update.effective_message.reply_text(res)
def purge(bot: Bot, update: Update, args: List[str]) -> str: msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] if msg.reply_to_message: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] if can_delete(chat, bot.id): message_id = msg.reply_to_message.message_id delete_to = msg.message_id - 1 if args and args[0].isdigit(): new_del = message_id + int(args[0]) # No point deleting messages which haven't been written yet. if new_del < delete_to: delete_to = new_del for m_id in range(delete_to, message_id - 1, -1): # Reverse iteration over message ids try: bot.deleteMessage(chat.id, m_id) except BadRequest as err: if err.message == "Message can't be deleted": LOGGER.exception("Error while purging chat messages.") elif err.message != "Message to delete not found": LOGGER.exception("Error while purging chat messages.") try: msg.delete() except BadRequest as err: if err.message == "Message can't be deleted": LOGGER.exception("Error while purging chat messages.") elif err.message != "Message to delete not found": LOGGER.exception("Error while purging chat messages.") bot.send_message(chat.id, tld(chat.id, "Purge complete.")) return "<b>{}:</b>" \ "\n#PURGE" \ "\n<b>Admin:</b> {}" \ "\nPurged <code>{}</code> messages.".format(html.escape(chat.title), mention_html(user.id, user.first_name), delete_to - message_id) else: msg.reply_text( tld(chat.id, "Reply to a message to select where to start purging from.")) return ""
def adminlist(bot: Bot, update: Update): chat = update.effective_chat administrators = update.effective_chat.get_administrators() text = tld(chat.id, "Admins in *{}*:").format(update.effective_chat.title or tld(chat.id, "This chat").lower()) for admin in administrators: user = admin.user name = "[{}](tg://user?id={})".format(user.first_name, user.id) if user.username: esc = escape_markdown("@" + user.username) name = "[{}](tg://user?id={})".format(esc, user.id) text += "\n - {}".format(name) update.effective_message.reply_text(text, parse_mode=ParseMode.MARKDOWN)
def unsetlog(bot: Bot, update: Update): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] log_channel = sql.stop_chat_logging(chat.id) if log_channel: bot.send_message( log_channel, tld(chat.id, "Channel has been unlinked from {}").format(chat.title)) message.reply_text(tld(chat.id, "Log channel has been un-set.")) else: message.reply_text(tld(chat.id, "No log channel has been set yet!"))
def help_button(bot: Bot, update: Update): query = update.callback_query chat = update.effective_chat # type: Optional[Chat] mod_match = re.match(r"help_module\((.+?)\)", query.data) prev_match = re.match(r"help_prev\((.+?)\)", query.data) next_match = re.match(r"help_next\((.+?)\)", query.data) back_match = re.match(r"help_back", query.data) try: if mod_match: module = mod_match.group(1) mod_name = tld(chat.id, HELPABLE[module].__mod_name__) help_txt = tld_help(chat.id, HELPABLE[module].__mod_name__) if help_txt == False: help_txt = HELPABLE[module].__help__ text = tld(chat.id, "Here is the help for the *{}* module:\n{}").format( mod_name, help_txt) bot.edit_message_text(chat_id=query.message.chat_id, message_id=query.message.message_id, text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text=tld(chat.id, "🔙 Back"), callback_data="help_back") ]]), disable_web_page_preview=False) elif back_match: bot.edit_message_text(chat_id=query.message.chat_id, message_id=query.message.message_id, text=tld(chat.id, "send-help").format( dispatcher.bot.first_name, tld(chat.id, "cmd_multitrigger")), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(chat.id, 0, HELPABLE, "help")), disable_web_page_preview=False) # ensure no spinny white circle bot.answer_callback_query(query.id) # query.message.delete() except BadRequest: pass
def unlock(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] if is_user_admin(chat, message.from_user.id): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=False) message.reply_text(tld(chat.id, "Unlocked {} for everyone!").format(args[0])) return "<b>{}:</b>" \ "\n#UNLOCK" \ "\n<b>Admin:</b> {}" \ "\nUnlocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) elif args[0] in RESTRICTION_TYPES: sql.update_restriction(chat.id, args[0], locked=False) """ members = users_sql.get_chat_members(chat.id) if args[0] == "messages": unrestr_members(bot, chat.id, members, media=False, other=False, previews=False) elif args[0] == "media": unrestr_members(bot, chat.id, members, other=False, previews=False) elif args[0] == "other": unrestr_members(bot, chat.id, members, previews=False) elif args[0] == "previews": unrestr_members(bot, chat.id, members) elif args[0] == "all": unrestr_members(bot, chat.id, members, True, True, True, True) """ message.reply_text(tld(chat.id, "Unlocked {} for everyone!").format(args[0])) return "<b>{}:</b>" \ "\n#UNLOCK" \ "\n<b>Admin:</b> {}" \ "\nUnlocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: message.reply_text(tld(chat.id, "What are you trying to unlock...? Try /locktypes for the list of lockables")) else: bot.sendMessage(chat.id, tld(chat.id, "What are you trying to unlock...?")) return ""
def fed_chat(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) user_id = update.effective_message.from_user.id if not is_user_admin(update.effective_chat, user_id): update.effective_message.reply_text( "You must be a chat administrator to run this command :P") return if not fed_id: update.effective_message.reply_text( tld(chat.id, "This group not in any federation!")) return print(fed_id) user = update.effective_user # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] info = sql.get_fed_info(fed_id) text = "This chat is part of the following federation:" text += "\n{} (ID: <code>{}</code>)".format(info.fed_name, fed_id) update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def setlog(bot: Bot, update: Update): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] if chat.type == chat.CHANNEL: message.reply_text( tld( chat.id, "Now, forward the /setlog to the group you want to tie this channel to!" )) elif message.forward_from_chat: sql.set_chat_log_channel(chat.id, message.forward_from_chat.id) try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception( "Error deleting message in log channel. Should work anyway though." ) try: bot.send_message( message.forward_from_chat.id, tld( chat.id, "This channel has been set as the log channel for {}." ).format(chat.title or chat.first_name)) except Unauthorized as excp: if excp.message == "Forbidden: bot is not a member of the channel chat": bot.send_message( chat.id, tld(chat.id, "Successfully set log channel!")) else: LOGGER.exception("ERROR in setting the log channel.") bot.send_message(chat.id, tld(chat.id, "Successfully set log channel!")) else: message.reply_text( tld( chat.id, "*The steps to set a log channel are:*\n" " • add bot to the desired channel\n" " • send /setlog to the channel\n" " • forward the /setlog to the group\n"), ParseMode.MARKDOWN)
def cmd_get(bot: Bot, update: Update, args: List[str]): if len(args) >= 2 and args[1].lower() == "noformat": get(bot, update, args[0], show_none=True, no_format=True) elif len(args) >= 1: get(bot, update, args[0], show_none=True) else: update.effective_message.reply_text( tld(update.effective_chat.id, "Muh Me Lega bsdk ?"))
def add_blacklist(bot: Bot, update: Update): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] words = msg.text.split(None, 1) conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": exit(1) else: chat_name = chat.title if len(words) > 1: text = words[1] to_blacklist = list( set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) for trigger in to_blacklist: sql.add_to_blacklist(chat_id, trigger.lower()) if len(to_blacklist) == 1: msg.reply_text(tld( chat.id, "Added <code>{}</code> to the blacklist in <b>{}</b>!").format( html.escape(to_blacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: msg.reply_text(tld( chat.id, "Added <code>{}</code> to the blacklist in <b>{}</b>!").format( len(to_blacklist)), chat_name, parse_mode=ParseMode.HTML) else: msg.reply_text( tld(chat.id, "Tell me what words you would like to add to the blacklist."))
def join_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message administrators = chat.get_administrators() fed_id = sql.get_fed_id(chat.id) if user.id in SUDO_USERS: pass else: for admin in administrators: status = admin.status if status == "creator": print(admin) if str(admin.user.id) == str(user.id): pass else: update.effective_message.reply_text( tld(chat.id, "Only group creator can do it!")) return if fed_id: message.reply_text( tld(chat.id, "Uh, Are you gonna join two federations at one chat?")) return if len(args) >= 1: fedd = args[0] print(fedd) if sql.search_fed_by_id(fedd) == False: message.reply_text( tld(chat.id, "Please enter valid federation id.")) return x = sql.chat_join_fed(fedd, chat.id) if not x: message.reply_text( tld( chat.id, "Failed to join to federation! Due to some errors that basically I have no idea, try reporting it in support group!" )) return message.reply_text(tld(chat.id, "Chat joined to federation!"))
def fed_info(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) info = sql.get_fed_info(fed_id) if not fed_id: update.effective_message.reply_text( tld(chat.id, "This group is not in any federation!")) return if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text( tld(chat.id, "Only fed admins can do this!")) return OW = bot.get_chat(info.owner_id) HAHA = OW.id FEDADMIN = sql.all_fed_users(fed_id) FEDADMIN.append(int(HAHA)) ACTUALADMIN = len(FEDADMIN) print(fed_id) user = update.effective_user # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] info = sql.get_fed_info(fed_id) text = "<b>Fed info:</b>" text += "\nFedID: <code>{}</code>".format(fed_id) text += "\nName: {}".format(info.fed_name) text += "\nCreator: {}".format(mention_html(HAHA, "this guy")) text += "\nNumber of admins: <code>{}</code>".format(ACTUALADMIN) R = 0 for O in sql.get_all_fban_users(fed_id): R = R + 1 text += "\nNumber of bans: <code>{}</code>".format(R) h = sql.all_fed_chats(fed_id) asdf = len(h) text += "\nNumber of connected chats: <code>{}</code>".format(asdf) update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def set_frules(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if not fed_id: update.effective_message.reply_text( tld(chat.id, "This chat is not in any federation!")) return if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text( tld(chat.id, "Only fed admins can do this!")) return if len(args) >= 1: msg = update.effective_message # type: Optional[Message] raw_text = msg.text args = raw_text.split( None, 1) # use python's maxsplit to separate cmd and args if len(args) == 2: txt = args[1] offset = len(txt) - len( raw_text) # set correct offset relative to command markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset) x = sql.set_frules(fed_id, markdown_rules) if not x: update.effective_message.reply_text( tld( chat.id, "Big F! There is an error while setting federation rules! If you wondered why please ask it in support group!" )) return rules = sql.get_fed_info(fed_id).fed_name update.effective_message.reply_text( tld(chat.id, f"Rules are set for {rules}!")) else: update.effective_message.reply_text( tld(chat.id, "Please write rules to set it up!"))
def get_help(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] args = update.effective_message.text.split(None, 1) # ONLY send help in PM if chat.type != chat.PRIVATE: update.effective_message.reply_text( "Contact me in PM to get the list of possible commands.", reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text="My Commands ⚙️", url="t.me/{}?start=help".format( bot.username)) ]])) return elif len(args) >= 2 and any(args[1].lower() == x for x in HELPABLE): module = args[1].lower() mod_name = tld(chat.id, HELPABLE[module].__mod_name__) help_txt = tld_help(chat.id, HELPABLE[module].__mod_name__) if help_txt == False: help_txt = HELPABLE[module].__help__ text = tld(chat.id, "Here is the help for the *{}* module:\n{}").format( mod_name, help_txt) send_help( chat.id, text, InlineKeyboardMarkup([[ InlineKeyboardButton(text=tld(chat.id, "Back"), callback_data="help_back") ]])) else: send_help( chat.id, tld(chat.id, "send-help").format( dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld( chat.id, "\nAll commands can either be used with `/` or `!`.\n")))