Skip to content

Commit 192be21

Browse files
committed
Add calladmin command
1 parent 3f90b6f commit 192be21

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/BF2WebAdmin.Common/Entities/Game/Player.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Player : Entity
2323
// Custom/Aggregate properties from modules
2424
public IDictionary<int, int> PingHistory { get; } = new Dictionary<int, int>();
2525
public DateTime LastLeaveNotification { get; set; }
26+
public DateTime LastAdminCall { get; set; }
2627

2728
public string DisplayName => Name?.Trim();
2829
public string ShortName

src/BF2WebAdmin.Server/Commands/BF2/DiscordCommands.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ namespace BF2WebAdmin.Server.Commands.BF2;
88
public class LeaveCommand : BaseCommand
99
{
1010
public int Minutes { get; set; }
11-
}
11+
}
12+
13+
[Command("calladmin <Reason>", Auth.All)]
14+
public class CallAdminCommand : BaseCommand
15+
{
16+
public string Reason { get; set; }
17+
}

src/BF2WebAdmin.Server/Modules/BF2/DiscordModule.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class DiscordModule : BaseModule,
3030
IHandleEventAsync<GameStreamStartedEvent>,
3131
IHandleEventAsync<GameStreamStoppedEvent>,
3232
IHandleCommandAsync<LeaveCommand>,
33+
IHandleCommandAsync<CallAdminCommand>,
3334
IHandleCommandAsync<StartStreamCommand>,
3435
IHandleCommandAsync<StopStreamCommand>
3536
{
@@ -643,4 +644,16 @@ private async Task StopStreamAsync()
643644
{
644645
await _gameStreamService.StopGameStreamAsync(GameServer.IpAddress.ToString(), GameServer.GamePort);
645646
}
646-
}
647+
648+
public async ValueTask HandleAsync(CallAdminCommand command)
649+
{
650+
var isCommandCooldown = DateTime.UtcNow - command.Message.Player.LastAdminCall < TimeSpan.FromMinutes(30);
651+
if (isCommandCooldown)
652+
return;
653+
654+
command.Message.Player.LastAdminCall = DateTime.UtcNow;
655+
656+
await SendTextMessageToChannelsAsync($"@everyone Admin requested by {Sanitize(command.Message.Player.Name)}: {Sanitize(command.Reason)}");
657+
_game.GameWriter.SendText($"{command.Message.Player.Name} called an admin");
658+
}
659+
}

0 commit comments

Comments
 (0)