aboutsummaryrefslogtreecommitdiffstats
path: root/bot/cogs
diff options
context:
space:
mode:
Diffstat (limited to 'bot/cogs')
-rw-r--r--bot/cogs/hacktober/halloween_facts.py5
-rw-r--r--bot/cogs/hacktober/spookysound.py46
2 files changed, 49 insertions, 2 deletions
diff --git a/bot/cogs/hacktober/halloween_facts.py b/bot/cogs/hacktober/halloween_facts.py
index 304d5d94..bd164e30 100644
--- a/bot/cogs/hacktober/halloween_facts.py
+++ b/bot/cogs/hacktober/halloween_facts.py
@@ -7,6 +7,8 @@ from pathlib import Path
import discord
from discord.ext import commands
+from bot.constants import HACKTOBER_CHANNEL_ID
+
SPOOKY_EMOJIS = [
"\N{BAT}",
"\N{DERELICT HOUSE BUILDING}",
@@ -18,7 +20,6 @@ SPOOKY_EMOJIS = [
"\N{SPIDER WEB}",
]
PUMPKIN_ORANGE = discord.Color(0xFF7518)
-HACKTOBERBOT_CHANNEL_ID = 498804484324196362
INTERVAL = timedelta(hours=6).total_seconds()
@@ -32,7 +33,7 @@ class HalloweenFacts:
self.last_fact = None
async def on_ready(self):
- self.channel = self.bot.get_channel(HACKTOBERBOT_CHANNEL_ID)
+ self.channel = self.bot.get_channel(HACKTOBER_CHANNEL_ID)
self.bot.loop.create_task(self._fact_publisher_task())
async def _fact_publisher_task(self):
diff --git a/bot/cogs/hacktober/spookysound.py b/bot/cogs/hacktober/spookysound.py
new file mode 100644
index 00000000..e1598517
--- /dev/null
+++ b/bot/cogs/hacktober/spookysound.py
@@ -0,0 +1,46 @@
+import random
+from pathlib import Path
+
+import discord
+from discord.ext import commands
+
+from bot.constants import HACKTOBER_VOICE_CHANNEL_ID
+
+
+class SpookySound:
+ """
+ A cog that plays a spooky sound in a voice channel on command.
+ """
+
+ def __init__(self, bot):
+ self.bot = bot
+ self.sound_files = list(Path("./bot/resources/spookysounds").glob("*.mp3"))
+ self.channel = None
+
+ @commands.cooldown(rate=1, per=1)
+ @commands.command(brief="Play a spooky sound, restricted to once per 2 mins")
+ async def spookysound(self, ctx):
+ """
+ Connect to the Hacktoberbot voice channel, play a random spooky sound, then disconnect. Cannot be used more than
+ once in 2 minutes.
+ """
+ if not self.channel:
+ await self.bot.wait_until_ready()
+ self.channel = self.bot.get_channel(HACKTOBER_VOICE_CHANNEL_ID)
+
+ await ctx.send("Initiating spooky sound...")
+ file_path = random.choice(self.sound_files)
+ src = discord.FFmpegPCMAudio(str(file_path.resolve()))
+ voice = await self.channel.connect()
+ voice.play(src, after=lambda e: self.bot.loop.create_task(self.disconnect(voice)))
+
+ @staticmethod
+ async def disconnect(voice):
+ """
+ Helper method to disconnect a given voice client.
+ """
+ await voice.disconnect()
+
+
+def setup(bot):
+ bot.add_cog(SpookySound(bot))