def join_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_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, "common_group_creator_only")) return if fed_id: message.reply_text(tld(chat.id, "feds_group_joined_fed")) return if len(args) >= 1: fedd = args[0] print(fedd) if sql.search_fed_by_id(fedd) == False: message.reply_text(tld(chat.id, "feds_fedid_invalid")) return x = sql.chat_join_fed(fedd, chat.id) if not x: message.reply_text(tld(chat.id, "feds_join_unknown_err")) return message.reply_text(tld(chat.id, "feds_join_success"))
def get_paste_content(bot: Bot, update: Update, args: List[str]): BURL = 'https://del.dog' message = update.effective_message chat = update.effective_chat # type: Optional[Chat] if len(args) >= 1: key = args[0] else: message.reply_text(tld(chat.id, "misc_get_pasted_invalid")) return format_normal = f'{BURL}/' format_view = f'{BURL}/v/' if key.startswith(format_view): key = key[len(format_view):] elif key.startswith(format_normal): key = key[len(format_normal):] r = requests.get(f'{BURL}/raw/{key}') if r.status_code != 200: try: res = r.json() update.effective_message.reply_text(res['message']) except Exception: if r.status_code == 404: update.effective_message.reply_text( tld(chat.id, "misc_paste_404")) else: update.effective_message.reply_text( tld(chat.id, "misc_get_pasted_unknown")) r.raise_for_status() update.effective_message.reply_text('```' + escape_markdown(r.text) + '```', parse_mode=ParseMode.MARKDOWN)
def fed_info(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_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, "feds_group_not_in_fed")) return if is_user_fed_admin(fed_id, user.id) == False: update.effective_message.reply_text(tld(chat.id, "feds_fedadmin_only")) return owner = bot.get_chat(info['owner']) try: owner_name = owner.first_name + " " + owner.last_name except Exception: owner_name = owner.first_name FEDADMIN = sql.all_fed_users(fed_id) FEDADMIN.append(int(owner.id)) TotalAdminFed = len(FEDADMIN) user = update.effective_user chat = update.effective_chat info = sql.get_fed_info(fed_id) getfban = sql.get_all_fban_users(fed_id) getfchat = sql.all_fed_chats(fed_id) text = tld(chat.id, "feds_info").format(fed_id, info['fname'], mention_html(owner.id, owner_name), TotalAdminFed, len(getfban), len(getfchat)) update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def set_warn_limit(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat user = update.effective_user msg = update.effective_message if args: if args[0].isdigit(): if int(args[0]) < 1: msg.reply_text(tld(chat.id, 'warns_warnlimit_min_1')) else: sql.set_warn_limit(chat.id, int(args[0])) msg.reply_text( tld(chat.id, 'warns_warnlimit_updated_success').format(args[0])) return tld(chat.id, 'warns_set_warn_limit_log_channel').format( html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: msg.reply_text(tld(chat.id, 'warns_warnlimit_invalid_arg')) else: limit, soft_warn = sql.get_warn_setting(chat.id) msg.reply_text(tld(chat.id, 'warns_warnlimit_current').format(limit)) return ""
def stop_filter(bot: Bot, update: Update): chat = update.effective_chat user = update.effective_user args = update.effective_message.text.split(None, 1) conn = connected(bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = tld(chat.id, "cust_filters_local") else: chat_name = chat.title if len(args) < 2: return chat_filters = sql.get_chat_triggers(chat_id) if not chat_filters: update.effective_message.reply_text( tld(chat.id, "cust_filters_list_empty").format(chat_name)) return for keyword in chat_filters: if keyword == args[1].lower(): sql.remove_filter(chat_id, args[1].lower()) update.effective_message.reply_text( tld(chat.id, "cust_filters_stop_success").format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop update.effective_message.reply_text( tld(chat.id, "cust_filters_err_wrong_filter"))
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, "log_channel_fwd_cmd")) 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, "log_channel_chn_curr_conf").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, "log_channel_link_success")) else: LOGGER.exception("ERROR in setting the log channel.") bot.send_message(chat.id, tld(chat.id, "log_channel_link_success")) else: message.reply_text(tld(chat.id, "log_channel_invalid_message"), ParseMode.MARKDOWN)
def security_mute(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] getcur, cur_value, cust_text = sql.welcome_security(chat.id) if len(args) >= 1: var = args[0] if var[:1] == "0": mutetime = "0" sql.set_welcome_security(chat.id, getcur, "0", cust_text) text = tld(chat.id, 'welcome_mute_time_none') else: mutetime = extract_time(message, var) if mutetime == "": return sql.set_welcome_security(chat.id, getcur, str(var), cust_text) text = tld(chat.id, 'welcome_mute_time').format(var) update.effective_message.reply_text(text) else: if str(cur_value) == "0": update.effective_message.reply_text( tld(chat.id, 'welcome_mute_time_settings_none')) else: update.effective_message.reply_text( tld(chat.id, 'welcome_mute_time_settings').format(cur_value))
def set_goodbye(bot: Bot, update: Update) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] text, data_type, content, buttons = get_welcome_type(msg) # If user is not set text and not reply a message if not msg.reply_to_message: if len(msg.text.split()) == 1: msg.reply_text(tld(chat.id, 'welcome_set_welcome_no_text'), parse_mode="markdown") return "" if data_type is None: msg.reply_text(tld(chat.id, 'welcome_set_welcome_no_datatype')) return "" sql.set_custom_gdbye(chat.id, content, text, data_type, buttons) msg.reply_text(tld(chat.id, 'welcome_set_goodbye_success')) return "<b>{}:</b>" \ "\n#SET_GOODBYE" \ "\n<b>Admin:</b> {}" \ "\nSet the goodbye message.".format(escape(chat.title), mention_html(user.id, user.first_name))
def clear(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_user conn = connected(bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = tld(chat.id, "note_is_local") else: chat_name = chat.title if len(args) >= 1: notename = args[0].lower() if sql.rm_note(chat_id, notename): update.effective_message.reply_text(tld( chat.id, "clear_success").format(chat_name), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( tld(chat.id, "note_not_existed"))
def unblacklist(bot: Bot, update: Update): msg = update.effective_message chat = update.effective_chat user = update.effective_user words = msg.text.split(None, 1) conn = connected(bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": return else: chat_name = chat.title if len(words) > 1: text = words[1] to_unblacklist = list( set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) successful = 0 for trigger in to_unblacklist: success = sql.rm_from_blacklist(chat_id, trigger.lower()) if success: successful += 1 if len(to_unblacklist) == 1: if successful: msg.reply_text(tld(chat.id, "blacklist_del").format( html.escape(to_unblacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: msg.reply_text(tld(chat.id, "blacklist_err_not_trigger")) elif successful == len(to_unblacklist): msg.reply_text(tld(chat.id, "blacklist_multi_del").format( successful, chat_name), parse_mode=ParseMode.HTML) elif not successful: msg.reply_text(tld(chat.id, "blacklist_err_multidel_no_trigger").format( successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: msg.reply_text(tld( chat.id, "blacklist_err_multidel_some_no_trigger").format( successful, chat_name, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: msg.reply_text(tld(chat.id, "blacklist_err_del_no_args"))
def start(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # query = update.callback_query #Unused variable uptime = get_readable_time((time.time() - StartTime)) if update.effective_chat.type == "private": if len(args) >= 1: if args[0].lower() == "help": send_help( update.effective_chat.id, tld(chat.id, "send-help").format(dispatcher.bot.first_name, tld(chat.id, "cmd_multitrigger"))) elif args[0][1:].isdigit() and "rules" in IMPORTED: IMPORTED["rules"].send_rules(update, args[0], from_pm=True) else: send_start(bot, update) else: try: update.effective_message.reply_text( tld(chat.id, 'main_start_group')) except Exception: print("Nut")
def slap(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat msg = update.effective_message # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "******" + escape_markdown(msg.from_user.username) else: curr_user = "******".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user if slapped_user.username == "Destroyer32": reply_text(tld(chat.id, "memes_not_doing_that")) return if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id) user2 = curr_user temp = random.choice(tld_list(chat.id, "memes_slaps_templates_list")) item = random.choice(tld_list(chat.id, "memes_items_list")) hit = random.choice(tld_list(chat.id, "memes_hit_list")) throw = random.choice(tld_list(chat.id, "memes_throw_list")) itemp = random.choice(tld_list(chat.id, "memes_items_list")) itemr = random.choice(tld_list(chat.id, "memes_items_list")) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw, itemp=itemp, itemr=itemr) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
def warn_user(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message chat = update.effective_chat warner = update.effective_user user_id, reason = extract_user_and_text(message, args) if user_id: if message.reply_to_message and message.reply_to_message.from_user.id == user_id: return warn(message.reply_to_message.from_user, chat, reason, message.reply_to_message, warner) else: return warn( chat.get_member(user_id).user, chat, reason, message, warner) else: message.reply_text(tld(chat.id, 'common_err_no_user')) return ""
def build_lock_message(chat, chatP, user, chatname): locks = sql.get_locks(chat.id) restr = sql.get_restr(chat.id) if not locks: sql.init_permissions(chat.id) locks = sql.get_locks(chat.id) if not restr: sql.init_restrictions(chat.id) restr = sql.get_restr(chat.id) res = tld(chatP.id, "locks_list").format( chatname, 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, restr.messages, restr.media, restr.other, restr.preview, all([restr.messages, restr.media, restr.other, restr.preview])) return res
def is_admin(bot: Bot, update: Update, *args, **kwargs): user = update.effective_user chat = update.effective_chat if user and is_user_admin(update.effective_chat, user.id): try: return func(bot, update, *args, **kwargs) except Exception: return elif not user: pass elif DEL_CMDS and " " not in update.effective_message.text: update.effective_message.delete() elif (admin_sql.command_reaction(chat.id) == True): update.effective_message.reply_text( tld(chat.id, 'helpers_user_not_admin'))
def no_longer_afk(bot: Bot, update: Update): user = update.effective_user chat = update.effective_chat message = update.effective_message if not user: # ignore channels return res = sql.rm_afk(user.id) if res: if message.new_chat_members: #dont say msg return firstname = update.effective_user.first_name try: message.reply_text( tld(chat.id, "user_no_longer_afk").format(firstname)) except Exception: return
def afk(bot: Bot, update: Update): chat = update.effective_chat user = update.effective_user if not user: # ignore channels return if user.id == 777000: return args = update.effective_message.text.split(None, 1) if len(args) >= 2: reason = args[1] else: reason = "" sql.set_afk(update.effective_user.id, reason) fname = update.effective_user.first_name update.effective_message.reply_text( tld(chat.id, "user_now_afk").format(fname))
async def phh(event): if event.sender_id is None: return chat_id = event.chat_id fetch = get( "https://api.github.com/repos/phhusson/treble_experimentations/releases/latest" ) usr = json.loads(fetch.content) reply_text = tld(chat_id, "phh_releases") for i in range(len(usr)): try: name = usr['assets'][i]['name'] url = usr['assets'][i]['browser_download_url'] reply_text += f"[{name}]({url})\n" except IndexError: continue await event.reply(reply_text)
def log_action(bot: Bot, update: Update, *args, **kwargs): try: result = func(bot, update, *args, **kwargs) except Exception: return chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] if result: if chat.type == chat.SUPERGROUP and chat.username: result += tld(chat.id, "log_channel_link").format( chat.username, message.message_id) log_chat = sql.get_chat_log_channel(chat.id) if log_chat: send_log(bot, log_chat, chat.id, result) elif result == "": pass else: LOGGER.warning( "%s was set as loggable, but had no return statement.", func) return result
def help_button(bot: Bot, update: Update): query = update.callback_query chat = update.effective_chat back_match = re.match(r"help_back", query.data) mod_match = re.match(r"help_module\((.+?)\)", query.data) try: if mod_match: module = mod_match.group(1) mod_name = tld(chat.id, "modname_" + module).strip() help_txt = tld( chat.id, module + "_help") # tld_help(chat.id, HELPABLE[module].__mod_name__) if not help_txt: LOGGER.exception(f"Help string for {module} not found!") text = tld(chat.id, "here_is_help").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, "btn_go_back"), callback_data="help_back") ]]), disable_web_page_preview=True) 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=True) # ensure no spinny white circle bot.answer_callback_query(query.id) # query.message.delete() except BadRequest: pass
def user_join_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_user msg = update.effective_message fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id): user_id = extract_user(msg, args) if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities([MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "common_err_no_user")) return else: LOGGER.warning('error') getuser = sql.search_user_in_fed(fed_id, user_id) fed_id = sql.get_fed_id(chat.id) info = sql.get_fed_info(fed_id) get_owner = eval(info['fusers'])['owner'] get_owner = bot.get_chat(get_owner).id if user_id == get_owner: update.effective_message.reply_text( tld(chat.id, "feds_promote_owner")) return if getuser: update.effective_message.reply_text( tld(chat.id, "feds_promote_owner")) return if user_id == bot.id: update.effective_message.reply_text( tld(chat.id, "feds_promote_bot")) return res = sql.user_join_fed(fed_id, user_id) if res: update.effective_message.reply_text( tld(chat.id, "feds_promote_success")) else: update.effective_message.reply_text("") else: update.effective_message.reply_text(tld(chat.id, "feds_owner_only"))
def locale(bot, update, args): chat = update.effective_chat message = update.effective_message if len(args) > 0: locale = args[0].lower() if locale == 'en-us': locale = 'en-US' if locale in list_locales: if locale in LANGUAGES: switch_to_locale(chat.id, locale) if chat.type == "private": message.reply_text( tld(chat.id, 'language_switch_success_pm').format( list_locales[locale])) else: message.reply_text( tld(chat.id, 'language_switch_success').format( chat.title, list_locales[locale])) else: text = tld(chat.id, "language_not_supported").format( list_locales[locale]) text += "\n\n*Currently available languages:*\n" for lang in LANGUAGES: locale = list_locales[lang] text += "\n *{}* - `{}`".format(locale, lang) message.reply_text(text, parse_mode=ParseMode.MARKDOWN) else: text = tld(chat.id, "language_code_not_valid") text += "\n\n*Currently available languages:*\n" for lang in LANGUAGES: locale = list_locales[lang] text += "\n *{}* - `{}`".format(locale, lang) message.reply_text(text, parse_mode=ParseMode.MARKDOWN) else: LANGUAGE = prev_locale(chat.id) if LANGUAGE: locale = LANGUAGE.locale_name native_lang = list_locales[locale] message.reply_text(tld( chat.id, "language_current_locale").format(native_lang), parse_mode=ParseMode.MARKDOWN) else: message.reply_text(tld( chat.id, "language_current_locale").format("English (US)"), parse_mode=ParseMode.MARKDOWN)
def user_demote_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_user fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id): msg = update.effective_message user_id = extract_user(msg, args) if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities([MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "common_err_no_user")) return else: LOGGER.warning('error') if user_id == bot.id: update.effective_message.reply_text(tld(chat.id, "feds_demote_bot")) return if sql.search_user_in_fed(fed_id, user_id) == False: update.effective_message.reply_text( tld(chat.id, "feds_demote_target_not_admin")) return res = sql.user_demote_fed(fed_id, user_id) if res == True: update.effective_message.reply_text( tld(chat.id, "feds_demote_success")) else: update.effective_message.reply_text( tld(chat.id, "feds_demote_failed")) else: update.effective_message.reply_text(tld(chat.id, "feds_owner_only")) return
def set_about_bio(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message sender = update.effective_user if message.reply_to_message: repl_message = message.reply_to_message user_id = repl_message.from_user.id if user_id == 1087968824: message.reply_text(tld(chat.id, 'userinfo_anonymous_bio')) return if user_id == message.from_user.id: message.reply_text(tld(chat.id, 'userinfo_bio_you_cant_set')) return elif user_id == bot.id and sender.id not in SUDO_USERS: message.reply_text(tld(chat.id, 'userinfo_bio_bot_sudo_only')) return elif user_id in SUDO_USERS and sender.id not in SUDO_USERS: message.reply_text(tld(chat.id, 'userinfo_bio_sudo_sudo_only')) return elif user_id == OWNER_ID: message.reply_text(tld(chat.id, 'userinfo_bio_owner_nobio')) return text = message.text bio = text.split( None, 1 ) # use python's maxsplit to only remove the cmd, hence keeping newlines. if len(bio) == 2: if len(bio[1]) < MAX_MESSAGE_LENGTH // 4: sql.set_user_bio(user_id, bio[1]) message.reply_text("Updated {}'s bio!".format( repl_message.from_user.first_name)) else: message.reply_text( tld(chat.id, 'userinfo_bio_too_long').format( MAX_MESSAGE_LENGTH // 4, len(bio[1]))) else: message.reply_text(tld(chat.id, 'userinfo_bio_set_no_reply'))
def rm_blacklist_url(bot: Bot, update: Update): chat = update.effective_chat message = update.effective_message urls = message.text.split(None, 1) if len(urls) > 1: urls = urls[1] to_unblacklist = list( set(uri.strip() for uri in urls.split("\n") if uri.strip())) unblacklisted = 0 for uri in to_unblacklist: extract_url = tldextract.extract(uri) success = sql.rm_url_from_blacklist( chat.id, extract_url.domain + "." + extract_url.suffix) if success: unblacklisted += 1 if len(to_unblacklist) == 1: if unblacklisted: message.reply_text(tld(chat.id, "url_blacklist_remove_success").format( html.escape(to_unblacklist[0])), parse_mode=ParseMode.HTML) else: message.reply_text(tld(chat.id, "url_blacklist_remove_invalid")) elif unblacklisted == len(to_unblacklist): message.reply_text( tld(chat.id, "url_blacklist_remove_success_2").format(unblacklisted), parse_mode=ParseMode.HTML) elif not unblacklisted: message.reply_text(tld(chat.id, "url_blacklist_remove_invalid_2"), parse_mode=ParseMode.HTML) else: message.reply_text(tld(chat.id, "url_blacklist_remove_success_3").format( unblacklisted, len(to_unblacklist) - unblacklisted), parse_mode=ParseMode.HTML) else: message.reply_text(tld(chat.id, "url_blacklist_remove_invalid_3"))
def del_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_user if chat.type != "private": update.effective_message.reply_text(tld(chat.id, "common_cmd_pm_only")) return if args: is_fed_id = args[0] getinfo = sql.get_fed_info(is_fed_id) if getinfo == False: update.effective_message.reply_text( tld(chat.id, "feds_delete_not_found")) return if int(getinfo['owner']) == int(user.id): fed_id = is_fed_id else: update.effective_message.reply_text(tld(chat.id, "feds_owner_only")) return else: update.effective_message.reply_text(tld(chat.id, "feds_err_no_args")) return if is_user_fed_owner(fed_id, user.id) == False: update.effective_message.reply_text(tld(chat.id, "feds_owner_only")) return update.effective_message.reply_text( tld(chat.id, "feds_delete_confirm").format(getinfo['fname']), reply_markup=InlineKeyboardMarkup([ [ InlineKeyboardButton( text="⚠️ Delete Federation ⚠️", callback_data="rmfed_{}".format(fed_id), ) ], [ InlineKeyboardButton(text="Cancel", callback_data="rmfed_cancel") ], ]), )
def new_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_user #message = update.effective_message if chat.type != "private": update.effective_message.reply_text(tld(chat.id, "common_cmd_pm_only")) return if not args: update.effective_message.reply_text(tld(chat.id, "feds_err_no_args")) return fednam = args[0] if not fednam == '': fed_id = str(uuid.uuid4()) fed_name = fednam LOGGER.info(fed_id) if user.id == int(OWNER_ID): fed_id = fed_name x = sql.new_fed(user.id, fed_name, fed_id) if not x: update.effective_message.reply_text( tld(chat.id, "feds_create_fail")) return update.effective_message.reply_text(tld(chat.id, "feds_create_success").format( fed_name, fed_id, fed_id), parse_mode=ParseMode.MARKDOWN) try: bot.send_message(MESSAGE_DUMP, tld(chat.id, "feds_create_success_logger").format( fed_name, fed_id), parse_mode=ParseMode.HTML) except Exception: LOGGER.warning("Cannot send a message to MESSAGE_DUMP") else: update.effective_message.reply_text(tld(chat.id, "feds_err_no_args"))
async def los(event): if event.sender_id is None: return chat_id = event.chat_id try: device_ = event.pattern_match.group(1) device = urllib.parse.quote_plus(device_) except Exception: device = '' if device == '': reply_text = tld(chat_id, "cmd_example").format("los") await event.reply(reply_text, link_preview=False) return fetch = get(f'https://download.lineageos.org/api/v1/{device}/nightly/*') if fetch.status_code == 200 and len(fetch.json()['response']) != 0: usr = json.loads(fetch.content) response = usr['response'][0] filename = response['filename'] url = response['url'] buildsize_a = response['size'] buildsize_b = sizee(int(buildsize_a)) version = response['version'] reply_text = tld(chat_id, "download").format(filename, url) reply_text += tld(chat_id, "build_size").format(buildsize_b) reply_text += tld(chat_id, "version").format(version) keyboard = [custom.Button.url(tld(chat_id, "btn_dl"), f"{url}")] await event.reply(reply_text, buttons=keyboard, link_preview=False) return else: reply_text = tld(chat_id, "err_not_found") await event.reply(reply_text, link_preview=False)
def list_notes(bot: Bot, update: Update): chat = update.effective_chat user = update.effective_user conn = connected(bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title msg = tld(chat.id, "note_in_chat") else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = tld(chat.id, "note_is_local") msg = tld(chat.id, "note_in_local") else: chat_name = chat.title msg = tld(chat.id, "note_in_chat") note_list = sql.get_all_chat_notes(chat_id) for note in note_list: note_name = " ➺ `#{}`\n".format(note.name.lower()) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if not note_list: update.effective_message.reply_text(tld( chat.id, "note_none_in_chat").format(chat_name), parse_mode=ParseMode.MARKDOWN) elif len(msg) != 0: msg += tld(chat.id, "note_get") update.effective_message.reply_text(msg.format(chat_name), parse_mode=ParseMode.MARKDOWN)
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message user = update.effective_user chat = update.effective_chat log_message = "" user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text(tld(chat.id, "common_err_no_user")) return if user_id == bot.id: message.reply_text(tld(chat.id, "antispam_err_usr_bot")) return if user_id in [777000, 1087968824]: message.reply_text(tld(chat.id, "antisoam_err_tg_support")) return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text(tld(chat.id, "antispam_err_notfound_usr")) return "" else: return if user_chat.type != "private": message.reply_text(tld(chat.id, "antispam_err_not_usr")) return if sql.is_user_gbanned(user_id): if not reason: message.reply_text(tld(chat.id, "antispam_err_no_new_reason")) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason ) if old_reason: message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason) ), parse_mode=ParseMode.HTML, ) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return message.reply_text("Banging...") start_time = time.time() datetime_fmt = "%Y-%m-%dT%H:%M" current_time = datetime.utcnow().strftime(datetime_fmt) if chat.type != "private": chat_origin = "<b>{} ({})</b>\n".format(html.escape(chat.title), chat.id) else: chat_origin = "<b>{}</b>\n".format(chat.id) log_message = ( f"#GBANNED\n" f"<b>Originated from:</b> <code>{chat_origin}</code>\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Banned User:</b> {mention_html(user_chat.id, user_chat.first_name)}\n" f"<b>Banned User ID:</b> <code>{user_chat.id}</code>\n" f"<b>Event Stamp:</b> <code>{current_time}</code>" ) if reason: if chat.type == chat.SUPERGROUP and chat.username: log_message += f'\n<b>Reason:</b> <a href="https://telegram.me/{chat.username}/{message.message_id}">{reason}</a>' else: log_message += f"\n<b>Reason:</b> <code>{reason}</code>" if EVENT_LOGS: try: log = bot.send_message(EVENT_LOGS, log_message, parse_mode=ParseMode.HTML) except BadRequest as excp: log = bot.send_message( EVENT_LOGS, log_message + "\n\nFormatting has been disabled due to an unexpected error.", ) else: send_to_list(bot, log_message, html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_user_com_chats(user_id) gbanned_chats = 0 for chat in chats: chat_id = int(chat) # Check if this group has disabled gbans if not sql.does_chat_gban(chat_id): continue try: bot.kick_chat_member(chat_id, user_id) gbanned_chats += 1 except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text(f"Could not gban due to: {excp.message}") if EVENT_LOGS: bot.send_message( EVENT_LOGS, f"Could not gban due to {excp.message}", parse_mode=ParseMode.HTML, ) else: send_to_list( bot, f"Could not gban due to: {excp.message}" ) sql.ungban_user(user_id) return except TelegramError: pass if EVENT_LOGS: log.edit_text( log_message + f"\n<b>Chats affected:</b> <code>{gbanned_chats}</code>", parse_mode=ParseMode.HTML, ) else: send_to_list( bot, f"Gban complete! (User banned in <code>{gbanned_chats}</code> chats)", html=True, ) end_time = time.time() gban_time = round((end_time - start_time), 2) if gban_time > 60: gban_time = round((gban_time / 60), 2) message.reply_text("Done! Gbanned.", parse_mode=ParseMode.HTML) else: message.reply_text("Done! Gbanned.", parse_mode=ParseMode.HTML) try: bot.send_message( user_id, "#EVENT" "You have been marked as Malicious and as such have been banned from any future groups we manage." f"\n<b>Reason:</b> <code>{html.escape(user.reason)}</code>" f"</b>Appeal Chat:</b> @{SUPPORT_CHAT}", parse_mode=ParseMode.HTML, ) except: pass # bot probably blocked by user