async def permissions(self, ctx, member: typing.Optional[discord.Member] = None, channel: typing.Union[discord.VoiceChannel, discord.TextChannel] = None): """Get a member's permissions in a channel Format like this: `<prefix> permissions (OPTIONAL)<@mention member> (OPTIONAL)<text OR voice channel>` If you don't put a member, I'll use you. If you don't put a channel, I'll use the channel the command was performed in ~~RIP mobile users~~ """ await ctx.channel.trigger_typing() if member is None: member = ctx.author if channel is None: channel = ctx.channel perms = dict(iter(member.permissions_in(channel))) if isinstance(channel, discord.TextChannel): embed = discord.Embed( description= f"**Permissions for {member.mention} in {channel.mention}**", color=find_color(ctx)) for i in [ _p for _p, _v in dict(iter( discord.Permissions.voice())).items() if _v ]: perms.pop(i, None) elif isinstance(channel, discord.VoiceChannel): embed = discord.Embed( description= f"**Permissions for {member.mention} in \U0001f509{channel.name}**", color=find_color(ctx)) for i in [ _p for _p, _v in dict(iter( discord.Permissions.text())).items() if _v ]: perms.pop(i, None) for p, v in perms.items(): if v: embed.add_field(name=p.replace("_", " ").replace( "guild", "server").replace("activation", "activity").title().replace( "Tts", "TTS"), value="\U00002705") else: embed.add_field(name=p.replace("_", " ").replace( "guild", "server").replace("activation", "activity").title().replace( "Tts", "TTS"), value="\U0000274c") await ctx.send(embed=embed)
async def rule34(self, ctx, *, tag: str=None): """Posts some Rule 34 Format like this: `<prefix> rule34 (OPTIONAL)<tag>` If you don't include a specific tag to search for, I'll just send a random rule 34 pic """ await ctx.channel.trigger_typing() if tag is None: return await get_reddit(ctx, 1, 100, True, False, "a post", "rule34") else: tag = tag.lower().replace(" ", "_") try: async with self.bot.session.get("https://rule34.xxx/index.php?page=dapi&s=post&q=" f"index&json=1&tags={tag}") as w: resp = json.loads(await w.text()) for p in resp.copy(): if "loli" in p["tags"] or "shota" in p["tags"]: resp.remove(p) data = random.choice(resp) embed = discord.Embed( title=tag, description=f"By [{data['owner']}](https://rule34.xxx/index.php?page=account" f"&s=profile&uname={data['owner']})", color=find_color(ctx)) embed.set_image( url=f"https://img.rule34.xxx/images/{data['directory']}/{data['image']}") embed.set_footer(text=f"rule34 | {ctx.author.display_name}") await ctx.send(embed=embed) except (json.JSONDecodeError, IndexError): await ctx.send(f"No images were found for the `{tag}` tag", delete_after=5.0) return await delete_message(ctx, 5)
async def ass(self, ctx): """Posts some ass""" try: with ctx.channel.typing(): async with self.bot.session.get( f"http://api.obutts.ru/butts/get/{random.randint(7, 5999)}") as w: resp = await w.json() try: resp = resp[0] except: pass url = "http://media.obutts.ru/" + resp["preview"] if resp["model"] is None or resp["model"] == "": model = "" else: model = "**Model**: " + resp["model"] embed = discord.Embed(color=find_color(ctx), description=model) embed.set_image(url=url) embed.set_footer(text=f"ass | {ctx.author.display_name}") await ctx.send(embed=embed) except: await ctx.send("Huh, something went wrong. I wasn't able to get the image. Try " "again later", delete_after=5.0) return await delete_message(ctx, 5)
async def captionbot(self, ctx, member_url: typing.Union[discord.Member, str] = None): """The CaptionBot AI will attempt to understand the content of an image and describe it""" with ctx.channel.typing(): img = await self.get_image(ctx, member_url) headers = {"Content-Type": "application/json; charset=utf-8"} payload = {"Content": img, "Type": "CaptionRequest"} try: async with self.bot.session.post( "https://captionbot.azurewebsites.net/api/messages", headers=headers, json=payload) as w: caption = await w.text() embed = discord.Embed( title=str(caption), description= "*Powered by [CaptionBot](https://www.captionbot.ai/)*", color=find_color(ctx)) embed.set_image(url=img) msg = await ctx.send(embed=embed) await msg.add_reaction("\U00002705") await msg.add_reaction("\U0000274c") await msg.add_reaction("\U0001f602") except: await ctx.send( "Huh, something went wrong. I wasn't able to get the data. Try " "again later", delete_after=5.0) return await delete_message(ctx, 5)
async def allchannels(self, ctx): """Sends a list of all the channels in the server""" await ctx.channel.trigger_typing() tchannels = ctx.guild.text_channels vchannels = ctx.guild.voice_channels embed = discord.Embed( title=f"All of the channels in {ctx.guild.name}", description=f"Command performed by {ctx.author.mention}", color=find_color(ctx)) embed.set_thumbnail(url=ctx.guild.icon_url) embed.set_footer( text="To get information on these channels, use the \"channelinfo\" " "command and I'll provide some basic info on it as long as I have " "access to the channel") embed.add_field(name=f"Text Channels ({len(tchannels)})", value=", ".join(c.mention for c in tchannels), inline=False) if vchannels: embed.add_field(name=f"Voice Channels ({len(vchannels)})", value=", ".join(f"\U0001f509{c.name}" for c in vchannels), inline=False) else: embed.add_field(name=f"Voice Channels ({len(vchannels)})", value="None", inline=False) await ctx.send(embed=embed)
async def speedtest_(self, ctx): """Test the current ping, download, and upload speeds of MY Wi-Fi network""" tester = speedtest.Speedtest() temp = await ctx.send("Retrieving speedtest.net server list...") with ctx.channel.typing(): await self.bot.loop.run_in_executor(None, tester.get_servers) await asyncio.sleep(1) await temp.edit(content="Retrieving speedtest.net server list... " "Selecting best server based on ping...") await self.bot.loop.run_in_executor(None, tester.get_best_server) await asyncio.sleep(1) await temp.edit(content="Testing download speed... Please wait...") await self.bot.loop.run_in_executor(None, tester.download) await temp.edit(content="Testing upload speed... Please wait...") await self.bot.loop.run_in_executor(None, tester.upload) await self.bot.loop.run_in_executor(None, tester.results.share) await temp.delete() embed = discord.Embed(title="Speedtest Results of MAT's Wi-Fi Network", color=find_color(ctx)) embed.set_image(url=tester.results.dict()["share"]) embed.set_footer(text=f"Test performed by {ctx.author.display_name}", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed)
async def about(self, ctx): """About me!""" app = await self.bot.application_info() embed = discord.Embed(title=str(self.bot.user), description=app.description + f"\n\n**User/Client ID**: {app.id}", color=find_color(ctx)) embed.set_thumbnail(url=app.icon_url) embed.add_field(name="Version", value=self.bot.__version__) embed.add_field(name="Author", value=app.owner) embed.add_field(name="Server Count", value=len(self.bot.guilds)) embed.add_field( name="Language", value= f"Python {sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}" ) embed.add_field( name="Library", value="[discord.py](https://github.com/Rapptz/discord.py)") embed.add_field( name="License", value="[GPL v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html)") embed.add_field(name="Github Repo", value="https://github.com/NinjaSnail1080/MATs-Bot", inline=False) embed.set_footer( text=f"Dedicated to {self.bot.get_user(422131370010214402)}") await ctx.send(embed=embed)
async def yandere(self, ctx, *, tag: str): """Searches yande.re for a tag Format like this: `<prefix> yandere <tag>` """ await ctx.channel.trigger_typing() async with self.bot.session.get(f"https://yande.re/post.json?limit=100&tags={tag}") as w: resp = await w.json() if resp: for p in resp.copy(): if "loli" in p["tags"] or "shota" in p["tags"]: resp.remove(p) try: data = random.choice(resp) except IndexError: await ctx.send(f"No posts were found for the `{tag}` tag", delete_after=5.0) return await delete_message(ctx, 5) embed = discord.Embed( title=f"#{data['id']} | " + data["tags"], description=f"By [{data['author']}](https://yande.re/user/show/" f"{data['creator_id']})", url=f"https://yande.re/post/show/{data['id']}", color=find_color(ctx)) embed.set_image(url=data["jpeg_url"]) embed.set_footer(text=f"yandere | {ctx.author.display_name}") await ctx.send(embed=embed) else: await ctx.send(f"No posts were found for the `{tag}` tag", delete_after=5.0) return await delete_message(ctx, 5)
async def roleinfo(self, ctx, *, role: discord.Role = None): """Info about a role on this server. Format like this: `<prefix> roleinfo <role name>` Note: Role name is case-sensitive """ await ctx.channel.trigger_typing() if role is None: await ctx.send( "You need to include the name of a role after the command so I can get info on " f"it, like this:\n`{ctx.prefix}roleinfo <role name>`\nNote: Role name is " "case-sensitive", delete_after=9.0) return await delete_message(ctx, 9) embed = discord.Embed(color=find_color(ctx)) embed.add_field(name="Role", value=role.mention) embed.add_field(name="ID", value=role.id) embed.add_field(name="Color", value=role.color) if role.managed: embed.add_field(name="Managed by Integration?", value="Yes") else: embed.add_field(name="Managed by Integration?", value="No") if role.hoist: embed.add_field(name="Displays Separately?", value="Yes") else: embed.add_field(name="Displays Separately?", value="No") if role.mentionable: embed.add_field(name="Mentionable?", value="Yes") else: embed.add_field(name="Mentionable?", value="No") embed.add_field(name="Position", value=role.position) embed.add_field( name="Members With Role", value=f"{len(role.members)} out of {ctx.guild.member_count}") embed.add_field(name="Created", value=role.created_at.strftime("%b %-d, %Y")) perms = "`, `".join([ p.replace("_", " ").replace("guild", "server").replace( "activation", "activity").capitalize().replace("Tts", "TTS") for p, v in dict(iter(role.permissions)).items() if v ]) if perms == "": embed.add_field(name="Permissions", value="`None`", inline=False) else: embed.add_field(name="Permissions", value=f"`{perms}`", inline=False) await ctx.send(embed=embed)
async def allroles(self, ctx): """Sends a list of all the roles in the server""" await ctx.channel.trigger_typing() embed = discord.Embed( title=f"All of the roles in {ctx.guild.name}", description=f"Command performed by {ctx.author.mention}", color=find_color(ctx)) embed.set_thumbnail(url=ctx.guild.icon_url) embed.add_field(name=f"Roles ({len(ctx.guild.roles)})", value=", ".join(r.mention for r in ctx.guild.roles[::-1]), inline=False) await ctx.send(embed=embed)
async def allbanned(self, ctx): """Sends a list of all the banned users from the server""" await ctx.channel.trigger_typing() banned = await ctx.guild.bans() if len(banned) == 0: return await ctx.send("This server hasn't banned any users yet") embed = discord.Embed( title=f"All users banned from {ctx.guild.name}", description=f"Command performed by {ctx.author.mention}", color=find_color(ctx)) embed.set_thumbnail(url=ctx.guild.icon_url) embed.add_field(name=f"Banned ({len(banned)})", value="\n".join( str(b.user) + f" (ID: {b.user.id})" for b in banned), inline=False) await ctx.send(embed=embed)
async def emojiinfo(self, ctx, emoji: discord.Emoji = None): """Info about an emoji. Only works with custom emojis. Format like this: `<prefix> emojiinfo <emoji>` """ if emoji is None: await ctx.send( "You need to include an emoji after the command. Keep in mind that it " "only works with custom emojis.", delete_after=7.0) return await delete_message(ctx, 7) await ctx.channel.trigger_typing() emoji = await ctx.guild.fetch_emoji(emoji.id) #* To gain access to the "user" attribute embed = discord.Embed(title=f"Info On The {emoji} Emoji", color=find_color(ctx)) embed.set_thumbnail(url=emoji.url) embed.add_field(name="Name", value=emoji.name) embed.add_field(name="ID", value=emoji.id) if emoji.require_colons: embed.add_field(name="Requires Colons?", value="Yes") else: embed.add_field(name="Requires Colons?", value="No") if emoji.animated: embed.add_field(name="Animated?", value="Yes") else: embed.add_field(name="Animated?", value="No") if emoji.managed: embed.add_field(name="Managed By Integration?", value="Yes") else: embed.add_field(name="Managed By Integration?", value="No") embed.add_field(name="Created On", value=emoji.created_at.strftime("%b %-d, %Y")) embed.add_field( name="Created By", value=f"{emoji.user.mention} (User ID: {emoji.user.id})", inline=False) await ctx.send(embed=embed)
async def neko(self, ctx): """Posts some lewd nekos if used in an NSFW channel, or nonlewd nekos if used in a regular channel.""" await ctx.channel.trigger_typing() if ctx.channel.is_nsfw(): url = "https://nekos.life/api/lewd/neko" else: url = "https://nekos.life/api/neko" try: async with self.bot.session.get(url) as w: resp = await w.json() embed = discord.Embed(color=find_color(ctx)) embed.set_image(url=resp["neko"]) embed.set_footer(text=f"neko | {ctx.author.display_name}") await ctx.send(embed=embed) except: await ctx.send("Huh, something went wrong. I wasn't able to get the image. Try " "again later", delete_after=5.0) return await delete_message(ctx, 5)
async def stats(self, ctx): """See some of my stats""" await ctx.channel.trigger_typing() cmds_used = self.bot.commands_used.most_common(11)[1:] embed = discord.Embed(description=f"User ID: {self.bot.user.id}", timestamp=datetime.datetime.utcnow(), color=find_color(ctx)) embed.add_field(name="Server Count", value=f"{len(self.bot.guilds):,} servers") embed.add_field(name="User Count", value=f"{len(self.bot.users):,} unique users") embed.add_field( name="Channel Count", value= f"{len(list(self.bot.get_all_channels()) + self.bot.private_channels):,} " "channels") embed.add_field( name="Memory Usage", value=f"{round(self.bot.process.memory_info().rss / 1000000, 2)} MB" ) embed.add_field(name="Total Messages Read", value=f"{self.bot.messages_read['TOTAL']:,}") embed.add_field(name="Total Commands Used", value=f"{self.bot.commands_used['TOTAL']:,}") embed.add_field( name="Most Popular Commands", value="\n".join( f"**{cmds_used.index(c) + 1}**. `{c[0]}` ({c[1]} total uses)" for c in cmds_used), inline=False) embed.set_author(name="MAT's Bot: Statistics", icon_url=self.bot.user.avatar_url) embed.set_footer(text="These statistics are accurate as of:") await ctx.send(embed=embed)
async def userinfo(self, ctx, user: discord.Member = None): """Info about a user. By default I'll show your user info, but you can specify a different member of your server. Format like this: `<prefix> userinfo (OPTIONAL)<@mention user>` """ await ctx.channel.trigger_typing() if user is None: user = ctx.author roles = [f"`{r.name}`" for r in user.roles if r.name != "@everyone"][::-1] if user.activity is not None: if user.activity.type is discord.ActivityType.listening: _type = "Listening to" activity = user.activity.title elif user.activity.type is discord.ActivityType.streaming: _type = "Streaming" activity = user.activity.name elif user.activity.type is discord.ActivityType.watching: _type = "Watching" activity = user.activity.name else: _type = "Playing" activity = user.activity.name else: _type = "Playing" activity = "Nothing" if user.status is discord.Status.online: status = "https://i.imgur.com/WcPjzNt.png" elif user.status is discord.Status.idle: status = "https://i.imgur.com/UdRIQ2S.png" elif user.status is discord.Status.dnd: status = "https://i.imgur.com/voWO5qd.png" else: status = "https://i.imgur.com/8OOawcF.png" embed = discord.Embed(description=f"User ID: {user.id}", color=find_color(ctx)) embed.set_author(name=str(user), icon_url=status) embed.set_thumbnail(url=user.avatar_url) embed.add_field(name="Display Name", value=user.display_name) embed.add_field(name="Status", value=str(user.status).replace( "dnd", "do not disturb").title()) if user.mobile_status is not discord.Status.offline or user.is_on_mobile( ): embed.add_field(name="Platform", value="Mobile") elif user.desktop_status is not discord.Status.offline: embed.add_field(name="Platform", value="Desktop") elif user.web_status is not discord.Status.offline: embed.add_field(name="Platform", value="Web") else: embed.add_field(name="Platform", value="None") embed.add_field(name=_type, value=activity) embed.add_field(name="Color", value=str(user.color)) if user.voice is not None: embed.add_field(name="Voice Channel", value="\U0001f509" + user.voice.channel.name) if user.voice.mute or user.voice.self_mute: embed.add_field(name="Muted?", value="Yes") else: embed.add_field(name="Muted?", value="No") if user.voice.deaf or user.voice.self_deaf: embed.add_field(name="Deafened?", value="Yes") else: embed.add_field(name="Deafened?", value="No") else: embed.add_field(name="Voice Channel", value="None") if user.top_role is ctx.guild.default_role: embed.add_field(name="Top Role", value=user.top_role.name) else: embed.add_field(name="Top Role", value=user.top_role.mention) embed.add_field(name="Joined Server", value=user.joined_at.strftime("%b %-d, %Y")) if user.bot: embed.add_field(name="Bot?", value="Yes") else: embed.add_field(name="Bot?", value="No") embed.add_field(name="Joined Discord", value=user.created_at.strftime("%b %-d, %Y")) if roles: embed.add_field(name=f"Roles ({len(roles)})", value=", ".join(roles), inline=False) else: embed.add_field(name="Roles", value="`No roles`") if user.id in self.bot.userdata: if self.bot.userdata[user.id]["commands_used"]: cmds_used = collections.Counter(self.bot.userdata[ user.id]["commands_used"]).most_common(11)[1:] total = self.bot.userdata[user.id]["commands_used"]["TOTAL"] list_cmds_used = list( f"**{cmds_used.index(c) + 1}**. `{c[0]}` ({c[1]} uses)" for c in cmds_used) embed.add_field(name="Most Used Commands", value=f"__**Total**__: {total:,} uses\n" + "\n".join(list_cmds_used), inline=False) delta = datetime.datetime.utcnow() - user.created_at y = int(delta.total_seconds() ) // 31557600 #* Number of seconds in 365.25 days mo = int(delta.total_seconds() ) // 2592000 % 12 #* Number of seconds in 30 days d = int( delta.total_seconds()) // 86400 % 30 #* Number of seconds in 1 day h = int( delta.total_seconds()) // 3600 % 24 #* Number of seconds in 1 hour mi = int(delta.total_seconds()) // 60 % 60 #* etc. se = int(delta.total_seconds()) % 60 footer = [] if y != 0: footer.append(f"{y} {'year' if y == 1 else 'years'}, ") if mo != 0: footer.append(f"{mo} {'month' if mo == 1 else 'months'}, ") if d != 0: footer.append(f"{d} {'day' if d == 1 else 'days'}, ") if h != 0: footer.append(f"{h} {'hour' if h == 1 else 'hours'}, ") if mi != 0: footer.append(f"{mi} {'minute' if mi == 1 else 'minutes'}, ") footer.append(f"and {se} {'second' if se == 1 else 'seconds'}.") embed.set_footer(text=user.name + " has been on Discord for roughly " + "".join(footer)) if user.premium_since is not None: await ctx.send( content="\U0001f537 This member is a Nitro server booster since " f"{user.premium_since.strftime('%b %-d, %Y')}!", embed=embed) else: await ctx.send(embed=embed)
async def help(self, ctx, cat=None): """MAT's Bot | Help command""" await ctx.channel.trigger_typing() if ctx.guild is not None: disabled = self.bot.guilddata[ctx.guild.id]["disabled"] else: disabled = [] cog_cmds = collections.Counter() for c in self.bot.commands: if not c.hidden and c.name not in disabled: cog_cmds[c.cog_name] += 1 if cat is None: embed = discord.Embed(title="MAT's Bot | Help command", description=self.show_info(ctx, True) + "\n\n__**Categories**__:", color=find_color(ctx)) embed.add_field(name="<:confetti:464831811558572035> Fun", value=f"{cog_cmds['Fun']} " "commands\n`<prefix> help fun` for more info") embed.add_field( name="<:paint:464836778000515072> Image Manipulation", value= f"{cog_cmds['Image']} commands\n`<prefix> help image` for more info" ) embed.add_field(name="<:info:540301057264189453> Info", value=f"{cog_cmds['Info']} commands" "\n`<prefix> help info` for more info") embed.add_field( name="<:raisedfist:470319397291163678> Moderation", value= f"{cog_cmds['Moderation']} commands\n`<prefix> help mod` for more info" ) embed.add_field( name=":musical_note: Music", value=f"{cog_cmds['Music']} commands\n`<prefix> help " "music` for more info") embed.add_field( name=":wink: NSFW", value=f"{cog_cmds['NSFW']} commands\n`<prefix> help nsfw` " "for more info") embed.add_field(name=":tools: Utility", value=f"{cog_cmds['Utility']} commands\n`<prefix> " "help utility` for more info") if disabled: embed.add_field(name=":no_entry_sign: Disabled Commands", value=f"`{'`, `'.join(disabled)}`", inline=False) embed.set_footer( text="Do \"<prefix> help all\" for a list of all of my commands" ) await ctx.send(embed=embed) elif cat.lower() == "economy": await ctx.send("No commands yet ¯\_(ツ)_/¯") elif cat.lower() == "fun": cmds = sorted(list(c for c in self.bot.commands if c.cog_name == "Fun" and not c.hidden and c.name not in disabled), key=lambda c: c.name) if not cmds: embed = discord.Embed( title="Help | Fun Commands", description=self.show_info(ctx) + "\n\n**All " "commands in this category have been disabled for this server by one of its " "Administrators**", color=find_color(ctx)) embed.set_author(name="MAT's Bot") return await ctx.send(embed=embed) cmds = list(chunks(cmds, 8)) embeds = [] for i in cmds: embed = discord.Embed( title="Help | Fun Commands", description=f"**__Page {cmds.index(i) + 1}/{len(cmds)}__** " f"({cog_cmds['Fun']} commands)\n\n" + self.show_info(ctx), color=find_color(ctx)) embed.set_author(name="MAT's Bot") if len(cmds) > 1: embed.set_footer( text= f"Click one of the emojis below to go to the next page or the " "previous one. This help message will be automatically deleted if it's " "left idle for longer than 5 minutes") for c in i: embed.add_field(name=c.name, value=c.help, inline=False) embeds.append(embed) return await send_basic_paginator(ctx, embeds, 5) elif cat.lower() == "image": cmds = sorted(list(c for c in self.bot.commands if c.cog_name == "Image" and not c.hidden and c.name not in disabled), key=lambda c: c.name) if not cmds: embed = discord.Embed( title="Help | Image Manipulation Commands", description=self.show_info(ctx) + "\n\n**All commands in this category " "have been disabled for this server by one of its Administrators**", color=find_color(ctx)) embed.set_author(name="MAT's Bot") return await ctx.send(embed=embed) cmds = list(chunks(cmds, 8)) embeds = [] for i in cmds: embed = discord.Embed( title="Help | Image Manipulation Commands", description=f"**__Page {cmds.index(i) + 1}/{len(cmds)}__** " f"({cog_cmds['Image']} commands)\n\n" + self.show_info(ctx) + "\n\n**For all " "of these commands you need to either attach an image, insert an image url, " "or @mention another user after the command to use their avatar. If you " "don't put anything, I'll search the previous 10 messages for an image and " "use it if I find one. If I don't, I'll just default to your user's avatar**", color=find_color(ctx)) embed.set_author(name="MAT's Bot") if len(cmds) > 1: embed.set_footer( text= f"Click one of the emojis below to go to the next page or the " "previous one. This help message will be automatically deleted if it's " "left idle for longer than 5 minutes") for c in i: embed.add_field(name=c.name, value=c.help, inline=False) embeds.append(embed) return await send_basic_paginator(ctx, embeds, 5) elif cat.lower() == "info" or cat.lower() == "information": cmds = sorted(list(c for c in self.bot.commands if c.cog_name == "Info" and not c.hidden and c.name not in disabled), key=lambda c: c.name) if not cmds: embed = discord.Embed( title="Help | Information Commands", description=self.show_info(ctx) + "\n\n**All commands in this category have been disabled for this server by " "one of its Administrators**", color=find_color(ctx)) embed.set_author(name="MAT's Bot") return await ctx.send(embed=embed) cmds = list(chunks(cmds, 7)) embeds = [] for i in cmds: embed = discord.Embed( title="Help | Information Commands", description=f"**__Page {cmds.index(i) + 1}/{len(cmds)}__** " f"({cog_cmds['Info']} commands)\n\n" + self.show_info(ctx), color=find_color(ctx)) embed.set_author(name="MAT's Bot") if len(cmds) > 1: embed.set_footer( text= f"Click one of the emojis below to go to the next page or the " "previous one. This help message will be automatically deleted if it's " "left idle for longer than 5 minutes") for c in i: embed.add_field(name=c.name, value=c.help, inline=False) embeds.append(embed) return await send_basic_paginator(ctx, embeds, 5) elif cat.lower() == "mod" or cat.lower() == "moderation": cmds = sorted(list(c for c in self.bot.commands if c.cog_name == "Moderation" and not c.hidden and c.name not in disabled), key=lambda c: c.name) cmds = list(chunks(cmds, 4)) embeds = [] for i in cmds: embed = discord.Embed( title="Help | Moderation Commands", description=f"**__Page {cmds.index(i) + 1}/{len(cmds)}__** " f"({cog_cmds['Moderation']} commands)\n\n" + self.show_info(ctx), color=find_color(ctx)) embed.set_author(name="MAT's Bot") if len(cmds) > 1: embed.set_footer( text= f"Click one of the emojis below to go to the next page or the " "previous one. This help message will be automatically deleted if it's " "left idle for longer than 5 minutes") for c in i: embed.add_field(name=c.name, value=c.help, inline=False) embeds.append(embed) return await send_basic_paginator(ctx, embeds, 5) elif cat.lower() == "music": cmds = sorted(list(c for c in self.bot.commands if c.cog_name == "Music" and not c.hidden and c.name not in disabled), key=lambda c: c.name) cmds = list(chunks(cmds, 6)) embeds = [] for i in cmds: embed = discord.Embed( title="Help | Music Commands", description=f"**__Page {cmds.index(i) + 1}/{len(cmds)}__** " f"({cog_cmds['Music']} commands)\n\n" + self.show_info(ctx) + "\n" "\n**For all the commands labled `DJ`, you must have either the " "\"Manage Messages\" perm or the DJ Role (see the `musicsettings` " "command for more info) to use it. Also note that the `ytsearch` " "and `soundcloud` commands from the Utility category might come " "in handy here**", color=find_color(ctx)) embed.set_author(name="MAT's Bot") if len(cmds) > 1: embed.set_footer( text= f"Click one of the emojis below to go to the next page or the " "previous one. This help message will be automatically deleted if it's " "left idle for longer than 5 minutes") for c in i: embed.add_field(name=c.name, value=c.help, inline=False) embeds.append(embed) return await send_basic_paginator(ctx, embeds, 5) elif cat.lower() == "utility": cmds = sorted(list(c for c in self.bot.commands if c.cog_name == "Utility" and not c.hidden and c.name not in disabled), key=lambda c: c.name) if not cmds: embed = discord.Embed( title="Help | Utility Commands", description=self.show_info(ctx) + "\n\n**All commands in this category have been disabled for this server by " "one of its Administrators**", color=find_color(ctx)) embed.set_author(name="MAT's Bot") return await ctx.send(embed=embed) cmds = list(chunks(cmds, 8)) embeds = [] for i in cmds: embed = discord.Embed( title="Help | Utility Commands", description=f"**__Page {cmds.index(i) + 1}/{len(cmds)}__** " f"({cog_cmds['Utility']} commands)\n\n" + self.show_info(ctx), color=find_color(ctx)) embed.set_author(name="MAT's Bot") if len(cmds) > 1: embed.set_footer( text= f"Click one of the emojis below to go to the next page or the " "previous one. This help message will be automatically deleted if it's " "left idle for longer than 5 minutes") for c in i: embed.add_field(name=c.name, value=c.help, inline=False) embeds.append(embed) return await send_basic_paginator(ctx, embeds, 5) elif cat.lower() == "nsfw": cmds = sorted(list(c for c in self.bot.commands if c.cog_name == "NSFW" and not c.hidden and c.name not in disabled), key=lambda c: c.name) if not cmds: embed = discord.Embed( title="Help | NSFW Commands", description=self.show_info(ctx) + "\n\n**" "All commands in this category have been disabled for this server by one of " "its Administrators**", color=find_color(ctx)) embed.set_author(name="MAT's Bot") return await ctx.send(embed=embed) cmds = list(chunks(cmds, 8)) embeds = [] for i in cmds: embed = discord.Embed( title="Help | NSFW Commands", description=f"**__Page {cmds.index(i) + 1}/{len(cmds)}__** " f"({cog_cmds['NSFW']} commands)\n\n" + self.show_info(ctx), color=find_color(ctx)) embed.set_author(name="MAT's Bot") if len(cmds) > 1: embed.set_footer( text= f"Click one of the emojis below to go to the next page or the " "previous one. This help message will be automatically deleted if it's " "left idle for longer than 5 minutes") for c in i: embed.add_field(name=c.name, value=c.help, inline=False) embeds.append(embed) return await send_basic_paginator(ctx, embeds, 5) elif cat.lower() == "all": cmds = sorted(list(self.bot.commands), key=lambda c: c.name) embed = discord.Embed(title="Help | All Commands", description=self.show_info(ctx), color=find_color(ctx)) embed.set_author(name="MAT's Bot") embed.set_footer( text= "Do \"<prefix> help <command name>\" for help on a specific command" ) embed.add_field(name="<:confetti:464831811558572035> Fun", value="\u200b" + ", ".join([ f"`{c.name}`" for c in cmds if c.cog_name == "Fun" and not c.hidden and c.name not in disabled ]), inline=False) embed.add_field( name="<:paint:464836778000515072> Image Manipulation", value="\u200b" + ", ".join([ f"`{c.name}`" for c in cmds if c.cog_name == "Image" and not c.hidden and c.name not in disabled ]), inline=False) embed.add_field(name="<:info:540301057264189453> Info", value="\u200b" + ", ".join([ f"`{c.name}`" for c in cmds if c.cog_name == "Info" and not c.hidden and c.name not in disabled ]), inline=False) embed.add_field(name="<:raisedfist:470319397291163678> Moderation", value="\u200b" + ", ".join([ f"`{c.name}`" for c in cmds if c.cog_name == "Moderation" and not c.hidden and c.name not in disabled ]), inline=False) embed.add_field(name=":musical_note: Music", value="\u200b" + ", ".join([ f"`{c.name}`" for c in cmds if c.cog_name == "Music" and not c.hidden and c.name not in disabled ]), inline=False) embed.add_field(name=":wink: NSFW", value="\u200b" + ", ".join([ f"`{c.name}`" for c in cmds if c.cog_name == "NSFW" and not c.hidden and c.name not in disabled ]), inline=False) embed.add_field(name=":tools: Utility", value="\u200b" + ", ".join([ f"`{c.name}`" for c in cmds if c.cog_name == "Utility" and not c.hidden and c.name not in disabled ]), inline=False) if disabled: embed.add_field(name=":no_entry_sign: Disabled Commands", value=f"`{'`, `'.join(disabled)}`", inline=False) await ctx.send(embed=embed) else: for cmd in self.bot.commands: if cat.lower() == cmd.name: embed = discord.Embed(title=f"Help | {cmd.name} Command", description=cmd.help.replace( "<prefix> ", ctx.prefix), color=find_color(ctx)) embed.set_author(name="MAT's Bot") if cmd.aliases: embed.add_field(name="Aliases", value=f"`{'`, `'.join(cmd.aliases)}`") return await ctx.send(embed=embed) await ctx.send( "That's not a category. The ones you can pick are:\n\n`fun` (Fun commands)\n" "`image` (Image Manipulation commands)\n`info` (Information commands)\n`mod` " "(Moderation commands)\n`nsfw` (NSFW commands)\n`utility` (Utility commands)\n\n" "You can also put the name of a command for help on that command only" )
async def channelinfo(self, ctx, *, channel: typing.Union[discord.VoiceChannel, discord.TextChannel] = None): """Info about a text or voice channel on this server. By default I'll show info about the channel the command was performed in, although you can specify a different one. Format like this: `<prefix> channelinfo (OPTIONAL)<text channel OR voice channel>` """ await ctx.channel.trigger_typing() if channel is None: c = ctx.channel else: c = channel embed = discord.Embed(color=find_color(ctx)) if isinstance(c, discord.TextChannel): try: embed.add_field(name="Channel", value=c.mention) embed.add_field(name="ID", value=c.id) embed.add_field(name="Category", value=str(c.category)) embed.add_field(name="Position", value=c.position + 1) if await c.pins(): embed.add_field(name="Messages Pinned", value=len(await c.pins())) else: embed.add_field(name="Messages Pinned", value="None") if c.is_nsfw(): embed.add_field(name="NSFW?", value="Yes") else: embed.add_field(name="NSFW?", value="No") embed.add_field( name="Members With Access", value=f"{len(c.members)} out of {c.guild.member_count}") if c.overwrites: embed.add_field(name="Overwrites", value=len(c.overwrites)) else: embed.add_field(name="Overwrites", value="None") if c.is_news(): embed.add_field(name="News Channel?", value="Yes") else: embed.add_field(name="News Channel?", value="No") try: if await c.webhooks(): embed.add_field(name="Webhooks", value=len(await c.webhooks())) else: embed.add_field(name="Webhooks", value="None") except discord.Forbidden: embed.add_field(name="Webhooks", value="Unknown") if not c.slowmode_delay: embed.add_field(name="Slowmode Delay", value="Disabled") else: embed.add_field(name="Slowmode Delay", value=f"{c.slowmode_delay} seconds") embed.add_field(name="Created", value=c.created_at.strftime("%b %-d, %Y")) if c.topic is None or c.topic == "": embed.add_field(name="Channel topic", value="```No topic```", inline=False) else: embed.add_field(name="Channel topic", value=f"```{c.topic}```", inline=False) await ctx.send(embed=embed) except discord.Forbidden: await ctx.send( "Unfortunately, I don't have access to that channel, so I wasn't " "able to get information from it", delete_after=7.0) return await delete_message(ctx, 7) elif isinstance(c, discord.VoiceChannel): try: embed.add_field(name="Channel", value=f"\U0001f509{c.name}") embed.add_field(name="ID", value=c.id) embed.add_field(name="Category", value=str(c.category)) embed.add_field(name="Position", value=c.position + 1) if c.user_limit == 0: embed.add_field(name="User Limit", value="No limit") else: embed.add_field(name="User Limit", value=c.user_limit) embed.add_field(name="Bitrate", value=f"{c.bitrate // 1000} kbps") if c.members: embed.add_field(name="Members Inside", value=len(c.members)) else: embed.add_field(name="Members Inside", value="No members inside") if c.overwrites: embed.add_field(name="Overwrites", value=len(c.overwrites)) else: embed.add_field(name="Overwrites", value="None") embed.add_field(name="Created", value=c.created_at.strftime("%b %-d, %Y")) await ctx.send(embed=embed) except discord.Forbidden: await ctx.send( "Unfortunately, I don't have access to that channel, so I wasn't " "able to get information from it", delete_after=7.0) return await delete_message(ctx, 7)
async def on_command_error(self, ctx, exception): exc = exception if str(exc) == ("Command raised an exception: Forbidden: FORBIDDEN (status code: " "403): Missing Permissions"): return elif str(exc) == ("Command raised an exception: NotFound: 404 NOT FOUND (error code: " "10008): Unknown Message"): return elif isinstance(exc, ChannelNotNSFW): await ctx.send("This command can only be used in NSFW-marked channels", delete_after=6.0) return await delete_message(ctx, 6) elif isinstance(exc, CommandDisabled): await ctx.send("Sorry, but this command has been disabled on your server by one of " "its Administrators", delete_after=7.0) return await delete_message(ctx, 7) elif isinstance(exc, VoteRequired): embed = discord.Embed( title="\U0001f44d Remember to vote!", description="Voting is required to use this command. On top of that, voting will " "also allow you to have shorter command cooldowns. You can vote by " "[clicking here](https://top.gg/bot/459559711210078209/vote)", url="https://top.gg/bot/459559711210078209/vote", color=find_color(ctx)) await ctx.send(embed=embed, delete_after=45.0) return await delete_message(ctx, 45) elif isinstance(exc, commands.CommandOnCooldown): c = exc.cooldown retry_after = exc.retry_after if await self.bot.is_owner(ctx.author): return await ctx.reinvoke() #* Voting reward if await self.bot.dbl.get_user_vote(ctx.author.id): if c.per - exc.retry_after >= c.per * (2/3): return ctx.reinvoke() retry_after = (c.per * (2/3)) - (c.per - exc.retry_after) embed = discord.Embed( title="This command is on cooldown", description=f"Try again in **{round(retry_after, 2)}** seconds.\n\n**Default " f"Cooldown**: {c.rate} use{'' if c.rate == 1 else 's'} every " f"{int(c.per)} second{'' if c.per == 1 else 's'}\n**[Voter](https://" f"top.gg/bot/459559711210078209/vote) Cooldown**: {c.rate} " f"use{'' if c.rate == 1 else 's'} every {int(c.per * (2/3))} " f"second{'' if c.per == 1 else 's'}", color=find_color(ctx)) #*Voting reward if await self.bot.dbl.get_user_vote(ctx.author.id): embed.set_footer(text=f"{ctx.author.display_name} has voted for MAT's Bot, so " "they get shorter cooldowns", icon_url=ctx.author.avatar_url) else: embed.set_footer( text="Vote for MAT's Bot using the link above to get shorter cooldowns") await ctx.send(embed=embed, delete_after=30) await delete_message(ctx, 30) #* Voting reward if await self.bot.dbl.get_user_vote(ctx.author.id): await asyncio.sleep(retry_after) ctx.command.reset_cooldown(ctx) return elif isinstance(exc, commands.NotOwner): await ctx.send( f"Only my owner, {self.bot.owner}, can use that command", delete_after=6.0) return await delete_message(ctx, 6) elif isinstance(exc, commands.BotMissingPermissions): if len(exc.missing_perms) == 1: return await ctx.send( "I don't have the proper perms to perform this command. To do this, I would " f"need the **{str(exc.missing_perms[0]).replace('_', ' ').title()}** " "permission. Could one of you guys in charge fix that and then get " "back to me?") else: m_perms = exc.missing_perms return await ctx.send( "I don't have the proper perms to perform this command. " "To do this, I would need these permissions:\n" f"**{'**, **'.join(str(p).replace('_', ' ').title() for p in m_perms)}**\n" "Could one of you guys in charge fix that and then get back to me?") elif isinstance(exc, commands.MissingPermissions): await ctx.send( f"You need the **{str(exc.missing_perms[0]).replace('_', ' ').title()}** " "permission in order to use this command", delete_after=7.0) return await delete_message(ctx, 7) elif isinstance(exc, commands.CommandNotFound): return await ctx.message.add_reaction(random.choice( ["\U00002753", "\U00002754", "\U0001f615", "\U0001f937", "\U0001f645"])) elif (isinstance(exc, commands.BadArgument) or isinstance(exc, commands.MissingRequiredArgument) or isinstance(exc, commands.BadUnionArgument)): #* I'm using command.brief as a custom error message for each command, #* not as some brief help text like it's intended to be used as. await ctx.send(ctx.command.brief.replace("<prefix> ", ctx.prefix), delete_after=60.0) return await delete_message(ctx, 60) elif isinstance(exc, commands.NoPrivateMessage): return await ctx.send( "This command cannot be used in private messages. You must be in a server") elif isinstance(exc, MusicCheckFailure): return elif isinstance(exc, discord.Forbidden): return elif isinstance(exc, discord.NotFound): return else: return await ctx.send( f"```Command: {ctx.command.qualified_name}\n{exc}```An unknown error occured " "and I wasn't able to complete that command. Sorry!\n\nPlease get in touch with " f"my owner, **{self.bot.owner}**, and tell him what happened so he can try " "and fix this issue. You can reach him at my support server: " "https://discord.gg/khGGxxj")
async def serverinfo(self, ctx): """Info about the server""" await ctx.channel.trigger_typing() s = ctx.guild on_members = [ m for m in s.members if m.status is not discord.Status.offline ] bots = [m for m in s.members if m.bot] anim_emojis = [e for e in s.emojis if e.animated] embed = discord.Embed(title=s.name, description=f"Server ID: {s.id}", color=find_color(ctx)) embed.set_thumbnail(url=s.icon_url) embed.set_image(url=s.banner_url) embed.add_field(name="Members", value=f"{s.member_count} (Online: {len(on_members)})") embed.add_field(name="Roles", value=len(s.roles)) embed.add_field(name="Text Channels", value=len(s.text_channels)) embed.add_field(name="Voice Channels", value=len(s.voice_channels)) embed.add_field(name="Categories", value=len(s.categories)) if anim_emojis: embed.add_field( name="Custom Emojis", value= f"{len(s.emojis)} out of {s.emoji_limit} (Animated: {len(anim_emojis)})" ) else: embed.add_field(name="Custom Emojis", value=f"{len(s.emojis)} out of {s.emoji_limit}") embed.add_field(name="Bots", value=len(bots)) try: if await s.webhooks(): embed.add_field(name="Webhooks", value=len(await s.webhooks())) else: embed.add_field(name="Webhooks", value="None") except: embed.add_field(name="Webhooks", value="Unknown") embed.add_field(name="File Size Upload Limit", value=f"{s.filesize_limit // 1000000} MB") embed.add_field(name="Bitrate Limit", value=f"{int(s.bitrate_limit // 1000)} kbps") if s.premium_tier: embed.add_field(name="Nitro Server Boost Status", value=f"Level {s.premium_tier}") else: embed.add_field(name="Nitro Server Boost Status", value="No Levels Achieved") if s.premium_subscription_count: embed.add_field(name="Nitro Server Boosts", value=s.premium_subscription_count) else: embed.add_field(name="Nitro Server Boosts", value="None") if s.system_channel is not None: embed.add_field(name="System Channel", value=s.system_channel.mention) else: embed.add_field(name="System Channel", value="No System Channel") embed.add_field(name="Region", value=str(s.region).replace("-", " ").replace( "south", "south ").replace("hong", "hong ").title().replace( "Us", "U.S.").replace("Eu ", "EUR ").replace( "Vip", "V.I.P.")) if s.mfa_level: embed.add_field(name="Requires 2FA?", value="Yes") else: embed.add_field(name="Requires 2FA?", value="No") embed.add_field(name="Default Notification Level", value=str(s.default_notifications)[18:].replace( "_", " ").title()) embed.add_field(name="Verification Level", value=str(s.verification_level).capitalize()) embed.add_field(name="Explicit Content Filter", value=str(s.explicit_content_filter).replace( "_", " ").title()) if s.afk_channel is not None: if s.afk_timeout // 60 == 1: minute_s = " minute" else: minute_s = " minutes" embed.add_field(name="AFK Channel", value="\U0001f509" + s.afk_channel.name + " after " + str(s.afk_timeout // 60) + minute_s) else: embed.add_field(name="AFK Channel", value="No AFK channel") embed.add_field(name="Server Created", value=s.created_at.strftime("%b %-d, %Y")) if s.features: embed.add_field( name="Server Features", value="`" + "`, `".join([f.replace("_", " ") for f in s.features]) + "`", inline=False) embed.add_field(name="Server Owner", value=s.owner.mention + " (User ID: " + str(s.owner_id) + ")", inline=False) embed.add_field(name="Total Messages I've Read", value=f"{self.bot.messages_read[str(s.id)]:,}", inline=False) if self.bot.guilddata[s.id]["commands_used"]: cmds_used = collections.Counter( self.bot.guilddata[s.id]["commands_used"]).most_common(11)[1:] total = self.bot.guilddata[s.id]["commands_used"]["TOTAL"] embed.add_field( name="Most Popular Commands", value=f"__**Total**:__ {total:,} uses\n" + "\n".join( f"**{cmds_used.index(c) + 1}**. `{c[0]}` ({c[1]} uses)" for c in cmds_used), inline=False) delta = datetime.datetime.utcnow() - s.created_at y = int(delta.total_seconds() ) // 31557600 #* Number of seconds in 365.25 days mo = int(delta.total_seconds() ) // 2592000 % 12 #* Number of seconds in 30 days d = int( delta.total_seconds()) // 86400 % 30 #* Number of seconds in 1 day h = int( delta.total_seconds()) // 3600 % 24 #* Number of seconds in 1 hour mi = int(delta.total_seconds()) // 60 % 60 #* etc. se = int(delta.total_seconds()) % 60 footer = [] if y != 0: footer.append(f"{y} {('year' if y == 1 else 'years')}, ") if mo != 0: footer.append(f"{mo} {'month' if mo == 1 else 'months'}, ") if d != 0: footer.append(f"{d} {'day' if d == 1 else 'days'}, ") if h != 0: footer.append(f"{h} {'hour' if h == 1 else 'hours'}, ") if mi != 0: footer.append(f"{mi} {'minute' if mi == 1 else 'minutes'}, ") footer.append(f"and {se} {'second' if se == 1 else 'seconds'}.") embed.set_footer(text=s.name + " has been around for roughly " + "".join(footer)) await ctx.send(embed=embed)
def best_player_hand(players, debug=True): #function determines winner around the table for player in players: if player.state != 'fold': player.hand = [player.first_card, player.second_card] for card in poker_round.flop_cards: player.hand.append(card) for card in poker_round.turn_cards: player.hand.append(card) for card in poker_round.river_cards: player.hand.append(card) if debug: print(player.hand) # build highest hand possible player_new_hand = utils.find_best(player.hand) player.hand_name = 'High Card' if len(utils.find_pairs(player.hand)) != 0: high_card = utils.find_best(player.hand) #descending high card player_new_hand = utils.find_pairs(player.hand) if len(player_new_hand) >= 4: for index in range( len(player_new_hand) - 4): #reduce hand to 4 cards if len above 4 player_new_hand.pop() player.hand_name = 'Two Pairs' else: player.hand_name = 'One Pair' for high in high_card: if (not (high in player_new_hand) and len(player_new_hand) < 5): #build up to 5 with highest card after pairs player_new_hand.append(high) if len(utils.find_triplet( player.hand)) != 0: #building three of a kind high_card = utils.find_best(player.hand) #descending high card player_new_hand = utils.find_triplet(player.hand) if len(player_new_hand) > 3: for index in range( len(player_new_hand) - 3): #reduce hand to 3 cards if len above 3 player_new_hand.pop() for high in high_card: if (not (high in player_new_hand) and len(player_new_hand) < 5): #build up to 5 with highest card afeter pairs player_new_hand.append(high) player.hand_name = 'Three of a kind' if len(utils.find_straight( player.hand)) != 0: #condition on straight player_new_hand = utils.find_straight(player.hand) #straight player.hand_name = 'Straight' if len(utils.find_color(player.hand)) != 0: player_new_hand = utils.find_color(player.hand) player.hand_name = 'Flush' if len(utils.find_triplet(player.hand)) != 0: #building fullhouse if len(utils.find_pairs(player.hand)) != 0: player_new_hand = utils.find_triplet( player.hand) + utils.find_pairs(player.hand) player.hand_name = 'Full House' elif len(utils.find_triplet(player.hand)) == 6: player_new_hand = utils.find_triplet(player.hand) player_new_hand.pop( ) ### ISSUE, on vire bien le plus faible ? player.hand_name = 'Full House' if len(utils.find_four( player.hand)) != 0: #conditions on not empty high_card = utils.find_best(player.hand) #descending high card player_new_hand = utils.find_four( player.hand) #probable syntax error for high in high_card: if ( not (high in player_new_hand) and len(player_new_hand) < 5 ): #build up to 5 with highest card afeter four of a kind player_new_hand.append(high) player.hand_name = 'Four of a kind' if len(utils.find_color(player.hand)) != 0: #condition on color player_flush = utils.find_color(player.hand) #color if len(utils.find_straight_flush( player_flush)) != 0: #condition on straight in color player_new_hand = utils.find_straight_flush( player_flush) #straight flush if player.hand[0] == 13: player.hand_name = 'Royal Flush' else: player.hand_name = 'Straight Flush' player.hand = player_new_hand #update player's hand too best hand found (list of objects card to list of hand value) print(player.hand)