initial setup and help command

This commit is contained in:
2023-05-21 23:34:13 +01:00
parent 99384803db
commit 9569ad7ace
4 changed files with 163 additions and 0 deletions

92
config.py Normal file
View 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}")