Allow adding notes to players without warning them

/note -- add a note to a player that anyone may see
/opnote -- add a note to a player that only ops may see
This commit is contained in:
Goodlyay 2024-05-05 18:59:43 -07:00
parent acdb29e7be
commit 52c7079a39
6 changed files with 124 additions and 25 deletions

View File

@ -38,6 +38,8 @@ namespace MCGalaxy.Core {
case ModActionType.UnbanIP: DoUnbanIP(action); break;
case ModActionType.Warned: DoWarn(action); break;
case ModActionType.Rank: DoRank(action); break;
case ModActionType.Noted: DoNote(action); break;
case ModActionType.OpNoted: DoNote(action); break;
}
}
@ -52,7 +54,7 @@ namespace MCGalaxy.Core {
Chat.Message(ChatScope.Global, e.FormatMessage(targetNick, action),
null, null, true);
} else {
Chat.MessageOps(e.FormatMessage(targetNick, action));
Chat.MessageOps("To Ops: " + e.FormatMessage(targetNick, action));
}
action = Colors.StripUsed(action);
@ -255,5 +257,15 @@ namespace MCGalaxy.Core {
string assigner = e.Actor.name;
return assigner + " " + assign + " " + expiry;
}
static void DoNote(ModAction e) {
if (!Server.Config.LogNotes) {
e.Actor.Message("Notes logging must be enabled to note players."); return;
}
// No null checking because LogAction who parameter isn't used
Player who = PlayerInfo.FindExact(e.Target);
LogAction(e, who, "&egiven a note");
}
}
}

View File

@ -84,8 +84,8 @@ namespace MCGalaxy.Events
}
public delegate void OnModAction(ModAction action);
/// <summary> Types of moderation actions that can occur. </summary>
/// <summary> Types of moderation actions that can occur. To make a mod action logged to /notes, add a new NoteAcronym in NotesPlugin NoteAcronym. </summary>
public enum ModActionType
{
/// <summary> Player was banned. </summary>
@ -119,6 +119,10 @@ namespace MCGalaxy.Events
Kicked,
/// <summary> Player was reported </summary>
Reported,
/// <summary> Player was given a note </summary>
Noted,
/// <summary> Player was given a note that only operators may read </summary>
OpNoted,
}
/// <summary> Raised when a moderation action occurs. </summary>

View File

@ -590,6 +590,7 @@
<Compile Include="Modules\Games\ZombieSurvival\ZSGame.Plugin.cs" />
<Compile Include="Modules\Games\ZombieSurvival\ZSGame.Round.cs" />
<Compile Include="Modules\Games\ZombieSurvival\ZSPlugin.cs" />
<Compile Include="Modules\Moderation\Notes\CmdNote.cs" />
<Compile Include="Modules\Moderation\Notes\CmdNotes.cs" />
<Compile Include="Modules\Moderation\Notes\NotesPlugin.cs" />
<Compile Include="Modules\Moderation\Review\CmdReview.cs" />

View File

