|
import requests |
|
import os |
|
import urllib3 |
|
import logging |
|
from logging import getLogger |
|
from quart.logging import default_handler |
|
getLogger('quart.serving').removeHandler(default_handler) |
|
getLogger('quart.serving').setLevel(logging.ERROR) |
|
session = requests.Session() |
|
session.verify = False |
|
urllib3.disable_warnings() |
|
import discord |
|
from discord.ext import commands |
|
from quart import Quart, render_template |
|
from decouple import config |
|
import firebase_admin |
|
from firebase_admin import credentials |
|
import asyncio |
|
from threading import Thread |
|
import requests |
|
from datetime import datetime |
|
from humanfriendly import format_timespan |
|
#quart |
|
app = Quart(__name__) |
|
ready = False |
|
inittime = datetime.now() |
|
@app.route("/", methods = ["get"]) |
|
async def index(): |
|
while ready: |
|
# Anything can go here. THis can be used for status page logic, or really anything else. Wil show the other page if the bot |
|
# is still booting up. |
|
return await render_template("index.html") |
|
else: |
|
return await render_template("notready.html") |
|
#discord |
|
CLIENTTOKEN = config('CLIENTTOKEN') |
|
intents = discord.Intents.default() |
|
client = commands.AutoShardedBot(command_prefix = '>', intents=intents) |
|
client.remove_command('help') |
|
|
|
@client.event |
|
async def on_ready(): |
|
print(f'Bot is ready. Logged in as {client.user}(ID: {client.user.id})') |
|
print(f'Shards: {client.shard_count}') |
|
await client.change_presence(activity = discord.Activity(type = discord.ActivityType.watching, name = "/help")) |
|
global ready |
|
ready = True |
|
|
|
# Reload cog command ONLY for development. |
|
# @client.tree.command(name="reload", description="Reloads a cog.") |
|
# async def reload(interaction: discord.Interaction, cog: str = None): |
|
# try: |
|
# await client.reload_extension(f"cogs.{cog}") |
|
# await interaction.response.send_message(f"Reloaded {cog}") |
|
# await client.tree.sync() |
|
# except Exception as e: |
|
# await interaction.response.send_message(f"{e}") |
|
|
|
class async_discord_thread(Thread): |
|
# thanks @FrankWhoee for this code snippet |
|
def __init__(self): |
|
Thread.__init__(self) |
|
self.loop = asyncio.get_event_loop() |
|
self.start() |
|
async def starter(self): |
|
async def load_extensions(): |
|
for filename in os.listdir("./cogs"): |
|
if filename.endswith(".py"): |
|
await client.load_extension(f"cogs.{filename[:-3]}") |
|
await load_extensions() |
|
await client.start(CLIENTTOKEN) |
|
def run(self): |
|
self.name = 'Discord.py' |
|
self.loop.create_task(self.starter()) |
|
self.loop.run_forever() |
|
discord_thread = async_discord_thread() |
|
app.run(host="0.0.0.0", port="5001") |