mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
Add it just works
This commit is contained in:
parent
6a9e0af902
commit
a1e00cd3bb
4 changed files with 34 additions and 0 deletions
BIN
assets/it-just-works.mp3
Normal file
BIN
assets/it-just-works.mp3
Normal file
Binary file not shown.
BIN
assets/it-just-works.ogg
Normal file
BIN
assets/it-just-works.ogg
Normal file
Binary file not shown.
Binary file not shown.
|
@ -1,7 +1,9 @@
|
||||||
import io
|
import io
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import asyncio
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
import discord
|
import discord
|
||||||
|
@ -153,6 +155,21 @@ class Events(commands.Cog):
|
||||||
if message.channel.permissions_for(message.guild.me).manage_messages:
|
if message.channel.permissions_for(message.guild.me).manage_messages:
|
||||||
await message.edit(suppress=True)
|
await message.edit(suppress=True)
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_voice_state_update(
|
||||||
|
self,
|
||||||
|
member: discord.Member,
|
||||||
|
*_
|
||||||
|
):
|
||||||
|
me_voice = member.guild.voice_state
|
||||||
|
if me_voice is None or me_voice.channel is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
channel = me_voice.channel
|
||||||
|
if len(channel.members) - 1 == 0:
|
||||||
|
# We are the only one in the channel
|
||||||
|
await me_voice.disconnect()
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_message(self, message: discord.Message):
|
async def on_message(self, message: discord.Message):
|
||||||
if not message.guild:
|
if not message.guild:
|
||||||
|
@ -206,6 +223,23 @@ class Events(commands.Cog):
|
||||||
# Only respond if the message has content...
|
# Only respond if the message has content...
|
||||||
if message.content:
|
if message.content:
|
||||||
if message.channel.can_send(): # ... and we can send messages
|
if message.channel.can_send(): # ... and we can send messages
|
||||||
|
if "it just works" in message.content.lower():
|
||||||
|
file = Path.cwd() / "assets" / "it-just-works.ogg"
|
||||||
|
if message.author.voice is not None:
|
||||||
|
if message.guild.voice is not None:
|
||||||
|
await message.guild.voice.disconnect()
|
||||||
|
my_voice = await message.author.voice.channel.connect()
|
||||||
|
voice = await message.author.voice.channel.connect()
|
||||||
|
voice.play(
|
||||||
|
discord.FFmpegPCMAudio(str(file), stderr=subprocess.DEVNULL),
|
||||||
|
after=lambda _: asyncio.run_coroutine_threadsafe(
|
||||||
|
voice.disconnect(),
|
||||||
|
self.bot.loop
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await message.reply(file=discord.File(file))
|
||||||
|
|
||||||
if "linux" in message.content.lower() and self.bot.user in message.mentions:
|
if "linux" in message.content.lower() and self.bot.user in message.mentions:
|
||||||
console.log(f"Responding to {message.author} with linux copypasta")
|
console.log(f"Responding to {message.author} with linux copypasta")
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue