[Raid] Update role select with preferred role and emote
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Cocotte.Services;
|
using Cocotte.Services;
|
||||||
|
using Cocotte.Utils;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Interactions;
|
using Discord.Interactions;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
@@ -122,6 +123,32 @@ public class PingModule : InteractionModuleBase<SocketInteractionContext>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SlashCommand("emote", "Test sending an emote")]
|
||||||
|
public async Task SendEmote(string emoteText)
|
||||||
|
{
|
||||||
|
if (Emote.TryParse(emoteText, out var emote))
|
||||||
|
{
|
||||||
|
await RespondAsync($"{emote}/{emoteText}: `{emoteText}/{emote}`");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await RespondAsync(embed: EmbedUtils.ErrorEmbed("Couldn't parse the emote").Build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[SlashCommand("emoji", "Test sending an emoji")]
|
||||||
|
public async Task SendEmoji(string emojiText)
|
||||||
|
{
|
||||||
|
if (Emoji.TryParse(emojiText, out var emoji))
|
||||||
|
{
|
||||||
|
await RespondAsync($"{emoji}/{emojiText}: `{emojiText}/{emoji}`");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await RespondAsync(embed: EmbedUtils.ErrorEmbed("Couldn't parse the emoji").Build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[SlashCommand("test-button", "Test buttons components")]
|
[SlashCommand("test-button", "Test buttons components")]
|
||||||
public async Task TestButton()
|
public async Task TestButton()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ namespace Cocotte.Modules.Raids;
|
|||||||
public interface IPlayerInfosRepository
|
public interface IPlayerInfosRepository
|
||||||
{
|
{
|
||||||
bool TryGetPlayerInfo(ulong playerId, [MaybeNullWhen(false)] out PlayerInfo playerInfo);
|
bool TryGetPlayerInfo(ulong playerId, [MaybeNullWhen(false)] out PlayerInfo playerInfo);
|
||||||
void UpdatePlayerInfo(PlayerInfo playerInfo);
|
void UpdatePlayerInfo(ulong id, Action<PlayerInfo> updater);
|
||||||
}
|
}
|
||||||
@@ -16,8 +16,18 @@ public class MemoryPlayerInfosRepository : IPlayerInfosRepository
|
|||||||
return _playerInfos.TryGetValue(playerId, out playerInfo);
|
return _playerInfos.TryGetValue(playerId, out playerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePlayerInfo(PlayerInfo playerInfo)
|
public void UpdatePlayerInfo(ulong id, Action<PlayerInfo> updater)
|
||||||
{
|
{
|
||||||
_playerInfos[playerInfo.Id] = playerInfo;
|
if (_playerInfos.TryGetValue(id, out var playerInfo))
|
||||||
|
{
|
||||||
|
updater(playerInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerInfo = new PlayerInfo(id, 0);
|
||||||
|
updater(playerInfo);
|
||||||
|
|
||||||
|
_playerInfos[playerInfo.Id] = playerInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,12 +5,13 @@ public class PlayerInfo
|
|||||||
public static TimeSpan FcUpdateInterval { get; } = TimeSpan.FromDays(3);
|
public static TimeSpan FcUpdateInterval { get; } = TimeSpan.FromDays(3);
|
||||||
|
|
||||||
public ulong Id { get; }
|
public ulong Id { get; }
|
||||||
|
public PlayerRole PreferredRole { get; set; } = PlayerRole.Dps;
|
||||||
|
|
||||||
private readonly uint _fc;
|
private uint _fc;
|
||||||
public uint Fc
|
public uint Fc
|
||||||
{
|
{
|
||||||
get => _fc;
|
get => _fc;
|
||||||
init
|
set
|
||||||
{
|
{
|
||||||
_fc = value;
|
_fc = value;
|
||||||
_lastFcUpdate = DateTime.Today;
|
_lastFcUpdate = DateTime.Today;
|
||||||
@@ -19,7 +20,7 @@ public class PlayerInfo
|
|||||||
|
|
||||||
public bool IsFcUpdateRequired => DateTime.Today - _lastFcUpdate > FcUpdateInterval;
|
public bool IsFcUpdateRequired => DateTime.Today - _lastFcUpdate > FcUpdateInterval;
|
||||||
|
|
||||||
private readonly DateTime _lastFcUpdate;
|
private DateTime _lastFcUpdate;
|
||||||
|
|
||||||
public PlayerInfo(ulong id, uint fc)
|
public PlayerInfo(ulong id, uint fc)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ public class RaidFormatter
|
|||||||
_rolesOptions = rolesOptions;
|
_rolesOptions = rolesOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string RoleToEmote(PlayerRole role) => role switch
|
public IEmote RoleToEmote(PlayerRole role) => role switch
|
||||||
{
|
{
|
||||||
PlayerRole.Dps => _rolesOptions.DpsEmote,
|
PlayerRole.Dps => _rolesOptions.DpsEmote.ToEmote(),
|
||||||
PlayerRole.Tank => _rolesOptions.TankEmote,
|
PlayerRole.Tank => _rolesOptions.TankEmote.ToEmote(),
|
||||||
PlayerRole.Healer => _rolesOptions.HealerEmote,
|
PlayerRole.Healer => _rolesOptions.HealerEmote.ToEmote(),
|
||||||
_ => ":question:"
|
_ => ":question:".ToEmote()
|
||||||
};
|
};
|
||||||
|
|
||||||
public static string FcFormat(uint fc) => fc switch
|
public static string FcFormat(uint fc) => fc switch
|
||||||
|
|||||||
@@ -125,7 +125,10 @@ public class RaidModule : InteractionModuleBase<SocketInteractionContext>
|
|||||||
|
|
||||||
if (_registerManager.RegisteringPlayers.TryGetValue((raidId, playerId), out var rosterPlayer))
|
if (_registerManager.RegisteringPlayers.TryGetValue((raidId, playerId), out var rosterPlayer))
|
||||||
{
|
{
|
||||||
_registerManager.RegisteringPlayers[(raidId, playerId)] = rosterPlayer with {Role = selectedRole};
|
_registerManager.RegisteringPlayers[(raidId, playerId)] = rosterPlayer with { Role = selectedRole };
|
||||||
|
|
||||||
|
// Also update preferred role
|
||||||
|
_playerInfos.UpdatePlayerInfo(playerId, p => p.PreferredRole = selectedRole);
|
||||||
|
|
||||||
await RespondAsync();
|
await RespondAsync();
|
||||||
}
|
}
|
||||||
@@ -210,7 +213,7 @@ public class RaidModule : InteractionModuleBase<SocketInteractionContext>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_playerInfos.UpdatePlayerInfo(new PlayerInfo(playerId, fc));
|
_playerInfos.UpdatePlayerInfo(playerId, p => p.Fc = fc);
|
||||||
|
|
||||||
await RegisterPlayer(raidId, rosterPlayer with { Fc = fc });
|
await RegisterPlayer(raidId, rosterPlayer with { Fc = fc });
|
||||||
}
|
}
|
||||||
@@ -316,15 +319,17 @@ public class RaidModule : InteractionModuleBase<SocketInteractionContext>
|
|||||||
private ComponentBuilder PlayerRoleComponent(Raid raid, IGuildUser user)
|
private ComponentBuilder PlayerRoleComponent(Raid raid, IGuildUser user)
|
||||||
{
|
{
|
||||||
var select = new SelectMenuBuilder()
|
var select = new SelectMenuBuilder()
|
||||||
.WithPlaceholder(PlayerRole.Dps.ToString())
|
|
||||||
.WithCustomId($"raid player_select_role:{raid.Id}:{user.Id}")
|
.WithCustomId($"raid player_select_role:{raid.Id}:{user.Id}")
|
||||||
.WithMinValues(1)
|
.WithMinValues(1)
|
||||||
.WithMaxValues(1);
|
.WithMaxValues(1);
|
||||||
|
|
||||||
|
// Preselect preferred role
|
||||||
|
var preferredRole = _playerInfos.TryGetPlayerInfo(user.Id, out var playerInfo) ? playerInfo.PreferredRole : PlayerRole.Dps;
|
||||||
|
|
||||||
foreach (var role in Enum.GetValues<PlayerRole>())
|
foreach (var role in Enum.GetValues<PlayerRole>())
|
||||||
{
|
{
|
||||||
// TODO add emote
|
var roleText = role.ToString();
|
||||||
select.AddOption(role.ToString(), role.ToString());
|
select.AddOption(roleText, roleText, emote: _raidFormatter.RoleToEmote(role), isDefault: role == preferredRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ComponentBuilder()
|
return new ComponentBuilder()
|
||||||
|
|||||||
16
Cocotte/Utils/EmoteUtils.cs
Normal file
16
Cocotte/Utils/EmoteUtils.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using Discord;
|
||||||
|
|
||||||
|
namespace Cocotte.Utils;
|
||||||
|
|
||||||
|
public static class EmoteUtils
|
||||||
|
{
|
||||||
|
public static IEmote ToEmote(this string emoteText)
|
||||||
|
{
|
||||||
|
if (Emote.TryParse(emoteText, out var emote))
|
||||||
|
{
|
||||||
|
return emote;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Emoji.Parse(emoteText);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user