edditing code
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import logging
|
||||
import tempfile
|
||||
from asyncio import sleep
|
||||
from os import path, makedirs, rename, remove
|
||||
from random import randrange
|
||||
import random
|
||||
|
||||
from disnake import FFmpegPCMAudio
|
||||
from disnake.ext import commands
|
||||
|
||||
from lib.DB import read_db, check_exist_audio, add_audio
|
||||
from lib.Player import play_audio
|
||||
|
||||
|
||||
class Audio(commands.Cog):
|
||||
@@ -22,24 +21,29 @@ class Audio(commands.Cog):
|
||||
async def on_voice_state_update(self, member, before, after):
|
||||
from lib.Comands import read_json
|
||||
role = await read_json(member.guild.id, 'tigger_role')
|
||||
audio = await read_db(member.guild.id, member.id, 'usertracks')
|
||||
# Read audio from DB
|
||||
audio_db = await read_db(member.guild.id, member.id, 'usertracks')
|
||||
def_audio_db = await read_db(member.guild.id, member.id, 'defaulttracks')
|
||||
if audio_db is not None:
|
||||
audio_db = audio_db.split(', ') # Need to fix creating list
|
||||
for i in range(len(audio_db)):
|
||||
audio_db[i] = f'{member.id}/{audio_db[i]}'
|
||||
print(audio_db)
|
||||
if def_audio_db is not None:
|
||||
def_audio_db = def_audio_db.split(', ')
|
||||
from lib.Comands import list_files
|
||||
audio_files = await list_files(f'audio/{member.id}')
|
||||
logging.info(f"state changed to user {member}")
|
||||
f = await list_files()
|
||||
if role is not None and before.channel is None and role in member.roles:
|
||||
track = randrange(0, len(f) - 1, 1)
|
||||
audio_source = FFmpegPCMAudio(f'audio/{f[track]}')
|
||||
def_audio_ls = await list_files()
|
||||
if before.channel is None and not member.bot:
|
||||
full_audio = []
|
||||
if def_audio_db or audio_db is not None:
|
||||
full_audio = def_audio_db + audio_db
|
||||
elif role in member.roles:
|
||||
full_audio = def_audio_ls
|
||||
print(full_audio)
|
||||
audio = random.choice(full_audio)
|
||||
print(audio)
|
||||
if not self.bot.voice_clients:
|
||||
await sleep(1)
|
||||
_channel = after.channel
|
||||
vc = await after.channel.connect()
|
||||
if not vc.is_playing():
|
||||
vc.play(audio_source, after=None)
|
||||
while vc.is_playing():
|
||||
await sleep(0.5)
|
||||
await sleep(1)
|
||||
await vc.disconnect()
|
||||
await play_audio(audio, self.bot, after.channel)
|
||||
|
||||
@commands.command(name="upload_audio")
|
||||
async def upload_audio(self, ctx, user=None):
|
||||
@@ -62,7 +66,7 @@ class Audio(commands.Cog):
|
||||
from pymediainfo import MediaInfo
|
||||
file = f'{tempfile.tempdir}/{user.id}/{at.filename}'
|
||||
duration = round(MediaInfo.parse(file).tracks[0].duration / 1000)
|
||||
if duration > 15:
|
||||
if duration > 20:
|
||||
await ctx.reply(f'Audio duration is {duration}, but max is 15')
|
||||
remove(f'{tempfile.tempdir}/{user.id}/{at.filename}')
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user