-
Notifications
You must be signed in to change notification settings - Fork 0
/
BraincellBot.py
161 lines (133 loc) · 5.3 KB
/
BraincellBot.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
150
151
152
153
import os
import re
import time
from datetime import datetime
import discord
from discord.ext import commands
from discord.ext.commands import CommandNotFound
from dotenv import load_dotenv
load_dotenv()
from mods import firestore, vars_, admin, timer
from exts import register
bot = commands.Bot(
command_prefix=commands.when_mentioned_or(''),
owner_id=179701226995318785,
)
mods = vars_.mods
ignore = vars_.ignore
first_ready = True
BOT_TOKEN = os.getenv('BOT_TOKEN')
@commands.command()
@commands.is_owner()
async def reload(ctx, modext=None):
st = discord.Embed(
title='Reload',
).set_thumbnail(url=bot.user.avatar_url).set_footer(text=vars_.default_footer_text)
if modext in ['-a', 'all', '--all']:
st.description = await admin.reload_all(bot, mods, ignore)
st.colour = vars_.colour_success
elif modext in ['-c', 'complete', '--complete']:
# Reloads twice to ensure all dependencies are reloaded
st.description = await admin.reload_all(bot, mods, ignore)
await admin.reload_all(bot, mods, ignore)
st.colour = vars_.colour_success
elif not modext:
st.description = "Here's a list of reloadable modules/extensions"
_ = ', '.join([str(mod) for mod in vars_.mods if str(mod) != '_'])
[
st.add_field(
name=cat,
value=', '.join([
f'`{str(set_)}`'
for set_ in vars_.info_[cat].keys()
]),
inline=False)
for cat in vars_.info_.keys()
]
st.add_field(
name='Modules',
value=', '.join(
[
f'`{str(mod)}`'
for mod in list(vars_.mods.keys())[1:]
]
),
inline=False)
st.colour = ctx.guild.me.colour
else:
try:
mods[modext], st.description = await admin.reload_load(modext, mods=mods)
st.colour = vars_.colour_success
except ModuleNotFoundError:
try:
st.description = await admin.reload_load(modext, bot=bot)
st.colour = vars_.colour_success
except commands.ExtensionNotFound:
st.description = f'Cannot find {modext}'
st.colour = vars_.colour_error
await ctx.send(embed=st)
bot.add_command(reload)
@bot.event
async def on_ready():
global first_ready
if first_ready:
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
await admin.reload_all(bot, mods, ignore)
print('------')
await bot.get_user(bot.owner_id).send("I'm online!")
first_ready = False
await bot.change_presence(activity=discord.Game(name='with some neurons'))
await vars_.newpfp_timer.run_timer()
last_braincell = time.mktime(time.gmtime(0))
last_meow = time.mktime(time.gmtime(0))
just_tried = False
@bot.event
async def on_message(message):
if message.author.bot:
return
user = message.author
uid = str(user.id)
user_ = await firestore.get_user(uid)
# TODO change regex to match the template in database
if re.match(r"^<@!?[0-9]+> braincells[+\-]{2}", message.content):
mentioned = message.mentions[0]
await bot.get_command('counter')(await bot.get_context(message), mentioned.mention)
return
if re.match(rf"^<@!?{bot.user.id}>$", message.content):
if user_:
await message.channel.send(f'Hello {message.author.mention} your prefix is '
f"**{user_['prefix']}**")
return
await message.channel.send("You're not registered. \U0001F641 Run `b!register` to register.")
return
if not user_ and message.content.startswith('b!') and 'register' not in message.content:
await register.self_host_no_reg(message.author)
message.content = message.content[2:]
await bot.process_commands(message)
return
if message.content.startswith('b!') and 'register' in message.content:
message.content = message.content[2:]
await bot.process_commands(message)
return
if user_: # if user not in database or account inactive
if not user_['active'] and message.guild is not None and message.content[2:] not in vars_.unreg:
await message.channel.send("Your account is deactivated. Activate it by running `b!register`.")
return
else:
prefix = user_['prefix']
if message.content.startswith(prefix):
message.content = message.content[len(prefix):]
if user_['token'] == '!':
await message.channel.send(f"{user.mention}*This is a one-time message: "
f"you were automatically registered "
"when you ran a command, to complete registration and gain access to "
f"core features run* `{prefix}register`")
await firestore.update_user_field(uid, 'token', None)
try:
await bot.process_commands(message)
except CommandNotFound:
await message.channel.send("That command doesn't exist.")
bot.run(BOT_TOKEN)