refactor: Update study module structure.
Prepare `study` module for session and timer systems. Move regular sync to the studybadge loop.
This commit is contained in:
@@ -68,9 +68,10 @@ async def preload_studying_members(client):
|
||||
)
|
||||
|
||||
|
||||
@module.launch_task
|
||||
async def launch_lion_sync_loop(client):
|
||||
asyncio.create_task(_lion_sync_loop())
|
||||
# Removing the sync loop in favour of the studybadge sync.
|
||||
# @module.launch_task
|
||||
# async def launch_lion_sync_loop(client):
|
||||
# asyncio.create_task(_lion_sync_loop())
|
||||
|
||||
|
||||
@module.unload_task
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
from .module import module
|
||||
|
||||
from . import data
|
||||
from . import admin
|
||||
from . import badge_tracker
|
||||
from . import time_tracker
|
||||
from . import badges
|
||||
from . import timers
|
||||
from . import tracking
|
||||
|
||||
from . import top_cmd
|
||||
from . import studybadge_cmd
|
||||
from . import stats_cmd
|
||||
|
||||
2
bot/modules/study/badges/__init__.py
Normal file
2
bot/modules/study/badges/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import badge_tracker
|
||||
from . import studybadge_cmd
|
||||
@@ -13,7 +13,7 @@ from core.data import lions
|
||||
from utils.lib import strfdur
|
||||
from settings import GuildSettings
|
||||
|
||||
from .module import module
|
||||
from ..module import module
|
||||
from .data import new_study_badges, study_badges
|
||||
|
||||
|
||||
@@ -287,6 +287,7 @@ async def study_badge_tracker():
|
||||
"""
|
||||
while True:
|
||||
try:
|
||||
Lion.sync()
|
||||
await update_study_badges()
|
||||
except Exception:
|
||||
# Unknown exception. Catch it so the loop doesn't die.
|
||||
@@ -2,8 +2,6 @@ from cachetools import cached
|
||||
|
||||
from data import Table, RowTable
|
||||
|
||||
untracked_channels = Table('untracked_channels')
|
||||
|
||||
study_badges = RowTable(
|
||||
'study_badges',
|
||||
('badgeid', 'guildid', 'roleid', 'required_time'),
|
||||
@@ -12,7 +12,7 @@ from wards import is_guild_admin
|
||||
from core.data import lions
|
||||
from settings import GuildSettings
|
||||
|
||||
from .module import module
|
||||
from ..module import module
|
||||
from .data import study_badges, guild_role_cache, new_study_badges
|
||||
from .badge_tracker import _update_guild_badges
|
||||
|
||||
0
bot/modules/study/timers/__init__.py
Normal file
0
bot/modules/study/timers/__init__.py
Normal file
4
bot/modules/study/tracking/__init__.py
Normal file
4
bot/modules/study/tracking/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from . import data
|
||||
from . import settings
|
||||
from . import time_tracker
|
||||
from . import session_tracker
|
||||
3
bot/modules/study/tracking/data.py
Normal file
3
bot/modules/study/tracking/data.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from data import Table
|
||||
|
||||
untracked_channels = Table('untracked_channels')
|
||||
0
bot/modules/study/tracking/session_tracker.py
Normal file
0
bot/modules/study/tracking/session_tracker.py
Normal file
@@ -7,8 +7,8 @@ from time import time
|
||||
from meta import client
|
||||
from core import Lion
|
||||
|
||||
from .module import module
|
||||
from . import admin
|
||||
from ..module import module
|
||||
from .settings import untracked_channels, hourly_reward, hourly_live_bonus
|
||||
|
||||
|
||||
last_scan = {} # guildid -> timestamp
|
||||
@@ -36,9 +36,9 @@ def _scan(guild):
|
||||
if interval > 60 * 20:
|
||||
return
|
||||
|
||||
untracked = admin.untracked_channels.get(guild.id).data
|
||||
hourly_reward = admin.hourly_reward.get(guild.id).data
|
||||
hourly_live_bonus = admin.hourly_live_bonus.get(guild.id).data
|
||||
untracked = untracked_channels.get(guild.id).data
|
||||
guild_hourly_reward = hourly_reward.get(guild.id).data
|
||||
guild_hourly_live_bonus = hourly_live_bonus.get(guild.id).data
|
||||
|
||||
channel_members = (
|
||||
channel.members for channel in guild.voice_channels if channel.id not in untracked
|
||||
@@ -61,9 +61,9 @@ def _scan(guild):
|
||||
lion.addTime(interval, flush=False)
|
||||
|
||||
# Add coins
|
||||
hour_reward = hourly_reward
|
||||
hour_reward = guild_hourly_reward
|
||||
if member.voice.self_stream or member.voice.self_video:
|
||||
hour_reward += hourly_live_bonus
|
||||
hour_reward += guild_hourly_live_bonus
|
||||
|
||||
lion.addCoins(hour_reward * interval / (3600), flush=False)
|
||||
|
||||
@@ -102,7 +102,7 @@ async def _study_tracker():
|
||||
@module.launch_task
|
||||
async def launch_study_tracker(client):
|
||||
# First pre-load the untracked channels
|
||||
await admin.untracked_channels.launch_task(client)
|
||||
await untracked_channels.launch_task(client)
|
||||
asyncio.create_task(_study_tracker())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user