diff --git a/kabot/kabot/kabot.py b/kabot/kabot/kabot.py index c6aea43..f488dc1 100644 --- a/kabot/kabot/kabot.py +++ b/kabot/kabot/kabot.py @@ -14,6 +14,8 @@ from subprocess import * from sys import argv +import aiocron + class Mybot(commands.Cog): def __init__(self, bot): self.bot = bot @@ -53,9 +55,8 @@ class Mybot(commands.Cog): @commands.command(help="optionnal args : [livre] [character]") async def kaamelott(self, ctx, *args): response = None - if not args: - url = 'https://kaamelott.chaudie.re/api/random' - else: + url = 'https://kaamelott.chaudie.re/api/random' + if args and ctx.message.content: args = list(args) if args[0].isdigit(): livre = int(args[0]) @@ -74,8 +75,11 @@ class Mybot(commands.Cog): else: url = 'https://kaamelott.chaudie.re/api/random/livre/%s' % livre try: + print(url) citation = requests.get(url).json()['citation'] + print(citation) response = "%s :\n```\n%s\n```" % (citation['infos']['personnage'], citation['citation']) + print(response) except: response = "Unknow error, try: !kaamelott [livre] [character]" await ctx.send(response) @@ -102,6 +106,18 @@ def main(): join = bot.get_command('join') await join.invoke(ctx) + @aiocron.crontab('50 9-23/1 * * *') + async def kron(): + if choice([True,True,False]): + for channel in bot.get_all_channels(): + if channel.name == "général": + current_chan = channel + ctx = await bot.get_context(current_chan.last_message) + ctx.message.content = "" + print(ctx.message.content) + kaamelott = bot.get_command('kaamelott') + await kaamelott.invoke(ctx) + @bot.event async def on_message(message): print(message.content) diff --git a/kabot/setup.py b/kabot/setup.py index 28c21c7..cedb869 100644 --- a/kabot/setup.py +++ b/kabot/setup.py @@ -15,6 +15,7 @@ requirements = [ 'discord.py', 'requests', 'PyNaCl', + 'aiocron', ] setup_requirements = [ ]