Implement chat muting TorchAPI/Essentials#81
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using VRage.Collections;
|
||||||
using VRage.Network;
|
using VRage.Network;
|
||||||
|
|
||||||
namespace Torch.API.Managers
|
namespace Torch.API.Managers
|
||||||
@@ -41,5 +42,24 @@ namespace Torch.API.Managers
|
|||||||
/// <param name="font">Font to use</param>
|
/// <param name="font">Font to use</param>
|
||||||
/// <param name="targetSteamId">Player to send the message to, or everyone by default</param>
|
/// <param name="targetSteamId">Player to send the message to, or everyone by default</param>
|
||||||
void SendMessageAsOther(string author, string message, string font, ulong targetSteamId = 0);
|
void SendMessageAsOther(string author, string message, string font, ulong targetSteamId = 0);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Mute user from global chat.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="steamId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool MuteUser(ulong steamId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unmute user from global chat.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="steamId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool UnmuteUser(ulong steamId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Users which are not allowed to chat.
|
||||||
|
/// </summary>
|
||||||
|
HashSetReader<ulong> MutedUsers { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@ using Torch.API.Managers;
|
|||||||
using Torch.Managers.PatchManager;
|
using Torch.Managers.PatchManager;
|
||||||
using Torch.Utils;
|
using Torch.Utils;
|
||||||
using VRage;
|
using VRage;
|
||||||
|
using VRage.Collections;
|
||||||
using VRage.Library.Collections;
|
using VRage.Library.Collections;
|
||||||
using VRage.Network;
|
using VRage.Network;
|
||||||
|
|
||||||
@@ -47,6 +48,10 @@ namespace Torch.Managers.ChatManager
|
|||||||
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
|
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
|
||||||
private static readonly Logger _chatLog = LogManager.GetLogger("Chat");
|
private static readonly Logger _chatLog = LogManager.GetLogger("Chat");
|
||||||
|
|
||||||
|
private readonly HashSet<ulong> _muted = new HashSet<ulong>();
|
||||||
|
/// <inheritdoc />
|
||||||
|
public HashSetReader<ulong> MutedUsers => _muted;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ChatManagerServer(ITorchBase torchInstance) : base(torchInstance)
|
public ChatManagerServer(ITorchBase torchInstance) : base(torchInstance)
|
||||||
{
|
{
|
||||||
@@ -56,6 +61,18 @@ namespace Torch.Managers.ChatManager
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public event MessageProcessingDel MessageProcessing;
|
public event MessageProcessingDel MessageProcessing;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool MuteUser(ulong steamId)
|
||||||
|
{
|
||||||
|
return _muted.Add(steamId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool UnmuteUser(ulong steamId)
|
||||||
|
{
|
||||||
|
return _muted.Remove(steamId);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void SendMessageAsOther(ulong authorId, string message, ulong targetSteamId = 0)
|
public void SendMessageAsOther(ulong authorId, string message, ulong targetSteamId = 0)
|
||||||
{
|
{
|
||||||
@@ -128,6 +145,13 @@ namespace Torch.Managers.ChatManager
|
|||||||
internal void RaiseMessageRecieved(ChatMsg message, ref bool consumed)
|
internal void RaiseMessageRecieved(ChatMsg message, ref bool consumed)
|
||||||
{
|
{
|
||||||
var torchMsg = new TorchChatMessage(GetMemberName(message.Author), message.Author, message.Text, (ChatChannel)message.Channel, message.TargetId);
|
var torchMsg = new TorchChatMessage(GetMemberName(message.Author), message.Author, message.Text, (ChatChannel)message.Channel, message.TargetId);
|
||||||
|
if (_muted.Contains(message.Author))
|
||||||
|
{
|
||||||
|
consumed = true;
|
||||||
|
_chatLog.Warn($"MUTED USER: [{torchMsg.Channel}:{torchMsg.Target}] {torchMsg.Author}: {torchMsg.Message}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MessageProcessing?.Invoke(torchMsg, ref consumed);
|
MessageProcessing?.Invoke(torchMsg, ref consumed);
|
||||||
|
|
||||||
if (!consumed)
|
if (!consumed)
|
||||||
|
Reference in New Issue
Block a user