mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2014
Posts: 10
H
Habilis Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Oct 2014
Posts: 10
Hi everyone! First post so bear with me. I've been working on a Twitch bot for a couple of days and I'm trying to figure out how to do a specific behavior. Currently, I wrote a script that keeps track of the latest subscribers to a channel. The channel owner usually likes to send a personal greeting through chat to the subscriber. I would like to find a way to log that personal greeting.

Since the greeting typically goes:
<channel_owner>: subscriber_name blah blah blah

I was thinking it would be best to scan my latest subscriber name list to the first word of inputted text, then, if they match write the the entire line to a hash table.

I've tried several variations of $read(sublist,ns,$) without success. Any suggestions would be appreciated!

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Assuming that the name that <channel_owner> is using to call "subscriber_name" is his actual $nick on the server, you should be able to use
Code:
on *:text:*:#: { 
if ($nick == channel_owner) {
var %user $1
if ($read(file.txt,ns,%user)) { log user message... }
}
}


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Oct 2014
Posts: 10
H
Habilis Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Oct 2014
Posts: 10
I apologize for my ignorance, I only started reading up on mSL a couple of days ago. But how is:
Code:
on *:text:*:#: { 
if ($nick == channel_owner) {
var %user $1
if ($read(file.txt,ns,%user)) { log user message... }
}
}


any different from:
Code:
on *:text:*:#: { 
if ($nick == channel_owner) {
if ($read(file.txt,ns,$1)) { log user message... }
}
}

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
It isn't. I just like making use of variables so that whenever I in the future go back to look at my code I can easily tell what they're for.

For advanced stuff I use comments as well.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Oct 2014
Posts: 10
H
Habilis Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Oct 2014
Posts: 10
So when using your code snippet I was getting a behavior where if there was a single word on a line in the text file like:
Code:
test
test1
test2


The $read() would return nothing. I found a workaround, when capturing the sublist, I just write the name twice, but I was wondering if there was another way. After reading wikichip, it sounds like ignoring the first entry when you do $read(file.txt, s, $1) is the desired behavior.

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
The s switch matches the first word and returns everything afterward, if you want an exact match you can use the w switch with no wildcards.

Joined: Oct 2014
Posts: 10
H
Habilis Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Oct 2014
Posts: 10
Thanks! Exactly what I was trying to do. Script works perfectly now!


Link Copied to Clipboard