From 9569ad7acef7d38a68096b19d84b529c8a0fa145 Mon Sep 17 00:00:00 2001 From: Top1055 <123alexfeetham@gmail.com> Date: Sun, 21 May 2023 23:34:13 +0100 Subject: [PATCH] initial setup and help command --- config.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ help.py | 23 ++++++++++++ main.py | 22 ++++++++++++ requirements.txt | 26 ++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 config.py create mode 100644 help.py create mode 100644 main.py create mode 100644 requirements.txt diff --git a/config.py b/config.py new file mode 100644 index 0000000..8abc6ba --- /dev/null +++ b/config.py @@ -0,0 +1,92 @@ +# config.py +# This file should parse all configurations within the bot + +import discord +import json + +# Read data from JSON file in ./data/config.json +def read_data(): + with open("./data/config.json", "r") as file: + return json.load(file) + + raise Exception("Could not load config data") + + +# Reading prefix +def get_prefix(): + data = read_data() + + prefix = data.get('prefix') + if prefix: + return prefix + + raise Exception("Missing config data: prefix") + + +# Fetch the bot secret token +def get_login(bot): + data = read_data() + if data is False or data.get(f"{bot}bot") is False: + raise Exception(f"Missing config data: {bot}bot") + + data = data.get(f"{bot}bot") + return data.get("secret") + + +# Read the status and text data +def get_status(): + data = read_data() + + if data is False or data.get('status') is False: + raise Exception("Missing config data: status") + + # Find type + data = data.get('status') + return translate_status( + data.get('type'), + data.get('text'), + data.get('link') + ) + + +# Taking JSON variables and converting them into a presence +# Use None url incase not provided +def translate_status(status_type, status_text, status_url=None): + if status_type == "playing": + return discord.Activity( + type=discord.ActivityType.playing, + name=status_text + ) + + + elif status_type == "streaming": + return discord.Activity( + type=discord.ActivityType.streaming, + name=status_text, + url=status_link + ) + + elif status_type == "listening": + return discord.Activity( + type=discord.ActivityType.listening, + name=status_text + ) + + + elif status_type == "watching": + return discord.Activity( + type=discord.ActivityType.watching, + name=status_text + ) + + elif status_type == "competing": + return discord.Activity( + type=discord.ActivityType.competing, + name=status_text + ) + + #TODO + # Implement custom status type + + else: + raise Exception(f"Invalid status type: {status_type}") diff --git a/help.py b/help.py new file mode 100644 index 0000000..ab6f26c --- /dev/null +++ b/help.py @@ -0,0 +1,23 @@ +import discord +from discord.ext import commands + +class AstroHelp(commands.HelpCommand): + + # Help regular + async def send_bot_help(self, mapping): + await self.context.send("This is help") + + + # Help with specific command + async def send_command_help(self, command): + await self.context.send(f"You asked for help with: {command}") + + + # Help for a group + async def send_group_help(self, group): + await self.context.send(f"This is a group: {group}") + + + # Help for cog + async def send_cog_help(self, cog): + await self.context.send(f"This is a cog: {cog}") diff --git a/main.py b/main.py new file mode 100644 index 0000000..1138c8d --- /dev/null +++ b/main.py @@ -0,0 +1,22 @@ +import discord +from discord.ext import commands +import config +import help + +cogs = [] + +class Serenity(commands.Bot): + + # Once the bot is up and running + async def on_ready(self): + # Set the status + await self.change_presence(activity=config.get_status()) + + # Setup commands + for cog in cogs: + await cog.setup(self) + +client = Serenity(command_prefix=config.get_prefix(), intents=discord.Intents.all()) +client.help_command = help.AstroHelp() + +client.run(config.get_login("dev")) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f4299ff --- /dev/null +++ b/requirements.txt @@ -0,0 +1,26 @@ +aiohttp==3.8.4 +aiosignal==1.3.1 +async-timeout==4.0.2 +attrs==23.1.0 +Brotli==1.0.9 +certifi==2023.5.7 +cffi==1.15.1 +charset-normalizer==3.1.0 +discord==2.2.3 +discord.py==2.2.3 +frozenlist==1.3.3 +idna==3.4 +multidict==6.0.4 +mutagen==1.46.0 +PyAudio==0.2.13 +pycparser==2.21 +pycryptodomex==3.18.0 +PyNaCl==1.5.0 +redis==4.5.5 +requests==2.30.0 +six==1.16.0 +spotipy==2.23.0 +urllib3==2.0.2 +websockets==11.0.3 +yarl==1.9.2 +yt-dlp==2023.3.4