fix some stuff
This commit is contained in:
parent
112760299f
commit
a9cc9e20c0
1 changed files with 47 additions and 9 deletions
|
@ -43,7 +43,12 @@ stream_handler.setLevel(logging.INFO)
|
|||
logger.addHandler(stream_handler)
|
||||
|
||||
|
||||
class Mybot(commands.Cog):
|
||||
ffmpeg_options = {
|
||||
'options': '-vn -loglevel debug',
|
||||
}
|
||||
|
||||
#class Mybot(commands.Cog):
|
||||
class Mybot(discord.Client):
|
||||
#Fonctions necesaires pour Kabot.
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -66,13 +71,18 @@ class Mybot(commands.Cog):
|
|||
self.sounds = []
|
||||
self.nickname = nickname
|
||||
self.sounds_history = []
|
||||
self.play_next.start()
|
||||
#self.play_next.start()
|
||||
|
||||
@tasks.loop(seconds=1.5)
|
||||
async def setup_hook(self) -> None:
|
||||
# create the background task and run it in the background
|
||||
self.bg_task = self.loop.create_task(self.play_next())
|
||||
|
||||
#@tasks.loop(seconds=1.5)
|
||||
async def play_next(self):
|
||||
if self.sounds:
|
||||
audio_file, ctx = self.sounds[0]
|
||||
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file))
|
||||
print(type(audio_file))
|
||||
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file,**ffmpeg_options))
|
||||
if not ctx.voice_client.is_playing() and ctx.voice_client.is_connected():
|
||||
ctx.voice_client.play(source, after=lambda e: print('Player error: %s' % e) if e else None)
|
||||
self.sounds.pop(0)
|
||||
|
@ -591,6 +601,9 @@ def get_word(word_type):
|
|||
|
||||
#Le do[main]e de Kabot.
|
||||
def main():
|
||||
intents = discord.Intents.default()
|
||||
intents.members = True
|
||||
intents.messages = True
|
||||
logger.info("Initialisation de Kabot")
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
|
@ -632,6 +645,8 @@ def main():
|
|||
gif_token = config['giphy']['token']
|
||||
bot = commands.Bot(
|
||||
command_prefix='!',
|
||||
intents=intents,
|
||||
audio_path="/home/mika/kabot-audio",
|
||||
)
|
||||
|
||||
test = False
|
||||
|
@ -658,6 +673,7 @@ def main():
|
|||
if message.author == bot.user:
|
||||
return
|
||||
else:
|
||||
print(message.content)
|
||||
if bot.user in message.mentions \
|
||||
and len(message.mentions) < 3 \
|
||||
and len(message.content.splitlines()) == 1:
|
||||
|
@ -669,6 +685,7 @@ def main():
|
|||
f.write(message.content + '\n')
|
||||
response = random.choice(lines).replace(str(bot.user.id), str(message.author.id))
|
||||
if response.startswith('!'):
|
||||
print('test')
|
||||
command_name = response.split()[0].replace('!', '')
|
||||
cmd = bot.get_command(command_name)
|
||||
await cmd.invoke(message)
|
||||
|
@ -681,6 +698,25 @@ def main():
|
|||
await message.channel.send(response)
|
||||
await bot.process_commands(message)
|
||||
|
||||
@bot.command()
|
||||
async def join(interaction: discord.Interaction):
|
||||
channel = [x for x in bot.get_all_channels() if x.name == voice_channel][0]
|
||||
await channel.connect()
|
||||
await asyncio.sleep(2)
|
||||
|
||||
@bot.command()
|
||||
async def welcome(interaction: discord.Interaction):
|
||||
# if ctx.message.author.name == self.bot.user.name:
|
||||
# return
|
||||
user = interaction.message.author.name
|
||||
print(user)
|
||||
try:
|
||||
audio_file = random.choice([f for f in os.listdir(bot.audio_path + '/%s/' % user) if f.endswith('.mp3')])
|
||||
audio_file = bot.audio_path + '/%s/' % user + audio_file
|
||||
except:
|
||||
audio_file = random.choice([f"{f}" for f in Path(bot.audio_path + '/').glob('**/*.mp3')])
|
||||
bot.sounds.append((audio_file, interaction))
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print('yeah baby!')
|
||||
|
@ -693,8 +729,8 @@ def main():
|
|||
await bot.user.edit(nick=nickname)
|
||||
await current_chan.send('Le troll est dans la place !')
|
||||
ctx = await bot.get_context(current_chan.last_message)
|
||||
join = bot.get_command('join')
|
||||
await join.invoke(ctx)
|
||||
#join = bot.get_command('join')
|
||||
#await join.invoke(ctx)
|
||||
for channel in bot.get_all_channels():
|
||||
if channel.name == voice_channel:
|
||||
for member in channel.members:
|
||||
|
@ -708,9 +744,9 @@ def main():
|
|||
current_chan = channel
|
||||
ctx = await bot.get_context(current_chan.last_message)
|
||||
ctx.message.author = member
|
||||
welcome = bot.get_command('welcome')
|
||||
#welcome = bot.get_command('welcome')
|
||||
await asyncio.sleep(2)
|
||||
await welcome.invoke(ctx)
|
||||
#await welcome.invoke(ctx)
|
||||
|
||||
@aiocron.crontab('*/5 * * * *')
|
||||
async def pipelette():
|
||||
|
@ -726,7 +762,9 @@ def main():
|
|||
ctx.message.content = ""
|
||||
joke = bot.get_command('joke')
|
||||
await joke.invoke(ctx)
|
||||
|
||||
@bot.command(help='check if bot always online')
|
||||
async def ping(ctx):
|
||||
await ctx.channel.send('pong')
|
||||
bot.add_cog(
|
||||
Mybot(
|
||||
bot,
|
||||
|
|
Loading…
Reference in a new issue