async def send_group_help(self, group: CustomCommand): embed = StyledEmbed(title='`' + group.qualified_name + '`') desc = "" if group.help: desc += group.help if group.usage: embed.add_field(name="**Usage**", value=f"`{prefix + group.usage}`", inline=False) if group.aliases and len(group.aliases) > 0: embed.add_field(name="**Aliases**", value=' '.join([f"`{prefix + alias}`" for alias in group.aliases]), inline=False) if hasattr(group, "available_args") and group.available_args: arg_builder = "" for typ in group.available_args: arg_builder += f"\n**{typ['type']}**" for arg in typ['args']: arg_builder += f"\n`{arg['name']}`\n***{arg['desc']}***" embed.add_field(name="**Arguments**", value=arg_builder) if hasattr(group, "examples") and group.examples: example_builder = "" for ex in group.examples: example_builder += f"\n`{ex['ex']}`\n{ex['desc']}" embed.add_field(name="**Examples**", value=example_builder) embed.description = desc await self.get_destination().send(embed=embed)
def get(self) -> Embed: embed = StyledEmbed(title="Search results (Page " + str(self.current_page + 1) + ")") description, count = get_song_selector_embed_desc_for_current_page( self.current_page, self.results) self.count = count embed.description = description return embed
def get_currently_playing_embed(current_track: Track, current_time=None): currently_playing_embed = StyledEmbed( title="<:music_note:718120922367787099> " + current_track.title) currently_playing_embed.set_author(name="Now playing", url=current_track.uri) if current_time: currently_playing_embed.description = get_song_progress_bar( current_time, current_track.duration) currently_playing_embed.add_field(name="Duration", value=get_friendly_time_delta( current_track.duration)) currently_playing_embed.add_field(name="Artist", value=current_track.author) if current_track.thumb is not None: currently_playing_embed.set_thumbnail(url=current_track.thumb) return currently_playing_embed
def get(self) -> Embed: embed = StyledEmbed( suppress_tips=True, title=self.title + " (Page " + str(self.current_page + 1) + "/" + str(math.ceil(len(self.contents) / self.show_per_page)) + ")") desc = "" count = 1 for track_index in range(len(self.contents)): try: track = self.contents[self.current_page * self.show_per_page + track_index] if count == self.show_per_page + 1: break desc += str(track) + "\n" count += 1 except IndexError: pass self.count = count embed.description = desc return embed
async def stats(self, ctx): """Shows useful information about the current node your chime player is connected to. Useful for troubleshooting.""" player = self.bot.wavelink.get_player(ctx.guild.id) node = player.node embed = StyledEmbed(title="chime stats") embed.description = f'Connected to {len(self.bot.wavelink.nodes)} node(s).\n' \ f'Best available node: **{self.bot.wavelink.get_best_node().__repr__()}**\n' embed.add_field(name="Stream count", value=f"{str(node.stats.playing_players)}") embed.add_field(name="Server Count", value=f"{len(self.bot.guilds)}") embed.add_field( name="Lavalink uptime", value= f"{str(datetime.timedelta(seconds=round(node.stats.uptime / 1000)))}" ) current_time = time.time() difference = int(round(current_time - self.bot.start_time)) timestamp = str(datetime.timedelta(seconds=difference)) embed.add_field(name="Bot uptime", value=f"{timestamp}") await ctx.send(embed=embed)
async def send_bot_help(self, mapping): embed = StyledEmbed(title='chime help') embed.set_thumbnail(url="https://raw.githubusercontent.com/realmayus/chime/master/assets/chime_banner.png?token=AJC6B5VTHEZ5UHNY7QNDCU263LCCK") embed.description = "chime is a versatile, yet intuitive music bot for discord. It aims to be as user-friendly as possible while still boasting many features. \n\n" \ "**More info and invite link [here](https://chime.realmayus.xyz)** \n\n" \ "Chime has a **web app** where you can manage and set up personal playlists and manage settings of your servers! https://chime.realmayus.xyz \n\n" \ "**Use** `" + self.clean_prefix + "help [command]` **for more info on a command.**" for cog, commands in mapping.items(): if cog is not None: # We don't want commands without categories! >:c name = cog.qualified_name filtered = await self.filter_commands(commands, sort=True) if filtered: builder = [] for command in commands: # filtering out hidden commands command: Command builder.append(f"`{prefix + command.name}`" if not command.hidden else "") value = ' '.join(builder) if cog and cog.description: value = '{0}\n{1}'.format(cog.description, value) embed.add_field(name=name, value=value) await self.get_destination().send(embed=embed)
async def on_command_error(self, ctx, error): """A local error handler for all errors arising from commands in this cog.""" if isinstance(error, commands.NoPrivateMessage): try: return await ctx.send(embed=StyledEmbed( description= "<:warning:746377344393936997> This command can't be executed in DMs.'" )) except discord.HTTPException: pass elif isinstance( error, discord.ext.commands.errors.CommandInvokeError) and isinstance( error.original, chime.misc.BadRequestException.BadRequestException): return await ctx.send(embed=StyledEmbed( description='<:warning:746377344393936997> ' + str(error.original.text))) elif isinstance(error, discord.ext.commands.errors.MissingRequiredArgument): return await ctx.send(embed=StyledEmbed( description='<:warning:746377344393936997> ' + str(error))) elif isinstance(error, discord.ext.commands.errors.BadArgument): return await ctx.send(embed=StyledEmbed( description='<:warning:746377344393936997> ' + str(error))) elif isinstance(error, discord.ext.commands.errors.CommandOnCooldown): return await ctx.send(embed=StyledEmbed( description='<:warning:746377344393936997> ' + str(error))) elif isinstance(error, discord.ext.commands.errors.CommandNotFound): return elif isinstance( error, discord.ext.commands.errors.CommandInvokeError) and isinstance( error.original, wavelink.errors.ZeroConnectedNodes): report_channel_ = await self.bot.fetch_channel(report_channel) error_embed = StyledEmbed( suppress_tips=True, title="<:warning:746377344393936997> Outage Report") error_embed.description = "Chime detected an outage:\n\n" + "```" + '\n'.join( [ line.strip('\n') for line in traceback.format_exception( type(error), error, error.__traceback__, limit=1) ]) + "```" error_embed.set_author(name="Automatic Outage Report") await report_channel_.send("<@&718113149651255386>", embed=error_embed) return await ctx.send(embed=StyledEmbed( description= '<:warning:746377344393936997> A critical outage has been detected and the developers **have been notified**. Sorry! You can get support here: \nhttps://discord.gg/DGd8T53' )) try: await ctx.send(embed=StyledEmbed( description= "<:warning:746377344393936997> Sorry, an unknown error occurred whilst executing this command. The error has been reported automatically. You can get support here: \nhttps://discord.gg/DGd8T53" )) except: pass print('Ignoring exception in command {}:'.format(ctx.command), file=sys.stderr) traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr) channel = await self.bot.fetch_channel(report_channel) error_embed = StyledEmbed( suppress_tips=True, title=f"<:warning:746377344393936997> `{type(error)}`") error_embed.set_author(name="Unhandled Error") # upload to hastebin key = json.loads( requests.post('https://hasteb.in/documents', data='Ignoring Exception in command ' + str(ctx.command) + ":\n\n" + '\n'.join([ line.strip('\n') for line in traceback.format_exception( type(error), error, error.__traceback__) ])).text)["key"] # send to auto-reports channel in chime lounge error_embed.description = f"chime witnessed an [unhandled exception](https://hasteb.in/{key}) whilst executing command `{ctx.command}`:\n\n```" + '\n'.join( [ line.strip('\n') for line in traceback.format_exception( type(error), error, error.__traceback__, limit=1) ]) + "```" await channel.send(embed=error_embed)
async def feedback(self, ctx): """Gives you options to send feedback or to report bugs.""" msg: Message = await ctx.send(embed=StyledEmbed( title="Feedback", description= "Thanks for helping to improve chime! What's the problem? \n \n " u"1\N{variation selector-16}\N{combining enclosing keycap}" + " I'd like to send feedback\n" u"2\N{variation selector-16}\N{combining enclosing keycap}" + " I'd like to report an outage\n" u"3\N{variation selector-16}\N{combining enclosing keycap}" + " I'd like to report a bug\n")) [ await msg.add_reaction( u"%s\N{variation selector-16}\N{combining enclosing keycap}" % str(x + 1)) for x in range(3) ] def check_reaction(reaction: RawReactionActionEvent): return reaction.member == ctx.author and isinstance( reaction.emoji.name, str) and ((reaction.emoji.name[0].isdigit() and int(str(reaction.emoji.name)[0]) in range(4)) and reaction.message_id == msg.id) try: reaction: RawReactionActionEvent = await self.bot.wait_for( 'raw_reaction_add', timeout=20.0, check=check_reaction) except asyncio.TimeoutError: """Handle Timeout""" else: if str(reaction.emoji.name[0]).isdigit() and int( str(reaction.emoji.name)[0]) in range(4): selected_number = int(str(reaction.emoji.name[0])) what_to_do = None if selected_number == 1: what_to_do = "Send Feedback" elif selected_number == 2: what_to_do = "Report Outage" elif selected_number == 3: what_to_do = "Report Bug" if selected_number == 2 or selected_number == 3: await msg.edit(embed=StyledEmbed( title=what_to_do, description= "Got it. Please describe the issue as precise as possible in your next message. Bonus points for steps to reproduce. Send `stop` to abort" )) await msg.clear_reactions() else: await msg.edit(embed=StyledEmbed( title=what_to_do, description= "Got it. Please describe your feedback in the next message you send. Send `stop` to abort" )) await msg.clear_reactions() try: description: Message = await self.bot.wait_for( 'message', timeout=60.0, check=lambda m: m.channel == ctx.channel and m.author == ctx.author) except asyncio.TimeoutError: await ctx.channel.send( "Aborting feedback wizard because no answer was sent.") else: if description.content == "stop": await ctx.send("Ok.") return if selected_number == 2 or selected_number == 3: if selected_number == 2: """Urgent issue""" captcha_solved = False while not captcha_solved: solution, file = self.get_captcha_file() embed: StyledEmbed = StyledEmbed( title="Please solve the captcha.", description= "Not case sensitive. To quit, enter `stop`, for a new captcha enter `new`" ) await ctx.send(file=file, embed=embed) try: captcha_sol: Message = await self.bot.wait_for( 'message', timeout=30.0, check=lambda ms: ms.channel == ctx. channel and ms.author == ctx.author) captcha_sol: str = captcha_sol.content except asyncio.TimeoutError: await ctx.channel.send( "Aborting feedback wizard because no captcha answer was sent." ) else: if captcha_sol.lower() == "stop": await ctx.send("Ok.") return if captcha_sol.lower().replace( "o", "0").replace("7", "1").replace( "8", "b") == solution.lower( ).replace("o", "0").replace( "7", "1").replace("8", "b"): captcha_solved = True report_channel_ = await self.bot.fetch_channel( report_channel) error_embed = StyledEmbed( suppress_tips=True, title=f"👥 Outage Report") error_embed.description = "A user has submitted an outage report:\n\n" + description.content error_embed.set_author(name="User Report") await report_channel_.send( "<@&718113149651255386>", embed=error_embed) await ctx.channel.send( "Thanks for the report and for making chime better! A developer will look into the issue as soon as possible." ) elif selected_number == 3: report_channel_ = await self.bot.fetch_channel( report_channel) error_embed = StyledEmbed( suppress_tips=True, title=f"👥 Bug Report") error_embed.description = "A user has submitted a bug report:\n\n" + description.content error_embed.set_author(name="User Report") await report_channel_.send(embed=error_embed) await ctx.channel.send( "Thanks for the report and for making chime better! A developer will look into the issue" + ("." if selected_number == 3 else " as soon as possible.")) elif selected_number == 1: report_channel_ = await self.bot.fetch_channel( report_channel) error_embed = StyledEmbed(suppress_tips=True, title=f"👥 Feedback") error_embed.description = "A user has submitted feedback:\n\n" + description.content error_embed.set_author(name="User Feedback") await report_channel_.send(embed=error_embed) await ctx.channel.send( "Thanks for the report and for making chime better! The feedback was sent to the developers." )