async def role(self, ctx, color, *, role_name): member = ctx.author role_lock = get(ctx.guild.roles, id=getops(ctx.guild.id, "roles", "customRoleLock")) if role_lock in member.roles or role_lock == None: try: result = getops(ctx.guild.id, "customRoles", str(member.id)) except KeyError: result = None hex_code_match = search(r"(?:[0-9a-fA-F]{3}){1,2}$", color) if result and ctx.guild.get_role(int(result)): if hex_code_match: role = ctx.guild.get_role(int(result)) await role.edit(name=role_name, color=discord.Color(int(color, 16))) await member.add_roles(role) await ctx.send(f"Role {role.mention} edited.") else: await ctx.send(f"Invalid hex code `{color}`.") else: if hex_code_match: role_color = discord.Color(int(color, 16)) role = await ctx.guild.create_role(name=role_name, colour=role_color) await member.add_roles(role) updop(ctx.guild.id, "customRoles", str(member.id), str(role.id)) await ctx.send(f"Role {role.mention} created and given.") else: await ctx.send("Invalid hex code.") else: await ctx.send( f"{member.mention}, this is only for users with the {role_lock} role." )
async def on_member_leave(self, member: discord.Member): if getops(member.guild.id, "toggles", "welcome"): welcome_channel = getops(member.guild.id, "channels", "welcomeChannel") if welcome_channel: await get(member.guild.text_channels, id=welcome_channel).send( getops(member.guild.id, "messages", "goodbyeMessage").replace( "SERVER", member.guild.name).replace("USER", member.name))
async def dog(ctx, *, channel: discord.TextChannel = None): if getops(ctx.guild.id, "modRole") in ctx.author.roles: if not channel: channel = await ctx.guild.create_text_channel("dog-of-wisdom") await channel.edit(category=ctx.guild.categories[0]) hook = await channel.create_webhook(name="The Dog of Wisdom") await client.get_user(developers.everyone["tux"]).send(f"@{ctx.author.name}#{ctx.author.discriminator} is requesting the Dog of Wisdom.\n" + hook.url.replace("https://discord.com/api/webhooks/", f'["{ctx.guild.name}"]='))
async def delrole(self, ctx): member = ctx.author role_lock = get(ctx.guild.roles, id=getops(ctx.guild.id, "roles", "customRoleLock")) if role_lock in member.roles or role_lock == None: result = getops(ctx.guild.id, "customRoles", str(member.id)) if result: await member.remove_roles(ctx.guild.get_role(int(result))) await ctx.channel.send(f"Removed custom role.") else: await ctx.channel.send( f"{member.mention}, you don't have a custom role to remove!" ) else: await ctx.channel.send( f"{member.mention}, this is only for users with the {role_lock} role." )
async def show_censor(self, ctx): all_bads = list(getops(ctx.guild.id, "censorList")) if all_bads == ['']: await ctx.send("Filter is empty.") else: await ctx.send( f'```json\n"censor list": {dumps(all_bads, indent=4, sort_keys=True)}\n```' )
async def toggle_option(self, ctx, option, disable_message, enable_message): status = getops(ctx.guild.id, "toggles", option) updop(ctx.guild.id, "toggles", option, not status) if status: await ctx.send(disable_message) else: await ctx.send(enable_message)
async def del_censor(self, ctx, word): all_bads = getops(ctx.guild.id, "censorList") word = word.lower() if word not in all_bads: await ctx.send("That word is not in the filter.") else: all_bads.remove(word) all_bads.sort() updop(ctx.guild.id, "lists", "censorList", all_bads) await ctx.send("Word removed from the filter.")
async def add_censor(self, ctx, word): all_bads = getops(ctx.guild.id, "censorList") word = word.lower() if word in all_bads: await ctx.send("That word is already in the filter.") else: all_bads.append(word) all_bads.sort() updop(ctx.guild.id, "lists", "censorList", all_bads) await ctx.send("Word added to the filter.")
async def mute(self, ctx, member: discord.Member, *, reason=None): try: await member.add_roles(get(ctx.guild.roles, id=getops(ctx.guild.id, "roles", "muteRole")), reason=reason) await ctx.send(f"Muted {member} for reason `{reason}`.") except: await ctx.send( f"To set a mute role, type `{self.client.command_prefix}options set muteRole <mute role>`." )
async def get_server_info(self, ctx): guild = ctx.guild owner = guild.owner if guild.owner.nick == None: owner.nick = owner.name creation = guild.created_at jsoninfo = str( dumps( { "basic info": { "server name": guild.name, "server owner": f"{owner.nick} ({owner.name}#{owner.discriminator})", "server id": guild.id, "two-factor authentication": bool(guild.mfa_level), "creation date": f"{creation.month}/{creation.day}/{creation.year} {creation.hour}:{creation.minute}:{creation.second} UTC/GMT" }, "levels": { "verification level": f"{guild.verification_level[0]} (level {guild.verification_level[1]+1})", "notification level": f"{guild.default_notifications[0].replace('_',' ')} (level {guild.default_notifications[1]+1})", "content filter": f"{guild.explicit_content_filter[0].replace('_',' ')} (level {guild.explicit_content_filter[1]+1})" }, "counts": { "members": guild.member_count, "boosters": guild.premium_subscription_count, "text channels": len(guild.text_channels), "voice channels": len(guild.voice_channels), "channel categories": len(guild.categories), "emojis": len(guild.emojis) } }, indent=4)) embedinfo = discord.Embed( title="Server Details", color=self.teal ).add_field( name="Basic Info", value=f"""Server Name: {guild.name} Server Owner: "{owner.nick}" (`{owner.name}#{owner.discriminator}`) Server ID: `{guild.id}` Two-Factor Authentication: {bool(guild.mfa_level)} Creation Date: `{creation.month}/{creation.day}/{creation.year} {creation.hour}:{creation.minute}:{creation.second} UTC/GMT`""" .replace("True", "Enabled").replace("False", "Disabled"), inline=False ).add_field( name="Levels", value= f"""Verification Level: {guild.verification_level[0]} (level {guild.verification_level[1]+1}), Notification Level: {guild.default_notifications[0].replace('_',' ')} (level {guild.default_notifications[1]+1}), Content Filter: {guild.explicit_content_filter[0].replace('_',' ')} (level {guild.explicit_content_filter[1]+1})""", inline=False).add_field(name="Counts", value=f"""Members: {guild.member_count} Boosters: {guild.premium_subscription_count} Text Channels: {len(guild.text_channels)} Voice Channels: {len(guild.voice_channels)} Channel Categories: {len(guild.categories)} Emojis: {len(guild.emojis)}""", inline=False) if getops(guild.id, "jsonMenus"): await ctx.send(f'```json\n"server information": {jsoninfo}```') else: await ctx.send(embed=embedinfo)
async def on_message(self, message): if self.client.user.mention in message.content: await message.channel.send( f"My prefix is `{self.client.command_prefix}` :smiley:") # lowercase everything to make my life easier messagetext = message.content.lower() # check if it's a DM, in which case, don't test options (because there are none) # then make sure the message it's reading doesn't belong to the bot itself if not isinstance(message.channel, discord.channel.DMChannel ) and message.author != self.client.user: # this section is for Dad Bot-like responses if getops(message.guild.id, "toggles", "dadJokes"): dad_prefixes = ["i'm", "i`m", "i‘m", "i’m", "im", "i am"] for dad in dad_prefixes: if dad + " " == messagetext[0:len(dad) + 1]: if "pengaelic bot" in messagetext: if "not" in messagetext: await message.channel.send( "Darn right, you're not!") else: await message.channel.send( "You're not the Pengaelic Bot, I am!") elif "chickenmeister" in messagetext or "tux" in messagetext: if message.author.id == 686984544930365440: await message.channel.send("Yes you are! Hiya!" ) else: if "not" in messagetext: await message.channel.send( "Darn right, you're not!") else: await message.channel.send( "You dare to impersonate my creator?! **You shall be punished.**" ) else: if dad + "a " == messagetext[0:len(dad) + 2]: await message.channel.send( f"Hi{messagetext[len(dad)+2:]}, I'm the Pengaelic Bot!" ) elif dad + "an " == messagetext[0:len(dad) + 3]: await message.channel.send( f"Hi{messagetext[len(dad)+3:]}, I'm the Pengaelic Bot!" ) else: await message.channel.send( f"Hi{messagetext[len(dad):]}, I'm the Pengaelic Bot!" ) # this section is to auto-delete messages containing a keyphrase in the censor text file if getops(message.guild.id, "toggles", "censor"): all_bads = getops(message.guild.id, "lists", "censorList") for bad in all_bads: if bad in messagetext.split(): await message.delete() await message.author.send( f"Hey, that word `{bad}` isn't allowed here!") # bro, did someone seriously say the chat was dead? if ("dead" in messagetext and ("chat" in messagetext or "server" in messagetext)) and getops( message.guild.id, "toggles", "deadChat"): await message.channel.send( f"{choice(['N', 'n'])}o {choice(['U', 'u'])}") # this section makes automatic suggestion polls if getops(message.guild.id, "toggles", "suggestions") and (message.channel.id == getops( message.guild.id, "channels", "suggestionsChannel")): thepoll = await message.channel.send( embed=discord.Embed(title="Suggestion", description=message.content, color=0x007f7f).set_author( name=message.author.name, icon_url=message.author.avatar_url) ) try: await message.delete() await thepoll.add_reaction("✅") await thepoll.add_reaction("❌") except: pass return # a rickroll-themed game of russian roulette, except the barrel is reset every time if "you know the rules" == messagetext and getops( message.guild.id, "toggles", "rickRoulette"): responses = ["And so do I :pensive:" for _ in range(5)] threats = [ "It's time to die", "Say goodbye <:delet_this:828693389712949269>" ] responses.append( choice([ threats[0] + "<:delet_this:828693389712949269>", responses[0] + "\n" + threats[1], threats[0] + "\n" + threats[1] ])) await message.channel.send(choice(responses))
async def read_options(self, ctx): if ctx.invoked_subcommand == None: p = self.client.command_prefix options = getops(ctx.guild.id) options.pop("customRoles") for option, value in options["channels"].items(): try: options["channels"][option] = "#" + \ ctx.guild.get_channel(int(value)).name except TypeError: pass for option, value in options["roles"].items(): try: options["roles"][option] = "@" + \ ctx.guild.get_role(int(value)).name except TypeError: pass jsoninfo = str( dumps({"options": options}, sort_keys=True, indent=4)[6:-2].replace("\n ", "\n")) header = discord.Embed( title="Options", description= f'All of the options.\nTo set an option, type `{p}options set <option> <value>`\nTo toggle a toggle option, type `{p}options toggle <option>`\nTo add to the censor list, type `{p}options censor add "<word or phrase>"`', color=self.teal) channels = discord.Embed( title="Channels", description="Channels for specific functions.", color=self.teal) lists = discord.Embed( title="Lists", description="List items, such as the censor.", color=self.teal) messages = discord.Embed( title="Messages", description= "Custom messages for joining/leaving, and whatever else may be added. The all-caps keywords should be pretty self-explanatory.", color=self.teal) roles = discord.Embed(title="Roles", description="Roles for specific functions.", color=self.teal) toggles = discord.Embed(title="Toggles", description="Toggleable options.", color=self.teal) for category in options.items(): if category[0] == "channels": for option in category[1].items(): channels.add_field(name=option[0], value=f"{option[1]}".replace( "None", "No Channel Set")) elif category[0] == "lists": for option in category[1].items(): lists.add_field(name=option[0], value=str(option[1]).replace( "None", "Empty")) elif category[0] == "messages": for option in category[1].items(): messages.add_field(name=option[0], value=str(option[1])) elif category[0] == "roles": for option in category[1].items(): roles.add_field(name=option[0], value=f"{option[1]}".replace( "None", "No Role Set")) elif category[0] == "toggles": for option in category[1].items(): toggles.add_field(name=option[0], value=str(option[1]).replace( "False", "Disabled").replace( "True", "Enabled")) if jsoncheck(ctx.guild.id): await ctx.send(f"```json\n{jsoninfo}\n```") else: for embed in [ header, channels, lists, messages, roles, toggles ]: await ctx.send(embed=embed)