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
|
import discord
import config
from command_utils import command, CommandClient
class Client(CommandClient):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.meta_channel = None
self.lobby_channel = None
async def on_ready(self):
print(f'the bot {config.NAME} is logged in as "{self.user}"')
@command(
names = ('help', 'hepl', 'h', '?'),
description = 'display this help message',
is_help = True
)
async def help(self, ctx):
command_doc = '\n'.join(
f' * {config.COMMAND_PREFIX.strip()} {c.names[0]:15} - {c.description}'
for c in self.get_commands())
await ctx.answer(f'''```
{config.HELP_TEXT}\nThese are all available commands:\n{command_doc}```''')
async def create_category(self, ctx):
category = await ctx.guild.create_category(config.CATEGORY_CHANNEL_NAME)
await ctx.answer(f'info: category created "{category}" ({category.id})')
return category
async def create_lobby(self, ctx):
lobby = await ctx.guild.create_voice_channel(config.LOBBY_CHANNEL_NAME, topic=config.LOBBY_CHANNEL_TOPIC, category=self.meta_channel)
await ctx.answer(f'info: voice channel created "{lobby}" ({lobby.id})')
return lobby
@command(
names = ('init', 'create', 'inti', 'craete', 'cretae', 'c', 'i', '+'),
description = 'create a new lobby'
)
async def init(self, ctx):
self.meta_channel = (
self.meta_channel
or discord.utils.get(ctx.guild.categories, name=config.CATEGORY_CHANNEL_NAME)
or await self.create_category(ctx)
)
self.lobby_channel = (
self.lobby_channel
or discord.utils.get(ctx.guild.voice_channels, name=config.LOBBY_CHANNEL_NAME, category=self.meta_channel)
or await self.create_lobby(ctx)
)
if __name__ == '__main__':
from os import getenv
token = getenv(config.TOKEN_ENV_VAR)
if token is None:
print('error: no token was given')
exit(1)
bot = Client(activity=discord.Game(name=config))
bot.run(token)
|