diff --git a/main.py b/main.py index 9454ac9..dc8b7e3 100644 --- a/main.py +++ b/main.py @@ -4,17 +4,19 @@ import os import aiohttp import revolt from revolt.ext import commands +import dotenv from dotenv import load_dotenv -load_dotenv() +env = dotenv.find_dotenv() +load_dotenv(env) token = os.getenv('TOKEN') api_url = os.getenv('API_URL') prefix = os.getenv('PREFIX') class Client(commands.CommandsClient): # This class contains all of the commands the bot uses. - async def get_prefix(self, message: revolt.Message): - return prefix + async def get_prefix(self, message: revolt.Message, input: str = prefix): + return input @commands.command() async def ping(self, ctx: commands.Context): @@ -25,18 +27,34 @@ class Client(commands.CommandsClient): mrm = mrm_list[0] ping = (time.monotonic() - before) * 1000 embeds = [revolt.SendableEmbed(title="🏓 Pong!", description=f"`\n{int(ping)} ms`", colour="#5d82d1")] - await mrm.edit(content=None, embeds=embeds) + await mrm.edit(content=" ", embeds=embeds) print(f'Ping {int(ping)}ms') @commands.command() - async def avatar(self, ctx: commands.Context, member: revolt.Member): - # This command retrieves a user's avatar. - if not isinstance(member, revolt.Member): - await ctx.send("Please provide a member argument!") + async def avatar(self, ctx: commands.Context, target: revolt.User): + # This command retrieves a user's avatar. CURRENTLY BROKEN + if not isinstance(target, revolt.User): + await ctx.send("Please provide a user argument!") return - avatar = member.avatar.url + avatar = target.avatar.url await ctx.send(f"{avatar}") + @commands.command() + @commands.is_bot_owner() + async def prefix(self, ctx: commands.Context, new_prefix: str = None): + # This command sets the bot's prefix. CURRENTLY BROKEN + if 'PREFIX' not in os.environ: + await ctx.send("Something is very wrong! You have managed to run a prefix command without having a prefix set in your `.env` file!") + print("ERROR: prefix_env_var check failed!") + return + if new_prefix is not None: + dotenv.set_key(env, 'PREFIX', new_prefix) + await ctx.send(f"Prefix has been changed from `{prefix}` to `{new_prefix}`!") + print(f"Prefix changed: {prefix} → {new_prefix}") + await Client.get_prefix(ctx.message, new_prefix) + else: + await ctx.send(f"The prefix is currently set to `{prefix}`.") + async def main(): # This function logs into the bot user. async with aiohttp.ClientSession() as session: