rewrite: Update voice tracker config.
This commit is contained in:
@@ -47,8 +47,8 @@ class VoiceTrackerCog(LionCog):
|
|||||||
|
|
||||||
self.bot.core.guild_config.register_model_setting(self.settings.HourlyReward)
|
self.bot.core.guild_config.register_model_setting(self.settings.HourlyReward)
|
||||||
self.bot.core.guild_config.register_model_setting(self.settings.HourlyLiveBonus)
|
self.bot.core.guild_config.register_model_setting(self.settings.HourlyLiveBonus)
|
||||||
self.bot.core.guild_config.register_model_setting(self.settings.UntrackedChannels)
|
|
||||||
self.bot.core.guild_config.register_model_setting(self.settings.DailyVoiceCap)
|
self.bot.core.guild_config.register_model_setting(self.settings.DailyVoiceCap)
|
||||||
|
self.bot.core.guild_config.register_setting(self.settings.UntrackedChannels)
|
||||||
|
|
||||||
# Update the tracked voice channel cache
|
# Update the tracked voice channel cache
|
||||||
await self.settings.UntrackedChannels.setup(self.bot)
|
await self.settings.UntrackedChannels.setup(self.bot)
|
||||||
@@ -607,10 +607,10 @@ class VoiceTrackerCog(LionCog):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@configure_group.command(
|
@configure_group.command(
|
||||||
name=_p('cmd:configure_voice_tracking', "voice_tracking"),
|
name=_p('cmd:configure_voice_rates', "voice_rewards"),
|
||||||
description=_p(
|
description=_p(
|
||||||
'cmd:configure_voice_tracking|desc',
|
'cmd:configure_voice_rates|desc',
|
||||||
"Voice tracking configuration panel"
|
"Configure Voice tracking rewards and experience"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@appcmds.rename(
|
@appcmds.rename(
|
||||||
@@ -695,6 +695,6 @@ class VoiceTrackerCog(LionCog):
|
|||||||
|
|
||||||
if ctx.channel.id not in VoiceTrackerConfigUI._listening or not modified:
|
if ctx.channel.id not in VoiceTrackerConfigUI._listening or not modified:
|
||||||
# Launch setting group UI
|
# Launch setting group UI
|
||||||
configui = VoiceTrackerConfigUI(self.bot, self.settings, ctx.guild.id, ctx.channel.id)
|
configui = VoiceTrackerConfigUI(self.bot, ctx.guild.id, ctx.channel.id)
|
||||||
await configui.run(ctx.interaction)
|
await configui.run(ctx.interaction)
|
||||||
await configui.wait()
|
await configui.wait()
|
||||||
|
|||||||
@@ -232,6 +232,14 @@ class VoiceSession:
|
|||||||
# End the ongoing session
|
# End the ongoing session
|
||||||
await self.data.close_study_session_at(self.guildid, self.userid, utc_now())
|
await self.data.close_study_session_at(self.guildid, self.userid, utc_now())
|
||||||
|
|
||||||
|
# Rank update
|
||||||
|
# TODO: Change to broadcasted event?
|
||||||
|
rank_cog = self.bot.get_cog('RankCog')
|
||||||
|
if rank_cog is not None:
|
||||||
|
asyncio.create_task(rank_cog.on_voice_session_complete(
|
||||||
|
(self.guildid, self.userid, int((utc_now() - self.data.start_time).total_seconds()), 0)
|
||||||
|
))
|
||||||
|
|
||||||
if self.start_task is not None:
|
if self.start_task is not None:
|
||||||
self.start_task.cancel()
|
self.start_task.cancel()
|
||||||
self.start_task = None
|
self.start_task = None
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
import asyncio
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import discord
|
import discord
|
||||||
from discord.ui.select import select, Select, ChannelSelect
|
from discord.ui.select import select, Select, ChannelSelect
|
||||||
@@ -11,7 +12,8 @@ from settings.setting_types import ChannelListSetting, IntegerSetting, DurationS
|
|||||||
from meta import conf, LionBot
|
from meta import conf, LionBot
|
||||||
from meta.sharding import THIS_SHARD
|
from meta.sharding import THIS_SHARD
|
||||||
from meta.logger import log_wrap
|
from meta.logger import log_wrap
|
||||||
from utils.ui import LeoUI
|
from utils.lib import MessageArgs
|
||||||
|
from utils.ui import LeoUI, ConfigUI, DashboardSection
|
||||||
|
|
||||||
from core.data import CoreData
|
from core.data import CoreData
|
||||||
from core.lion_guild import VoiceMode
|
from core.lion_guild import VoiceMode
|
||||||
@@ -101,6 +103,10 @@ class VoiceTrackerSettings(SettingGroup):
|
|||||||
'guildset:hourly_reward|mode:voice|desc',
|
'guildset:hourly_reward|mode:voice|desc',
|
||||||
"LionCoins given per hour in a voice channel."
|
"LionCoins given per hour in a voice channel."
|
||||||
)
|
)
|
||||||
|
_long_desc = _p(
|
||||||
|
'guildset:hourly_reward|mode:voice|long_desc',
|
||||||
|
"Number of LionCoins to each member per hour that they stay in a tracked voice channel."
|
||||||
|
)
|
||||||
|
|
||||||
_default = 50
|
_default = 50
|
||||||
_min = 0
|
_min = 0
|
||||||
@@ -136,7 +142,7 @@ class VoiceTrackerSettings(SettingGroup):
|
|||||||
)
|
)
|
||||||
_long_desc = _p(
|
_long_desc = _p(
|
||||||
'guildset:hourly_reward|mode:voice|long_desc',
|
'guildset:hourly_reward|mode:voice|long_desc',
|
||||||
"Number of LionCoins to each member per hour that they stay in a tracked voice channel."
|
"Number of LionCoins rewarded to each member per hour that they stay in a tracked voice channel."
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -274,7 +280,7 @@ class VoiceTrackerSettings(SettingGroup):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VoiceTrackerConfigUI(LeoUI):
|
class VoiceTrackerConfigUIALT(LeoUI):
|
||||||
# TODO: Bulk edit
|
# TODO: Bulk edit
|
||||||
# TODO: Cohesive exit
|
# TODO: Cohesive exit
|
||||||
# TODO: Back to main configuration panel
|
# TODO: Back to main configuration panel
|
||||||
@@ -303,6 +309,7 @@ class VoiceTrackerConfigUI(LeoUI):
|
|||||||
return (self.hourly_reward, self.hourly_live_bonus, self.daily_voice_cap, self.untracked_channels)
|
return (self.hourly_reward, self.hourly_live_bonus, self.daily_voice_cap, self.untracked_channels)
|
||||||
|
|
||||||
async def cleanup(self):
|
async def cleanup(self):
|
||||||
|
# TODO: Swap cleanup and close..
|
||||||
self._listening.pop(self.channelid, None)
|
self._listening.pop(self.channelid, None)
|
||||||
for instance in self.instances:
|
for instance in self.instances:
|
||||||
instance.deregister_callback(self.id)
|
instance.deregister_callback(self.id)
|
||||||
@@ -362,7 +369,7 @@ class VoiceTrackerConfigUI(LeoUI):
|
|||||||
|
|
||||||
if interaction.response.is_done():
|
if interaction.response.is_done():
|
||||||
# Use followup to respond
|
# Use followup to respond
|
||||||
self._mesage = await interaction.followup.send(embed=self.embed, view=self)
|
self._message = await interaction.followup.send(embed=self.embed, view=self)
|
||||||
else:
|
else:
|
||||||
# Use interaction response to respond
|
# Use interaction response to respond
|
||||||
self._original = interaction
|
self._original = interaction
|
||||||
@@ -431,3 +438,93 @@ class VoiceTrackerConfigUI(LeoUI):
|
|||||||
for setting in self.instances:
|
for setting in self.instances:
|
||||||
embed.add_field(**setting.embed_field, inline=False)
|
embed.add_field(**setting.embed_field, inline=False)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
|
||||||
|
class VoiceTrackerConfigUI(ConfigUI):
|
||||||
|
setting_classes = (
|
||||||
|
VoiceTrackerSettings.HourlyReward,
|
||||||
|
VoiceTrackerSettings.HourlyLiveBonus,
|
||||||
|
VoiceTrackerSettings.DailyVoiceCap,
|
||||||
|
VoiceTrackerSettings.UntrackedChannels,
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, bot: LionBot,
|
||||||
|
guildid: int, channelid: int, **kwargs):
|
||||||
|
self.settings = bot.get_cog('VoiceTrackerCog').settings
|
||||||
|
super().__init__(bot, guildid, channelid, **kwargs)
|
||||||
|
|
||||||
|
@select(
|
||||||
|
cls=ChannelSelect,
|
||||||
|
placeholder="UNTRACKED_CHANNELS_PLACEHOLDER",
|
||||||
|
min_values=0, max_values=25
|
||||||
|
)
|
||||||
|
async def untracked_channels_menu(self, selection: discord.Interaction, selected):
|
||||||
|
await selection.response.defer()
|
||||||
|
setting = self.instances[3]
|
||||||
|
setting.value = selected.values
|
||||||
|
await setting.write()
|
||||||
|
|
||||||
|
async def untracked_channels_menu_refresh(self):
|
||||||
|
t = self.bot.translator.t
|
||||||
|
self.untracked_channels_menu.placeholder = t(_p(
|
||||||
|
'ui:voice_tracker_config|menu:untracked_channels|placeholder',
|
||||||
|
"Select Untracked Channels"
|
||||||
|
))
|
||||||
|
|
||||||
|
async def make_message(self):
|
||||||
|
t = self.bot.translator.t
|
||||||
|
lguild = await self.bot.core.lions.fetch_guild(self.guildid)
|
||||||
|
mode = lguild.guild_mode
|
||||||
|
if mode.voice is VoiceMode.VOICE:
|
||||||
|
title = t(_p(
|
||||||
|
'ui:voice_tracker_config|mode:voice|embed|title',
|
||||||
|
"Voice Tracker Configuration Panel"
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
title = t(_p(
|
||||||
|
'ui:voice_tracker_config|mode:study|embed|title',
|
||||||
|
"Study Tracker Configuration Panel"
|
||||||
|
))
|
||||||
|
embed = discord.Embed(
|
||||||
|
colour=discord.Colour.orange(),
|
||||||
|
title=title
|
||||||
|
)
|
||||||
|
for setting in self.instances:
|
||||||
|
embed.add_field(**setting.embed_field, inline=False)
|
||||||
|
|
||||||
|
args = MessageArgs(embed=embed)
|
||||||
|
return args
|
||||||
|
|
||||||
|
async def reload(self):
|
||||||
|
lguild = await self.bot.core.lions.fetch_guild(self.guildid)
|
||||||
|
if lguild.guild_mode.voice is VoiceMode.VOICE:
|
||||||
|
hourly_reward = await self.settings.HourlyReward_Voice.get(self.guildid)
|
||||||
|
else:
|
||||||
|
hourly_reward = await self.settings.HourlyReward_Study.get(self.guildid)
|
||||||
|
hourly_live_bonus = lguild.config.get('hourly_live_bonus')
|
||||||
|
daily_voice_cap = lguild.config.get('daily_voice_cap')
|
||||||
|
untracked_channels = await self.settings.UntrackedChannels.get(self.guildid)
|
||||||
|
self.instances = (
|
||||||
|
hourly_reward, hourly_live_bonus, daily_voice_cap, untracked_channels
|
||||||
|
)
|
||||||
|
|
||||||
|
async def refresh_components(self):
|
||||||
|
await asyncio.gather(
|
||||||
|
self.edit_button_refresh(),
|
||||||
|
self.close_button_refresh(),
|
||||||
|
self.reset_button_refresh(),
|
||||||
|
self.untracked_channels_menu_refresh(),
|
||||||
|
)
|
||||||
|
self._layout = [
|
||||||
|
(self.untracked_channels_menu,),
|
||||||
|
(self.edit_button, self.reset_button, self.close_button)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class VoiceTrackerDashboard(DashboardSection):
|
||||||
|
section_name = _p(
|
||||||
|
'dash:voice_tracker|title',
|
||||||
|
"Voice Tracker Configuration"
|
||||||
|
)
|
||||||
|
configui = VoiceTrackerConfigUI
|
||||||
|
setting_classes = configui.setting_classes
|
||||||
|
|||||||
Reference in New Issue
Block a user