async def hug(self, ctx: commands.Context, *, target: converters.I_MemberConverter): # Can't send a message to yourself. Acknowledge anyway. if target == ctx.bot.user: await ctx.message.add_reaction("💖") return if not await self._get_status(target): await ctx.send("That person doesn't want to be hugged.", delete_after=15) return # Get hug gif async with aiohttp.ClientSession() as cs: async with cs.get( "https://purrbot.site/api/img/sfw/hug/gif") as response: resp_json = await response.json() if not resp_json["error"]: hug_gif = resp_json["link"] else: await ctx.send("`[Error in Purrbot's servers: " f"'{resp_json['message']}'. Sorry!]`") return # Construct embed to send embed = util.Embed() embed.title = "A hug for you!" embed.description = f"[Where from?]({ctx.message.jump_url})" embed.set_footer(text=f"Sent by {ctx.author.display_name}", icon_url=ctx.author.avatar_url) embed.set_image(url=hug_gif) await target.send(embed=embed) await ctx.send("Hug on the way!", delete_after=10)
async def send_group_help(self, group): embed = util.Embed() embed.title = self.clean_prefix + group.qualified_name embed.description = group.help + "\n\n" + self.get_ending_note() group_commands = await self.filter_commands(group.commands, sort=True) pagify = False if len(group_commands) <= 10 else True if pagify: pages = math.ceil(len(group_commands) / COMMANDS_PER_PAGE) page_on = 1 for index, command in enumerate(group_commands): embed.add_field(name=command.name, value=command.short_doc, inline=False) if (len(embed.fields) == COMMANDS_PER_PAGE and index != len(group_commands) - 1): # If there's enough subcommands to get here, pagify is True. embed.set_footer(text="Page " + str(page_on) + " of " + str(pages)) await self.get_destination().send(embed=embed) embed.title = self.clean_prefix + group.qualified_name + " (cont.)" page_on += 1 embed.clear_fields() if pagify: embed.set_footer(text="Page " + str(page_on) + " of " + str(pages)) await self.get_destination().send(embed=embed) await self.context.message.add_reaction("👌")
async def send_bot_help(self, mapping): """Sends the help message for all available commands.""" all_commands = [] for cog in mapping: all_commands.extend(mapping[cog]) all_commands = await self.filter_commands(all_commands, sort=True) embed = util.Embed() embed.title = f"Commands for {self.context.bot.user.name}" embed.description = self.get_ending_note() pages = math.ceil(len(all_commands) / COMMANDS_PER_PAGE) page_on = 1 for index, command in enumerate(all_commands): embed.add_field(name=self.clean_prefix + command.name, value=command.short_doc, inline=False) if len(embed.fields ) == COMMANDS_PER_PAGE and index != len(all_commands) - 1: embed.set_footer(text="Page " + str(page_on) + " of " + str(pages)) await self.get_destination().send(embed=embed) embed.title = f"Commands for {self.context.bot.user.name} (cont.)" page_on += 1 embed.clear_fields() embed.set_footer(text="Page " + str(page_on) + " of " + str(pages)) await self.context.message.add_reaction("👌") await self.get_destination().send(embed=embed)
async def info(self, ctx, tagname): """Gets info about a tag.""" tag_tup = await self._find_tag_or_alias(ctx, tagname) if not tag_tup: await ctx.send("Couldn't find that tag.") else: embed = util.Embed() owner = ctx.guild.get_member(tag_tup[1]['owner']) if owner: embed.set_author(name=owner.display_name, icon_url=owner.avatar_url) else: default_avvie = 'https://cdn.discordapp.com/embed/avatars/0.png' embed.set_author(name="(User not in guild)", icon_url=default_avvie) embed.title = tag_tup[1]['name'] if tag_tup[0] == 'tag': embed.add_field(name="Tag ID", value=tag_tup[1]['tag_id']) embed.add_field(name="Tag Owner", value=f"<@{tag_tup[1]['owner']}>") embed.add_field(name="Uses", value=tag_tup[1]['uses']) embed.set_footer(text="Tag created on") embed.timestamp = tag_tup[1]['created_date'] else: embed.add_field(name="Alias Owner", value=f"<@{tag_tup[1]['owner']}>") tag = await self._find_tag(ctx, tagname) embed.add_field(name="Referenced tag", value=tag['name']) await ctx.send(embed=embed)
async def inventory(self, ctx): """Sends an embed with the available color list.""" member = ctx.author guild = ctx.guild pref = ctx.prefix guild_roles = await self._get_guild_roles(ctx.guild) color_roles = [] # Holds color roles member_rev_roles = member.roles member_rev_roles.reverse() # I think d.py has them low to high. # Get the user's role colors. for role in member_rev_roles: if role.id in guild_roles: # for color_role_id in guild_roles[role.id]: # color_role = guild.get_role(color_role_id) # color_roles.append(color_role) color_role = guild.get_role(guild_roles[role.id]) color_roles.append(color_role) # If there are roles, build and send the embed. if color_roles: embed = util.Embed() embed.set_author(name=member.display_name, icon_url=member.avatar_url) embed.title = "Equippable Color Inventory" embed.description = ( f"Equip a color role by using `{pref}equip role" + " name` without the 'Colors'. \n" + f"e.g. `{pref}equip Trusted`\n\n") embed.description += '\n'.join([r.mention for r in color_roles]) await ctx.send(embed=embed) # If not, tell the user. else: await ctx.send(f"{ctx.author.mention}, you don't have any colors" + " in your inventory!")
async def about(self, ctx): """Some general information about the bot.""" async def im_in_guild(ctx) -> bool: if ctx.guild is not None: return ctx.guild.get_member(530420116815478794) is not None else: return False embed = util.Embed() embed.set_author(name=ctx.bot.user.name, icon_url=ctx.bot.user.avatar_url) embed.title = "About This Bot" if await im_in_guild(ctx): author = "<@530420116815478794>" else: author = "richardfrost#5699" embed.add_field(name="Developer", value=author, inline=False) DISCORDPY_LINK = "[discord.py](https://discordpy.readthedocs.io/en/latest/index.html)" embed.add_field(name="Library", value=DISCORDPY_LINK + ' ' + discord.__version__, inline=False) embed.add_field(name="Code Repo", value='[Available here!](' + REPO_LINK + ')', inline=False) await ctx.send(embed=embed)
async def info(self, ctx, *, member: converters.I_MemberConverter = None): """Get information on a member.""" if member is None: member = ctx.author embed = util.Embed() if member.nick: embed.set_author(name=f"{member.display_name} ({member})", icon_url=member.avatar_url) else: embed.set_author(name=str(member), icon_url=member.avatar_url) embed.description = "(" + member.mention + ")" # Example: "Sun, 28 Mar 2021 18:54:22 UTC" embed.add_field(name="ID", value=member.id) embed.add_field(name="Joined", value=util.timestamp(member.joined_at)) # ^ member.joined_at can be None but this is so uncommon I'm ignoring. # if it causes problems I'll add an exception. embed.add_field(name="Account Created", value=util.timestamp(member.created_at)) if member.bot: embed.add_field( name="Bot Invite Link", value="[Invite Bot](" # more below f"{discord.utils.oauth_url(member.id, scopes=('bot', 'applications.commands'))})" ) await ctx.send(embed=embed)
async def top(self, ctx): """Gets the top used tags for the guild.""" tags = await self._get_top_tags(ctx) embed = util.Embed() embed.title = f"Top tags in {ctx.guild}" embed.description = '\n'.join( [f"{tag[0]+1} - {tag[1]['name']} (id: {tag[1]['tag_id']}) - {tag[1]['uses']} uses" for tag in enumerate(tags)] ) await ctx.send(embed=embed)
async def avatar(self, ctx): embed = util.Embed() postable = False if len(ctx.message.mentions) == 0: embed.title = f"{ctx.author.name}'s Avatar" embed.set_image(url=ctx.author.avatar_url_as(size=256)) postable = True elif len(ctx.message.mentions) == 1: embed.title = f"{ctx.message.mentions[0].name}'s Avatar" embed.set_image(url=ctx.message.mentions[0].avatar_url_as( size=256)) postable = True else: await ctx.send( f"{ctx.author.mention}, Slow down please! :sweat_smile: I can only handle one at a time." ) if postable: await ctx.send(embed=embed)
async def notepad_save(self, reaction, user): if str(reaction) != "🗒️": return else: msg = reaction.message embed = util.Embed() embed.set_author(name=msg.author.display_name, icon_url=msg.author.avatar_url) embed.description = msg.clean_content embed.timestamp = msg.created_at if msg.guild: embed.set_footer(text=f"From #{msg.channel} in {msg.guild}", icon_url=msg.guild.icon_url) else: embed.set_footer(text=f"From {msg.channel}", icon_url=msg.channel.recipient.avatar_url) embed.add_field(name="Jump to post", value=f"[Original Message]({msg.jump_url})") await user.send(embed=embed)
async def on_message(self, message: discord.Message): """Message preview""" if message.author == self.bot.user: return MESSAGE_RE = "https:\/\/discord(?:app)?.com\/channels\/(\d+|@me)\/(\d+)\/(\d+)" match = re.search(MESSAGE_RE, message.clean_content) if match: message_tup = match.groups() # guild, channel, message channel_id = int(message_tup[1]) channel = self.bot.get_channel(channel_id) if channel: # I have access to the channel try: lookup_msg = await channel.fetch_message( int(message_tup[2])) except discord.NotFound: print("Message not fetched: not found") return # Message not found except discord.Forbidden: print("Message not fetched: forbidden") return # Not allowed. Might not be able to see it. except discord.HTTPException: print("Message not fetched: httpexception") return # Something else went wrong. # At this point lets assume we got the message and we're # home free. preview = util.Embed() # preview.title = "Preview" # preview.url = lookup_msg.jump_url preview.set_author(name=lookup_msg.author.display_name, icon_url=lookup_msg.author.avatar_url) preview.description = lookup_msg.clean_content preview.timestamp = lookup_msg.created_at if lookup_msg.guild: preview.set_footer( text=f"From #{channel} in {channel.guild}", icon_url=lookup_msg.guild.icon_url) else: preview.set_footer(text=f"From {channel}", icon_url=channel.recipient.avatar_url) await message.channel.send(embed=preview)
async def send_command_help(self, command: commands.Command): try: if await command.can_run(ctx=self.context): embed = util.Embed() embed.title = self.clean_prefix + command.qualified_name embed.description = command.help if command.cog_name: embed.add_field(name="Category", value=command.cog_name, inline=False) if command.usage: embed.add_field(name="Usage", value=self.clean_prefix + command.qualified_name + ' ' + command.usage, inline=False) else: embed.add_field(name="Usage", value=self.clean_prefix + command.qualified_name) if command.aliases: embed.add_field(name="Aliases", value=", ".join(command.aliases), inline=False) if command.description: embed.set_footer(text=command.description) await self.get_destination().send(embed=embed) else: await self.get_destination().send( "You can't run this command here.\n", "If this is in error, try running this" + " from a place where you can use it.") except commands.NotOwner: await self.get_destination().send( self.command_not_found(command.name)) except commands.CheckFailure: await self.get_destination().send( "You can't run this command here.")
async def send_cog_help(self, cog: commands.Cog): embed = util.Embed() embed.title = cog.qualified_name + " Commands" embed.description = self.get_ending_note() cog_commands = await self.filter_commands(cog.get_commands(), sort=True) pages = math.ceil(len(cog_commands) / COMMANDS_PER_PAGE) page_on = 1 for index, command in enumerate(cog_commands): embed.add_field(name=self.clean_prefix + command.name, value=command.short_doc, inline=False) if len(embed.fields ) == COMMANDS_PER_PAGE and index != len(cog_commands) - 1: embed.set_footer(text="Page " + str(page_on) + " of " + str(pages)) await self.get_destination().send(embed=embed) embed.title = cog.qualified_name + " Commands (cont.)" page_on += 1 embed.clear_fields() embed.set_footer(text="Page " + str(page_on) + " of " + str(pages)) await self.get_destination().send(embed=embed) await self.context.message.add_reaction("👌")
if color == None: color = random.randint(0, 360) # Open in Pillow. try: img = Image.open(img_in) except: await ctx.send("I can't open that file! I need an image.") return img = set_hue(img, color) # Now save it and ship it out! img_file = io.BytesIO() img.save(img_file, format="PNG") img_file.seek(0) file = discord.File(img_file, filename="colorize.png") # await ctx.send(f"Hue: {color}",file=file) embed = util.Embed() embed.set_image(url="attachment://colorize.png") embed.set_footer(text=f"Hue: {color}") await ctx.send(embed=embed, file=file) @commands.command(brief="Color shifts all hues", help="Colorizes an image. Colors go up to 360.\n" + "Shifts all the hues!\n" + "Gifs are not supported. Default is your avatar.", usage="[@user|url|attachment] [spin value]", description="Code by unutbu") async def colorme(self, ctx, *, msg=""): url_regex = "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" color_rot = None # Get image URL to colorize. img_in = io.BytesIO()