2023-06-19 19:10:03 -04:00
|
|
|
import time
|
2023-06-19 16:39:15 -04:00
|
|
|
import asyncio
|
|
|
|
import os
|
|
|
|
import aiohttp
|
|
|
|
import revolt
|
|
|
|
from revolt.ext import commands
|
2023-06-19 21:50:15 -04:00
|
|
|
import dotenv
|
2023-06-19 19:10:03 -04:00
|
|
|
from dotenv import load_dotenv
|
2023-06-19 16:39:15 -04:00
|
|
|
|
2023-06-19 21:50:15 -04:00
|
|
|
env = dotenv.find_dotenv()
|
|
|
|
load_dotenv(env)
|
2023-06-19 16:39:15 -04:00
|
|
|
token = os.getenv('TOKEN')
|
|
|
|
api_url = os.getenv('API_URL')
|
2023-06-19 16:47:48 -04:00
|
|
|
prefix = os.getenv('PREFIX')
|
2023-06-19 16:39:15 -04:00
|
|
|
|
2023-06-19 22:25:16 -04:00
|
|
|
class client(commands.CommandsClient):
|
2023-06-19 17:15:19 -04:00
|
|
|
# This class contains all of the commands the bot uses.
|
2023-06-19 21:50:15 -04:00
|
|
|
async def get_prefix(self, message: revolt.Message, input: str = prefix):
|
|
|
|
return input
|
2023-06-19 17:15:19 -04:00
|
|
|
|
2023-06-19 16:39:15 -04:00
|
|
|
@commands.command()
|
|
|
|
async def ping(self, ctx: commands.Context):
|
2023-06-19 19:01:43 -04:00
|
|
|
# This command checks the bot's latency.
|
|
|
|
before = time.monotonic()
|
2023-06-19 22:20:17 -04:00
|
|
|
await ctx.message.reply("🏓")
|
2023-06-19 19:01:43 -04:00
|
|
|
mrm_list = await ctx.channel.history(limit=1)
|
|
|
|
mrm = mrm_list[0]
|
|
|
|
ping = (time.monotonic() - before) * 1000
|
|
|
|
embeds = [revolt.SendableEmbed(title="🏓 Pong!", description=f"`\n{int(ping)} ms`", colour="#5d82d1")]
|
2023-06-19 21:50:15 -04:00
|
|
|
await mrm.edit(content=" ", embeds=embeds)
|
2023-06-19 19:01:43 -04:00
|
|
|
print(f'Ping {int(ping)}ms')
|
2023-06-19 16:39:15 -04:00
|
|
|
|
|
|
|
@commands.command()
|
2023-06-19 21:50:15 -04:00
|
|
|
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):
|
2023-06-19 22:23:40 -04:00
|
|
|
await ctx.message.reply("Please provide a user argument!")
|
2023-06-19 16:39:15 -04:00
|
|
|
return
|
2023-06-19 21:50:15 -04:00
|
|
|
avatar = target.avatar.url
|
2023-06-19 22:23:40 -04:00
|
|
|
await ctx.message.reply(f"{avatar}")
|
2023-06-19 16:39:15 -04:00
|
|
|
|
2023-06-19 21:50:15 -04:00
|
|
|
@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:
|
2023-06-19 22:23:40 -04:00
|
|
|
await ctx.message.reply("Something is very wrong! You have managed to run a prefix command without having a prefix set in your `.env` file!")
|
2023-06-19 21:50:15 -04:00
|
|
|
print("ERROR: prefix_env_var check failed!")
|
|
|
|
return
|
|
|
|
if new_prefix is not None:
|
|
|
|
dotenv.set_key(env, 'PREFIX', new_prefix)
|
2023-06-19 22:23:40 -04:00
|
|
|
await ctx.message.reply(f"Prefix has been changed from `{prefix}` to `{new_prefix}`!")
|
2023-06-19 21:50:15 -04:00
|
|
|
print(f"Prefix changed: {prefix} → {new_prefix}")
|
2023-06-19 22:25:16 -04:00
|
|
|
await client.get_prefix(ctx.message, new_prefix)
|
2023-06-19 21:50:15 -04:00
|
|
|
else:
|
2023-06-19 22:23:40 -04:00
|
|
|
await ctx.message.reply(f"The prefix is currently set to `{prefix}`.")
|
2023-06-19 21:50:15 -04:00
|
|
|
|
2023-06-19 16:39:15 -04:00
|
|
|
async def main():
|
2023-06-19 17:11:20 -04:00
|
|
|
# This function logs into the bot user.
|
2023-06-19 16:39:15 -04:00
|
|
|
async with aiohttp.ClientSession() as session:
|
2023-06-19 22:25:16 -04:00
|
|
|
client = client(session, token, api_url=api_url)
|
2023-06-19 16:39:15 -04:00
|
|
|
await client.start()
|
|
|
|
|
2023-06-19 17:11:20 -04:00
|
|
|
asyncio.run(main())
|