-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
73 lines (56 loc) · 1.88 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import asyncio
import traceback
import logging
import discord
from discord.ext import commands
import BotSettings
bot = commands.Bot(command_prefix=BotSettings.config.command_prefix)
extensions = [
'cogs.linkage_manager'
]
for extension in extensions:
try:
bot.load_extension(extension)
except Exception as e:
print(e)
traceback.print_exc()
async def main_loop():
while True:
if BotSettings.config.process_queue:
messages = BotSettings.DB.get_messages()
await BotSettings.bot_actions.process_messages(messages)
await BotSettings.bot_actions.process_dyk()
await asyncio.sleep(BotSettings.config.main_loop_timer)
@bot.command()
@commands.check(BotSettings.is_user_whitelisted)
async def load(ctx, extension: str):
"""
Loads an extension
Example: !load cogs.debug
"""
try:
bot.load_extension(extension)
except (AttributeError, ImportError) as e:
await ctx.send("```py\n{}: {}\n```".format(type(e).__name__, str(e)))
await ctx.send("{} loaded".format(extension))
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CheckFailure ):
print("WARNING --- User {} is attempting to execute the command '{}' but failed the whitelist/permissions checks.".format({"name": ctx.author.name, "id": ctx.author.id}, ctx.command.name))
else:
print(error)
@bot.event
async def on_error(event, *args, **kwargs):
print("\n### An error as occured.[BOT]\n")
message = args[0]
logging.warning(traceback.format_exc())
await message.context.send("You caused an error!")
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
BotSettings.setup_bot(bot)
bot.loop.create_task(main_loop())
bot.run(BotSettings.config.token, bot=True, reconnect=True)