from mediacenter.database.incidents import Incident from mediacenter import MediaCenterBot from mediacenter.plugins.admin.help import add_command_help from mediacenter.utils import custom_filters from mediacenter.utils.helpers import GetUserMentionable def format_message(incident): INCIDENT_MESSAGE = ( "Here's the latest incident that happened\n\n" f"{GetUserMentionable(user_dict=incident['user'])} tried to get into the mainframe. It's fine. We caught him " f"in his tracks. He thought sending \"{incident['crime']}\" would do anything for him." ) return INCIDENT_MESSAGE @MediaCenterBot.on_message(custom_filters.command("lastIncident", case_sensitive=True)) async def start(_, message: Message): incident = [x for x in Incident().find_latest_incident()] await message.reply(format_message(incident[0])) # Command help section add_command_help( 'incidents', [ ['/lastIncident', 'Shows the latest incident that occurred on {BOT_NAME}...'], ] )
import os import time from pyrogram import emoji from pyrogram.types import Message from mediacenter import MediaCenterBot from mediacenter.plugins.admin.help import add_command_help from mediacenter.utils import custom_filters @MediaCenterBot.on_message(custom_filters.command(['log', 'logs', 'logger'])) async def send_log_file(_, message: Message): if os.path.exists('logs/mediacenter.log'): await message.reply_chat_action('upload_document') await message.reply_document( document='logs/mediacenter.log', caption=f"{emoji.CLIPBOARD}: `{time.ctime(time.time())}`" ) else: await message.reply("Oddly enough, there is no log file. Try again?") # Command help section add_command_help( 'logs', [ ['/log', 'Sends the system log file as is before the command is sent.'], ] )
@MediaCenterBot.on_callback_query( custom_filters.current_module('qbt') & custom_filters.callback_query('list_categories', False)) async def list_categories(_, callback: CallbackQuery): categories: dict = QBT().all_categories() categories_list = [] for x in categories.keys(): categories_list.append(categories.get(x).get('name')) categories_list = "\n".join(categories_list) full_text = ("Here are all of your categories\n\n" "{categories}") await callback.answer("Listing Categories") try: await callback.edit_message_text( full_text.format(categories=categories_list), reply_markup=callback.message.reply_markup) except pyro_errors.MessageNotModified: pass # Command help section add_command_help('categories', [ ['/categories', 'Start the category'], ])
for btn in group: temp.append(InlineKeyboardButton(f"{modules[btn]}", f"switch+{btn}")) buttons.append(temp) buttons = InlineKeyboardMarkup(buttons) @MediaCenterBot.on_message(custom_filters.command(["modules", "module"])) async def modules_switcher(_, message: Message): await message.reply( "Here are the available modules. Select one to change to it.", reply_markup=buttons) print("This is the modules handler.") @MediaCenterBot.on_callback_query(custom_filters.callback_query('switch')) async def switch_module(_, callback: CallbackQuery): module = callback.payload UserDB().set_module(callback.from_user, module) await callback.answer() await callback.message.edit_text( f"Module Set to **{modules[module]}**. Select another to change to it.", reply_markup=buttons) # Command help section add_command_help('switch', [ ['/module(s)', 'Shows module selector'], ])
return buttons @MediaCenterBot.on_message(custom_filters.current_module('aria2') & custom_filters.command("list")) async def send_aria_list(_, message: Message): buttons = get_buttons() if buttons: await message.reply("Aria2c Active Downloads", reply_markup=InlineKeyboardMarkup(buttons)) else: await message.reply("No Download Running!") @MediaCenterBot.on_callback_query(custom_filters.current_module('aria2') & custom_filters.callback_query('back', False)) async def aria_go_back_to_list(_, callback: CallbackQuery): await callback.answer("Going back...") buttons = get_buttons() if buttons: await callback.message.edit("Aria2c Active Downloads", reply_markup=InlineKeyboardMarkup(buttons)) else: await callback.message.edit("No Download Running!") # Command help section add_command_help( 'aria2c', [ ['/list', 'Lists all the running downloads on Aria2c'], ] )
from pyrogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup from mediacenter import MediaCenterBot from mediacenter.api_interfaces.aria2p import Aria2p from mediacenter.plugins.admin.help import add_command_help from mediacenter.utils import custom_filters @MediaCenterBot.on_message( custom_filters.current_module('aria2') & custom_filters.command("add")) async def aria_add_download(_, message: Message): link = message.command[1:] new_download = Aria2p().add_download(link) button = InlineKeyboardMarkup( [[InlineKeyboardButton("Show Details", f"show+{new_download.gid}")]]) await message.reply(f"Started download of '{new_download.name}'!", reply_markup=button) # Command help section add_command_help('aria2c', [ ['/add', 'Add a new download. Send link as argument.'], ])
if output == 'OK': await message.reply("Purged everything from Aria2c") else: await message.reply("Purge failed.") @MediaCenterBot.on_message( custom_filters.current_module('aria2') & custom_filters.command(["stats", "stat"])) async def aria_stats(_, message: Message): output = Aria2p().stats() ac = PrettyTable() ac.field_names = ['Aria2c', 'Stats'] ac.header = True ac.align = 'l' ac.add_row(["Active", output.num_active]) ac.add_row(["Waiting", output.num_waiting]) ac.add_row(["Stopped", output.num_stopped]) ac.add_row(["DL", output.download_speed_string()]) ac.add_row(["UL", output.upload_speed_string()]) await message.reply(f"```{str(ac)}```") # Command help section add_command_help('aria2c', [ ['/purge', 'Purge all inactive items from Aria2c'], ['/stats', 'Show quick overview of Aria2c'], ])
async def start(_, message: Message): await message.reply(f"Welcome to {MediaCenterBot}! I help you control your media center.") async def real_restart(bot, message: Message): await bot.restart() await message.reply("Restarted!") @MediaCenterBot.on_message(custom_filters.allowed_users & custom_filters.command("restart")) async def restart(bot: MediaCenterBot, message: Message): await message.reply(f"Restarting {MediaCenterBot}.") if 'p' in message.text and 'g' in message.text: asyncio.get_event_loop().create_task(bot.restart(git_update=True, pip=True)) elif 'p' in message.text: asyncio.get_event_loop().create_task(bot.restart(pip=True)) elif 'g' in message.text: asyncio.get_event_loop().create_task(bot.restart(git_update=True)) else: asyncio.get_event_loop().create_task(bot.restart()) # Command help section add_command_help( 'start', [ ['/start', 'This command just starts the {BOT_NAME}.. Nothing much..'], ['/restart', 'Restarts the {BOT_NAME}. Lots happens in the background when restarting.'] ] )
await message.delete() @MediaCenterBot.on_message(custom_filters.current_module('qbt') & custom_filters.command("add")) async def add_torrent(_, message: Message): try: torrent_link = message.command[1] added_torrent = QBT().add_torrent(torrent_link) if added_torrent == "Ok.": await message.reply(f"**Torrent Added Successfully! {emoji.PARTY_POPPER}**") else: await message.reply( f"Either that was an incorrect torrent link or you just sent some gibberish " f"{emoji.FACE_VOMITING} " f"Nothing I can do to fix that {emoji.MAN_SHRUGGING_MEDIUM_LIGHT_SKIN_TONE}" ) except IndexError: await message.reply("Please send a the link to the torrent after the command") # # Command help section add_command_help( 'qbittorrent', [ ['/list', 'Lists all the torrents in the client.'], ['/torrents', 'Sends torrent buttons to interact with each torrent.'], ['/add', 'Add a new torrent. Send link to torrent as argument..'], ], )