-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
bot.py
149 lines (120 loc) · 4.9 KB
/
bot.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import asyncio
import discord
from discord.ext.commands._types import BotT
from Util import logger
import os
from typing import Any
import cogs
# Import a monkey patch, if that exists
try:
import monkeyPatch
except ImportError:
print("DEBUG: No Monkey patch found!")
TEST_GUILD = discord.Object(id=473953130371874826)
class DiscordGods(discord.ext.commands.AutoShardedBot):
def __init__(self, command_prefix, *, intents: discord.Intents,
**options: Any) -> None:
super().__init__(command_prefix=command_prefix, intents=intents, options=options)
async def setup_hook(self):
bot.remove_command("help")
# Load commands
for command_group in command_groups:
try:
bot.tree.add_command(command_group)
except Exception as e:
logger.logDebug(f"Failed to load command group {command_group}. - {e}", "ERROR")
# Load tasks
for task in tasks:
try:
await bot.load_extension(f"cogs.{task}")
except Exception as e:
logger.logDebug(f"Failed to load task {task}. - {e}", "ERROR")
# self.tree.copy_global_to(guild=TEST_GUILD)
# await self.tree.sync(guild=TEST_GUILD)
await self.tree.sync()
intents = discord.Intents.default()
bot: discord.ext.commands.AutoShardedBot = DiscordGods(intents=intents, description='Religion has never been easier!',
command_prefix=os.getenv("prefix"),
activity=discord.Game(name="with religions | /bot howto"))
@bot.event
async def on_connect():
logger.logDebug("----------[LOGIN SUCESSFULL]----------", "INFO")
logger.logDebug(" Username: " + bot.user.name, "INFO")
logger.logDebug(" UserID: " + str(bot.user.id), "INFO")
logger.logDebug("--------------------------------------", "INFO")
print("\n")
# Bot done starting up
logger.logDebug("Bot startup done!\n", "INFO")
@bot.event
async def on_ready():
# Bot startup is now done...
logger.logDebug("Gods has (re)connected to Discord!")
# @bot.event
# async def on_command_error(ctx: commands.Context, error):
# if isinstance(error, commands.NoPrivateMessage):
# await ctx.send("This command cannot be used in private messages")
# elif isinstance(error, commands.BotMissingPermissions):
# await ctx.send(
# embed=Embed(color=discord.Color.red(), description="I need permissions to do that!"))
# elif isinstance(error, commands.MissingPermissions):
# await ctx.send(
# embed=Embed(color=discord.Color.red(), description="You are missing permissions to do that!"))
# elif isinstance(error, commands.CheckFailure):
# return
# elif isinstance(error, commands.CommandOnCooldown):
# return
# elif isinstance(error, commands.MissingRequiredArgument):
# return
# elif isinstance(error, commands.BadArgument):
# return
# elif isinstance(error, commands.CommandNotFound):
# return
# elif "User not found!" in str(error):
# await ctx.send("Error: User not found! Try mentioning or using an ID!")
# else:
# await ctx.send("Something went wrong while executing that command... Sorry!")
# await logger.log("%s" % error, bot, "ERROR")
@bot.event
async def on_guild_join(guild: discord.Guild):
await logger.log("Joined a new guild (`%s` - `%s`)" % (guild.name, guild.id), bot, "INFO")
@bot.event
async def on_guild_remove(guild: discord.Guild):
import database
await logger.log("Left a new guild (`%s` - `%s`)" % (guild.name, guild.id), bot, "INFO")
# Disband any gods in the guild (done by cascade)
db_guild = database.getGuild(guild.id)
if db_guild:
db_guild.delete_instance()
# @bot.event
# async def on_message(message: discord.Message):
# if message.author.bot:
# return
# ctx: commands.Context = await bot.get_context(message)
#
# if ctx.command is not None:
# if isinstance(message.channel, discord.DMChannel):
# await logger.log("`%s` (%s) used the `%s` command in their DM's" % (
# ctx.author.name, ctx.author.id, ctx.invoked_with), bot, "INFO")
# else:
# await logger.log("`%s` (%s) used the `%s` command in the guild `%s` (%s), in the channel `%s` (%s)" % (
# ctx.author.name, ctx.author.id, ctx.invoked_with, ctx.guild.name, ctx.guild.id, ctx.channel.name,
# ctx.channel.id), bot, "INFO")
# await bot.invoke(ctx)
command_groups = [
cogs.BotManager(bot),
cogs.GodManager(bot),
cogs.BelieverManager(bot),
cogs.Info(bot),
cogs.Misc(bot),
cogs.AdminManager(bot)
]
tasks = [
"BotLists",
"Tasks"
]
async def main():
logger.setup_logger()
async with bot:
await bot.start(os.getenv('token'))
if __name__ == '__main__':
asyncio.run(main())