mIRC Home    About    Download    Register    News    Help

Print Thread
#260666 02/06/17 10:04 AM
Joined: Jun 2017
Posts: 4
T
Self-satisified door
OP Offline
Self-satisified door
T
Joined: Jun 2017
Posts: 4
I have been working on a script to allow users to leave notes for other users on Twitch and is triggered if either they type in chat or join the channel. However I think I must be doing something wrong because the message doesn't get displayed in chat. Here is what I have so far.
Code:
on *:TEXT:!note*:#:{
  if ( $2 ison $chan ) { return }
  set %notenick. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] $2
  set %notemsg. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] $3-
  msg $chan Your message has been left for that user
  return
}  
on *:JOIN:#:{
  if ( %notenick. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] == $nick ) {
    msg $chan %notemsg. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
    unset %notenick. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
    unset %notemsg. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
    return
  }
}
on *:TEXT:*:#:{
  if ( %notenick. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] == $nick ) {
    msg $chan %notemsg. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
    unset %notenick. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
    unset %notemsg. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
    return
  }
}


Last edited by Technodevster; 02/06/17 10:23 AM.
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
John wants to leave a note for Fred, so:

<John> !note Fred message goes here

Your script then creates the variable

%notenick.#channel.John Fred
%notemsg.#channel.John message goes here

Then Fred enters the channel, and it checks for %notenick.#channel.Fred which doesn't exist. The next time John enters the channel, %notenick.#channel.John does exist, however the contents of that variable are filled with Fred, so since Fred != John, no message is left. The only way a message could be triggered would be if John left a message for himself, but you're preventing that by checking if $2 is online.

When creating variables, you'd use $2 instead of $nick without verification of $2 being legit. You might want to create a list of approved nicks who can have messages left for them.

I tested leaving a note for $compress(versions.txt) and it didn't compress that file, so it's probably safe to use $2 here without checking that it's a legit nick. You should have the script do a test to make sure $2 doesn't contain characters not valid in a nick.

//if ($remove($2,_,-,\,[,],$({),$(}),^,`,$(|)) !isalnum) Msg $chan $2 not a nick, no note saved.

You also have potential for a build-up of bogus notes that will never be deliverable. You could fill $ctime into your notenick or create a %NoteTime variable so you can use that to delete variables reaching a certain age. If the script is working, you shouldn't need to check that the value of the variable is the same as the word used to create the variable name, just that it exists.

Also, the way things are now, Fred has no way to know who left the message for him, unless the sender includes in the message. And even worse, the sender could false flag:

<John> !note Fred This is Mary, I love you!

More reliable would be using "Message from $nick $+ : $3-" instead of just "$3-"

Also, your code for ON JOIN and ON TEXT are identical, both before and after your fix. You could streamline that code into an alias, then have the 2 events just call the alias.

on *:JOIN:#:{ newalias }
on *:TEXT:*:#:{ newalias }

The alias will still know the values for $chan and $nick.

Also, when the script is fixed, your ON TEXT which triggers for :*: checking if there's a message to display - doesn't activate when someone leaves a note, because those events are trapped by the 1st ON TEXT event. Because you're using ON JOIN, your 2nd ON TEXT would never get triggered unless someone enters channel with their alt-nick and changes nick once they're in channel. For those cases, you could check the ON NICK event to show the message then, instead of waiting for them to trigger the TEXT event.

If you do use ON NICK, your code is no longer the same, because ON NICK would need to inspect $newnick instead of $nick. You can adjust for that by doing things like:

if (variable == $nick )
becomes
if ( variable == $iif($event == NICK,$newnick,$nick) )
or
if ( variable == $iif($event isin TEXT JOIN,$nick,$newnick) )

You could have quickly caught your error by inserting a debug message into your script. At the top of the JOIN event, echo your IF statement, making sure that parenthesis aren't touching anything else:

echo -s $script $scriptline if ( %notenick. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] == $nick )

... would have shown you why it wasn't triggering your message.

Joined: Oct 2015
Posts: 112
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
I may have gotten a little carried away and rewrote a lot of the script for you. maroon's notes were on point and I used a lot of that info to write this one. I noticed some other issues with the script as well so I addressed those. Multiple users should be able to leave a message for the same person now as well. I left a few comments in the script to make it more clear what I changed. I hope this helps.

Code:
ON $*:TEXT:/^!note\s\w+\s/iS:#:{
  IF ( $2 ison $chan ) { return }
  ; set %notes_for.* variable that contains the names of everyone who has left a note for the targeted user
  SET %notes_for. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $2 ] ] %notes_for. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $2 ] ] $nick
  ; set %notes_from_to.* variable that contains the message from the user to the targeted user
  SET %note_from_to. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] [ $+ [ . ] ] [ $+ [ $2 ] ] Message from $nick to $2 $+ : $3-
  MSG $chan $nick $+ , your message has been left for $2 $+ .
}

on *:JOIN:#: { postmessage }
on *:TEXT:*:#: { postmessage }

alias postmessage {
  ; if user has any notes for left for them, then get all notes left for that user sent by any and all users that left them a note
  IF (%notes_for. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]) {
    VAR %x 1
    WHILE ($gettok(%notes_for. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ],%x,32)) {
      MSG $chan %note_from_to. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $v1 ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
      UNSET %note_from_to. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $v1 ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
      INC %x
    }
    UNSET %notes_for. [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
  }
}

Blas #260704 07/06/17 07:43 AM
Joined: Jun 2017
Posts: 4
T
Self-satisified door
OP Offline
Self-satisified door
T
Joined: Jun 2017
Posts: 4
That really helped but now I have another problem. If two or more people leave a message for the same user if that user types or joins the messages are being sent too quickly so quick that it's triggering the spam filters on Twitch. How would I go about adding about a 2 second delay between each note sent to that user?

Last edited by Technodevster; 07/06/17 07:46 AM.
Joined: Oct 2015
Posts: 112
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
That is odd. I have tested it with my channel bot and all the messages went through. Is your bot modded in your channel? If not, give that a try. Otherwise a delay would need to be added somehow.

Blas #260716 08/06/17 02:37 AM
Joined: Jun 2017
Posts: 4
T
Self-satisified door
OP Offline
Self-satisified door
T
Joined: Jun 2017
Posts: 4
The bot is modded in my channel but I have another streamer who I also host the bot for and the bot isn't a mod in that channel and it only seems to happen in channels where the bot isn't a mod.

Joined: Oct 2015
Posts: 112
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
Originally Posted By: Technodevster
The bot is modded in my channel but I have another streamer who I also host the bot for and the bot isn't a mod in that channel and it only seems to happen in channels where the bot isn't a mod.

That makes sense. A delay would need to be added then if the bot isn't a mod. IMO all channel bots should have mod access for reasons such as this. It would take some effort for me to add a delay in there when the problem could be easily solved by simply modding the channel bot. Perhaps someone else could help you with the delay approach if modding the channel bot is not an option. I hope you find an adequate solution. smile


Link Copied to Clipboard