IndiumRevolt/main.py

65 lines
2.4 KiB
Python
Raw Normal View History

import time
2023-06-19 16:39:15 -04:00
import asyncio
import os
import aiohttp
import revolt
from revolt.ext import commands
import dotenv
from dotenv import load_dotenv
2023-06-19 16:39: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
class Client(commands.CommandsClient):
2023-06-19 17:15:19 -04:00
# This class contains all of the commands the bot uses.
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()
await ctx.send("🏓")
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")]
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()
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!")
2023-06-19 16:39:15 -04:00
return
avatar = target.avatar.url
2023-06-19 16:39:15 -04:00
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}`.")
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:
client = Client(session, token, api_url=api_url)
await client.start()
2023-06-19 17:11:20 -04:00
asyncio.run(main())