async def on_call(self, channel: channel, ctx: Context, bot: Bot, args: list, globals: list, plugins: Container) -> None: channel = ctx.channel if ctx.author not in admins: await channel.send( f"Sorry, you have no permission to execute this command") return try: if args[0] == 'help': helpdoc = HelpDoc(self.prefix) helpdoc.add('load <module_name>') helpdoc.add('unload <module_name>') helpdoc.add('post <channel_id> <information>') helpdoc.add('stop') helpdoc.add('plugins') await channel.send(str(helpdoc)) # elif args[0] == 'test': # await channel.send(f"ctx: {globals['raw_ctx'].author.id}") elif args[0] == 'post': if args[1] == 'help': await channel.send(f"`post <channel_id> <information>`") try: int(args[1]) if int(args[1]) != eval(args[1]): return except: return try: channel = bot.get_channel(int(args[1])) await channel.send(args[2]) except: pass elif args[0] == 'load': try: if len(args) != 2: await channel.send(f"`load <module_name>`") elif plugins.load(args[1]): await channel.send(f"Successfully loaded {args[1]}") else: await channel.send(f"Failed to load {args[1]}") except Exception as exc: await channel.send(f"Failed to load {args[1]} ({exc})") elif args[0] == 'unload': if len(args) != 2: await channel.send(f'`unload <module_name>`') elif args[1] not in plugins.list(): await channel.send(f'Module "{args[1]}" is not loaded') else: plugins.unload(args[1]) elif args[0] == 'plugins': await channel.send(plugins.info()) elif args[0] == 'stop': await channel.send(f"Server Manager is offline") sys.exit(0) except IndexError: pass
async def getChannel(bot: Bot, id): channel = bot.get_channel(id) if not channel: try: channel = await bot.fetch_channel(id) except discord.InvalidData: channel = None except discord.HTTPException: channel = None return channel
async def _write_to_channel(bot: Bot, channel_id: int = 0, message=None, channel_type: str = ""): """ Writes a message to a channel and logs the message :param bot: The bot :param channel_id: The channel ID of the channel to send a message to :param message: The message or embed to send :param channel_type: The channel type or name for the logging output """ channel = bot.get_channel(channel_id) if not Config( ).DEBUG_MODE and channel is not None and message is not None and message: if isinstance(message, discord.Embed): await channel.send(embed=message) else: await channel.send(message) log_msg = get_loggable_str(message) chan_logger.info(f"{channel_type} : {log_msg}")
async def write_debug_channel(bot:Bot, message): """Writes the given message to the bot's debug channel""" debug_chan = bot.get_channel(DEBUG_CHAN_ID) if(debug_chan != None): await debug_chan.send(message)