-
Notifications
You must be signed in to change notification settings - Fork 3
/
bot.py
130 lines (110 loc) · 3.91 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
import os
import logging
import discord
import asyncio
from db import tokens
from logging.handlers import RotatingFileHandler
os.environ['PY_PRETTIFY_EXC'] = 'True'
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s: %(message)s'
DATE_FORMAT = f'%d/%m/%Y %H:%M:%S'
FORMATTER = logging.Formatter(LOG_FORMAT, datefmt=DATE_FORMAT)
discord_log = logging.getLogger('discord')
discord_log.setLevel(logging.DEBUG)
discord_handler = RotatingFileHandler(filename='logs/discord.log', mode='w', backupCount=5, encoding='utf-8',
maxBytes=2**22)
discord_handler.setFormatter(FORMATTER)
discord_log.addHandler(discord_handler)
diorite_log = logging.getLogger('diorite')
diorite_log.setLevel(logging.DEBUG)
diorite_handler = RotatingFileHandler(filename='logs/diorite.log', mode='w', backupCount=5, encoding='utf-8',
maxBytes=2**22)
diorite_handler.setFormatter(FORMATTER)
diorite_log.addHandler(diorite_handler)
import importlib
from core import bot as botfile
from core import i18n
BOT_EXTENSIONS = [
'cogs.owner',
'cogs.fun',
'cogs.info',
'cogs.moderation',
'cogs.utility',
'cogs.images',
'cogs.events',
'cogs.settings',
# 'cogs.music',
'cogs.private'
]
bot = botfile.BotCore(extensions=BOT_EXTENSIONS)
bot.maintenance_mode = False
@bot.before_invoke
async def bot_before_invoke(ctx):
if ctx.guild is None:
i18n.set_locale('en')
else:
i18n.set_locale(bot.cache.get("settings", ctx.guild.id, 'language'))
@bot.check
async def maintenance_mode(ctx):
if bot.maintenance_mode:
if ctx.author.id == bot.owner_id:
return True
e = discord.Embed(title=f"{ctx.emoji.warn} | Maintenance Mode")
e.description = 'My owner is currently working on some things. Maintenance mode has been enabled because important things may not be loaded or my owner needs to reboot me a lot. Apologies for the incoveniences, I\'ll be back soon!'
await ctx.send(embed=e)
return False
else:
return True
@bot.check
async def is_disabled(ctx):
if ctx.author.id == bot.owner_id:
return True
if not hasattr(ctx.command, 'perm_name') and not hasattr(ctx.command, 'category'):
return True
can_use = True
perms = ctx.command.category.perm_names
perms += ctx.command.perm_names
e = discord.Embed(color=0xFF7070)
e.title = _("{0} | No Access!").format(ctx.emoji.warn)
if cperms := ctx.cache.get_denied_perms(ctx.channel.id):
need = None
for x in cperms:
if x in perms:
can_use = False
need = x
break
e.description = "This command can not be used here because the `{0}` permission has been disabled in this channel!".format(need)
if uperms := ctx.cache.get_denied_perms(ctx.author.id):
need = None
for x in uperms:
if x in perms:
can_use = False
need = x
break
e.description = "You can not use this command because you dont have the `{0}` permission!".format(need)
for role in list(ctx.author._roles):
if rperms := ctx.cache.get_denied_perms(role):
need = None
for x in rperms:
if x in perms:
can_use = False
need = x
break
e.description = "You can not use this command because your role <@&{1}> doesn't have the `{0}` permission!".format(need, role)
else:
if not can_use:
break
else:
continue
if can_use:
return True
else:
await ctx.message.delete(silent=True)
await ctx.send(embed=e, delete_after=6)
return False
# @bot.ipc.route()
# async def get_test_data(data):
# bot.ipc.start()
async def main():
async with bot:
await bot.start(tokens.BOT)
asyncio.run(main())