mirror of https://github.com/sgoudham/Enso-Bot.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
502 lines
20 KiB
Python
502 lines
20 KiB
Python
5 years ago
|
import asyncio
|
||
5 years ago
|
import datetime
|
||
5 years ago
|
import random
|
||
|
import string
|
||
|
|
||
5 years ago
|
import discord
|
||
5 years ago
|
from discord import Embed, Colour
|
||
|
from discord.ext import commands
|
||
5 years ago
|
from discord.ext.commands import cooldown, BucketType, command, is_owner
|
||
5 years ago
|
|
||
|
import settings
|
||
5 years ago
|
from settings import colour_list, enso_guild_ID, enso_ensochancommands_Mention, blank_space, enso_embedmod_colours, \
|
||
|
enso_verification_ID
|
||
5 years ago
|
|
||
5 years ago
|
"""events = {
|
||
|
"🎤": 722483603409469470, # Karaoke Night
|
||
|
"🎧": 696753950879383605, # Enso Bros Podcast
|
||
|
"🎥": 722482922518609990, # Movie Night
|
||
|
"🎮": 722493033882452078, # Game Night
|
||
|
":GameNight:": 722493033882452078,
|
||
|
":EnsoBros:": 696753950879383605,
|
||
|
":MovieNight:": 722482922518609990,
|
||
|
":Karaoke:": 722483603409469470
|
||
|
}"""
|
||
|
|
||
5 years ago
|
|
||
|
# Error handling function to make sure that the commands only work in "enso-chan-commands"
|
||
|
def error_function():
|
||
|
return f"**Sorry! I only work in {enso_ensochancommands_Mention}**"
|
||
5 years ago
|
|
||
|
|
||
5 years ago
|
# Send a message to the channel that Enso~Chan has dm'ed them!
|
||
|
def helpDm():
|
||
|
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>" \
|
||
|
f"\nPlease ping my owner {hamothyID} for any issues/questions you have!"
|
||
|
|
||
|
|
||
|
# Method to retrieve information about the user and the guild
|
||
|
def get_user_info(self, ctx):
|
||
|
# Allowing the bot to dm the user
|
||
|
author = ctx.author
|
||
|
|
||
|
# Define guild icon, enso bot icon and enso bot name
|
||
|
guild_icon = ctx.guild.icon_url
|
||
|
enso_icon = self.bot.user.avatar_url
|
||
|
enso_name = self.bot.user.display_name
|
||
|
|
||
|
return author, guild_icon, enso_icon, enso_name
|
||
|
|
||
|
|
||
5 years ago
|
# Gets the member and user avatar
|
||
|
def getMember(ctx):
|
||
5 years ago
|
# Set member as the author
|
||
|
member = ctx.message.author
|
||
5 years ago
|
# Get the member avatar
|
||
5 years ago
|
userAvatar = member.avatar_url
|
||
|
|
||
5 years ago
|
return member, userAvatar
|
||
|
|
||
|
|
||
|
# Function to display all the images requested of the people
|
||
|
def displayServerImage(array, ctx, name):
|
||
|
# Get the member and the userAvatar
|
||
|
member, userAvatar = getMember(ctx)
|
||
|
|
||
5 years ago
|
# Set embed up for the person requested by the user
|
||
|
embed = Embed(
|
||
5 years ago
|
title=f"**Look At What A Cutie {name.capitalize()} is! <a:huh:676195228872474643> <a:huh:676195228872474643> **",
|
||
5 years ago
|
colour=Colour(random.choice(colour_list)),
|
||
5 years ago
|
timestamp=datetime.datetime.utcnow())
|
||
5 years ago
|
embed.set_image(url=random.choice(array))
|
||
|
embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar))
|
||
|
|
||
|
return embed
|
||
|
|
||
|
|
||
5 years ago
|
class Enso(commands.Cog):
|
||
5 years ago
|
def __init__(self, bot):
|
||
|
self.bot = bot
|
||
|
|
||
|
# Bot ~ensoPerson command for the server members
|
||
|
@command(name="enso", aliases=['Enso'])
|
||
|
@cooldown(1, 1, BucketType.user)
|
||
|
async def enso_person(self, ctx, name=None):
|
||
|
|
||
5 years ago
|
# Making sure this command only works in Enso
|
||
5 years ago
|
if not ctx.guild.id == enso_guild_ID:
|
||
5 years ago
|
await ctx.send("**Sorry! That command is only for a certain guild!**")
|
||
5 years ago
|
return
|
||
|
|
||
5 years ago
|
# Defining array of all the people that have images stored in the bot
|
||
5 years ago
|
array = ['hammy', 'hussein', 'inna', 'kate', 'calvin',
|
||
5 years ago
|
'lukas', 'stitch', 'corona', 'ging', 'ash',
|
||
|
'gria', 'lilu', 'ifrah', 'skye', 'chloe',
|
||
5 years ago
|
'connor', 'taz', 'ryder', 'ange', 'rin',
|
||
5 years ago
|
'izzy', 'david', 'clarity', 'angel', "studentjon"]
|
||
5 years ago
|
|
||
|
# If the channel that the command has been sent is in the list of accepted channels
|
||
|
if str(ctx.channel) in settings.channels:
|
||
|
|
||
|
# if a name is specified
|
||
|
if name:
|
||
|
# Get the lowercase
|
||
|
proper_name = name.lower()
|
||
|
|
||
|
# Surround with try/except to catch any exceptions that may occur
|
||
|
try:
|
||
|
|
||
|
# if the user does ~enso list
|
||
|
if proper_name == "list":
|
||
|
# Tell the user to try the names in the array
|
||
|
await ctx.send(f"Try the names listed below!")
|
||
|
|
||
|
# Send the list of members in the bot to the channel
|
||
|
server_members = string.capwords(', '.join(map(str, array)))
|
||
|
await ctx.send(server_members)
|
||
|
|
||
|
else:
|
||
|
|
||
|
# Retrieve image of the member specified
|
||
|
with open(f'images/ServerMembers/{proper_name}.txt') as file:
|
||
|
images_array = file.readlines()
|
||
|
|
||
|
# Embed the image into a message and send it to the channel
|
||
|
embed = displayServerImage(images_array, ctx, proper_name)
|
||
|
await ctx.send(embed=embed)
|
||
|
|
||
|
except Exception as e:
|
||
|
print(e)
|
||
|
|
||
|
# Send error message saying that the person isn't recognised
|
||
5 years ago
|
await ctx.send(f"Sorry! That person doesn't exist! Try the names listed below!")
|
||
5 years ago
|
|
||
|
# Send the list of available members to the channel
|
||
|
nice = string.capwords(', '.join(map(str, array)))
|
||
|
await ctx.send(nice)
|
||
|
|
||
|
# Else if the name is not specified
|
||
|
else:
|
||
|
|
||
|
# Retrieve a random image of a member in the bot
|
||
|
with open(f'images/ServerMembers/{random.choice(array)}.txt') as file:
|
||
|
array = file.readlines()
|
||
|
|
||
5 years ago
|
# Get the member and the userAvatar
|
||
|
member, userAvatar = getMember(ctx)
|
||
5 years ago
|
|
||
|
# Embed the image in a message and send it to the channel
|
||
|
embed = Embed(
|
||
|
title=f"Oh Look! A Cute Person <a:huh:676195228872474643> <a:huh:676195228872474643> ",
|
||
5 years ago
|
colour=Colour(random.choice(colour_list)),
|
||
5 years ago
|
timestamp=datetime.datetime.utcnow())
|
||
5 years ago
|
embed.set_image(url=random.choice(array))
|
||
|
embed.set_footer(text=f"Requested by {member}", icon_url='{}'.format(userAvatar))
|
||
|
|
||
|
await ctx.send(embed=embed)
|
||
|
|
||
|
else:
|
||
|
|
||
|
message = await ctx.send(error_function())
|
||
|
|
||
|
# Let the user read the message for 2.5 seconds
|
||
|
await asyncio.sleep(2.5)
|
||
|
# Delete the message
|
||
|
await message.delete()
|
||
5 years ago
|
|
||
5 years ago
|
@command(name="rules", aliases=["Rules"])
|
||
|
@cooldown(1, 5, BucketType.user)
|
||
|
async def rules(self, ctx):
|
||
|
"""Ruleset for Ensō"""
|
||
|
|
||
|
# Making sure this command only works in Enso
|
||
|
if not ctx.guild.id == enso_guild_ID:
|
||
|
await ctx.send("**Sorry! That command is only for a certain guild!**")
|
||
|
return
|
||
|
|
||
|
# Define Izzy's roles ID
|
||
|
izzyID = '<@397944038440828928>'
|
||
|
|
||
|
# Get information about the user and the guild
|
||
|
author, guild_icon, enso_icon, enso_name = get_user_info(self, ctx)
|
||
|
|
||
|
# Set up embed to list all the rules within the server
|
||
|
embed = Embed(title="(っ◔◡◔)っ Ensō Rules",
|
||
|
colour=enso_embedmod_colours,
|
||
|
description="ヽ(͡◕ ͜ʖ ͡◕)ノ Please respect the following rules that are going to be listed below ヽ(͡◕ ͜ʖ ͡◕)ノ",
|
||
|
timestamp=datetime.datetime.utcnow())
|
||
|
|
||
|
embed.set_thumbnail(url=guild_icon)
|
||
|
embed.set_author(name=enso_name,
|
||
|
icon_url=enso_icon)
|
||
|
|
||
|
fields = [
|
||
|
(blank_space,
|
||
|
"**➳ Don't be overly toxic/purposely problematic** \n This one is pretty self explanatory, just treat others the way you want to be treated and you'll get along with everyone :)",
|
||
|
False),
|
||
|
(blank_space,
|
||
|
"**➳ Respect all admins and staff** \n They are enforcing these rules to help make and keep this server a fantastic place to hang out.",
|
||
|
False),
|
||
|
(blank_space,
|
||
|
"**➳ Keep content organized into their respective channels** \n For example. When connected to a voice channel, all messages relating to the discussion in voice-chat should be sent in #vc-chat",
|
||
|
False),
|
||
|
(blank_space,
|
||
|
"**➳ No advertising other servers** \nIt's disrespectful to do that and won't be tolerated in this server",
|
||
|
False),
|
||
|
(blank_space,
|
||
|
"**➳ No pornographic/adult/other NSFW material** \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",
|
||
|
False),
|
||
|
(blank_space,
|
||
|
"**➳ Don't take insults too far** \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." +
|
||
|
"\nIf you end up causing a problem or taking things into your in hands, you will be punished",
|
||
|
False),
|
||
|
(blank_space,
|
||
|
"**➳ Explicit Language** \n Swearing is perfectly fine as long as it's not in excess, with some exceptions of course." +
|
||
|
"These exceptions being racial, sexual, and ethnic slurs",
|
||
|
False),
|
||
|
(blank_space,
|
||
|
"**➳ Discord ToS** \n As well as following the rules we have set forth, please make sure to follow Discord's ToS https://discordapp.com/terms ",
|
||
|
False),
|
||
|
(blank_space,
|
||
|
"```( ͡°ω ͡°) Disciplinary Actions ( ͡°ω ͡°)```", False),
|
||
|
(blank_space,
|
||
|
"**➳ First Offense** \n Warning",
|
||
|
True),
|
||
|
(blank_space,
|
||
|
"**➳ Second Offense** \n1 hour mute",
|
||
|
True),
|
||
|
(blank_space,
|
||
|
"**➳ Third Offense** \n12 hour mute",
|
||
|
True),
|
||
|
(blank_space,
|
||
|
"**➳ Fourth Offense** \n24 hour mute",
|
||
|
True),
|
||
|
(blank_space,
|
||
|
"**➳Fifth Offense** \n Kicked from the server",
|
||
|
True),
|
||
|
(blank_space,
|
||
|
"**➳ Sixth Offense** \n Banned from the server",
|
||
|
True),
|
||
|
(blank_space,
|
||
|
"**➳ There are, of course, exceptions to these rules based on the severity of the offense Minor offenses will play out as described but major offenses will be dealt with at the discretion of the staff member involved.**",
|
||
|
False),
|
||
|
(blank_space,
|
||
|
f"**➳ Any disputes about a staff members choices or actions can be brought to myself, {ctx.message.author.mention} or my co-owner, {izzyID}**",
|
||
|
False)]
|
||
|
|
||
|
# Add fields to the embed
|
||
|
for name, value, inline in fields:
|
||
|
embed.add_field(name=name, value=value, inline=inline)
|
||
|
|
||
|
# Dm the user the embedded message
|
||
|
await author.send(embed=embed)
|
||
|
|
||
|
# Send the helpDm() message to the channel that the user is in
|
||
|
message = await ctx.send(helpDm())
|
||
|
|
||
|
# Let the user read the message for 10 seconds
|
||
|
await asyncio.sleep(10)
|
||
|
# Delete the message
|
||
|
await message.delete()
|
||
|
|
||
|
@command(name="roles", aliases=["Roles"])
|
||
|
@cooldown(1, 5, BucketType.user)
|
||
|
async def roles(self, ctx):
|
||
|
"""Leveled role/xp system for Ensō"""
|
||
|
|
||
|
if not ctx.guild.id == enso_guild_ID:
|
||
|
await ctx.send("**Sorry! That command is only for a certain guild!**")
|
||
|
return
|
||
|
|
||
|
# Get the url of the leveled roles image
|
||
|
roles_image = "https://media.discordapp.net/attachments/669812887564320769/717149671771996180/unknown.png"
|
||
|
|
||
|
# Setting up embedded message about the leveled roles system within the server
|
||
|
embed = Embed(title="```So you wanna know how the leveled roles system works huh?```",
|
||
|
colour=enso_embedmod_colours,
|
||
|
description="------------------------------------------------",
|
||
|
timestamp=datetime.datetime.utcnow())
|
||
|
|
||
|
# Get information about the user and the guild
|
||
|
author, guild_icon, enso_icon, enso_name = get_user_info(self, ctx)
|
||
|
|
||
|
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.**",
|
||
|
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)
|
||
|
|
||
|
# Dm the user the embedded message
|
||
|
await author.send(embed=embed)
|
||
|
|
||
|
# Send the helpDm() message to the channel that the user is in
|
||
|
message = await ctx.send(helpDm())
|
||
|
|
||
|
# Let the user read the message for 10 seconds
|
||
|
await asyncio.sleep(10)
|
||
|
# Delete the message
|
||
|
await message.delete()
|
||
|
|
||
5 years ago
|
@commands.Cog.listener()
|
||
|
async def on_raw_reaction_add(self, payload):
|
||
|
"""Verification listener for Ensō"""
|
||
|
|
||
|
# Get the guild
|
||
|
guild = self.bot.get_guild(enso_guild_ID)
|
||
|
# Get the member
|
||
|
member = guild.get_member(payload.user_id)
|
||
|
# Getting the channel verification by setting it to #verification
|
||
|
channel = guild.get_channel(enso_verification_ID)
|
||
|
|
||
|
# If the channel is #verification
|
||
|
if payload.channel_id == channel.id:
|
||
|
|
||
|
# A check that makes sure that the reaction is done by the bot
|
||
|
def check(m):
|
||
|
return m == self.bot.user
|
||
|
|
||
|
# If the member is not a user, do nothing
|
||
|
if check(payload.member):
|
||
|
return
|
||
|
else:
|
||
|
|
||
|
# Get the 'Lucid' role and then give it to the user
|
||
|
role = discord.utils.get(guild.roles, name='Lucid')
|
||
|
|
||
|
# if the emoji that was reacted is the tick mark.
|
||
|
if payload.emoji.name == "✅":
|
||
|
await member.add_roles(role)
|
||
|
|
||
|
# Set hamothyID equal to my id in discord
|
||
|
hamothyID = '<@&715412394968350756>'
|
||
|
|
||
|
# Set the channel id to "general"
|
||
|
general = guild.get_channel(663651584399507481)
|
||
|
|
||
|
# String for welcoming people in the #general channel
|
||
|
general_welcome = f"Welcome to the server! {member.mention} I hope you enjoy your stay here <a:huh:676195228872474643> <a:huh:676195228872474643> " \
|
||
|
f"\nPlease go into <#722347423913213992> to choose some ping-able roles for events! " \
|
||
|
f"\nPlease ping {hamothyID} for any questions about the server and of course, the other staff members!"
|
||
|
|
||
|
# Send welcome message to #general
|
||
|
await general.send(general_welcome)
|
||
|
|
||
|
# Allowing people to get ping-able self roles
|
||
|
@command(name="verification", hidden=True)
|
||
|
@is_owner()
|
||
|
async def verification(self, ctx):
|
||
|
# Set up embed to let the user know that they have to react with ✅
|
||
|
embed = Embed(title="**Verification**",
|
||
|
colour=Colour(0xFF69B4),
|
||
|
timestamp=datetime.datetime.utcnow())
|
||
|
|
||
|
embed.set_thumbnail(url=ctx.guild.icon_url)
|
||
|
embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
|
||
|
embed.add_field(
|
||
|
name="Remember to read the rules!",
|
||
|
value="React with ✅ to gain access to the rest of the server!",
|
||
|
inline=False)
|
||
|
|
||
|
# Send embed to the channel it was called in and automatically add the reaction ✅
|
||
|
# verif = await ctx.send(embed=embed)
|
||
|
# await verif.add_reaction('✅')
|
||
|
|
||
|
# Edit the Embed And Update it
|
||
|
verif = await ctx.fetch_message(728424149692842115)
|
||
|
await verif.edit(embed=embed)
|
||
|
|
||
5 years ago
|
# 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")
|
||
|
|
||
|
"""# Make sure the reaction event doesn't count other channels
|
||
|
if not payload.channel_id == 722347423913213992:
|
||
|
return
|
||
|
|
||
|
role = payload.member.guild.get_role(events.get(payload.emoji.name))
|
||
|
await payload.member.add_roles(role)
|
||
|
print(f"{payload.member.name} Was Given Role {role}")"""
|
||
|
|
||
|
# 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)
|
||
|
|
||
|
"""# Make sure the reaction event doesn't count other channels
|
||
|
if not payload.channel_id == 722347423913213992:
|
||
|
return
|
||
|
|
||
|
guild = self.bot.get_guild(payload.guild_id)
|
||
|
|
||
|
member = guild.get_member(payload.user_id)
|
||
|
role = guild.get_role(events.get(payload.emoji.name))
|
||
|
await member.remove_roles(role)
|
||
|
print(f"{member.name} Was Removed from Role {role}")"""
|
||
|
|
||
|
# Allowing people to get ping-able self roles
|
||
|
@command(name="rolemenu", hidden=True)
|
||
|
@is_owner()
|
||
|
async def role_menu(self, ctx):
|
||
|
# Setting the channel to "
|
||
|
channel = ctx.guild.get_channel(722347423913213992)
|
||
|
|
||
|
# Set up embed to let people know what ping-able roles can be chosen
|
||
|
embed = Embed(title="**Role Menu: Ping-Able Roles**",
|
||
|
colour=Colour.orange(),
|
||
|
timestamp=datetime.datetime.utcnow())
|
||
|
|
||
|
embed.set_thumbnail(url=ctx.guild.icon_url)
|
||
|
embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
|
||
|
embed.set_footer(text=f"{ctx.message.author}", icon_url=ctx.author.avatar_url)
|
||
|
embed.add_field(
|
||
|
name="\u200b",
|
||
|
value="React to give yourself roles to be pinged for these events!",
|
||
|
inline=False)
|
||
|
embed.add_field(
|
||
|
name="\u200b",
|
||
|
value="🎥 : `Movie Nights`",
|
||
|
inline=False)
|
||
|
embed.add_field(
|
||
|
name="\u200b",
|
||
|
value="🎤 : `Karaoke Nights`",
|
||
|
inline=False)
|
||
|
embed.add_field(
|
||
|
name="\u200b",
|
||
|
value="🎧 : `Enso Bros Podcasts`",
|
||
|
inline=False)
|
||
|
embed.add_field(
|
||
|
name="\u200b",
|
||
|
value="🎮 : `Game Nights`",
|
||
|
inline=False)
|
||
|
|
||
|
# Edit the Embed And Update it
|
||
|
message = await ctx.fetch_message(722514840559812649)
|
||
|
await message.edit(embed=embed)
|
||
|
|
||
|
# Send the embed to the channel "newpeople"
|
||
|
# await channel.send(embed=embed)
|
||
|
|
||
5 years ago
|
|
||
|
def setup(bot):
|
||
|
bot.add_cog(Enso(bot))
|