Moderation Commands #1

Merged
Moonbase merged 6 commits from moderation-commands into main 2025-03-07 18:15:42 -08:00
Showing only changes of commit 86b9d39266 - Show all commits

View File

@ -0,0 +1,34 @@
using System;
using System.Net.Http.Json;
using sodoffmmo.Attributes;
using sodoffmmo.Core;
namespace sodoffmmo.Management.Commands;
[ManagementCommand("ban", Role.Moderator)]
class BanCommand : IManagementCommand
{
public void Handle(Client client, string[] arguments)
{
if(arguments.Length < 2) { client.Send(Utils.BuildServerSideMessage($"Expected 3 Args, Got {arguments.Length + 1}", "Server")); return; }
// send an http request to the api set in appsettings
HttpClient httpClient = new();
var content = new FormUrlEncodedContent(
new Dictionary<string, string> {
{ "token", client.PlayerData.UNToken },
{ "userId", arguments[0] },
{ "banType", arguments[1] },
{ "days", arguments[2] }
}
);
httpClient.Timeout = new TimeSpan(0, 0, 3);
var response = httpClient.PostAsync($"{Configuration.ServerConfiguration.ApiUrl}/Moderation/AddBanToVikingByGuid", content).Result;
string? responseString = response.Content.ReadAsStringAsync().Result;
if (response.StatusCode != System.Net.HttpStatusCode.OK && responseString != null) { client.Send(Utils.BuildServerSideMessage(responseString, "Server")); return; }
else if (responseString != null) { client.Send(Utils.BuildServerSideMessage("User Banned Successfully", "Server")); return; }
else { client.Send(Utils.BuildServerSideMessage("Empty Response", "Server")); }
}
}