cogs now work. Also i added logging and some try catch thingies. I will convert the web interface into a cog the next commit or atleast i hope

main
supopur 2 years ago
parent 19207cd26b
commit 63d82f5785

@ -3,19 +3,15 @@
[webserver] [webserver]
#set to false if you dont have a certificate #set to false if you dont have a certificate
usessl = true usessl = false
port = "5000" port = "5000"
#DO NOT USE IN PRODUCTION. Do not even use flask it is recomended to use a production ready wsgi server such as gunicorn #DO NOT USE IN PRODUCTION. Do not even use flask it is recomended to use a production ready wsgi server such as gunicorn
debug = true debug = false
#Leave it like this if you dont know what your doing. #Leave it like this if you dont know what your doing.
ip = "0.0.0.0" ip = "0.0.0.0"
crt = "certs/certificate.crt" crt = "/path/to/certificate.crt"
key = "certs/private.key" key = "/path/to/private.key"
[bot]
[commands] [bot]
hello=false cogs=["cogs.example", "cogs.web"]
stop=false

@ -1,13 +1,47 @@
import discord, flask, os, quart, sys, toml, time, datetime import discord, flask, os, quart, sys, toml, time, datetime, logging
from quart import render_template from quart import render_template
from quart.helpers import make_response from quart.helpers import make_response
from discord.ext import commands from discord.ext import commands
with open("config.toml", "r") as f: with open("config.toml", "r") as f:
config = toml.load(f) config = toml.load(f)
token = os.environ.get('MEETOO_TOKEN') if config["webserver"]["debug"] == "true":
logging.basicConfig(filename='latest.log', encoding='utf-8', level=logging.DEBUG)
else:
logging.basicConfig(filename='latest.log', encoding='utf-8', level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler())
def log(level, log):
if level == "inf":
logging.info(log)
elif level == "wrn":
logging.warning(log)
elif level == "dbg":
logging.debug(log)
elif level == "err":
logging.error(log)
log("inf", "Logging utility set up.")
try:
token = os.environ.get('MEETOO_TOKEN')
except:
log("err", 'Error no token is present type: export MEETOO_TOKEN="[Your token here]" into your terminall NOW!')
if token == "":
log("err", 'Error no token is present type: export MEETOO_TOKEN="[Your token here]" into your terminall NOW!')
log("dbg", f"Token is: {token}")
start_time = time.time() start_time = time.time()
@ -17,24 +51,39 @@ intents.members = True
bot = commands.Bot(command_prefix='!', intents=intents) bot = commands.Bot(command_prefix='!', intents=intents)
logging.debug("Loaded the client.")
#Load all the extensions
for x in config["bot"]["cogs"]:
log("inf", f"Loading {x}...")
try:
bot.load_extension(x)
except Exception as e:
log("wrn", f"{x} Failed to load skipping... Error: {e}")
log("inf", "Loading all cogs completed.")
@bot.event @bot.event
async def on_ready(): async def on_ready():
print(f"We have logged in as {bot.user}") log("inf", f"We have logged in as {bot.user}")
@bot.slash_command(guild_ids=["823188238260633600"])
async def hello(ctx):
await ctx.respond("Hello!")
@bot.slash_command(guild_ids=["823188238260633600"]) @bot.slash_command(guild_ids=["823188238260633600"])
async def stop(ctx): async def stop(ctx):
if ctx.author.guild_permissions.administrator: if ctx.author.guild_permissions.administrator:
print("Terminating the bot...") print("Terminating the bot...")
await ctx.respond("https://media4.giphy.com/media/CC5MVO9Jx4RqMQRfvT/giphy.gif") try:
await ctx.respond("https://media4.giphy.com/media/CC5MVO9Jx4RqMQRfvT/giphy.gif")
except:
pass
sys.exit("Terminated.") sys.exit("Terminated.")
else: else:
await ctx.respond("https://media.tenor.com/Iv6oKRuAhVEAAAAC/hal9000-im-sorry-dave.gif") await ctx.respond("https://media.tenor.com/Iv6oKRuAhVEAAAAC/hal9000-im-sorry-dave.gif")
log("inf", "Loading Quart...")
#webserver #webserver
app = quart.Quart(__name__) app = quart.Quart(__name__)
log("inf", "Quart loaded.")
#The index. #The index.
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
async def index(): async def index():

Loading…
Cancel
Save