prep for usage of multiprocessing pools for some commands like /mcimg
-if __import__("os").name == "nt":
- import colorama
-
- colorama.init()
-
+if __name__ == "__main__":
from discord_slash import SlashCommand
from discord.ext import commands
import classyjson as cj
@@ -11,12 +7,8 @@ import asyncpg
import discord
import logging
import random
-
-# import uvloop
import arrow
-# uvloop.install()
-
# set up basic logging
logging.basicConfig(level=logging.INFO, format="%(levelname)s:%(name)s: %(message)s")
logging.getLogger("asyncio").setLevel(logging.WARNING) # hide annoying asyncio info
@@ -27,7 +19,6 @@ logger.info("loading private keys...")
with open("data/keys.json", "r") as k: # load bot keys
keys = cj.load(k)
-
async def get_prefix(_bot, ctx): # async function to fetch a prefix from the database
if ctx.guild is None:
return _bot.d.default_prefix
@@ -36,7 +27,6 @@ async def get_prefix(_bot, ctx): # async function to fetch a prefix from the da
return _bot.d.default_prefix if prefix is None else prefix
-
intents = discord.Intents.default()
intents.guilds = True
intents.members = True
@@ -75,15 +65,15 @@ bot.slashbot = SlashCommand(
bot.logger = logger
-
-async def send(_bot, location, message): # send function/method for easy sending of embed messages with small amounts of text
+ async def send(
+ _bot, location, message
+ ): # send function/method for easy sending of embed messages with small amounts of text
try:
await location.send(embed=discord.Embed(color=_bot.d.cc, description=message))
return True
except discord.Forbidden:
return False
-
async def get_lang(_bot, ctx):
if ctx.guild is None:
return _bot.langs.en
@@ -95,11 +85,9 @@ async def get_lang(_bot, ctx):
return _bot.langs[lang]
-
bot.send = send.__get__(bot) # bind send() to bot without subclassing bot
bot.get_lang = get_lang.__get__(bot)
-
async def setup_database(): # init pool connection to database
logger.info("setting up connection to database and db pool...")
bot.db = await asyncpg.create_pool(
@@ -111,7 +99,6 @@ async def setup_database(): # init pool connection to database
command_timeout=5,
)
-
asyncio.get_event_loop().run_until_complete(setup_database())
logger.info("loading villager bot text from data/text.json...")
@@ -180,12 +167,10 @@ for cog in bot.cog_list: # load every cog in bot.cog_list
logger.info(f"loading extension: {cog}")
bot.load_extension(cog)
-
async def send_tip(ctx):
await asyncio.sleep(1)
await ctx.send(f"{random.choice(ctx.l.misc.tip_intros)} {random.choice(ctx.l.misc.tips)}")
-
@bot.check # everythingggg goes through here
async def global_check(ctx):
ctx.l = await bot.get_lang(ctx)
@@ -224,5 +209,4 @@ async def global_check(ctx):
return True
-
bot.run(keys.discord) # run the bot, this is a blocking call
