diff --git a/api/auth.py b/api/auth.py index 19d6bcee..8f1e9d7e 100644 --- a/api/auth.py +++ b/api/auth.py @@ -30,9 +30,18 @@ def get_secret(): def get_public_key(): """Returns the bot's public key in `runtimeconfig.json`, if it exists.""" - if config["public_key"]: return config["public_key"] + if config["public_key"] != "": return config["public_key"] else: return "Public key has not been set." def get_mode() -> bool: """Returns a boolean of the current runtime mode.\n\nReturns `True` if replit mode is active, returns `False` if replit mode is inactive.""" return config["replit"] + +def ext_token(token_name: str) -> str: + """Returns an external extra authorization token from `runtimeconfig.json`, if it exists.""" + return str(config["other_keys"][token_name]) + #except KeyError: return "This external authorization key does not exist." + +def get_runtime_options() -> dict: + """Returns a dict of all the client's runtime configuration options, as well as their respective values.""" + return dict(config["runtime_options"]) diff --git a/api/runtimeconfig.json b/api/runtimeconfig.json index e7c0a7a0..1ad0f84d 100644 --- a/api/runtimeconfig.json +++ b/api/runtimeconfig.json @@ -2,6 +2,21 @@ "token": "", "secret": "", "public_key": "", - "runtime_options": [], - "replit": true + "runtime_options": { + "themes": false, + "log_messages": true, + "guild_log_blacklist": {}, + "only_log_whitelist": false, + "guild_log_whitelist": {}, + "ping_server_override": false, + "debug_mode": false, + "show_ping_on_startup": true + }, + "replit": false, + "other_keys": { + "openweathermap": "", + "reddit": "", + "ossapi": "", + "chatgpt": "" + } } diff --git a/cogs/osu.py b/cogs/osu.py index 6ed8cef8..81fab535 100644 --- a/cogs/osu.py +++ b/cogs/osu.py @@ -3,6 +3,7 @@ # Imports import discord import os +from api import auth from ossapi import * from discord import option, ApplicationContext from discord.ext import commands @@ -11,8 +12,8 @@ class Osu(commands.Cog): def __init__(self, bot): self.bot = bot - self.api = OssapiV2(13110, os.environ['ossapi_CLIENT_SECRET']) - + self.api = OssapiV2(13110, auth.ext_token("ossapi")) + @commands.slash_command( name="osu_user", description="View information on an osu! player." diff --git a/cogs/reddit.py b/cogs/reddit.py index 0f7bb335..5cd15a6a 100644 --- a/cogs/reddit.py +++ b/cogs/reddit.py @@ -4,19 +4,20 @@ import discord import praw import os +from api import auth from discord import ApplicationContext, option from discord.ext import commands from random import randint # Variables color = discord.Color.random() -reddit = praw.Reddit(client_id='_pazwWZHi9JldA', client_secret=os.environ['reddit_CLIENT_SECRET'], user_agent='idk', check_for_async=False) +reddit = praw.Reddit(client_id='_pazwWZHi9JldA', client_secret=auth.ext_token('reddit'), user_agent='idk', check_for_async=False) # Commands class RedditMedia(commands.Cog): def __init__(self, bot): self.bot = bot - + @commands.slash_command( name='memes', description='Finely hand-picks a high-quality meme from the depths of reddit.' diff --git a/cogs/utils.py b/cogs/utils.py index cf295511..794a9832 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -6,6 +6,7 @@ import psutil import openai import discord +from api import auth from framework.isobot import currency, embedengine, commands as cmds from framework.isobot.db import levelling from discord import option, ApplicationContext @@ -17,7 +18,8 @@ color = discord.Color.random() currency = currency.CurrencyAPI("database/currency.json", "logs/currency.log") levelling = levelling.Levelling() -openai.api_key = os.getenv("chatgpt_API_KEY") +# openai.api_key = os.getenv("chatgpt_API_KEY") +openai.api_key = auth.ext_token('chatgpt') chatgpt_conversation = dict() _presence = Presence() diff --git a/cogs/weather.py b/cogs/weather.py index 8ca3c075..3ea92f93 100644 --- a/cogs/weather.py +++ b/cogs/weather.py @@ -3,12 +3,14 @@ import json import requests import os +from api import auth from framework.isobot.db import weather from discord import ApplicationContext, option from discord.ext import commands # Variables -api_key = os.environ['openweathermap_API_KEY'] +#api_key = os.environ['openweathermap_API_KEY'] +api_key = auth.ext_token('openweathermap') weather = weather.Weather() # Commands