Moving the reaction roles into the cog HelpCommands.py

pull/4/head
sgoudham 4 years ago
parent 7b662adfd9
commit 65cb86fedd

@ -1,6 +1,7 @@
import asyncio import asyncio
import datetime import datetime
import discord
from discord import Embed, Colour from discord import Embed, Colour
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import command, cooldown, BucketType from discord.ext.commands import command, cooldown, BucketType
@ -11,6 +12,62 @@ class CustomHelp(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# Cog listener for enabling roles to be added to users when they react to the embedded message
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
# If the message id equals the self roles message
if payload.message_id == 722514840559812649:
# Print out the emoji name
print(payload.emoji.name)
# Find a role corresponding to the Emoji name.
guild_id = payload.guild_id
# Find the guild Enso and find the role of the emoji that has been reacted to
guild = discord.utils.find(lambda g: g.id == guild_id, self.bot.guilds)
role = discord.utils.find(lambda r: r.name == payload.emoji.name, guild.roles)
# if the role does exist
if role is not None:
# Print to me that the role was found and display the id of the role
print(role.name + " was found!")
print(role.id)
# Find the member who had reacted to the emoji
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
# Add the role to the member
await member.add_roles(role)
# Print to me that the role has been added
print("done")
# Cog listener for enabling roles to be removed from users when they unreact to the embedded messaged
@commands.Cog.listener()
async def on_raw_reaction_remove(self, payload):
# If the message id equals the self roles message
if payload.message_id == 722514840559812649:
# Print out the emoji name
print(payload.emoji.name)
# Get the server id
guild_id = payload.guild_id
# Find the guild Enso and find the role of the emoji that has been unreacted to
guild = discord.utils.find(lambda g: g.id == guild_id, self.bot.guilds)
role = discord.utils.find(lambda r: r.name == payload.emoji.name, guild.roles)
# if the role does exist
if role is not None:
# Find the member that has the role which the emoji is connected to
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
# Remove the role from the member
await member.remove_roles(role)
# ~rules command allows for an embed message about the leveled roles and xp system # ~rules command allows for an embed message about the leveled roles and xp system
@command(name="rules", aliases=["Rules"]) @command(name="rules", aliases=["Rules"])
@cooldown(1, 5, BucketType.user) @cooldown(1, 5, BucketType.user)
@ -26,119 +83,113 @@ class CustomHelp(commands.Cog):
enso_icon = self.bot.user.avatar_url enso_icon = self.bot.user.avatar_url
enso_name = self.bot.user.display_name enso_name = self.bot.user.display_name
# Surround with try/except to catch any exceptions that may occur # Set up embed to list all the rules within the server
try: embed = Embed(title="```(っ◔◡◔)っ Ensō Rules```",
colour=Colour(0xFF69B4),
# Set up embed to list all the rules within the server description="``` ヽ(͡◕ ͜ʖ ͡◕)ノ Please respect the following rules that are going to be listed below ヽ(͡◕ ͜ʖ ͡◕)ノ ```",
embed = Embed(title="```(っ◔◡◔)っ Ensō Rules```", timestamp=datetime.datetime.utcnow())
colour=Colour(0xFF69B4),
description="``` ヽ(͡◕ ͜ʖ ͡◕)ノ Please respect the following rules that are going to be listed below ヽ(͡◕ ͜ʖ ͡◕)ノ ```", embed.set_thumbnail(url=guild_icon)
timestamp=datetime.datetime.utcnow()) embed.set_author(name=enso_name,
icon_url=enso_icon)
embed.set_thumbnail(url=guild_icon)
embed.set_author(name=enso_name, embed.add_field(
icon_url=enso_icon) name="\u200b",
value="**➳ Don't be overly toxic/purposely problematic**" +
embed.add_field( "\n This one is pretty self explanatory, just treat others the way you want to be treated and you'll get along with everyone :)",
name="\u200b", inline=False)
value="**➳ Don't be overly toxic/purposely problematic**" + embed.add_field(
"\n This one is pretty self explanatory, just treat others the way you want to be treated and you'll get along with everyone :)", name="\u200b",
inline=False) value="**➳ Respect all admins and staff**" +
embed.add_field( "\n They are enforcing these rules to help make and keep this server a fantastic place to hang out.",
name="\u200b", inline=False)
value="**➳ Respect all admins and staff**" + embed.add_field(
"\n They are enforcing these rules to help make and keep this server a fantastic place to hang out.", name="\u200b",
inline=False) value="**➳ Keep content organized into their respective channels**" +
embed.add_field( "\n For example. When connected to a voice channel, all messages relating to the discussion in voice-chat should be sent in #vc-chat",
name="\u200b", inline=False)
value="**➳ Keep content organized into their respective channels**" + embed.add_field(
"\n For example. When connected to a voice channel, all messages relating to the discussion in voice-chat should be sent in #vc-chat", name="\u200b",
inline=False) value="**➳ No advertising other servers**" +
embed.add_field( "\nIt's disrespectful to do that and won't be tolerated in this server",
name="\u200b", inline=False)
value="**➳ No advertising other servers**" + embed.add_field(
"\nIt's disrespectful to do that and won't be tolerated in this server", name="\u200b",
inline=False) value="**➳ No pornographic/adult/other NSFW material**" +
embed.add_field( "\n This is a community server and not meant to share this kind of material. Try to stay around PG 13 as most of our users are between 13 - 16",
name="\u200b", inline=False)
value="**➳ No pornographic/adult/other NSFW material**" + embed.add_field(
"\n This is a community server and not meant to share this kind of material. Try to stay around PG 13 as most of our users are between 13 - 16", name="\u200b",
inline=False) value="**➳ Don't take insults too far**" +
embed.add_field( "\n Poking fun at others is okay, just don't take it too far. Any disputes can be brought up to a staff member and they will handle it." +
name="\u200b", "\nIf you end up causing a problem or taking things into your in hands, you will be punished",
value="**➳ Don't take insults too far**" + inline=False)
"\n Poking fun at others is okay, just don't take it too far. Any disputes can be brought up to a staff member and they will handle it." + embed.add_field(
"\nIf you end up causing a problem or taking things into your in hands, you will be punished", name="\u200b",
inline=False) value="**➳ Explicit Language**" +
embed.add_field( "\n Swearing is perfectly fine as long as it's not in excess, with some exceptions of course." +
name="\u200b", "These exceptions being racial, sexual, and ethnic slurs",
value="**➳ Explicit Language**" + inline=False)
"\n Swearing is perfectly fine as long as it's not in excess, with some exceptions of course." + embed.add_field(
"These exceptions being racial, sexual, and ethnic slurs", name="\u200b",
inline=False) value="**➳ Discord ToS**" +
embed.add_field( "\n As well as following the rules we have set forth, please make sure to follow Discord's ToS https://discordapp.com/terms ",
name="\u200b", inline=False)
value="**➳ Discord ToS**" + embed.add_field(
"\n As well as following the rules we have set forth, please make sure to follow Discord's ToS https://discordapp.com/terms ", name="\u200b \u200b ",
inline=False) value="```( ͡°ω ͡°) Disciplinary Actions ( ͡°ω ͡°)```",
embed.add_field( inline=False)
name="\u200b \u200b ", embed.add_field(
value="```( ͡°ω ͡°) Disciplinary Actions ( ͡°ω ͡°)```", name="\u200b",
inline=False) value="**➳ First Offense**" +
embed.add_field( "\n Warning",
name="\u200b", inline=True)
value="**➳ First Offense**" + embed.add_field(
"\n Warning", name="\u200b",
inline=True) value="**➳ Second Offense**" +
embed.add_field( "\n1 hour mute",
name="\u200b", inline=True)
value="**➳ Second Offense**" + embed.add_field(
"\n1 hour mute", name="\u200b",
inline=True) value="**➳ Third Offense**" +
embed.add_field( "\n12 hour mute",
name="\u200b", inline=True)
value="**➳ Third Offense**" + embed.add_field(
"\n12 hour mute", name="\u200b",
inline=True) value="**➳ Fourth Offense**" +
embed.add_field( "\n24 hour mute",
name="\u200b", inline=True)
value="**➳ Fourth Offense**" + embed.add_field(
"\n24 hour mute", name="\u200b",
inline=True) value="**➳Fifth Offense**" +
embed.add_field( "\n Kicked from the server",
name="\u200b", inline=True)
value="**➳Fifth Offense**" + embed.add_field(
"\n Kicked from the server", name="\u200b",
inline=True) value="**➳ Sixth Offense**" +
embed.add_field( "\n Banned from the server",
name="\u200b", inline=True)
value="**➳ Sixth Offense**" + embed.add_field(
"\n Banned from the server", name="\u200b",
inline=True) value="**➳ There are, of course, exceptions to these rules based on the severity of the offense. "
embed.add_field( "Minor offenses will play out as described but major offenses will be dealt with at the discretion of the staff member involved.**",
name="\u200b", inline=False)
value="**➳ There are, of course, exceptions to these rules based on the severity of the offense. " embed.add_field(
"Minor offenses will play out as described but major offenses will be dealt with at the discretion of the staff member involved.**", name="\u200b",
inline=False) value=f"**➳ Any disputes about a staff members choices or actions can be brought to myself, {ctx.message.author.mention} " +
embed.add_field( f", or my co-owner, {izzyID}**",
name="\u200b", inline=False)
value=f"**➳ Any disputes about a staff members choices or actions can be brought to myself, {ctx.message.author.mention} " +
f", or my co-owner, {izzyID}**", # Dm the user the embedded message
inline=False) await author.send(embed=embed)
# Dm the user the embedded message # Send the helpDm() message to the channel that the user is in
await author.send(embed=embed) message = await ctx.send(helpDm())
# Send the helpDm() message to the channel that the user is in # Let the user read the message for 2.5 seconds
message = await ctx.send(helpDm()) await asyncio.sleep(10)
# Delete the message
# Let the user read the message for 2.5 seconds await message.delete()
await asyncio.sleep(10)
# Delete the message
await message.delete()
except Exception as e:
print(e)
# ~roles command allows for an embed message about roles # ~roles command allows for an embed message about roles
@command(name="roles", aliases=["Roles"]) @command(name="roles", aliases=["Roles"])
@ -155,50 +206,45 @@ class CustomHelp(commands.Cog):
# Get the url of the leveled roles image # Get the url of the leveled roles image
roles_image = "https://media.discordapp.net/attachments/669812887564320769/717149671771996180/unknown.png" roles_image = "https://media.discordapp.net/attachments/669812887564320769/717149671771996180/unknown.png"
# Surround with try/except to catch any exceptions that may occur # Setting up embedded message about the leveled roles system within the server
try: embed = Embed(title="```So you wanna know how the leveled roles system works huh?```",
colour=Colour(0xFF69B4),
# Setting up embedded message about the leveled roles system within the server description="------------------------------------------------",
embed = Embed(title="```So you wanna know how the leveled roles system works huh?```", timestamp=datetime.datetime.utcnow())
colour=Colour(0xFF69B4),
description="------------------------------------------------",
timestamp=datetime.datetime.utcnow())
embed.set_image(url=roles_image)
embed.set_thumbnail(url=guild_icon)
embed.set_author(name=enso_name,
icon_url=enso_icon)
embed.add_field(name="Cooldown", value="**•XP is gained every time you talk with a 2 minute cooldown.**", embed.set_image(url=roles_image)
inline=False), embed.set_thumbnail(url=guild_icon)
embed.add_field(name="Message Length", embed.set_author(name=enso_name,
value="**•XP is not determined by the size of the message. You will not get more XP just because " icon_url=enso_icon)
"the message is bigger.**",
inline=False),
embed.add_field(name="Roles",
value="**•As seen below, those are the colours and roles that will be achieved upon gaining that "
"amount of experience**",
inline=False)
# Dm the user the embedded message embed.add_field(name="Cooldown", value="**•XP is gained every time you talk with a 2 minute cooldown.**",
await author.send(embed=embed) inline=False),
embed.add_field(name="Message Length",
value="**•XP is not determined by the size of the message. You will not get more XP just because "
"the message is bigger.**",
inline=False),
embed.add_field(name="Roles",
value="**•As seen below, those are the colours and roles that will be achieved upon gaining that "
"amount of experience**",
inline=False)
# Send the helpDm() message to the channel that the user is in # Dm the user the embedded message
message = await ctx.send(helpDm()) await author.send(embed=embed)
# Let the user read the message for 10 seconds # Send the helpDm() message to the channel that the user is in
await asyncio.sleep(10) message = await ctx.send(helpDm())
# Delete the message
await message.delete()
except Exception as e: # Let the user read the message for 10 seconds
print(e) await asyncio.sleep(10)
# Delete the message
await message.delete()
# Send a message to the channel that Enso~Chan has dm'ed them! # Send a message to the channel that Enso~Chan has dm'ed them!
def helpDm(): def helpDm():
hamothyID = '<@&715412394968350756>' hamothyID = '<@&715412394968350756>'
# Returning F String to send to the User
return f"I've just pinged your dms UwU! <a:huh:676195228872474643> <a:huh:676195228872474643>" \ return f"I've just pinged your dms UwU! <a:huh:676195228872474643> <a:huh:676195228872474643>" \
f"\nPlease ping my owner {hamothyID} for any issues/questions you have!" f"\nPlease ping my owner {hamothyID} for any issues/questions you have!"

Loading…
Cancel
Save