mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
implement profile interaction registration through plugins (mute and vpn detection implementation)
This commit is contained in:
@ -1,12 +1,18 @@
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Helpers;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
||||
namespace Mute;
|
||||
|
||||
public class Plugin : IPlugin
|
||||
{
|
||||
public Plugin(IMetaServiceV2 metaService)
|
||||
private readonly IInteractionRegistration _interactionRegistration;
|
||||
private static readonly string MuteInteraction = nameof(MuteInteraction);
|
||||
|
||||
public Plugin(IMetaServiceV2 metaService, IInteractionRegistration interactionRegistration)
|
||||
{
|
||||
_interactionRegistration = interactionRegistration;
|
||||
DataManager = new DataManager(metaService);
|
||||
}
|
||||
|
||||
@ -45,11 +51,58 @@ public class Plugin : IPlugin
|
||||
|
||||
public Task OnLoadAsync(IManager manager)
|
||||
{
|
||||
_interactionRegistration.RegisterInteraction(MuteInteraction, async (clientId, game, token) =>
|
||||
{
|
||||
if (!clientId.HasValue || game.HasValue && !SupportedGames.Contains((Server.Game)game.Value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var muteState = await DataManager.ReadPersistentData(new EFClient { ClientId = clientId.Value });
|
||||
|
||||
return muteState is MuteState.Unmuted or MuteState.Unmuting
|
||||
? new InteractionData
|
||||
{
|
||||
EntityId = clientId,
|
||||
Name = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_CONTEXT_MENU_ACTION_MUTE"],
|
||||
DisplayMeta = "oi-volume-off",
|
||||
ActionPath = "DynamicAction",
|
||||
ActionMeta = new()
|
||||
{
|
||||
{ "InteractionId", "command" },
|
||||
{ "Data", $"mute @{clientId.Value}" },
|
||||
{ "ActionButtonLabel", Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_CONTEXT_MENU_ACTION_MUTE"] },
|
||||
{ "Name", Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_CONTEXT_MENU_ACTION_MUTE"] },
|
||||
{ "ShouldRefresh", true.ToString() }
|
||||
},
|
||||
MinimumPermission = Data.Models.Client.EFClient.Permission.Moderator,
|
||||
Source = Name
|
||||
}
|
||||
: new InteractionData
|
||||
{
|
||||
EntityId = clientId,
|
||||
Name = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_CONTEXT_MENU_ACTION_UNMUTE"],
|
||||
DisplayMeta = "oi-volume-high",
|
||||
ActionPath = "DynamicAction",
|
||||
ActionMeta = new()
|
||||
{
|
||||
{ "InteractionId", "command" },
|
||||
{ "Data", $"mute @{clientId.Value}" },
|
||||
{ "ActionButtonLabel", Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_CONTEXT_MENU_ACTION_UNMUTE"] },
|
||||
{ "Name", Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_CONTEXT_MENU_ACTION_UNMUTE"] },
|
||||
{ "ShouldRefresh", true.ToString() }
|
||||
},
|
||||
MinimumPermission = Data.Models.Client.EFClient.Permission.Moderator,
|
||||
Source = Name
|
||||
};
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task OnUnloadAsync()
|
||||
{
|
||||
_interactionRegistration.UnregisterInteraction(MuteInteraction);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user