added activity check

This commit is contained in:
2022-08-25 08:30:26 +03:00
parent a6eaec4190
commit a603898f2d
2 changed files with 39 additions and 32 deletions

View File

@@ -19,35 +19,39 @@ class Audio(commands.Cog):
@commands.Cog.listener()
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')
# 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]}'
if def_audio_db is not None:
def_audio_db = def_audio_db.split(', ')
from lib.Comands import list_files
def_audio_ls = await list_files()
if before.channel is None and not member.bot:
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 = []
logging.info(f'Play audio from DB')
full_audio = def_audio_db + audio_db
audio = random.choice(full_audio)
await play_audio(audio, self.bot, after.channel)
elif len(member.roles) == 1 or _role is None:
logging.info(f'Skip playing')
elif any(str(role.id) in _role for role in member.roles):
logging.info(f'Play audio from list by role')
audio = random.choice(def_audio_ls)
await play_audio(audio, self.bot, after.channel)
else:
logging.info(f'Skip playing')
if any('Escape from Tarkov' in str(user.activity) for user in after.channel.members):
logging.info('Skip playing by Game')
else:
from lib.Comands import read_json
_role = await read_json(member.guild.id, 'tigger_role')
# 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]}'
if def_audio_db is not None:
def_audio_db = def_audio_db.split(', ')
from lib.Comands import list_files
def_audio_ls = await list_files()
if before.channel is None and not member.bot:
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 = []
logging.info(f'Play audio from DB')
full_audio = def_audio_db + audio_db
audio = random.choice(full_audio)
await play_audio(audio, self.bot, after.channel)
elif len(member.roles) == 1 or _role is None:
logging.info(f'Skip playing')
elif any(str(role.id) in _role for role in member.roles):
logging.info(f'Play audio from list by role')
audio = random.choice(def_audio_ls)
await play_audio(audio, self.bot, after.channel)
else:
logging.info(f'Skip playing')
@commands.command(name="upload_audio")
async def upload_audio(self, ctx, user=None):