mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-07-05 03:19:08 -05:00
implement profile interaction registration through plugins (mute and vpn detection implementation)
This commit is contained in:
@ -11,10 +11,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.6.16.1"/>
|
||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.9.8.1" PrivateAssets="All"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="dotnet publish $(ProjectPath) -c $(ConfigurationName) -o $(ProjectDir)..\..\Build\Plugins --no-build --no-restore --no-dependencies"/>
|
||||
<Exec Command="dotnet publish $(ProjectPath) -c $(ConfigurationName) -o $(ProjectDir)..\..\Build\Plugins --no-build --no-restore --no-dependencies" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
@ -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