modify playing status so it changes based on time of day

Fixes #57
This commit is contained in:
Abigail 2019-12-23 13:29:04 -05:00
parent 781a3fa4dd
commit f649d15890
3 changed files with 32 additions and 4 deletions

23
main.py
View File

@ -8,12 +8,14 @@ This file is part of discord-qrm2 and is released under the terms of the GNU
General Public License, version 2.
"""
from datetime import time, datetime
import discord
from discord.ext import commands, tasks
import pytz
import common as cmn
import info
import data.options as opt
import data.keys as keys
@ -129,7 +131,24 @@ async def on_message(message):
@tasks.loop(minutes=5)
async def _ensure_activity():
await bot.change_presence(activity=discord.Game(name=opt.game))
status = opt.status_default
try:
tz = pytz.timezone(opt.status_tz)
except pytz.exceptions.UnknownTimeZoneError:
print(f'[!!] UnknownTimeZoneError: {opt.status_tz}')
await bot.change_presence(activity=discord.Game(name=status))
return
now = datetime.now(tz=tz).time()
for sts in opt.statuses:
start_time = time(hour=sts[1][0], minute=sts[1][1], tzinfo=tz)
end_time = time(hour=sts[2][0], minute=sts[2][1], tzinfo=tz)
if start_time < now <= end_time:
status = sts[0]
await bot.change_presence(activity=discord.Game(name=status))
@_ensure_activity.before_loop

View File

@ -2,3 +2,4 @@ discord.py
ctyparser
beautifulsoup4
lxml
pytz

View File

@ -29,8 +29,16 @@ owners_uids = (200102491231092736,)
# The extensions to load when running the bot.
exts = ['ae7q', 'base', 'fun', 'grid', 'ham', 'image', 'lookup', 'morse', 'qrz', 'study', 'weather']
# The text to put in the "playing" status.
game = 'with lids on 7.200'
# Timezone for the status (string)
status_tz = 'US/Eastern'
# The text to put in the "playing" status, with start and stop times
statuses = [('with lids on 3.840', (00,00), (6,00)),
('with lids on 7.200', (6,00), (10,00)),
('with lids on 14.313', (10,00), (18,00)),
('with lids on 7.200', (18,00), (20,00)),
('with lids on 3.840', (20,00), (23,59))]
# The text to put in the "playing" status otherwise
status_default = 'with lids on the air'
# Emoji IDs and keywords for emoji reactions
# Use the format {emoji_id (int): ('tuple', 'of', 'lowercase', 'keywords')}