add the apscheduler
This commit is contained in:
parent
bc2796492a
commit
fcdef2e17c
1 changed files with 23 additions and 1 deletions
|
@ -1,15 +1,22 @@
|
||||||
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import discord
|
import discord
|
||||||
import requests
|
import requests
|
||||||
|
from datetime import datetime
|
||||||
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
|
|
||||||
# Read env variables
|
# Read env variables
|
||||||
bot_token = os.environ.get('DISCORDBOT_TOKEN', 'token')
|
bot_token = os.environ.get('DISCORDBOT_TOKEN', 'token')
|
||||||
scheduler_hostname = os.environ.get('SCHEDULER_API_HOSTNAME', 'tv.example.com')
|
scheduler_hostname = os.environ.get('SCHEDULER_API_HOSTNAME', 'tv.example.com')
|
||||||
|
|
||||||
|
# Scheduler
|
||||||
|
scheduler = AsyncIOScheduler()
|
||||||
|
|
||||||
# Intents
|
# Intents
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
|
|
||||||
|
# Client
|
||||||
client = discord.Client(intents=intents)
|
client = discord.Client(intents=intents)
|
||||||
|
|
||||||
# Define an event when the bot is ready
|
# Define an event when the bot is ready
|
||||||
|
@ -43,4 +50,19 @@ async def on_message(message):
|
||||||
if message.content.startswith('!epg'):
|
if message.content.startswith('!epg'):
|
||||||
await epg(message)
|
await epg(message)
|
||||||
|
|
||||||
client.run(bot_token)
|
client.run(bot_token)
|
||||||
|
|
||||||
|
def tick():
|
||||||
|
print('Tick! The time is: %s' % datetime.now())
|
||||||
|
|
||||||
|
scheduler.add_job(tick, 'interval', seconds=3)
|
||||||
|
scheduler.start()
|
||||||
|
|
||||||
|
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
|
||||||
|
|
||||||
|
# Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
|
||||||
|
try:
|
||||||
|
asyncio.get_event_loop().run_forever()
|
||||||
|
except (KeyboardInterrupt, SystemExit):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue