Raised This Month: $32 Target: $400
 8% 

[ANY] Chat Responder [UPDATED 2/27/16]


Post New Thread Reply   
 
Thread Tools Display Modes
Author
headline
SourceMod Moderator
Join Date: Mar 2015
Plugin ID:
5039
Plugin Version:
1.1
Plugin Category:
General Purpose
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
    4 
    Plugin Description:
    A plugin that responds to strings of text
    Old 02-11-2016 , 21:46   [ANY] Chat Responder [UPDATED 2/27/16]
    Reply With Quote #1

    [ANY] Chat Responder

    ABOUT:
    This plugin takes triggers and responces from a config file and when a player types a phrase, it'll check to see if there are any triggers in it. If so, it'll print back. It can be configured to detect "exact" or "contains" phrases.

    If I type "Hey whats up!" and "Hey whats up!" is registered as an exact trigger, it'll cause a response.
    If I type "Banana Man yo" and "yo" is registered as a "contains" trigger, then it'll cause a responce.

    The config file looks like this
    Config File


    Where "Hi" will trigger the response and "type" will determine if it's supposed to be an exact or a contain trigger.

    CREDITS:
    Thanks to ThatOneGuy for introducing me to ADT Arrays when I was learning and also shout out to this thread for giving me the idea [link]

    BUGS:
    If there are any bugs please comment below, don't forget to check your error logs!

    SOURCE:
    PHP Code:
    /****************************************************************************
        [ANY] Chat Responder - A friend inside the code                            *
        Copyright (C) 2015  Michael Flaherty                                    *        

        This program is free software: you can redistribute it and/or modify    *
        it under the terms of the GNU General Public License as published by    *
        the Free Software Foundation, either version 3 of the License, or        *
        (at your option) any later version.                                        *

        This program is distributed in the hope that it will be useful,            *
        but WITHOUT ANY WARRANTY; without even the implied warranty of            *
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
        GNU General Public License for more details.                            *

        You should have received a copy of the GNU General Public License        *
        along with this program.  If not, see <http://www.gnu.org/licenses/>    *
    *****************************************************************************/
    #include <sourcemod>
    #include <autoexecconfig>
    #include <colorvariables>

    #pragma semicolon 1
    #pragma newdecls required
    #pragma dynamic 131072 //increase stack space to from 4 kB to 131072 cells (or 512KB, a cell is 4 bytes).

    #define TAG " \x04"
    #define PLUGIN_VERSION "1.3.4"
    #define MAX_TEXT_LENGTH 512

    /* ADT Arrays */
    Handle gh_adtExactTextsResponse;
    Handle gh_adtExactTextsTrigger;
    Handle gh_adtContainTextTrigger;
    Handle gh_adtContainTextResponse;

    /* Bools */
    bool g_bLateLoad;
    bool ga_bCooldown[MAXPLAYERS 1];

    /* Strings */
    char g_sPath[PLATFORM_MAX_PATH];

    /* ConVars */
    ConVar gcv_bPluginEnabled;
    ConVar gcv_sFilePath;
    ConVar gcv_bGlobalReply;
    ConVar gcv_fCoolDownTime;

    public 
    Plugin myinfo =
    {
        
    name "[ANY] Chat Responder",
        
    author "Headline",
        
    description "A simple chat bot",
        
    version PLUGIN_VERSION,
        
    url "http://www.michaelwflaherty.com"
    };

    public 
    APLRes AskPluginLoad2(Handle hMyselfbool bLatechar[] sErrorint err_max)
    {
        
    g_bLateLoad bLate;
        
        return 
    APLRes_Success;
    }

    public 
    void OnPluginStart()
    {
        
    AutoExecConfig_SetFile("hl_chatresponder");
        
    AutoExecConfig_CreateConVar("hl_chatresponder_version"PLUGIN_VERSION"Headline's Chat Responder : Version"FCVAR_NOTIFY|FCVAR_DONTRECORD);
        
        
    gcv_bPluginEnabled AutoExecConfig_CreateConVar("hl_chatresponder_enable""1""Enable the plugin?\n (1 = Yes, 0 = No)"FCVAR_NONEtrue0.0true1.0);    
        
        
    gcv_sFilePath AutoExecConfig_CreateConVar("hl_chatresponder_filepath""configs/hl_chatresponder.txt""File path to parse"FCVAR_NONE);
        
        
    gcv_bGlobalReply AutoExecConfig_CreateConVar("hl_chatresponder_global_reply""1""Make it so the Bot's responses are visible to everyone?\n (1 = Yes, 0 = No)"FCVAR_NONEtrue0.0true1.0);    

        
    gcv_fCoolDownTime AutoExecConfig_CreateConVar("hl_chatresponder_cooldown_time""10.0""Cooldown time for chat responses. (to prevent spam)"FCVAR_NONEtrue0.0true1.0);    

        
    AutoExecConfig_ExecuteFile();
        
    AutoExecConfig_CleanFile();
        
        if(
    g_bLateLoad)
        {
            
    OnConfigsExecuted();
        }
        
        
    AddCommandListener(OnSay"say"); 
        
    AddCommandListener(OnSay"say_team");
    }

    public 
    void OnConfigsExecuted()
    {
        if (
    gcv_bPluginEnabled.BoolValue)
        {
            
    InitializeADTArrays();
        }
    }

    public 
    void OnClientConnected(int client)
    {
        
    ga_bCooldown[client] = false;
    }

    public 
    void OnClientDisconnect(int client)
    {
        
    ga_bCooldown[client] = false;
    }

    public 
    Action OnSay(int client, const char[] commandint args
    {
        if (!
    gcv_bPluginEnabled.BoolValue)
        {
            return 
    Plugin_Continue;
        }
        if (!
    IsValidClient(client))
        {
            return 
    Plugin_Continue;
        }
        else
        {
            
    char sText[4096]; 
            
    GetCmdArgString(sTextsizeof(sText));
            
            
    StripQuotes(sText);
            
            
    Handle hData CreateDataPack();
            
    WritePackCell(hDataclient);
            
    WritePackString(hDatasText);
            
    ResetPack(hData);
            
            
    CreateTimer(0.3Timer_ReplyhDataTIMER_FLAG_NO_MAPCHANGE);
        }
        return 
    Plugin_Continue;
    }
        
    public 
    Action Timer_Reply(Handle hTimerHandle hData)
    {
        
    char sText[4096]; 

        
    int client ReadPackCell(hData);
        
    ReadPackString(hDatasTextsizeof(sText));
        
    CloseHandle(hData);
        if (
    IsValidClient(client))
        {
            
    char sTrigger[128];
            
    char sResponse[MAX_TEXT_LENGTH];

            
    bool bFoundResponse false;
            
    int iArrayIndex FindStringInArray(gh_adtExactTextsTriggersText);
            if (
    iArrayIndex != -1)
            {
                
    GetArrayString(gh_adtExactTextsResponseiArrayIndexsResponsesizeof(sResponse));

                if (
    StrContains(sResponse"{NAME}"))
                {
                    
    char sName[MAX_NAME_LENGTH];
                    
    GetClientName(clientsNamesizeof(sName));
                    
    ReplaceString(sResponsesizeof(sResponse), "{NAME}"sName);
                }
                
                
    int count 0;
                for (
    int j 0sResponse[j]; j++) {
                    if (
    sResponse[j] == '\n')
                        
    count++;
                }

                
    char[][] lines = new char[count+1][MAX_TEXT_LENGTH];
                
    ExplodeString(sResponse"\n"linescount+1MAX_TEXT_LENGTH);

                if (!
    ga_bCooldown[client])
                {
                    for (
    int j 0count+1j++)
                    {
                        if (
    gcv_bGlobalReply.BoolValue)
                        {
                            
    CPrintToChatAll("%s%s"TAGlines[j]);
                        }
                        else
                        {
                            
    CPrintToChat(client"%s%s"TAGlines[j]);
                        }
                    }
                }
                else
                {
                    
    PrintToChat(client"%sDo not spam the chat responder!"TAG);
                }
                
    bFoundResponse true;
            }
            else
            {
                
    bFoundResponse false;
            }
            
            if (!
    bFoundResponse)
            {
                for (
    int i 0GetArraySize(gh_adtContainTextTrigger); i++)
                {
                    
    GetArrayString(gh_adtContainTextTriggerisTriggersizeof(sTrigger));
                    if (
    StrContains(sTextsTriggerfalse) != -1)
                    {
                        
    GetArrayString(gh_adtContainTextResponseisResponsesizeof(sResponse));
                        
                        
    int count 0;
                        for (
    int j 0sResponse[j]; j++) {
                            if (
    sResponse[j] == '\n')
                                
    count++;
                        }

                        
    char[][] lines = new char[count+1][MAX_TEXT_LENGTH];
                        
    ExplodeString(sResponse"\n"linescount+1MAX_TEXT_LENGTH);

                        if (!
    ga_bCooldown[client])
                        {
                            for (
    int j 0count+1j++)
                            {
                                if (
    gcv_bGlobalReply.BoolValue)
                                {
                                    
    CPrintToChatAll("%s%s"TAGlines[j]);
                                }
                                else
                                {
                                    
    CPrintToChat(client"%s%s"TAGlines[j]);
                                }
                            }
                        }
                        else
                        {
                            
    PrintToChat(client"%sDo not spam the chat responder!"TAG);
                        }
                            
                        
    bFoundResponse true;
                        break;
                    }
                }
            }
            if (
    bFoundResponse && gcv_fCoolDownTime.FloatValue 0.1)
            {
                
    CreateTimer(gcv_fCoolDownTime.FloatValueTimer_CooldownGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
                
    ga_bCooldown[client] = true;
            }
        }
    }

    public 
    Action Timer_Cooldown(Handle hTimerint iUserID)
    {
        
    int client GetClientOfUserId(iUserID);
        if (
    IsValidClient(client))
        {
            if (
    ga_bCooldown[client])
            {
                
    ga_bCooldown[client] = false;
            }
        }
    }

    public 
    void ParseKvFile()
    {
        
    char sPath[PLATFORM_MAX_PATH];
        
    gcv_sFilePath.GetString(sPathsizeof(sPath));
        
    BuildPath(Path_SMg_sPathsizeof(g_sPath), sPath);
        
    Handle hKeyValues CreateKeyValues("Chat Responder");

        if(!
    FileExists(g_sPath))
        {
            
    SetFailState("Configuration file %s not found!"g_sPath);
            return;
        }

        if(!
    FileToKeyValues(hKeyValuesg_sPath))
        {
            
    SetFailState("Improper structure for configuration file %s!"g_sPath);
            return;
        }

        if(
    KvGotoFirstSubKey(hKeyValues))
        {
            do
            {
                
    char sSectionName[128];
                
    char sType[128];
                
    char sText[MAX_TEXT_LENGTH];

                
    KvGetSectionName(hKeyValuessSectionNamesizeof(sSectionName));    //get name of section
                
                
    KvGetString(hKeyValues"response"sTextsizeof(sText));
                
    KvGetString(hKeyValues"type"sTypesizeof(sType));    //call key-value by name of key and store value in variable, with default as "blah" if it doesnt exist

                
    ReplaceString(sTextsizeof(sText), "{new_line}""\n");
                if (
    StrEqual(sType"e"false))
                {
                    
    PushArrayString(gh_adtExactTextsTriggersSectionName);
                    
    PushArrayString(gh_adtExactTextsResponsesText);
                }
                else if (
    StrEqual(sType"c"false))
                {
                    
    PushArrayString(gh_adtContainTextTriggersSectionName);
                    
    PushArrayString(gh_adtContainTextResponsesText);
                }
            }
            while(
    KvGotoNextKey(hKeyValuesfalse));
            
    KvGoBack(hKeyValues);
        }
        else
        {
            
    SetFailState("Can't find first subkey in configuration file %s!"g_sPath);
            
    CloseHandle(hKeyValues);
            return;
        }
        
    CloseHandle(hKeyValues);
    }

    stock void InitializeADTArrays()
    {
        
    gh_adtExactTextsTrigger CreateArray(64);
        
    gh_adtExactTextsResponse CreateArray(MAX_TEXT_LENGTH);
        
    ClearArray(gh_adtExactTextsTrigger);
        
    ClearArray(gh_adtExactTextsResponse);

        
    gh_adtContainTextTrigger CreateArray(64);
        
    gh_adtContainTextResponse CreateArray(MAX_TEXT_LENGTH);
        
    ClearArray(gh_adtContainTextTrigger);
        
    ClearArray(gh_adtContainTextResponse);

        
    ParseKvFile();
    }

    stock bool IsValidClient(int clientbool bAllowBots falsebool bAllowDead true)
    {
        if(!(
    <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
        {
            return 
    false;
        }
        return 
    true;
    }

    /*
        Change log
        1.0
            * Initial release
        1.1
            * Fixed some dumb mistakes
            * Added a cooldown timer to prevent spam
            * Added a few IsValidClient checks to make sure we don't get errors in error logs
            * Implemented some of ThatOneGuy's suggestions
        1.3.3
            * Fixed {new_line}
        1.3.4
            * Fixed issue where client's cooldowns would not be reset
    */ 
    Attached Files
    File Type: zip hl_chatresponder-1.0.zip (15.6 KB, 350 views)
    File Type: zip hl_chatresponder-1.1.zip (16.5 KB, 378 views)
    File Type: zip hl_chatresponder-1.2.zip (16.9 KB, 167 views)
    File Type: zip hl_chatresponder-1.3.2.zip (35.0 KB, 320 views)
    File Type: zip hl_chatresponder-1.3.3.zip (35.5 KB, 423 views)
    File Type: zip hl_chatresponder-1.3.4.zip (34.6 KB, 944 views)

    Last edited by headline; 03-03-2020 at 23:11.
    headline is offline
    Windroid
    Member
    Join Date: Mar 2013
    Old 02-13-2016 , 01:46   Re: [ANY] Chat Responder [UPDATED 2/11/15]
    Reply With Quote #2

    So...it's similar to this?
    https://forums.alliedmods.net/showthread.php?p=883997
    Windroid is offline
    headline
    SourceMod Moderator
    Join Date: Mar 2015
    Old 02-13-2016 , 02:36   Re: [ANY] Chat Responder [UPDATED 2/11/15]
    Reply With Quote #3

    Quote:
    Originally Posted by Windroid View Post
    It's similar, but that one creates an actual bot. This just simply responds to text. It's not a "chat bot"
    headline is offline
    Randommagic
    Senior Member
    Join Date: Jun 2014
    Location: -
    Old 02-13-2016 , 11:46   Re: [ANY] Chat Responder [UPDATED 2/11/15]
    Reply With Quote #4

    https://forums.alliedmods.net/showthread.php?t=259863
    __________________

    Last edited by Randommagic; 02-13-2016 at 11:48.
    Randommagic is offline
    badboy2050
    Junior Member
    Join Date: Feb 2016
    Old 02-13-2016 , 17:09   Re: [ANY] Chat Responder [UPDATED 2/11/15]
    Reply With Quote #5

    and how to stop the people form abuse it by spam ?
    any idea
    badboy2050 is offline
    ThatOneGuy
    Veteran Member
    Join Date: Jul 2012
    Location: Oregon, USA
    Old 02-23-2016 , 03:00   Re: [ANY] Chat Responder [UPDATED 2/11/15]
    Reply With Quote #6

    Long time no see, Headline! I saw this plugin and thought "I wonder if he is using ADT arrays or something better than re-parsing each time." Then, I saw the "Credits". Thanks man. Also, instead of looping your ADT arrays to check for the string, you could use FindStringInArray (and check if != -1). This would make sense to do for your "exact" array, but not your "contains" one, since I'm unsure if FindStringInArray would work for substrings like that (you could always test to find out) so you would need the loop. The difference is fairly negligible, but I believe (I might be wrong) it is slightly more efficient using FindStringInArray, and it is also easier to code, since it avoids typing out the loop.

    Quote:
    Originally Posted by badboy2050 View Post
    and how to stop the people form abuse it by spam ?
    any idea
    He has a cvar to disable it showing to everyone. You could change that. On a side note (Headline), it looks like you accidently put a space in your cvar name: "hl_chatresponder_global reply". Another thought, is that the global vs show to client could be a kv on each setup, but I cant really think of when it would be needed for a global message, so idk if it is worth coding in the configurability.
    __________________
    ThatOneGuy is offline
    headline
    SourceMod Moderator
    Join Date: Mar 2015
    Old 02-28-2016 , 01:02   Re: [ANY] Chat Responder [UPDATED 2/27/16]
    Reply With Quote #7

    Version 1.1
    - Fixed stupid cvar naming error
    - Added more IsValidClient checks to avoid errors
    - Added FindStringInArray instead of looping (idk what I was thinking thanks TOG)
    - Created a cooldown system to prevent users from spamming the server with their chat response!
    headline is offline
    jewny24
    Member
    Join Date: Oct 2016
    Old 11-29-2016 , 06:08   Re: [ANY] Chat Responder [UPDATED 2/27/16]
    Reply With Quote #8

    I added the files in the correct folders but it doesn't work. I tried restarting the server and in the error logs in only shows this, which is from the earlier sourcemod incompatibility with the newest csgo update:

    Quote:
    L 11/29/2016 - 10:48:49: [SM] Blaming: csgo_gore.smx
    L 11/29/2016 - 10:48:49: [SM] Call stack trace:
    L 11/29/2016 - 10:48:49: [SM] [0] TE_Start
    L 11/29/2016 - 10:48:49: [SM] [1] Line 132, /home/forums/content/files/3/7/8/1/107845.attach::GoreDecal
    L 11/29/2016 - 10:48:49: [SM] [2] Line 169, /home/forums/content/files/3/7/8/1/107845.attach::EventDamage
    What do?

    Also, my chatresponder.txt looks like this:

    Quote:
    "Chat Responder"
    {
    "Forum"
    {
    "response" "indungi.ro/forum/forum/27283-competitive-es/"
    "type" "forum"
    }
    "Steam group"
    {
    "response" "steamcommunity.com/groups/esindungiro"
    "type" "steam"
    }
    }
    __________________
    Just a noob admin always searching for help.
    Thanks AlliedModders.

    Last edited by jewny24; 11-29-2016 at 06:18.
    jewny24 is offline
    headline
    SourceMod Moderator
    Join Date: Mar 2015
    Old 11-29-2016 , 11:14   Re: [ANY] Chat Responder [UPDATED 2/27/16]
    Reply With Quote #9

    Quote:
    Originally Posted by jewny24 View Post
    I added the files in the correct folders but it doesn't work. I tried restarting the server and in the error logs in only shows this, which is from the earlier sourcemod incompatibility with the newest csgo update:



    What do?

    Also, my chatresponder.txt looks like this:
    The "type" field should either be the letter e or the letter c. For exact or contains. Re-read the about section and review the default cfg
    headline is offline
    Nachtfrische
    Member
    Join Date: Aug 2015
    Location: Dream Community
    Old 08-18-2018 , 11:54   Re: [ANY] Chat Responder [UPDATED 2/27/16]
    Reply With Quote #10

    Quote:
    Originally Posted by Headline View Post
    - Created a cooldown system to prevent users from spamming the server with their chat response!
    The cooldown timer doesn't seem to work for me.

    I put "hl_chatresponder_cooldown_time" = "0.0" and it still says "Do not spam the chat responder" in the chat. Even worse, it's constantly saying that, regardless of how long I wait.

    There is nothing in the error logs.
    __________________
    Visit us at: http://dream-community.de

    Our 35HP Knife Server:


    Our Jailbreak Server:

    Last edited by Nachtfrische; 08-18-2018 at 11:58.
    Nachtfrische is offline
    Reply


    Thread Tools
    Display Modes

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 09:33.


    Powered by vBulletin®
    Copyright ©2000 - 2024, vBulletin Solutions, Inc.
    Theme made by Freecode