Spaces:
Runtime error
Runtime error
Create d.py
Browse files
cogs/d.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import discord, os, setting, re, asyncio
|
| 2 |
+
from discord.ext import commands
|
| 3 |
+
from logging import getLogger
|
| 4 |
+
import logging
|
| 5 |
+
|
| 6 |
+
def make_log():
|
| 7 |
+
logger = getLogger(__name__)
|
| 8 |
+
logger.setLevel(logging.INFO)
|
| 9 |
+
streamHandler = logging.StreamHandler()
|
| 10 |
+
logger.addHandler(streamHandler)
|
| 11 |
+
|
| 12 |
+
return logger
|
| 13 |
+
|
| 14 |
+
log = make_log()
|
| 15 |
+
|
| 16 |
+
async def v_after(sink: discord.sinks, vc):
|
| 17 |
+
user_id = ""
|
| 18 |
+
for user_id, audio in sink.audio_data.itmes():
|
| 19 |
+
user_id_raw = user_id
|
| 20 |
+
user_id = f"<@{user_id}>"
|
| 21 |
+
with open("./out.mp3", "wb") as f:
|
| 22 |
+
f.write(audio.file.getbuffer())
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class DDD(commands.Cog):
|
| 26 |
+
|
| 27 |
+
"""
|
| 28 |
+
๋ด ์ํ ํ์ผ ์
๋๋ค.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
def __init__(self, bot):
|
| 32 |
+
self.bot = bot
|
| 33 |
+
|
| 34 |
+
@commands.Cog.listener()
|
| 35 |
+
async def on_voice_state_update(self, member, before, after):
|
| 36 |
+
if before.channel:
|
| 37 |
+
voice_client = discord.utils.get(self.bot.voice_clients, guild=member.guild.id)
|
| 38 |
+
if voice_client is None:
|
| 39 |
+
vc = await member.voice.channel.connect()
|
| 40 |
+
else:
|
| 41 |
+
vc = voice_client
|
| 42 |
+
|
| 43 |
+
if os.fath.exists("./out.mp3")
|
| 44 |
+
os.remove("./out.mp3")
|
| 45 |
+
|
| 46 |
+
vc.start_recording(
|
| 47 |
+
discord.sinks.MP3Sink(),
|
| 48 |
+
v_after,
|
| 49 |
+
vc
|
| 50 |
+
)
|
| 51 |
+
await asyncio.sleep(10)
|
| 52 |
+
vc.stop_recording()
|
| 53 |
+
|
| 54 |
+
# if (before.channel is None) and (after.channel is not None):
|
| 55 |
+
# if member == self.bot.user:
|
| 56 |
+
# await member.edit(deafen=True, mute=False)
|
| 57 |
+
if after.channel:
|
| 58 |
+
if (before.channel is not None) and (after.channel is not before.channel):
|
| 59 |
+
if ((self.bot.user.id in before.channel.voice_states.keys() and len(before.channel.voice_states) == 1) or (member == self.bot.user)):
|
| 60 |
+
if member != self.bot.user:
|
| 61 |
+
player = member.guild.voice_client
|
| 62 |
+
await player.disconnect()
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def setup(bot):
|
| 66 |
+
bot.add_cog(DDD(bot))
|