From 3dd4a879dfc60da0d2546b0b4dad41791540cd03 Mon Sep 17 00:00:00 2001 From: Faiz Ahmed Date: Sat, 17 Jul 2021 11:16:07 -0400 Subject: [PATCH] moved config into app/app/ to retain previous users --- app/{ => app}/config/.gitignore | 0 run.py | 92 +++++++++++++++++++++++++++------ 2 files changed, 75 insertions(+), 17 deletions(-) rename app/{ => app}/config/.gitignore (100%) diff --git a/app/config/.gitignore b/app/app/config/.gitignore similarity index 100% rename from app/config/.gitignore rename to app/app/config/.gitignore diff --git a/run.py b/run.py index b40771f..2a5e0b1 100644 --- a/run.py +++ b/run.py @@ -1,17 +1,75 @@ -from app import app -from app import db, bcrypt -from app.models import User -from os import path -''' -if path.exists("app.config.app.db") is False: - db.create_all() - try: - hashed_password = bcrypt.generate_password_hash(DEFAULT_PASS).decode('utf-8') - user = User(username=DEFAULT_USER, password=hashed_password) - db.session.add(user) - db.session.commit() - except: - print("Some error in setting up.") -''' -if __name__ == "__main__": - app.run(debug=True) +import discord +import os +from discord.ext import commands, tasks +from discord.utils import get +import asyncio +import json +import Cogs.Json.jshelper as jshelper +import sys + +jshelper.prestart() +data = jshelper.openf("/app/config/app.db") +if data["token"] == "": + print("Missing Config.") + sys.exit() + +data = jshelper.openf("/config/app.db") +TOKEN = data["token"] +intents = discord.Intents.default() +intents.members = True +bot = commands.Bot(command_prefix=".", intents = intents) +bot.remove_command('help') + + +@bot.event +async def on_ready(): + print("bot is online.") + + +@bot.command() +@commands.has_permissions(administrator=True) +async def load(ctx, name): + bot.load_extension(f'Cogs.{name}') + print(f"The {name} cog has been loaded successfully.") + + +@bot.command() +@commands.has_permissions(administrator=True) +async def unload(ctx, name): + bot.unload_extension(f'Cogs.{name}') + print(f"The {name} cog has been unloaded successfully.") + + +@bot.command() +@commands.has_permissions(administrator=True) +async def reload(ctx, name): + bot.unload_extension(f'Cogs.{name}') + bot.load_extension(f'Cogs.{name}') + print(f"The {name} cog has been reloaded successfully.") + + +@bot.event +async def on_message(message): + if message.author.id == bot.user.id: + return + if not message.guild: + return + await bot.process_commands(message) + +@bot.command() +@commands.has_permissions(administrator=True) +async def all(ctx): + for filename in os.listdir("Cogs"): + if filename.endswith('.py'): + bot.unload_extension(f'Cogs.{filename[:-3]}') + for filename in os.listdir("Cogs"): + if filename.endswith('.py'): + bot.load_extension(f'Cogs.{filename[:-3]}') + print("All cogs has been reloaded.") + + +for filename in os.listdir("Cogs"): + if filename.endswith('.py'): + bot.load_extension(f'Cogs.{filename[:-3]}') + +bot.run(TOKEN) \ No newline at end of file