From e767fb564b886561ccac4d55a29bcfbbdc9f4f46 Mon Sep 17 00:00:00 2001 From: Daniel afx Date: Thu, 24 Mar 2022 01:27:00 +0200 Subject: [PATCH] use bradme's code --- .dockerignore | 1 - config/config.example.ini => .env.dist | 3 --- .gitignore | 2 +- Dockerfile | 2 -- docker-compose.yml | 3 +++ main.py | 35 ++++++++++++++++++++++++++ 6 files changed, 39 insertions(+), 7 deletions(-) delete mode 100644 .dockerignore rename config/config.example.ini => .env.dist (88%) create mode 100644 main.py diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 3507a4c..0000000 --- a/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -config.ini \ No newline at end of file diff --git a/config/config.example.ini b/.env.dist similarity index 88% rename from config/config.example.ini rename to .env.dist index 7953210..ac51c45 100644 --- a/config/config.example.ini +++ b/.env.dist @@ -1,9 +1,6 @@ -[radio] token = "radio_bot_token" channel = "channel_id" name = "Example Radio" url = "http://example.net" - -[voice] passes = 2 bitrate = 44100 diff --git a/.gitignore b/.gitignore index 1422eef..763423b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ # Internal -config/config.ini \ No newline at end of file +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9094f8e..327bd6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,4 @@ RUN pip --no-cache-dir install \ WORKDIR /app -ENV CONFIG_FILE="./config/config.ini" - COPY . /app \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1865383..6eb38a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,4 +5,7 @@ services: build: context: . dockerfile: Dockerfile + env_file: + - .env + command: python3 main.py restart: always diff --git a/main.py b/main.py new file mode 100644 index 0000000..e6b6e79 --- /dev/null +++ b/main.py @@ -0,0 +1,35 @@ +import discord +from discord.ext.commands import Bot + +bot_version = "0.1" + +client = Bot(command_prefix="!") +isPlaying = False +class MyClient(discord.Client): + + async def on_ready(self): + print('Logged on as', self.user) + + async def on_message(self, message): + # don't respond to ourselves + if message.author == self.user: + return + + if message.content == 'version': + await message.channel.send('radiobot ' + bot_version) + + @client.event + async def on_voice_state_update(self, member, before, after): + clients_before = len(before.channel.members) + + # If nobody in the channel based on before, invoke join the channel + if clients_before == 0: + self.voiceChannel = await after.channel.connect() + + # if after join channel members > 0, join the channel + if clients_before == 1: + print("gg") + await self.voiceChannel.disconnect() + +client = MyClient() +client.run('') # Get token for this shit \ No newline at end of file