Refactor bot setup and improve error handling; update command prefix handling and enhance session security in Flask app. Add profile and balance card generation features with image processing capabilities.
This commit is contained in:
@@ -3,15 +3,7 @@ import discord
|
||||
from discord.ext import commands
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from web.app import app
|
||||
from utils.sql_commands import initialize_database
|
||||
import threading
|
||||
import itertools
|
||||
|
||||
|
||||
def run_web():
|
||||
app.run(debug=False, host="0.0.0.0", port=8080)
|
||||
return
|
||||
|
||||
|
||||
class MyNewHelp(commands.MinimalHelpCommand):
|
||||
@@ -25,17 +17,12 @@ class MyNewHelp(commands.MinimalHelpCommand):
|
||||
class Client(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
command_prefix=self.iterate_prefix("Vamoc")+self.iterate_prefix("!V"),
|
||||
command_prefix=["Vamoc", "!V"],
|
||||
strip_after_prefix=True,
|
||||
case_insensitive=True,
|
||||
intents=discord.Intents.all(),
|
||||
help_command=MyNewHelp(),
|
||||
)
|
||||
def iterate_prefix(self, prefix):
|
||||
prefixes = list(map(''.join, itertools.product(*zip(prefix.upper(), prefix.lower()))))
|
||||
print(prefixes)
|
||||
|
||||
return prefixes
|
||||
|
||||
async def setup_hook(self): # overwriting a handler
|
||||
cogs_folder = f"{os.path.abspath(os.path.dirname(__file__))}/cogs"
|
||||
@@ -53,12 +40,10 @@ def main():
|
||||
load_dotenv()
|
||||
initialize_database()
|
||||
client = Client()
|
||||
token = os.getenv("TOKEN")
|
||||
if token is not None:
|
||||
threading.Thread(target=run_web, daemon=True).start()
|
||||
client.run(token)
|
||||
else:
|
||||
print("Token is missing.")
|
||||
token = os.getenv("DISCORD_TOKEN") or os.getenv("TOKEN")
|
||||
if not token:
|
||||
raise SystemExit("ERROR: Discord token not found. Set DISCORD_TOKEN or TOKEN in environment.")
|
||||
client.run(token)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user