Skip to content

Commit

Permalink
Merge pull request #8 from royce-mathew/master
Browse files Browse the repository at this point in the history
Changes
  • Loading branch information
royce-mathew authored Dec 23, 2022
2 parents 5efcebb + 5455a90 commit 5370d79
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 188 deletions.
68 changes: 0 additions & 68 deletions cogs/ErrorHandler.py

This file was deleted.

2 changes: 1 addition & 1 deletion cogs/Fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from random import randrange

from modules.functions import get_fact, create_embed
from modules.utils import get_fact, create_embed


class Fun(commands.Cog):
Expand Down
2 changes: 1 addition & 1 deletion cogs/Help.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import discord
from discord.ext import commands
from modules.functions import create_embed
from modules.utils import create_embed
from modules.data_handler import GuildData


Expand Down
70 changes: 17 additions & 53 deletions cogs/Moderation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from modules import functions
from modules.utils import create_embed
import discord
from discord.ext import commands
from modules.data_handler import UserData, GuildData
Expand All @@ -22,7 +22,7 @@ def __init__(self, client: discord.Client):
self.client = client

@commands.command(name="Mute", description="Mute a user")
@commands.check(functions.is_server_admin)
@commands.has_permissions(administrator=True)
# member: discord.Member = None basically checks if the member has type discord.Member, if not then let it be None
async def mute(self, ctx: commands.Context, member: discord.Member = None):
# If member has the default value
Expand All @@ -33,14 +33,14 @@ async def mute(self, ctx: commands.Context, member: discord.Member = None):
role = discord.utils.get(member.guild.roles, name="Muted")
await member.add_roles(role)
await ctx.send(
embed=functions.create_embed(
embed=create_embed(
"Muted",
f"User `{member.display_name}` was muted by `{ctx.message.author.display_name}`"
)
)

@commands.command(name="Unmute", description="Unmute a user")
@commands.check(functions.is_server_admin)
@commands.has_permissions(administrator=True)
async def unmute(self, ctx: commands.Context, member: discord.Member = None):
if member is None:
await ctx.send("User was not passed")
Expand All @@ -49,14 +49,14 @@ async def unmute(self, ctx: commands.Context, member: discord.Member = None):
role = discord.utils.get(member.guild.roles, name="Muted")
await member.remove_roles(role)
await ctx.send(
embed=functions.create_embed(
embed=create_embed(
"Unmuted",
f"User `{member.display_name}` was unmuted by `{ctx.message.author.display_name}`"
)
)

@commands.command(name="Nick", description="Give user nickname", aliases=["nickname", "rename"])
@commands.check(functions.is_server_admin)
@commands.has_permissions(administrator=True)
async def nick(self, ctx: commands.Context, member: discord.Member = None,
# Default value for nickname
new_nickname=f"User_{random.randrange(1000, 100000)}"):
Expand All @@ -67,50 +67,14 @@ async def nick(self, ctx: commands.Context, member: discord.Member = None,

await member.edit(nick=new_nickname)
await ctx.send(
embed=functions.create_embed(
embed=create_embed(
"Set Nickname",
f"User `{member.name}` was renamed to `{new_nickname}` by `{ctx.message.author.display_name}`"
)
)


@commands.command(name="setup", description="Setup the current server for the bot", aliases=["set"])
@commands.check(functions.is_server_admin)
async def setup(self, ctx: commands.Context, specific_command: str = None, set_to: str = None):
if specific_command is not None and set_to is not None:
# Set the server's data to the specific command that was passed
if GuildData.edit_guild_settings(ctx.guild, { specific_command: set_to }) == 0:
# Invalid Key set
embed_obj = functions.create_embed("Invalid Arguments", f"The argument that you passed was invalid.\n\nValid Keys:")
for key, value in GuildData.get_valid_keys().items():
embed_obj.add_field(name=f"** ❯ {key.replace('_', ' ').capitalize()} **", value=f"Key: `{key}`\tType: `{value}`", inline=True)
await ctx.send(embed=embed_obj)
else:
await ctx.send(embed=functions.create_embed("Success", f"The key {specific_command} was set to {set_to}"))
else:
embed_obj = functions.create_embed("Invalid Arguments", f"Please pass two arguments to this command: (`command_to_set`, `value_to_set_to`).\n\n```Valid Keys:```")
for key, value in GuildData.get_valid_keys().items():
embed_obj.add_field(name=f"** ❯ {key.replace('_', ' ').capitalize()} **", value=f"Key: `{key}`\nDefault: `{value}`", inline=True)

await ctx.send(embed=embed_obj)

@commands.command(name="settings", description="View the current settings in your server")
@commands.check(functions.is_server_admin)
async def settings(self, ctx: commands.Context):
embed_obj = functions.create_embed("Settings", f"These are the following settings for this guild. To change the settings for your server, use the `setup` command.")
local_data = GuildData.get_guild_data(ctx.guild)
for key, default_value in GuildData.get_valid_keys().items():

if (value := local_data.get(key, None)) is None: # The key does not exist
value = default_value

embed_obj.add_field(name=f"❯ {key.replace('_', ' ').capitalize()}", value=f"```{value}```", inline=True)

await ctx.send(embed=embed_obj)



@commands.command(name="register", description="Register for using commands that store data")
@commands.command(name="Register", description="Register for using commands that store data")
async def register(self, ctx: commands.Context):
author: discord.Message.author = ctx.message.author # Message Author
user_id: str = str(author.id) # Author ID converted to String
Expand All @@ -119,53 +83,53 @@ async def register(self, ctx: commands.Context):
# CHECKS
# Check if user already has role
if (local_data := UserData.get_user_data(user_id)) is not None and local_data.get('name', None) is not None and role in author.roles:
embed = functions.create_embed("Registered", "You are already registered")
embed = create_embed("Registered", "You are already registered")
return
# Check if terms of conditions were set up in this guild
if (terms_of_conditions := GuildData.get_value(ctx.guild, "terms_and_conditions")) == "":
embed = functions.create_embed("Terms and Conditions Not Setup", "Terms and Conditions were not set for this server. Please run the setup command to set variables for your server.")
embed = create_embed("Terms and Conditions Not Setup", "Terms and Conditions were not set for this server. Please run the setup command to set variables for your server.")
await ctx.send(embed=embed);
return;


# Send initial message
bot_message: discord.Message = await ctx.send(embed=functions.create_embed("Registration Process", "This process may take a while."))
bot_message: discord.Message = await ctx.send(embed=create_embed("Registration Process", "This process may take a while."))

# Wait 2 seconds
await asyncio.sleep(2)

# Name Prompt
await bot_message.edit(embed=functions.create_embed("Name", "Enter username, has to be an ascii character [A-Z,a-z]"))
await bot_message.edit(embed=create_embed("Name", "Enter username, has to be an ascii character [A-Z,a-z]"))

# Wait for client input
client_response = await self.client.wait_for('message', check=check(author), timeout=30)
name: str = client_response.content

# Check if name is valid
if not string_regex.match(name):
embed = functions.create_embed("Invalid Characters in Name", "Characters must be [A-Z,a-z]. \nRun the !register command again.")
embed = create_embed("Invalid Characters in Name", "Characters must be [A-Z,a-z]. \nRun the !register command again.")
await bot_message.edit(embed=embed)
return


# Terms of Conditions Prompt
embed = functions.create_embed("Terms of Conditions",
embed = create_embed("Terms of Conditions",
description=f"{terms_of_conditions}\n\nDo you agree with these conditions? [Y | N] [Yes | No]")

await bot_message.edit(embed=embed) # Edit the message
client_response = await self.client.wait_for('message', check=check(author), timeout=30) # Wait for response

# Check valid string
if not string_regex.match(client_response.content):
embed = functions.create_embed("Invalid Characters in Response",
embed = create_embed("Invalid Characters in Response",
"Characters must be [A-Z,a-z]. \nRun the "
"!register command again.")
await ctx.send(embed=embed)
return;

# Check if yes
if client_response.content.lower() == "y" or client_response.content.lower() == "yes":
embed = functions.create_embed("Successfully Registered", f"You were registered as {name}. Welcome to the Server.")
embed = create_embed("Successfully Registered", f"You were registered as {name}. Welcome to the Server.")
await bot_message.edit(embed=embed)

if role is not None:
Expand All @@ -175,7 +139,7 @@ async def register(self, ctx: commands.Context):
print(f"Verified {name}")

else:
embed = functions.create_embed("Error", "You did not agree to the Terms of Conditions.")
embed = create_embed("Error", "You did not agree to the Terms of Conditions.")
await bot_message.edit(embed=embed)


Expand Down
Loading

0 comments on commit 5370d79

Please sign in to comment.