summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatrixAeria <upezu@student.kit.edu>2020-09-28 03:31:53 +0200
committerNatrixAeria <upezu@student.kit.edu>2020-09-28 03:31:53 +0200
commit146496c146dd489023c19323027288508c4abb9d (patch)
treeaa7545fceca27596a695cf2b1fd1d5e13d142c3f
parent89e0c7df2b88daf83b6a415c1ab2b95e2d6bc46d (diff)
Create channels
-rw-r--r--bot.py26
-rw-r--r--command_utils.py1
-rw-r--r--config.py4
3 files changed, 30 insertions, 1 deletions
diff --git a/bot.py b/bot.py
index ced131d..779ef1e 100644
--- a/bot.py
+++ b/bot.py
@@ -4,6 +4,11 @@ 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}"')
@@ -19,12 +24,31 @@ class Client(CommandClient):
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):
- await ctx.answer(f'NIY')
+ 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__':
diff --git a/command_utils.py b/command_utils.py
index 6a82e7b..dc7f433 100644
--- a/command_utils.py
+++ b/command_utils.py
@@ -11,6 +11,7 @@ class Context:
def __init__(self, msg, args):
self.msg = msg
self.args = args
+ self.guild = msg.guild
async def answer(self, value):
await self.msg.channel.send(f'{self.msg.author.mention} {value}')
diff --git a/config.py b/config.py
index 9ac127c..404c66a 100644
--- a/config.py
+++ b/config.py
@@ -7,3 +7,7 @@ HELP_TEXT = f'''{NAME.title()} - your partner for getting shuffled.
{NAME.title()} is a discord bot to get to know your people.
This software is open-source <https://git.kobert.dev/lovefinderrz.git/>!
'''
+
+CATEGORY_CHANNEL_NAME = NAME.title()
+LOBBY_CHANNEL_NAME = 'lobby'
+LOBBY_CHANNEL_TOPIC = "You wanna get shuffled? You're at the right place!"