mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 20:53:40 -04:00
Move code related to /notes acronyms into one place
This commit is contained in:
parent
e163baf4dc
commit
acdb29e7be
@ -76,21 +76,10 @@ namespace MCGalaxy.Modules.Moderation.Notes
|
|||||||
if (args.Length > 5) long.TryParse(args[5], out duration);
|
if (args.Length > 5) long.TryParse(args[5], out duration);
|
||||||
|
|
||||||
p.Message("{0} by {1} &Son {2}{3}{4}",
|
p.Message("{0} by {1} &Son {2}{3}{4}",
|
||||||
Action(args[1]), p.FormatNick(args[2]), args[3],
|
NoteAcronym.GetAction(args[1]), p.FormatNick(args[2]), args[3],
|
||||||
duration == 0 ? "" : " for " + TimeSpan.FromTicks(duration).Shorten(true),
|
duration == 0 ? "" : " for " + TimeSpan.FromTicks(duration).Shorten(true),
|
||||||
reason.Length == 0 ? "" : " - " + reason.Replace("%20", " "));
|
reason.Length == 0 ? "" : " - " + reason.Replace("%20", " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
static string Action(string arg) {
|
|
||||||
if (arg.CaselessEq("W")) return "Warned";
|
|
||||||
if (arg.CaselessEq("K")) return "Kicked";
|
|
||||||
if (arg.CaselessEq("M")) return "Muted";
|
|
||||||
if (arg.CaselessEq("B")) return "Banned";
|
|
||||||
if (arg.CaselessEq("J")) return "Jailed";
|
|
||||||
if (arg.CaselessEq("F")) return "Frozen";
|
|
||||||
if (arg.CaselessEq("T")) return "Temp-Banned";
|
|
||||||
return arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Help(Player p) {
|
public override void Help(Player p) {
|
||||||
p.Message("&T/Notes [name] &H- views that player's notes.");
|
p.Message("&T/Notes [name] &H- views that player's notes.");
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using MCGalaxy.Events;
|
using MCGalaxy.Events;
|
||||||
using MCGalaxy.Events.ServerEvents;
|
using MCGalaxy.Events.ServerEvents;
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ namespace MCGalaxy.Modules.Moderation.Notes
|
|||||||
OnModActionEvent.Register(HandleModerationAction, Priority.Low);
|
OnModActionEvent.Register(HandleModerationAction, Priority.Low);
|
||||||
Command.Register(cmdNotes);
|
Command.Register(cmdNotes);
|
||||||
Command.Register(cmdMyNotes);
|
Command.Register(cmdMyNotes);
|
||||||
|
NoteAcronym.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Unload(bool shutdown) {
|
public override void Unload(bool shutdown) {
|
||||||
@ -41,21 +43,12 @@ namespace MCGalaxy.Modules.Moderation.Notes
|
|||||||
|
|
||||||
|
|
||||||
static void HandleModerationAction(ModAction action) {
|
static void HandleModerationAction(ModAction action) {
|
||||||
switch (action.Type) {
|
string acronym = NoteAcronym.GetAcronym(action);
|
||||||
case ModActionType.Frozen:
|
if (acronym == null) return;
|
||||||
AddNote(action, "F"); break;
|
|
||||||
case ModActionType.Kicked:
|
AddNote(action, acronym);
|
||||||
AddNote(action, "K"); break;
|
|
||||||
case ModActionType.Muted:
|
|
||||||
AddNote(action, "M"); break;
|
|
||||||
case ModActionType.Warned:
|
|
||||||
AddNote(action, "W"); break;
|
|
||||||
case ModActionType.Ban:
|
|
||||||
string banType = action.Duration.Ticks != 0 ? "T" : "B";
|
|
||||||
AddNote(action, banType); break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddNote(ModAction e, string type) {
|
static void AddNote(ModAction e, string type) {
|
||||||
if (!Server.Config.LogNotes) return;
|
if (!Server.Config.LogNotes) return;
|
||||||
string src = e.Actor.name;
|
string src = e.Actor.name;
|
||||||
@ -66,4 +59,56 @@ namespace MCGalaxy.Modules.Moderation.Notes
|
|||||||
Server.Notes.Append(data);
|
Server.Notes.Append(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moderation note actions are logged to disk using single-letter acronyms. This class handles translating these to and from human-readable actions.
|
||||||
|
/// </summary>
|
||||||
|
public class NoteAcronym
|
||||||
|
{
|
||||||
|
readonly static NoteAcronym Warned = new NoteAcronym("W", "Warned");
|
||||||
|
readonly static NoteAcronym Kicked = new NoteAcronym("K", "Kicked");
|
||||||
|
readonly static NoteAcronym Muted = new NoteAcronym("M", "Muted");
|
||||||
|
readonly static NoteAcronym Banned = new NoteAcronym("B", "Banned");
|
||||||
|
readonly static NoteAcronym Jailed = new NoteAcronym("J", "Jailed"); //Jailing was removed, but still appears in notes for historical reasons
|
||||||
|
readonly static NoteAcronym Frozen = new NoteAcronym("F", "Frozen");
|
||||||
|
readonly static NoteAcronym TempBanned = new NoteAcronym("T", "Temp-Banned");
|
||||||
|
|
||||||
|
static NoteAcronym[] All;
|
||||||
|
|
||||||
|
internal static void Init() {
|
||||||
|
All = new NoteAcronym[] { Warned, Kicked, Muted, Banned, Jailed, Frozen, TempBanned };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the appropriate Acronym to log when a mod action occurs.
|
||||||
|
/// </summary>
|
||||||
|
public static string GetAcronym(ModAction action) {
|
||||||
|
if (action.Type == ModActionType.Ban) {
|
||||||
|
return action.Duration.Ticks != 0 ? TempBanned.Acronym : Banned.Acronym;
|
||||||
|
}
|
||||||
|
|
||||||
|
string modActionString = action.Type.ToString();
|
||||||
|
foreach (var na in All) {
|
||||||
|
if (na.Action == modActionString) { return na.Acronym; }
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the appropriate Action from a mod note acronym. If none are found, returns the original argument.
|
||||||
|
/// </summary>
|
||||||
|
public static string GetAction(string acronym) {
|
||||||
|
foreach (var na in All) {
|
||||||
|
if (na.Acronym == acronym) { return na.Action; }
|
||||||
|
}
|
||||||
|
return acronym;
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly string Acronym;
|
||||||
|
readonly string Action;
|
||||||
|
|
||||||
|
private NoteAcronym(string acronym, string action) {
|
||||||
|
Acronym = acronym;
|
||||||
|
Action = action;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user