@ -0,0 +1,69 @@
/*
Copyright 2015 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
https://opensource.org/license/ecl-2-0/
https://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using MCGalaxy.Commands.Moderation;
using MCGalaxy.Events;
namespace MCGalaxy.Modules.Moderation.Notes {
public class CmdNote : Command2 {
public override string name { get { return "Note"; } }
public override string type { get { return CommandTypes.Moderation; } }
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
protected virtual bool announce { get { return true; } }
protected virtual ModActionType modActionType { get { return ModActionType.Noted; } }
public override void Use(Player p, string message, CommandData data) {
if (!Server.Config.LogNotes) {
p.Message("Notes logging must be enabled to note players."); return;
}
if (message.Length == 0) { Help(p); return; }
string[] args = message.SplitSpaces(2);
if (args.Length == 1) { p.Message("&WYou must provide text for the note."); return; }
string note = args[1];
string target = ModActionCmd.FindName(p, "note", "/"+name, "", args[0], ref note);
if (target == null) return;
note = ModActionCmd.ExpandReason(p, note);
if (note == null) return;
Group group = ModActionCmd.CheckTarget(p, data, "note", target);
if (group == null) return;
ModAction action = new ModAction(target, p, modActionType, note);
action.Announce = announce;
OnModActionEvent.Call(action);
}
public override void Help(Player p) {
p.Message("&T/Note [player] [text]");
p.Message("&HAdds a note to [player]'s /notes");
p.Message("&HFor [text], @number can be used as a shortcut for that rule.");
}
}
public class CmdOpNote : CmdNote {
public override string name { get { return "OpNote"; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
protected override bool announce { get { return false; } }
protected override ModActionType modActionType { get { return ModActionType.OpNoted; } }
public override void Help(Player p) {
p.Message("&T/OpNote [player] [text]");
p.Message("&HAdds a note to [player]'s /notes that only ops may see.");
p.Message("&HFor [text], @number can be used as a shortcut for that rule.");
}
}
}

View File

@ -46,10 +46,24 @@ namespace MCGalaxy.Modules.Moderation.Notes
p.Message("The server does not have notes logging enabled."); return;
}
List<string> notes = Server.Notes.FindAllExact(name);
List<string> allNotes = Server.Notes.FindAllExact(name);
List<string> visibleNotes;
if (p.group.Permission >= Chat.OpchatPerms.MinRank) {
visibleNotes = allNotes;
} else {
visibleNotes = new List<string>();
foreach (string note in allNotes) {
string[] sections = note.SplitSpaces();
if (sections.Length <= 3) continue; // Malformed note, don't include
if (sections[1] == NoteAcronym.OpNoted.Acronym) continue; // Only Ops may see this note, don't include
visibleNotes.Add(note);
}
}
string nick = p.FormatNick(name);
if (notes.Count == 0) {
if (visibleNotes.Count == 0) {
p.Message("{0} &Shas no notes.", nick); return;
} else {
p.Message(" Notes for {0}:", nick);
@ -57,13 +71,13 @@ namespace MCGalaxy.Modules.Moderation.Notes
// special case "/Notes" to show latest notes by default
if (modifier.Length == 0) {
Paginator.Output(p, notes, PrintNote, cmd, "Notes",
(1 + (notes.Count - 8)).ToString());
Paginator.Output(p, visibleNotes, PrintNote, cmd, "Notes",
(1 + (visibleNotes.Count - 8)).ToString());
p.Message("To see all Notes, use &T/{0} all", cmd);
return;
}
Paginator.Output(p, notes, PrintNote,
Paginator.Output(p, visibleNotes, PrintNote,
cmd, "Notes", modifier);
}

View File

@ -16,9 +16,7 @@
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using MCGalaxy.Events;
using MCGalaxy.Events.ServerEvents;
namespace MCGalaxy.Modules.Moderation.Notes
{
@ -26,19 +24,18 @@ namespace MCGalaxy.Modules.Moderation.Notes
{
public override string name { get { return "Notes"; } }
Command cmdNotes = new CmdNotes();
Command cmdMyNotes = new CmdMyNotes();
static Command[] cmds = new Command[] { new CmdNotes(), new CmdMyNotes(), new CmdNote(), new CmdOpNote(), };
public override void Load(bool startup) {
OnModActionEvent.Register(HandleModerationAction, Priority.Low);
Command.Register(cmdNotes);
Command.Register(cmdMyNotes);
foreach (Command cmd in cmds) { Command.Register(cmd); }
NoteAcronym.Init();
}
public override void Unload(bool shutdown) {
OnModActionEvent.Unregister(HandleModerationAction);
Command.Unregister(cmdNotes, cmdMyNotes);
Command.Unregister(cmds);
}
@ -65,18 +62,20 @@ namespace MCGalaxy.Modules.Moderation.Notes
/// </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");
private readonly static NoteAcronym Warned = new NoteAcronym("W", "Warned");
private readonly static NoteAcronym Kicked = new NoteAcronym("K", "Kicked");
private readonly static NoteAcronym Muted = new NoteAcronym("M", "Muted");
private readonly static NoteAcronym Banned = new NoteAcronym("B", "Banned");
private readonly static NoteAcronym Jailed = new NoteAcronym("J", "Jailed"); // Jailing was removed, but still appears in notes for historical reasons
private readonly static NoteAcronym Frozen = new NoteAcronym("F", "Frozen");
private readonly static NoteAcronym TempBanned = new NoteAcronym("T", "Temp-Banned");
private readonly static NoteAcronym Noted = new NoteAcronym("N", "Noted");
public readonly static NoteAcronym OpNoted = new NoteAcronym("O", "OpNoted");
static NoteAcronym[] All;
internal static void Init() {
All = new NoteAcronym[] { Warned, Kicked, Muted, Banned, Jailed, Frozen, TempBanned };
All = new NoteAcronym[] { Warned, Kicked, Muted, Banned, Jailed, Frozen, TempBanned, Noted, OpNoted };
}
/// <summary>
@ -103,8 +102,8 @@ namespace MCGalaxy.Modules.Moderation.Notes
return acronym;
}
readonly string Acronym;
readonly string Action;
public readonly string Acronym;
public readonly string Action;
private NoteAcronym(string acronym, string action) {
Acronym = acronym;