add random joke in crontab && joke can find keyword match

This commit is contained in:
Milka64 2019-10-18 16:34:44 +02:00
parent 0f40126348
commit 8e0023be1d

View file

@ -32,19 +32,24 @@ class Mybot(commands.Cog):
await ctx.guild.voice_client.disconnect()
@commands.command()
async def joke(self, ctx):
async def joke(self, ctx, folder=None):
if ctx.message.author.name == self.bot.user.name:
return
user = ctx.message.author.name
audio_file = random.choice([f for f in Path('/home/mika/kabot/kabot/kabot/Audio/').glob('**/*.mp3')])
if not folder:
audio_file = random.choice([f for f in Path('/home/mika/kabot/kabot/kabot/Audio/').glob('**/*.mp3')])
else:
folder = folder.lower()
audio_file = random.choice([f for f in Path('/home/mika/kabot/kabot/kabot/Audio/').glob('**/*.mp3') if folder in str(f).lower()])
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file))
self.sounds.append((source,ctx))
@commands.command()
async def welcome(self, ctx):
if ctx.message.author.name == self.bot.user.name:
return
#if ctx.message.author.name == self.bot.user.name:
# return
user = ctx.message.author.name
print(user)
try:
audio_file = random.choice([f for f in os.listdir('/home/mika/kabot/kabot/kabot/Audio/%s/' % user) if f.endswith('.mp3')])
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("/home/mika/kabot/kabot/kabot/Audio/%s/%s" % (user,audio_file)))
@ -52,6 +57,7 @@ class Mybot(commands.Cog):
audio_file = random.choice([f for f in Path('/home/mika/kabot/kabot/kabot/Audio/').glob('**/*.mp3')])
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file))
self.sounds.append((source,ctx))
print(self.sounds)
@commands.command(help='Update local repo')
async def update(self, message):
@ -103,7 +109,7 @@ class Mybot(commands.Cog):
async def play_next(self):
if self.sounds:
source,ctx = self.sounds[0]
if not ctx.voice_client.is_playing():
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)
@ -128,14 +134,10 @@ def main():
ctx = await bot.get_context(current_chan.last_message)
join = bot.get_command('join')
await join.invoke(ctx)
user = ctx.message.author.name
audio_file = random.choice([f for f in os.listdir('/home/mika/kabot/kabot/kabot/Audio/%s/' % user) if f.endswith('.mp3')])
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("/home/mika/kabot/kabot/kabot/Audio/%s/%s" % (user,audio_file)))
self.sounds.append((source,ctx))
@aiocron.crontab('50 9-23/1 * * *')
async def kron():
if random.choice([True,True,False]):
if random.choice([True,False,False]):
for channel in bot.get_all_channels():
if channel.name == "général":
current_chan = channel
@ -145,6 +147,21 @@ def main():
kaamelott = bot.get_command('kaamelott')
await kaamelott.invoke(ctx)
@aiocron.crontab('*/5 * * * *')
async def pipelette():
for channel in bot.get_all_channels():
if channel.name == "Général" and\
len(channel.members) > 1 and\
random.choice([True,False,False]):
for channel in bot.get_all_channels():
if channel.name == "général":
current_chan = channel
sleep(choice(range(350)))
ctx = await bot.get_context(current_chan.last_message)
ctx.message.content = ""
joke = bot.get_command('joke')
await joke.invoke(ctx)
@bot.event
async def on_message(message):
print(message.content)