finishising play func
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
from os import path, makedirs, rename, remove
|
from os import path, makedirs, rename, remove
|
||||||
import random
|
|
||||||
|
|
||||||
from disnake.ext import commands
|
from disnake.ext import commands
|
||||||
|
|
||||||
@@ -20,30 +19,44 @@ class Audio(commands.Cog):
|
|||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_voice_state_update(self, member, before, after):
|
async def on_voice_state_update(self, member, before, after):
|
||||||
from lib.Comands import read_json
|
from lib.Comands import read_json
|
||||||
role = await read_json(member.guild.id, 'tigger_role')
|
_role = await read_json(member.guild.id, 'tigger_role')
|
||||||
# Read audio from DB
|
# Read audio from DB
|
||||||
audio_db = await read_db(member.guild.id, member.id, 'usertracks')
|
audio_db = await read_db(member.guild.id, member.id, 'usertracks')
|
||||||
def_audio_db = await read_db(member.guild.id, member.id, 'defaulttracks')
|
def_audio_db = await read_db(member.guild.id, member.id, 'defaulttracks')
|
||||||
|
print(f'Trigger role: {_role}')
|
||||||
|
print(f' Memder roles {member.roles}')
|
||||||
|
print(role.id in _role for role in member.roles)
|
||||||
|
|
||||||
|
print(f'Audio DB: {audio_db}')
|
||||||
|
print(f'Def audio DB: {def_audio_db}')
|
||||||
|
print(f' Memder is bot {member.bot}')
|
||||||
|
print(f' Before channel {before.channel}')
|
||||||
|
print('------------------------------------------')
|
||||||
|
|
||||||
if audio_db is not None:
|
if audio_db is not None:
|
||||||
audio_db = audio_db.split(', ') # Need to fix creating list
|
audio_db = audio_db.split(', ') # Need to fix creating list
|
||||||
for i in range(len(audio_db)):
|
for i in range(len(audio_db)):
|
||||||
audio_db[i] = f'{member.id}/{audio_db[i]}'
|
audio_db[i] = f'{member.id}/{audio_db[i]}'
|
||||||
print(audio_db)
|
|
||||||
if def_audio_db is not None:
|
if def_audio_db is not None:
|
||||||
def_audio_db = def_audio_db.split(', ')
|
def_audio_db = def_audio_db.split(', ')
|
||||||
from lib.Comands import list_files
|
from lib.Comands import list_files
|
||||||
def_audio_ls = await list_files()
|
def_audio_ls = await list_files()
|
||||||
if before.channel is None and not member.bot:
|
if before.channel is None and not member.bot:
|
||||||
full_audio = []
|
|
||||||
if def_audio_db or audio_db is not None:
|
if def_audio_db or audio_db is not None:
|
||||||
|
if def_audio_db is None: def_audio_db = []
|
||||||
|
if audio_db is None: audio_db = []
|
||||||
|
print(audio_db, def_audio_db)
|
||||||
|
logging.info(f'Play audio from DB')
|
||||||
full_audio = def_audio_db + audio_db
|
full_audio = def_audio_db + audio_db
|
||||||
elif role in member.roles:
|
|
||||||
full_audio = def_audio_ls
|
if not self.bot.voice_clients:
|
||||||
print(full_audio)
|
await play_audio(full_audio, self.bot, after.channel)
|
||||||
audio = random.choice(full_audio)
|
elif (role.id in _role for role in member.roles):
|
||||||
print(audio)
|
logging.info(f'Play audio from list by role')
|
||||||
if not self.bot.voice_clients:
|
if not self.bot.voice_clients:
|
||||||
await play_audio(audio, self.bot, after.channel)
|
await play_audio(def_audio_ls, self.bot, after.channel)
|
||||||
|
else:
|
||||||
|
logging.info(f'Skip playing')
|
||||||
|
|
||||||
@commands.command(name="upload_audio")
|
@commands.command(name="upload_audio")
|
||||||
async def upload_audio(self, ctx, user=None):
|
async def upload_audio(self, ctx, user=None):
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
import logging
|
||||||
|
import random
|
||||||
from asyncio import sleep
|
from asyncio import sleep
|
||||||
|
|
||||||
from disnake import FFmpegPCMAudio
|
from disnake import FFmpegPCMAudio
|
||||||
|
|
||||||
|
|
||||||
async def play_audio(audio, bot, vc):
|
async def play_audio(full_audio, bot, vc):
|
||||||
if not bot.voice_clients:
|
if not bot.voice_clients:
|
||||||
|
audio = random.choice(full_audio)
|
||||||
|
logging.error(f'Playing: {audio}')
|
||||||
await sleep(1)
|
await sleep(1)
|
||||||
vp = await vc.connect()
|
vp = await vc.connect()
|
||||||
if not vp.is_playing():
|
if not vp.is_playing():
|
||||||
|
|||||||
Reference in New Issue
Block a user