add command: `unban profile <profile-id>`

To remove a banned profile ID from the ban list.
This commit is contained in:
Robin C. Ladiges 2023-03-22 21:48:53 +01:00
parent 2cd7abf0bd
commit 52c270a210
No known key found for this signature in database
GPG Key ID: B494D3DF92661B99
1 changed files with 24 additions and 2 deletions

View File

@ -107,6 +107,17 @@ public static class BanLists {
IPs.Remove(ipv4);
}
private static void UnbanProfile(Client user) {
UnbanProfile(user.Id);
}
private static void UnbanProfile(string str) {
if (!Guid.TryParse(str, out Guid id)) { return; }
UnbanProfile(id);
}
private static void UnbanProfile(Guid id) {
Profiles.Remove(id);
}
private static void Save() {
Settings.SaveSettings(true);
@ -203,7 +214,7 @@ public static class BanLists {
public static string HandleUnbanCommand(string[] args) {
if (args.Length != 2) {
return "Usage: unban ip <ipv4-address>";
return "Usage: unban {profile|ip} <value>";
}
string cmd = args[0];
@ -211,7 +222,18 @@ public static class BanLists {
switch (cmd) {
default:
return "Usage: unban ip <ipv4-address>";
return "Usage: unban {profile|ip} <value>";
case "profile":
if (!Guid.TryParse(val, out Guid id)) {
return "Invalid profile ID value!";
}
if (!IsProfileBanned(id)) {
return "Profile " + id.ToString() + " is not banned.";
}
UnbanProfile(id);
Save();
return "Unbanned profile: " + id.ToString();
case "ip":
if (!IsIPv4(val)) {