def ban_bot(bot, update, chat_data, to_ban: Bot, ban_state: bool): if to_ban.disabled and ban_state is True: update.message.reply_text( mdformat.none_action("{} is already banned.".format(to_ban)), parse_mode="markdown", ) return if not to_ban.disabled and ban_state is False: update.message.reply_text( mdformat.none_action("{} is not banned.".format(to_ban)), parse_mode="markdown", ) return if ban_state: to_ban.disable(Bot.DisabledReason.banned) update.message.reply_text("Bot was banned.") else: to_ban.enable() update.message.reply_text("Bot was unbanned.") to_ban.save() from components.explore import send_bot_details return send_bot_details(bot, update, chat_data, to_ban)
async def disable_decider(bot: TelegramBot, to_check: BotModel): assert to_check.disabled_reason != BotModel.DisabledReason.banned if ( to_check.offline and to_check.offline_for > settings.DISABLE_BOT_INACTIVITY_DELTA and to_check.disabled_reason != BotModel.DisabledReason.offline ): # Disable if the bot has been offline for too long if to_check.disable(to_check.DisabledReason.offline): to_check.save() if to_check.last_response: reason = "its last response was " + helpers.slang_datetime(to_check.last_response) else: reason = "it's been offline for.. like... ever" msg = "❌ {} disabled as {}.".format(to_check, reason) log.info(msg) bot.send_message(settings.BOTLIST_NOTIFICATIONS_ID, msg, timeout=30, parse_mode='markdown') else: log.info("huhwtf") elif ( to_check.online and to_check.disabled_reason == BotModel.DisabledReason.offline ): # Re-enable if the bot is disabled and came back online if to_check.enable(): to_check.save() msg = "{} was included in the @BotList again as it came back online.".format(to_check) log.info(msg) bot.send_message(settings.BOTLIST_NOTIFICATIONS_ID, msg, timeout=30, parse_mode='markdown') else: log.info("huhwtf")