From dc8a2330c5ca4ddef307101b6ce47de99ba61522 Mon Sep 17 00:00:00 2001 From: meooow25 Date: Sun, 14 Oct 2018 19:58:26 +0530 Subject: Add cog to play spooky sounds * Add SpookySound cog * Add sound files * Add PyNaCl to Pipfile (required for Discord voice) --- bot/cogs/spookysound.py | 39 ++++++++++++++++++++ .../spookysounds/109710__tomlija__horror-gate.mp3 | Bin 0 -> 118125 bytes .../spookysounds/126113__klankbeeld__laugh.mp3 | Bin 0 -> 112365 bytes ...ugh-original-132802-nanakisan-evil-laugh-08.mp3 | Bin 0 -> 137385 bytes .../spookysounds/14570__oscillator__ghost-fx.mp3 | Bin 0 -> 135405 bytes .../spookysounds/168650__0xmusex0__doorcreak.mp3 | Bin 0 -> 162421 bytes ...71078__klankbeeld__horror-scream-woman-long.mp3 | Bin 0 -> 131625 bytes .../193812__geoneo0__four-voices-whispering-6.mp3 | Bin 0 -> 163257 bytes ...37282__devilfish101__frantic-violin-screech.mp3 | Bin 0 -> 131566 bytes .../249686__cylon8472__cthulhu-growl.mp3 | Bin 0 -> 153226 bytes .../spookysounds/35716__analogchill__scream.mp3 | Bin 0 -> 114773 bytes ...15__inspectorj__something-evil-approaches-a.mp3 | Bin 0 -> 298717 bytes .../60571__gabemiller74__breathofdeath.mp3 | Bin 0 -> 177049 bytes .../spookysounds/Female_Monster_Growls_.mp3 | Bin 0 -> 148276 bytes bot/resources/spookysounds/Male_Zombie_Roar_.mp3 | Bin 0 -> 62171 bytes .../spookysounds/Monster_Alien_Growl_Calm_.mp3 | Bin 0 -> 133651 bytes .../spookysounds/Monster_Alien_Grunt_Hiss_.mp3 | Bin 0 -> 74718 bytes bot/resources/spookysounds/sources.txt | 41 +++++++++++++++++++++ 18 files changed, 80 insertions(+) create mode 100644 bot/cogs/spookysound.py create mode 100644 bot/resources/spookysounds/109710__tomlija__horror-gate.mp3 create mode 100644 bot/resources/spookysounds/126113__klankbeeld__laugh.mp3 create mode 100644 bot/resources/spookysounds/133674__klankbeeld__horror-laugh-original-132802-nanakisan-evil-laugh-08.mp3 create mode 100644 bot/resources/spookysounds/14570__oscillator__ghost-fx.mp3 create mode 100644 bot/resources/spookysounds/168650__0xmusex0__doorcreak.mp3 create mode 100644 bot/resources/spookysounds/171078__klankbeeld__horror-scream-woman-long.mp3 create mode 100644 bot/resources/spookysounds/193812__geoneo0__four-voices-whispering-6.mp3 create mode 100644 bot/resources/spookysounds/237282__devilfish101__frantic-violin-screech.mp3 create mode 100644 bot/resources/spookysounds/249686__cylon8472__cthulhu-growl.mp3 create mode 100644 bot/resources/spookysounds/35716__analogchill__scream.mp3 create mode 100644 bot/resources/spookysounds/413315__inspectorj__something-evil-approaches-a.mp3 create mode 100644 bot/resources/spookysounds/60571__gabemiller74__breathofdeath.mp3 create mode 100644 bot/resources/spookysounds/Female_Monster_Growls_.mp3 create mode 100644 bot/resources/spookysounds/Male_Zombie_Roar_.mp3 create mode 100644 bot/resources/spookysounds/Monster_Alien_Growl_Calm_.mp3 create mode 100644 bot/resources/spookysounds/Monster_Alien_Grunt_Hiss_.mp3 create mode 100644 bot/resources/spookysounds/sources.txt (limited to 'bot') diff --git a/bot/cogs/spookysound.py b/bot/cogs/spookysound.py new file mode 100644 index 00000000..99c1ae24 --- /dev/null +++ b/bot/cogs/spookysound.py @@ -0,0 +1,39 @@ +import random +from pathlib import Path + +import discord +from discord.ext import commands + +HACKTOBERBOT_VOICE_CHANNEL_ID = 101010 # Replace with actual channel ID + + +class SpookySound: + + def __init__(self, bot): + self.bot = bot + self.sound_files = list(Path("./bot/resources/spookysounds").glob("*.mp3")) + self.channel = None + + async def on_ready(self): + self.channel = self.bot.get_channel(HACKTOBERBOT_VOICE_CHANNEL_ID) + + @commands.cooldown(rate=1, per=120) + @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. + """ + await ctx.send("Initiating spooky sound...") + voice = await self.channel.connect() + file_path = random.choice(self.sound_files) + src = discord.FFmpegPCMAudio(str(file_path.resolve())) + + async def disconnect(): + await voice.disconnect() + + voice.play(src, after=lambda e: self.bot.loop.create_task(disconnect())) + + +def setup(bot): + bot.add_cog(SpookySound(bot)) diff --git a/bot/resources/spookysounds/109710__tomlija__horror-gate.mp3 b/bot/resources/spookysounds/109710__tomlija__horror-gate.mp3 new file mode 100644 index 00000000..495f2bd1 Binary files /dev/null and b/bot/resources/spookysounds/109710__tomlija__horror-gate.mp3 differ diff --git a/bot/resources/spookysounds/126113__klankbeeld__laugh.mp3 b/bot/resources/spookysounds/126113__klankbeeld__laugh.mp3 new file mode 100644 index 00000000..538feabc Binary files /dev/null and b/bot/resources/spookysounds/126113__klankbeeld__laugh.mp3 differ diff --git a/bot/resources/spookysounds/133674__klankbeeld__horror-laugh-original-132802-nanakisan-evil-laugh-08.mp3 b/bot/resources/spookysounds/133674__klankbeeld__horror-laugh-original-132802-nanakisan-evil-laugh-08.mp3 new file mode 100644 index 00000000..17f66698 Binary files /dev/null and b/bot/resources/spookysounds/133674__klankbeeld__horror-laugh-original-132802-nanakisan-evil-laugh-08.mp3 differ diff --git a/bot/resources/spookysounds/14570__oscillator__ghost-fx.mp3 b/bot/resources/spookysounds/14570__oscillator__ghost-fx.mp3 new file mode 100644 index 00000000..5670657c Binary files /dev/null and b/bot/resources/spookysounds/14570__oscillator__ghost-fx.mp3 differ diff --git a/bot/resources/spookysounds/168650__0xmusex0__doorcreak.mp3 b/bot/resources/spookysounds/168650__0xmusex0__doorcreak.mp3 new file mode 100644 index 00000000..42f9e9fd Binary files /dev/null and b/bot/resources/spookysounds/168650__0xmusex0__doorcreak.mp3 differ diff --git a/bot/resources/spookysounds/171078__klankbeeld__horror-scream-woman-long.mp3 b/bot/resources/spookysounds/171078__klankbeeld__horror-scream-woman-long.mp3 new file mode 100644 index 00000000..1cdb0f4d Binary files /dev/null and b/bot/resources/spookysounds/171078__klankbeeld__horror-scream-woman-long.mp3 differ diff --git a/bot/resources/spookysounds/193812__geoneo0__four-voices-whispering-6.mp3 b/bot/resources/spookysounds/193812__geoneo0__four-voices-whispering-6.mp3 new file mode 100644 index 00000000..89150d57 Binary files /dev/null and b/bot/resources/spookysounds/193812__geoneo0__four-voices-whispering-6.mp3 differ diff --git a/bot/resources/spookysounds/237282__devilfish101__frantic-violin-screech.mp3 b/bot/resources/spookysounds/237282__devilfish101__frantic-violin-screech.mp3 new file mode 100644 index 00000000..b5f85f8d Binary files /dev/null and b/bot/resources/spookysounds/237282__devilfish101__frantic-violin-screech.mp3 differ diff --git a/bot/resources/spookysounds/249686__cylon8472__cthulhu-growl.mp3 b/bot/resources/spookysounds/249686__cylon8472__cthulhu-growl.mp3 new file mode 100644 index 00000000..d141f68e Binary files /dev/null and b/bot/resources/spookysounds/249686__cylon8472__cthulhu-growl.mp3 differ diff --git a/bot/resources/spookysounds/35716__analogchill__scream.mp3 b/bot/resources/spookysounds/35716__analogchill__scream.mp3 new file mode 100644 index 00000000..a0614b53 Binary files /dev/null and b/bot/resources/spookysounds/35716__analogchill__scream.mp3 differ diff --git a/bot/resources/spookysounds/413315__inspectorj__something-evil-approaches-a.mp3 b/bot/resources/spookysounds/413315__inspectorj__something-evil-approaches-a.mp3 new file mode 100644 index 00000000..38374316 Binary files /dev/null and b/bot/resources/spookysounds/413315__inspectorj__something-evil-approaches-a.mp3 differ diff --git a/bot/resources/spookysounds/60571__gabemiller74__breathofdeath.mp3 b/bot/resources/spookysounds/60571__gabemiller74__breathofdeath.mp3 new file mode 100644 index 00000000..f769d9d8 Binary files /dev/null and b/bot/resources/spookysounds/60571__gabemiller74__breathofdeath.mp3 differ diff --git a/bot/resources/spookysounds/Female_Monster_Growls_.mp3 b/bot/resources/spookysounds/Female_Monster_Growls_.mp3 new file mode 100644 index 00000000..8b04f0f5 Binary files /dev/null and b/bot/resources/spookysounds/Female_Monster_Growls_.mp3 differ diff --git a/bot/resources/spookysounds/Male_Zombie_Roar_.mp3 b/bot/resources/spookysounds/Male_Zombie_Roar_.mp3 new file mode 100644 index 00000000..964d685e Binary files /dev/null and b/bot/resources/spookysounds/Male_Zombie_Roar_.mp3 differ diff --git a/bot/resources/spookysounds/Monster_Alien_Growl_Calm_.mp3 b/bot/resources/spookysounds/Monster_Alien_Growl_Calm_.mp3 new file mode 100644 index 00000000..9e643773 Binary files /dev/null and b/bot/resources/spookysounds/Monster_Alien_Growl_Calm_.mp3 differ diff --git a/bot/resources/spookysounds/Monster_Alien_Grunt_Hiss_.mp3 b/bot/resources/spookysounds/Monster_Alien_Grunt_Hiss_.mp3 new file mode 100644 index 00000000..ad99cf76 Binary files /dev/null and b/bot/resources/spookysounds/Monster_Alien_Grunt_Hiss_.mp3 differ diff --git a/bot/resources/spookysounds/sources.txt b/bot/resources/spookysounds/sources.txt new file mode 100644 index 00000000..7df03c2e --- /dev/null +++ b/bot/resources/spookysounds/sources.txt @@ -0,0 +1,41 @@ +Female_Monster_Growls_ +Male_Zombie_Roar_ +Monster_Alien_Growl_Calm_ +Monster_Alien_Grunt_Hiss_ +https://www.youtube.com/audiolibrary/soundeffects + +413315__inspectorj__something-evil-approaches-a +https://freesound.org/people/InspectorJ/sounds/413315/ + +133674__klankbeeld__horror-laugh-original-132802-nanakisan-evil-laugh-08 +https://freesound.org/people/klankbeeld/sounds/133674/ + +35716__analogchill__scream +https://freesound.org/people/analogchill/sounds/35716/ + +249686__cylon8472__cthulhu-growl +https://freesound.org/people/cylon8472/sounds/249686/ + +126113__klankbeeld__laugh +https://freesound.org/people/klankbeeld/sounds/126113/ + +14570__oscillator__ghost-fx +https://freesound.org/people/oscillator/sounds/14570/ + +60571__gabemiller74__breathofdeath +https://freesound.org/people/gabemiller74/sounds/60571/ + +168650__0xmusex0__doorcreak +https://freesound.org/people/0XMUSEX0/sounds/168650/ + +193812__geoneo0__four-voices-whispering-6 +https://freesound.org/people/geoneo0/sounds/193812/ + +109710__tomlija__horror-gate +https://freesound.org/people/Tomlija/sounds/109710/ + +171078__klankbeeld__horror-scream-woman-long +https://freesound.org/people/klankbeeld/sounds/171078/ + +237282__devilfish101__frantic-violin-screech +https://freesound.org/people/devilfish101/sounds/237282/ -- cgit v1.2.3 From d019893bc598528730297bfb22ddc746e1c9734e Mon Sep 17 00:00:00 2001 From: meooow25 Date: Wed, 17 Oct 2018 12:38:32 +0530 Subject: * Update channel ID. * Add class docstring. * Make `disconnect` a helper static method. --- bot/cogs/spookysound.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'bot') diff --git a/bot/cogs/spookysound.py b/bot/cogs/spookysound.py index 99c1ae24..dd607097 100644 --- a/bot/cogs/spookysound.py +++ b/bot/cogs/spookysound.py @@ -4,10 +4,13 @@ from pathlib import Path import discord from discord.ext import commands -HACKTOBERBOT_VOICE_CHANNEL_ID = 101010 # Replace with actual channel ID +HACKTOBERBOT_VOICE_CHANNEL_ID = 498804789287714816 class SpookySound: + """ + A cog that plays a spooky sound in a voice channel on command. + """ def __init__(self, bot): self.bot = bot @@ -25,14 +28,17 @@ class SpookySound: once in 2 minutes. """ await ctx.send("Initiating spooky sound...") - voice = await self.channel.connect() 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))) - async def disconnect(): - await voice.disconnect() - - voice.play(src, after=lambda e: self.bot.loop.create_task(disconnect())) + @staticmethod + async def disconnect(voice): + """ + Helper method to disconnect a given voice client. + """ + await voice.disconnect() def setup(bot): -- cgit v1.2.3