some minor changes

This commit is contained in:
bacon
2024-03-07 21:37:50 +03:00
parent 9934c5272c
commit 73cf9f3c6e
6 changed files with 10 additions and 90 deletions

2
bot.py
View File

@@ -33,7 +33,7 @@ asyncio.run(work_with_cogs('load', bot, asyncio.run(cog_list())))
@bot.event @bot.event
async def on_ready(): async def on_ready():
logger.info(f'Bot started') logger.info('Bot started')
logger.info(f'Disnake version {disnake.__version__}') logger.info(f'Disnake version {disnake.__version__}')
logger.info('We have logged in as {0.user}'.format(bot)) logger.info('We have logged in as {0.user}'.format(bot))
logger.info(f'Version of bot is - v{ver.major}.{ver.minor}.{ver.micro}-{ver.releaselevel}') logger.info(f'Version of bot is - v{ver.major}.{ver.minor}.{ver.micro}-{ver.releaselevel}')

View File

@@ -38,15 +38,15 @@ class Audio(commands.Cog, name='Audio'):
audio = await list_files() audio = await list_files()
if audio_db is not None: if audio_db is not None:
logger.info(f'Play audio from DB') logger.info('Play audio from DB')
await play_audio(f'audio/{random.choice(audio)}', self.bot, after.channel) await play_audio(f'audio/{random.choice(audio)}', self.bot, after.channel)
elif len(member.roles) == 1 or _role is None: elif len(member.roles) == 1 or _role is None:
logger.info(f'Skip playing by role') logger.info('Skip playing by role')
elif any(str(role.id) in _role for role in member.roles): elif any(str(role.id) in _role for role in member.roles):
logger.info(f'Play audio from list by role') logger.info('Play audio from list by role')
await play_audio(f'audio/{random.choice(audio)}', self.bot, after.channel) await play_audio(f'audio/{random.choice(audio)}', self.bot, after.channel)
else: else:
logger.info(f'Skip playing by any else') logger.info('Skip playing by any else')
@commands.slash_command(name="play_audio", @commands.slash_command(name="play_audio",
description="Make possible playing audio by command", description="Make possible playing audio by command",

View File

@@ -41,7 +41,7 @@ class General(commands.Cog):
audios = "Not selected audio" audios = "Not selected audio"
emb = disnake.Embed( emb = disnake.Embed(
title=f"General information", title="General information",
description=f"General information on server about {user}", description=f"General information on server about {user}",
color=Colour.random() color=Colour.random()
) )

View File

@@ -23,8 +23,8 @@ class BotInfo(commands.Cog, name='Bot Info'):
_pid = os.getpid() _pid = os.getpid()
_process = psutil.Process(_pid) _process = psutil.Process(_pid)
emb = disnake.Embed( emb = disnake.Embed(
title=f"General information", title="General information",
description=f"General information on about bot", description="General information on about bot",
) )
emb.set_thumbnail(self.bot.user.avatar.url) emb.set_thumbnail(self.bot.user.avatar.url)
emb.add_field(name="System info:", value=f"Memory Usage: {round(_process.memory_info().rss / 2 ** 20, 2)} Mb\n" emb.add_field(name="System info:", value=f"Memory Usage: {round(_process.memory_info().rss / 2 ** 20, 2)} Mb\n"
@@ -33,7 +33,7 @@ class BotInfo(commands.Cog, name='Bot Info'):
f'Prefix: `{determine_prefix(self.bot, inter)}\n`' f'Prefix: `{determine_prefix(self.bot, inter)}\n`'
f"Max audio duration: {determine_time(inter)} sec\n" f"Max audio duration: {determine_time(inter)} sec\n"
) )
emb.add_field(name="Bot info:", value=f"Bot owner: <@386629192743256065>\n" emb.add_field(name="Bot info:", value="Bot owner: <@386629192743256065>\n"
f"Bot version: {ver.major}.{ver.minor}.{ver.micro}-{ver.releaselevel}") f"Bot version: {ver.major}.{ver.minor}.{ver.micro}-{ver.releaselevel}")
emb.set_footer(text="Information requested by: {}".format(inter.author.display_name)) emb.set_footer(text="Information requested by: {}".format(inter.author.display_name))

80
main.py
View File

@@ -1,80 +0,0 @@
import random
import sys
import threading
import logging
import discord
from asyncio import sleep
from os import walk
from discord import user, member
from discord import FFmpegPCMAudio
from discord.ext import commands
threading.current_thread().name = "main"
logging.basicConfig(stream=sys.stdout, filemode='w', level='INFO',
format='%(asctime)s - %(levelname)s - %(threadName)s - %(message)s')
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='$', guild_subscriptions=True, intents=intents)
f = []
for filenames in walk('audio'):
f.extend(filenames)
break
f = f[2]
@bot.event
async def on_voice_state_update(member, before, after):
# channel = bot.get_channel(783729824896122930)
_role = 929729495370461205
_memb = 375664768087752714
_bot_id = 946819004314570852
role = discord.utils.find(lambda r: r.name == 'тарковчане', member.roles)
if before.channel is None and role in member.roles:
track = random.randint(0, len(f) - 1)
audio_source = FFmpegPCMAudio(f'audio/{f[track]}')
logging.error(f'{track}\t\t{f[track]}')
if not 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()
if before.channel is None and member.id == _memb:
track = random.randint(0, len(f) - 1)
audio_source = FFmpegPCMAudio(f'audio/{_memb}/bear2_enemy_scav3.wav')
logging.error(f'{track}\t\t\t{f[track]}')
if not 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()
@bot.event
async def on_member_join(member):
if member.bot == 0:
role = discord.utils.get(member.guild.roles, id=734358428939452486)
else:
role = discord.utils.get(member.guild.roles, id=734358434945826858)
logging.info(f"Adding to {member} role {role}")
await member.add_roles(role)
@bot.event
async def on_ready():
logging.info(f'Bot started')
bot.run('OTQ2ODE5MDA0MzE0NTcwODUy.YhkP6Q.dhFqi2MJMrxzHt5FtjK5Cl-5BI8')

View File

@@ -1,4 +1,4 @@
disnake[audio]==2.8.0 disnake[audio]==2.9.1
psutil==5.9.4 psutil==5.9.4
pymediainfo==6.0.1 pymediainfo==6.0.1
pyNaCl~=1.5.0 pyNaCl~=1.5.0