initial setup and help command
This commit is contained in:
92
config.py
Normal file
92
config.py
Normal file
@@ -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}")
|
||||
23
help.py
Normal file
23
help.py
Normal file
@@ -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}")
|
||||
22
main.py
Normal file
22
main.py
Normal file
@@ -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"))
|
||||
26
requirements.txt
Normal file
26
requirements.txt
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user