-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (66 loc) · 2.29 KB
/
Copy pathmain.py
File metadata and controls
88 lines (66 loc) · 2.29 KB
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
import discord
import dotenv
import os
import help
import logging
import utils.logger
from cogs.minigame.minigame import Minigame
from discord.ext import commands
from discord.ext.commands import DisabledCommand
from typing import Union
EXTENSIONS = [
'cogs.utility',
'cogs.info',
'cogs.fun'
]
# The detailed and brief descriptions, plus aliases, of the command `help` itself.
HELP_TEXTS = {
'description': 'To see a list of commands.',
'help': 'This command will show all the commands available in Yuuto.',
'aliases': ['manual', 'cmds', 'commands']
}
intents = discord.Intents.default()
intents.members = True
# only try to load the env file if found, docker will use actual env vars
if os.path.exists('.env'):
dotenv.load_dotenv()
prefix = os.getenv('PREFIX') or 'y!'
bot = commands.Bot(command_prefix=prefix, help_command=help.Help(HELP_TEXTS), intents=intents)
@bot.event
async def on_ready():
logging.info(f'Logged in as {bot.user}')
game = discord.Game('Volleyball')
await bot.change_presence(activity=game, status=discord.Status.online)
@bot.event
async def on_message(message: discord.Message):
if message.author.bot:
return
if message.guild is None:
return
botcmds = os.getenv(f'BOTCMDS_{message.guild.id}')
if botcmds is not None and int(botcmds) != message.channel.id:
return
try:
await bot.process_commands(message)
except DisabledCommand:
pass
@bot.event
async def on_reaction_add(reaction: discord.Reaction, user: Union[discord.Member, discord.User]):
standby_messages = list(filter(lambda x: x == reaction.message.id, Minigame.standby_messages))
if len(standby_messages) == 0:
return
if user.bot:
return
Minigame.register_player(reaction.message.channel.id, user)
@bot.event
async def on_reaction_remove(reaction: discord.Reaction, user: Union[discord.Member, discord.User]):
standby_messages = list(filter(lambda x: x == reaction.message.id, Minigame.standby_messages))
if len(standby_messages) == 0:
return
if user.bot:
return
Minigame.deregister_player(reaction.message.channel.id, user)
if __name__ == '__main__':
for extension in EXTENSIONS:
bot.load_extension(extension)
bot.run(os.getenv('TOKEN'), bot=True, reconnect=True)