Search Unity

Trouble sending whisper message via irc twitchapi among other commands. really picky syntax?

Discussion in 'Scripting' started by ReggieBeRetro, Sep 16, 2020.

  1. ReggieBeRetro

    ReggieBeRetro

    Joined:
    Aug 30, 2015
    Posts:
    73
    Having some trouble with this
    code is first explanation at the bottom..


    Code (CSharp):
    1. private void CheckInputs (string ChatInputs)
    2.     {
    3.  
    4.         if (ChatInputs.ToLower () == "badword") {
    5.             writer = new StreamWriter (TwitchChatObj.GetComponent<TwitchChat> ().twitchClient.GetStream ());
    6.             if (incommingName != null) {
    7.                 writer.WriteLine (String.Format ("PRIVMSG #{0} /w {1}", channelName, incommingName + " Timeout issued regarding a restricted word. Keep making infractions to the rules and this timeout will only increase."));
    8.                 writer.WriteLine ("PRIVMSG #" + channelName + String.Format (" {0} {1} {2}", "/timeout", incommingName, Timeout_BadWordThisDuration));
    9.                 //writer.WriteLine ("CLEARCHAT #" + channelName + " :" + incommingName);
    10.                 writer.Flush ();
    11.             } else {
    12.                 incommingName = "Server";
    13.                 int randNum = UnityEngine.Random.Range (22222222, 88888888);
    14.                 CreateElementLine (incommingName, incommingMessage, randNum, "black", "red");
    15.             }
    16.         }
    17.  
    18.         //when recieved chat is check for bad words more commands can be added here later.
    19.  
    20.         //player.AddForce(Vector3.left * (speed * 1000));
    21.     }
    22.  
    23.     public void sendCMsg ()
    24.     {
    25.         string MsgtoSend = TwitchChatObj.GetComponent<TwitchChat> ().ChannelMsgTypePanel.transform.GetChild (0).GetComponent<InputField> ().text;
    26.         if (Input.GetMouseButtonUp (0) || Input.GetKey (KeyCode.Return)) {
    27.             if (MsgtoSend.Length > 0) {
    28.                 if (TwitchChatObj.GetComponent<TwitchChat> ().twitchClient.Connected == true) {
    29.                     int randNum = UnityEngine.Random.Range (22222222, 88888888);
    30.                     string pubchannelName = TwitchChatObj.GetComponent<TwitchChat> ().channelName;
    31.                     botusername = TwitchChatObj.GetComponent<TwitchChat> ().botusername.ToLower ();
    32.                     writer = new StreamWriter (TwitchChatObj.GetComponent<TwitchChat> ().twitchClient.GetStream ());
    33.                     writer.WriteLine (String.Format ("PRIVMSG #{0} :{1}", pubchannelName, MsgtoSend));
    34.                     writer.Flush ();
    35.                     CreateElementLine (botusername, MsgtoSend, randNum, "black", "grey");
    36.                 } else {
    37.                     int randNum = UnityEngine.Random.Range (22222222, 88888888);
    38.                     CreateElementLine ("System", "Bot is not connected and try again. (Message was not sent to the channel.)", randNum, "black", "red");
    39.                 }
    40.             } else {
    41.                 int randNum = UnityEngine.Random.Range (22222222, 88888888);
    42.                 CreateElementLine ("System", "Message field can not be blank enter a message and try again. (Message was not sent to the channel.)", randNum, "black", "red");
    43.             }
    44.         }
    45.     }
    46.  
    47.     public void sendQuickWhisperMsg ()
    48.     {
    49.         string UserToWhisper = TwitchChatObj.GetComponent<TwitchChat> ().WhisperMsgTypePanel.transform.GetChild (1).GetComponent<InputField> ().text;
    50.         string MsgtoSend = TwitchChatObj.GetComponent<TwitchChat> ().WhisperMsgTypePanel.transform.GetChild (0).GetComponent<InputField> ().text;
    51.  
    52.         if (Input.GetMouseButtonUp (0) || Input.GetKey (KeyCode.Return)) {
    53.             if (UserToWhisper.Length > 0) {
    54.                 if (MsgtoSend.Length > 0) {
    55.                     if (TwitchChatObj.GetComponent<TwitchChat> ().twitchClient.Connected == true) {
    56.                         int randNum = UnityEngine.Random.Range (22222222, 88888888);
    57.                         string pubchannelName = TwitchChatObj.GetComponent<TwitchChat> ().channelName;
    58.                         MsgtoSend = TwitchChatObj.GetComponent<TwitchChat> ().WhisperMsgTypePanel.transform.GetChild (0).GetComponent<InputField> ().text;
    59.                         UserToWhisper = TwitchChatObj.GetComponent<TwitchChat> ().WhisperMsgTypePanel.transform.GetChild (1).GetComponent<InputField> ().text;
    60.                         botusername = TwitchChatObj.GetComponent<TwitchChat> ().botusername.ToLower ();
    61.                         writer = new StreamWriter (TwitchChatObj.GetComponent<TwitchChat> ().twitchClient.GetStream ());
    62.                         writer.WriteLine (String.Format ("PRIVMSG #{0} /w {1} :{2}", pubchannelName, UserToWhisper, MsgtoSend));
    63.                         writer.Flush ();
    64.                         CreateElementLine (botusername, "Whispered>> " + UserToWhisper + ": " + MsgtoSend, randNum, "black", "blue");
    65.                         TwitchChatObj.GetComponent<TwitchChat> ().WhisperMsgTypePanel.transform.GetChild (0).GetComponent<InputField> ().text = "";
    66.                         //Debug.Log ();
    67.                     } else {
    68.                         int randNum = UnityEngine.Random.Range (22222222, 88888888);
    69.                         CreateElementLine ("System", "Bot is not connected and try again. (Unalbe to whisper user.)", randNum, "black", "red");
    70.                     }
    71.                 } else {
    72.                     int randNum = UnityEngine.Random.Range (22222222, 88888888);
    73.                     CreateElementLine ("System", "Message field can not be blank enter a message and try again. (Unalbe to whisper user.)", randNum, "black", "red");
    74.  
    75.                 }
    76.             } else {
    77.                 int randNum = UnityEngine.Random.Range (22222222, 88888888);
    78.                 CreateElementLine ("System", "Username field can not be blank enter a user name and try again. (Unalbe to whisper user.)", randNum, "black", "red");
    79.             }
    80.         }
    81.     }
    They are all closely related. 2 of which are 1 or 2 lines from being 100% functional.
    So to explain quickly. I have been working on a twitch channel protection bot in c#.

    I have successfully made connections to the twitch irc server. everything is working on that end.
    My issue comes into play when I try to send a whisper message.

    currently I am able to send a message to the channel using sendCMsg() this syntax on line 33 is 100% working

    while reading the api documentation https://dev.twitch.tv/docs/irc/guide

    the syntax seams to be pretty straight forward to send any other type of command. remove everything after the colon and add /thecommandyouwishtouse right? Well I have not had much luck. I have also tried removing the colon completely and no error is returned. But if I was to add something like /whispering a command that does not exists I do see a error returned from the twitch irc api.

    To whisper should be close to what I have on line 62 in side of sendQuickWhisperMsg (). Please help!. :)

    I also included CheckInputs() which obviously check for bad words when users are chatting. i am not having much success with this either. But whenver a "badword" is caught I do see a error "Unknow Command" from the irc twitchapi server if I was to uncomment the CLEARCHAT line 9. And again I cant seam to send the timeout command with the duration.

    What am I missing? I've been stuck on this for a few days now. :/

    Any insight or direction is appreciated.
     
    Last edited: Sep 16, 2020
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  3. ReggieBeRetro

    ReggieBeRetro

    Joined:
    Aug 30, 2015
    Posts:
    73
    OMG!! I just found 2 lines of code while reading some of the LopapaGames. The way these assets are setup is over my head using a thread dispatcher I have only ever used threads in vb2010 so its been a while wrapping my head around that. But I was able to scan through and find something that looks familiar to me.

    I had to add before a connection is attempted.

    writer.WriteLine("CAP REQ :twitch.tv/tags");
    writer.WriteLine("CAP REQ :twitch.tv/commands");

    Now I'm seeing all of the color, badge details ect
    Im still stuck with the whisper syntax but I feel like this is a step in the right direction.

    You sir are a legend!!
     
    Last edited: Sep 16, 2020