mirror of
https://github.com/alterware/aw-bot.git
synced 2025-11-18 00:52:09 +00:00
feat: best voice ever
This commit is contained in:
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@@ -0,0 +1 @@
|
||||
.env
|
||||
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
||||
2
.github/workflows/docker-publish.yml
vendored
2
.github/workflows/docker-publish.yml
vendored
@@ -15,6 +15,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@main
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3.10.0
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -18,6 +18,9 @@ ENV/
|
||||
logs/
|
||||
*.log
|
||||
|
||||
# App specific
|
||||
bot-data/
|
||||
|
||||
# IDE / Editor settings
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
FROM python:alpine
|
||||
FROM python:slim-bookworm
|
||||
|
||||
RUN apt update && apt install -y ffmpeg
|
||||
|
||||
WORKDIR /aw-bot
|
||||
|
||||
@@ -7,6 +9,7 @@ RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY bot /aw-bot/bot
|
||||
COPY database /aw-bot/database
|
||||
COPY sounds /aw-bot/sounds
|
||||
COPY aw.py .
|
||||
|
||||
ENV BOT_TOKEN=""
|
||||
|
||||
4
aw.py
4
aw.py
@@ -1,3 +1,4 @@
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
import discord
|
||||
@@ -13,6 +14,9 @@ OFFTOPIC_CHANNEL = 1112048063448617142
|
||||
intents = discord.Intents.all()
|
||||
bot = commands.Bot(command_prefix="!", intents=intents)
|
||||
|
||||
# Load environment variables from .env file (if it exists)
|
||||
load_dotenv(override=True)
|
||||
|
||||
initialize_db()
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from bot.events_handlers import (
|
||||
handle_bulk_message_delete,
|
||||
handle_message_delete,
|
||||
handle_message,
|
||||
handle_voice_state_update,
|
||||
)
|
||||
|
||||
|
||||
@@ -38,4 +39,8 @@ async def setup(bot):
|
||||
async def on_message_edit(before, after):
|
||||
await handle_message_edit(before, after, bot)
|
||||
|
||||
@bot.event
|
||||
async def on_voice_state_update(member, before, after):
|
||||
await handle_voice_state_update(member, before, after, bot)
|
||||
|
||||
print("Events extension loaded!")
|
||||
|
||||
@@ -6,3 +6,4 @@ from .message_events import (
|
||||
handle_message_delete,
|
||||
handle_message,
|
||||
)
|
||||
from .voice_events import handle_voice_state_update
|
||||
|
||||
31
bot/events_handlers/voice_events.py
Normal file
31
bot/events_handlers/voice_events.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import discord
|
||||
import asyncio
|
||||
|
||||
MP3_PATH = "sounds/hello.mp3"
|
||||
|
||||
|
||||
async def handle_voice_state_update(member, before, after, bot):
|
||||
# Ignore bot users
|
||||
if member.bot:
|
||||
return
|
||||
|
||||
# Check if the member joined a new voice channel
|
||||
if after.channel and (before.channel != after.channel):
|
||||
voice_channel = after.channel
|
||||
|
||||
try:
|
||||
# Join the voice channel
|
||||
vc = await voice_channel.connect()
|
||||
|
||||
# Play the MP3 file
|
||||
vc.play(discord.FFmpegPCMAudio(MP3_PATH))
|
||||
|
||||
# Wait for playback to finish
|
||||
while vc.is_playing():
|
||||
await asyncio.sleep(1)
|
||||
|
||||
# Disconnect
|
||||
await vc.disconnect()
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
@@ -1,3 +1,5 @@
|
||||
discord.py
|
||||
requests
|
||||
audioop-lts
|
||||
python-dotenv
|
||||
pynacl
|
||||
|
||||
3
sounds/hello.mp3
Normal file
3
sounds/hello.mp3
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ca2ae9afe287a472266ec3875db378154582a7344e459d205a1bfa5569615dc3
|
||||
size 23691
|
||||
Reference in New Issue
Block a user