add cron command

This commit is contained in:
Milka64 2019-10-08 16:21:29 +02:00
parent afe379120c
commit c10a91e9da
2 changed files with 20 additions and 3 deletions

View file

@ -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:
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)

View file

@ -15,6 +15,7 @@ requirements = [
'discord.py',
'requests',
'PyNaCl',
'aiocron',
]
setup_requirements = [ ]