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 from sys import argv
import aiocron
class Mybot(commands.Cog): class Mybot(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@ -53,9 +55,8 @@ class Mybot(commands.Cog):
@commands.command(help="optionnal args : [livre] [character]") @commands.command(help="optionnal args : [livre] [character]")
async def kaamelott(self, ctx, *args): async def kaamelott(self, ctx, *args):
response = None response = None
if not args: url = 'https://kaamelott.chaudie.re/api/random'
url = 'https://kaamelott.chaudie.re/api/random' if args and ctx.message.content:
else:
args = list(args) args = list(args)
if args[0].isdigit(): if args[0].isdigit():
livre = int(args[0]) livre = int(args[0])
@ -74,8 +75,11 @@ class Mybot(commands.Cog):
else: else:
url = 'https://kaamelott.chaudie.re/api/random/livre/%s' % livre url = 'https://kaamelott.chaudie.re/api/random/livre/%s' % livre
try: try:
print(url)
citation = requests.get(url).json()['citation'] citation = requests.get(url).json()['citation']
print(citation)
response = "%s :\n```\n%s\n```" % (citation['infos']['personnage'], citation['citation']) response = "%s :\n```\n%s\n```" % (citation['infos']['personnage'], citation['citation'])
print(response)
except: except:
response = "Unknow error, try: !kaamelott [livre] [character]" response = "Unknow error, try: !kaamelott [livre] [character]"
await ctx.send(response) await ctx.send(response)
@ -102,6 +106,18 @@ def main():
join = bot.get_command('join') join = bot.get_command('join')
await join.invoke(ctx) 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 @bot.event
async def on_message(message): async def on_message(message):
print(message.content) print(message.content)

View file

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