mirror of
https://github.com/miaowware/qrm2.git
synced 2024-10-01 08:16:44 -04:00
Merge pull request #129 from classabbyamp/dynamic-status
modify playing status so it changes based on time of day
This commit is contained in:
commit
0bc368877b
49
main.py
49
main.py
@ -8,12 +8,16 @@ This file is part of discord-qrm2 and is released under the terms of the GNU
|
|||||||
General Public License, version 2.
|
General Public License, version 2.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from datetime import time, datetime
|
||||||
|
import random
|
||||||
|
|
||||||
|
import pytz
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
|
|
||||||
import common as cmn
|
import common as cmn
|
||||||
import info
|
import info
|
||||||
|
|
||||||
import data.options as opt
|
import data.options as opt
|
||||||
import data.keys as keys
|
import data.keys as keys
|
||||||
|
|
||||||
@ -113,6 +117,12 @@ async def _extctl_unload(ctx: commands.Context, extension: str):
|
|||||||
async def on_ready():
|
async def on_ready():
|
||||||
print(f"Logged in as: {bot.user} - {bot.user.id}")
|
print(f"Logged in as: {bot.user} - {bot.user.id}")
|
||||||
print("------")
|
print("------")
|
||||||
|
if opt.status_mode == "time":
|
||||||
|
_ensure_activity_time.start()
|
||||||
|
elif opt.status_mode == "random":
|
||||||
|
_ensure_activity_random.start()
|
||||||
|
else:
|
||||||
|
_ensure_activity_fixed.start()
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
@ -128,13 +138,38 @@ async def on_message(message):
|
|||||||
# --- Tasks ---
|
# --- Tasks ---
|
||||||
|
|
||||||
@tasks.loop(minutes=5)
|
@tasks.loop(minutes=5)
|
||||||
async def _ensure_activity():
|
async def _ensure_activity_time():
|
||||||
await bot.change_presence(activity=discord.Game(name=opt.game))
|
status = opt.statuses[0]
|
||||||
|
|
||||||
|
try:
|
||||||
|
tz = pytz.timezone(opt.status_tz)
|
||||||
|
except pytz.exceptions.UnknownTimeZoneError:
|
||||||
|
await bot.change_presence(activity=discord.Game(name="with invalid timezones."))
|
||||||
|
return
|
||||||
|
|
||||||
|
now = datetime.now(tz=tz).time()
|
||||||
|
|
||||||
|
for sts in opt.time_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
|
@tasks.loop(minutes=5)
|
||||||
async def _before_ensure_activity():
|
async def _ensure_activity_random():
|
||||||
await bot.wait_until_ready()
|
status = random.choice(opt.statuses)
|
||||||
|
|
||||||
|
await bot.change_presence(activity=discord.Game(name=status))
|
||||||
|
|
||||||
|
|
||||||
|
@tasks.loop(minutes=5)
|
||||||
|
async def _ensure_activity_fixed():
|
||||||
|
status = opt.statuses[0]
|
||||||
|
|
||||||
|
await bot.change_presence(activity=discord.Game(name=status))
|
||||||
|
|
||||||
|
|
||||||
# --- Run ---
|
# --- Run ---
|
||||||
@ -142,8 +177,6 @@ async def _before_ensure_activity():
|
|||||||
for ext in opt.exts:
|
for ext in opt.exts:
|
||||||
bot.load_extension(ext_dir + '.' + ext)
|
bot.load_extension(ext_dir + '.' + ext)
|
||||||
|
|
||||||
_ensure_activity.start()
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bot.run(keys.discord_token)
|
bot.run(keys.discord_token)
|
||||||
|
@ -2,3 +2,4 @@ discord.py
|
|||||||
ctyparser
|
ctyparser
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
lxml
|
lxml
|
||||||
|
pytz
|
||||||
|
@ -29,8 +29,21 @@ owners_uids = (200102491231092736,)
|
|||||||
# The extensions to load when running the bot.
|
# The extensions to load when running the bot.
|
||||||
exts = ['ae7q', 'base', 'fun', 'grid', 'ham', 'image', 'lookup', 'morse', 'qrz', 'study', 'weather']
|
exts = ['ae7q', 'base', 'fun', 'grid', 'ham', 'image', 'lookup', 'morse', 'qrz', 'study', 'weather']
|
||||||
|
|
||||||
# The text to put in the "playing" status.
|
# Either "time", "random", or "fixed" (first item in statuses)
|
||||||
game = 'with lids on 7.200'
|
status_mode = "fixed"
|
||||||
|
|
||||||
|
# Random statuses pool
|
||||||
|
statuses = ["with lids on the air", "with fire"]
|
||||||
|
|
||||||
|
# Timezone for the status (string)
|
||||||
|
# See https://pythonhosted.org/pytz/ for more info
|
||||||
|
status_tz = 'US/Eastern'
|
||||||
|
# The text to put in the "playing" status, with start and stop times
|
||||||
|
time_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))]
|
||||||
|
|
||||||
# Emoji IDs and keywords for emoji reactions
|
# Emoji IDs and keywords for emoji reactions
|
||||||
# Use the format {emoji_id (int): ('tuple', 'of', 'lowercase', 'keywords')}
|
# Use the format {emoji_id (int): ('tuple', 'of', 'lowercase', 'keywords')}
|
||||||
|
Loading…
Reference in New Issue
Block a user