Solved Ignore chat

Discussion in 'Plugin Requests' started by Togoshige, Apr 2, 2017.

  1. Code:
    playerReceiving.Message($"<color=#55aaff>{player.Name}</color>: " + message);
    This worked to add default light blue color to usernames

    I tested the code on my server, was successfully able to ignore other players :D

    TODO:
    - steam profile image
    - clan tag support
     
  2. Oh, maybe Im going about this the wrong way,
    OnPlayerChat(), OnUserChat() hooks are when a player SENDS a message,

    What if I hooked into when a player RECIEVES a message?, and do the ignore checking there,
    I found OnMessagePlayer() and OnServerMessage() hooks:

    Oxide API for Rust
    Oxide API for Rust

    Doing it this way, you then wouldnt have to worry about all the formatting stuff, you either let the message pass through or stop it.
    Would this work? Is there a Covalence way of doing this?
     
  3. Wulf

    Wulf Community Admin

    Filtering who gets the message is the right way with OnPlayerChat or OnUserChat.
     
  4. Would filtering at end of message process OnMessagePlayer() technically work? I havent tested yet, but will soon :)

    Ideally Id still like to be able to use BetterChat and have Title support, etc
    Id also like this plugin to be able to work with other chat plugins (mute, anti-spam, etc)

    I think efficiency wise, filtering at beginning of process is better,
    but plugin eco-system, not reinvent the wheel wise, makes sense to dodge having to deal with formatting messages and to have a plugin that works with all the other plugins.

    Ideally Ideally this would be part of BetterChat, or a plugin that works alongside BetterChat.
    [DOUBLEPOST=1495558298][/DOUBLEPOST]Tested those other hooks, OnMessagePlayer() didnt hook into chat messages (couldnt see OnServerMessage() fire off in a minute of testing), anyways It would be hard to figure out who sent the message since its not a parameter, would have to extract the username from the message or something
     
  5. LaseryHydra updated BetterChat to version 5.0.12 to allow the ability to block messages going to players -----> Better Chat - 5.0.12 | Oxide

    I present to you, BetterChatIgnore,
    please give any feedback, I tested and it works

    Code:
    using Oxide.Core.Plugins;
    using Oxide.Core.Libraries.Covalence;
    using System;
    using System.Collections.Generic;
    using UnityEngine;namespace Oxide.Plugins
    {
        [Info("BetterChatIgnore", "Togoshige", 0.2)]
        [Description("Players Can Ignore Chat Messages From Other Players")]
        public class BetterChatIgnore : RustPlugin
        {
            [PluginReference]
            private Plugin Ignore;        [PluginReference]
            private Plugin BetterChat;        object OnBetterChat(Dictionary<string, object> messageData)
            {
                IPlayer playerSendingMessage = (IPlayer)messageData["Player"];
                ulong playerSendingMessage_userID = Convert.ToUInt64(playerSendingMessage.Id);            List<string> blockedReceivers = new List<string>();
                foreach (BasePlayer playerReceivingMessage in BasePlayer.activePlayerList)
                {
                    var hasIgnored = Ignore?.CallHook("HasIgnored", playerReceivingMessage.userID, playerSendingMessage_userID);
                    if (hasIgnored != null && (bool)hasIgnored)
                    {
                        blockedReceivers.Add(playerReceivingMessage.userID.ToString());
                    }
                }            messageData["BlockedReceivers"] = blockedReceivers;
                return messageData;
            }
        }
    }
    
    TODO
    - error if Ignore plugin is missing
    - error if BetterChat plugin is missing

    - turn into Covalence/Universal plugin
    --- make Ignore plugin Covalence/Universal

    NEW PLUGIN?
    - restrict player names to have at least 4-6 alphanumeric chars in a row
    (so players cant hide from being ignored with special charachters)
     
    Last edited by a moderator: May 27, 2017
  6. Wulf

    Wulf Community Admin

    There are already plugins for name requirements and restrictions. Also, if you are going to release your plugin, please use the Plugins section.
     
  7. Hey there Wulf,

    Do you happen to know of plugins that restrict names? I couldnt find any yet, I was about to make a post in Plugin Requests for it

    I do plan to release the plugin to Oxide officially, but Im looking for feedback/code review before I do,
    I also know you wanted this as a Universal plugin and its only a Rust plugin at the moment (I pushed on Nogrod to make Ignore API a Universal/Covalence plugin ----> http://oxidemod.org/threads/ignore-api.8783/#post-327408 [But looks like your okay with it staying a Rust plugin for now?])
    [DOUBLEPOST=1495919082][/DOUBLEPOST]Found a name plugin ----> Name Manager | Oxide
     
  8. So since BetterChat and Ignore API are required dependencies,
    is there much more I can do than the code below? (Checking if PluginReferences are null and printing warnings)

    Code:
            [PluginReference]
            private Plugin BetterChat;        [PluginReference]
            private Plugin Ignore;        void OnServerInitialized()
            {
                if (!BetterChat) { PrintWarning("BetterChat not detected"); }
                if (!Ignore) { PrintWarning("Ignore API not detected"); }
            }
    Code:
            // BetterChat Hook
            object OnBetterChat(Dictionary<string, object> messageData)
            {
                if (!Ignore) { PrintWarning("Ignore API not detected"); return messageData; }
    
     
  9. Plugin was accepted! Hooray!, please mark as Solved :)