async def build_info_embed(ctx, bot): """ build the info embed :param ctx: the discord context object :param bot: the bot object :return: the info embed """ stats = generate_info(guilds=bot.servers, members=bot.get_all_members(), channels=bot.get_all_channels(), voice=bot.voice_clients, logged_in=bot.is_logged_in) user = bot.user lan = bot.localize(ctx) ram = stats['ram'] guild_count = comma(stats['guild_count']) user_count = comma(stats['user_count']) text_count = comma(stats['text_channel_count']) voice_count = comma(stats['voice_count']) if ram < 1024: ram_str = '{0:.2f}MB'.format(ram) else: ram_str = '{0:.2f}GB'.format(ram / 1024) total_ram = virtual_memory().total / 1024 / 1024 / 1024 total_ram_str = '{0:.2f}GB'.format(total_ram) embed = Embed(colour=bot.config['Bot']['colour']) embed.set_author(name=user.name, icon_url='{0.avatar_url}'.format(user)) embed.set_footer( text=lan['info_footer'].format(get_prefix(bot, ctx.message))) embed.add_field(name=lan['ram_used'] + '/' + lan['total_ram'], value=f'{ram_str}/{total_ram_str}') embed.add_field(name=lan['uptime'], value=get_uptime(bot.start_time, lan['days'])) embed.add_field(name=lan['python_ver'], value=platform.python_version()) embed.add_field(name=lan['lib'], value='Discord.py v{}.{}.{}'.format( version_info.major, version_info.minor, version_info.micro)) embed.add_field(name=lan['sys'], value=get_system_name()) devs = bot.config['Bot']['devs'] if devs: embed.add_field(name=lan['devs'], value='\n'.join(devs)) helpers = bot.config['Bot']['helpers'] if helpers: embed.add_field(name=lan['helper'], value='\n'.join(helpers)) embed.add_field(name=lan['guilds'], value=guild_count) embed.add_field(name=lan['users'], value=user_count) embed.add_field(name=lan['text_channels'], value=text_count) embed.add_field(name=lan['voice_channels'], value=voice_count) return embed
async def prefix(self, ctx): """ Show the prefix for the current server :param ctx: the discord context """ if ctx.invoked_subcommand is None: localize = self.bot.localize(ctx) await self.bot.say(localize['prefix'].format( get_prefix(self.bot, ctx.message), self.bot.default_prefix))
async def selfrole(self, ctx): """ Command group for selfrole :param ctx: the discord context """ if ctx.invoked_subcommand is None: localize = self.bot.localize(ctx) await self.bot.say(localize['selfrole_bad_command'].format( get_prefix(self.bot, ctx.message)))
async def language(self, ctx): """ Get the language of the server :param ctx: the discord context object """ if ctx.invoked_subcommand is None: localize = self.bot.localize(ctx) await self.bot.say(localize['language'].format( generate_language_entry(localize['language_data']), get_prefix(self.bot, ctx.message), self.bot.default_language))
async def p_reset(self, ctx): """ Reset the prefix of the server :param ctx: the discord context """ localize = self.bot.localize(ctx) await self.bot.data_manager.set_prefix(int(ctx.message.server.id), None) prefix = get_prefix(self.bot, ctx.message) await self.bot.say(localize['set_prefix'].format(prefix))
async def resume(self, ctx): """Resumes the currently played song.""" localize = self.bot.localize(ctx) state = self.get_voice_state(ctx.message.server) if state.is_playing(): player = state.player player.resume() await self.bot.say(localize['resume'].format(get_prefix(self.bot, ctx.message))) else: await self.bot.say(localize['no_play'])
async def process_commands(self, message): """ Overwrites the process_commands method to provide command black list support. Check :func:`Bot.process_commands` for more details. """ if message.author.bot: return prefix = get_prefix(self, message) name = message.content.split(' ')[0][len(prefix):] # TODO Implement command black list await super().process_commands(message)
async def __set_language(self, ctx, language): """ Helper method to set the language of a guild. :param ctx: the discord context. :param language: the language to set to. """ localize = self.bot.localize(ctx) if language not in self.bot.language: await self.bot.say(localize['lan_no_exist'].format( language, get_prefix(self.bot, ctx.message))) else: await self.bot.say(await set_language(self.bot, ctx, language))
async def fact(self, ctx): """ Command group for all the facts commands. If no subcommand is invoked the bot will say the list of subcommands. :param ctx: the discord context """ if ctx.invoked_subcommand is None: localize = self.bot.localize(ctx) await self.bot.say( localize['fact_list'].format( get_prefix(self.bot, ctx.message), '\n'.join(tuple(self.fact.commands.keys())) ) )
async def join(self, ctx): """Summons the bot to join your voice channel.""" localize = self.bot.localize(ctx) summoned_channel = ctx.message.author.voice_channel if summoned_channel is None: await self.bot.say(localize['no_voice']) state = self.get_voice_state(ctx.message.server) if state.voice is None: state.voice = await self.bot.join_voice_channel(summoned_channel) await self.bot.say(localize['music_join'].format(get_prefix( self.bot, ctx.message))) await state.wait_play() else: await self.bot.say(localize['music_already_joined'])
async def modlog(self, ctx): """ Command group for modlog, if no sub command is invoked, the bot will display a generic message stating the list of modlogs :param ctx: the discord context """ if ctx.invoked_subcommand is None: localize = self.bot.localize(ctx) modlog = await get_modlog(self.bot.data_manager, ctx.message.server) if modlog: await self.bot.say(localize['mod_log_channel'].format( modlog.name)) else: await self.bot.say(localize['mod_log_empty']) await self.bot.say(localize['mod_log_info'].format( get_prefix(self.bot, ctx.message)))
async def process_message(bot, message): """ Process the message recieved from Client.on_message :param bot: The bot instance. :param message: The message recieved. """ author = message.author content = message.content channel = message.channel prefix = get_prefix(bot, message) if (author.bot or content.startswith(prefix) or not isinstance(content, str) or not isinstance(channel, Messageable)): return prefix_msg = __for_prefix(bot, message, prefix, bot.default_prefix) if prefix_msg: await channel.send(prefix_msg)
def __init__(self, ctx, bot: Hifumi, args, api: Trivia): """ Initialize an instance of this class :param ctx: the discord context :param bot: the bot :param args: the args the user passed in from trivia command :param api: the trivia api """ self.api = api self.bot = bot self.ctx = ctx self.data_manager = bot.data_manager self.prefix = get_prefix(self.bot, self.ctx.message) self.args = args self.channel = ctx.message.channel self.author = ctx.message.author self.user_id = int(self.author.id) self.localize = bot.localize(ctx) self.bet = 0
async def queue(self, ctx, *, page=1): """Shows info about the currently played song. You can also search by pages. """ localize = self.bot.localize(ctx) state = self.get_voice_state(ctx.message.server) total_pages = int(len(state.playlist) / 20 + 1) if page < 1 or page > total_pages: await self.bot.say(localize['invalid_page']) elif not isinstance(page, int): await self.bot.say(localize['not_integer_page']) elif not state.playlist: await self.bot.say(localize['empty_queue']) else: temp = [] temp.append(localize['np'].format(state.playlist[0])) page_playlist = state.playlist[20*page-20:20*page] for index in range(len(page_playlist)): if page == 1 and index == 0: pass elif index == 21: break else: temp.append("{}. {}".format((int(20*page-20) + index + 1), page_playlist[index])) m, s = divmod(state.queuelength, 60) h, m = divmod(m, 60) temp.append('') temp.append(localize['total_duration'].format(str(h), str(m).zfill(2), str(s).zfill(2))) if total_pages == 1: temp.append(localize['page_list'].format(page, total_pages)) else: temp.append(localize['page_extended'].format(page, total_pages, get_prefix(self.bot, ctx.message))) await self.bot.say("\n".join(temp))
async def on_message(self, message): """ Events for reading messages :param message: the message """ prefix = get_prefix(self.bot, message) token = str(self.bot.config['Bot']['token']) if check_message_startwith(self.bot, message, '{}eval'.format(prefix)): localize = self.bot.localize(message) # FIXME Remove casting after lib rewrite if int(message.author.id) in self.bot.config['Bot']['owners']: args = clense_prefix(message, '{}eval'.format(prefix)) res, success = handle_eval(args) str_out = code_block(res, 'Python') header = localize['bash_success'] if success else localize[ 'bash_fail'] await self.bot.send_message(message.channel, header) for s in str_out: s = s.replace(token, localize['lewd_token']) await self.bot.send_message(message.channel, s) else: await self.bot.send_message(message.channel, localize['owner_only'])