mIRC Homepage
Posted By: Angrycat Variables and things - 24/01/05 05:24 PM
I am wanting to have a system where by people I am friends with can type a command and be given the latest news.

such as !news would check my friends list (a var - %friend John Jack Tim Fred Sally)

Check to make sure that they have identified with the server.

Then message them the latest news from a variable (%news This is todays news. A cat got stuck in a tree.)

I am happy to manually edit the variables when they need changing.

Any / all help appreciated.

I got as far as
Code:
 on *:text:!news:#: if ($nick == %friend)/msg $nick test %news 

it doesnt work confused

and variable definations (global)

thanks smile
Posted By: DaveC Re: Variables and things - 24/01/05 05:45 PM
on *:text:!news:#: if ($istok(%friend,$nick,32)) { msg $nick test %news } [/code]

since %freind is a space seperated list of nicks, you must see if $nick is one of the tokens (nicks) in the list, the list of tokens has spaces (ascII 32) seperating each one, so
$istok(%friend,$nick,32) becomes true in $nick is in %friend, before u were checking if $nick was the same as the whole list.

This does not confront the issue of them identifing to the server
Posted By: Angrycat Re: Variables and things - 24/01/05 06:04 PM
Thanks a lot for that Dave, very much appreciated.

If anyone can offer advice on how to check if the user has ID'd with the server that would be great.

Thanks.
Posted By: Angrycat Re: Variables and things - 24/01/05 06:32 PM
I am thinking about using the STATUS command

-NickServ- 0 - no such user online or nickname not registered
-NickServ- 1 - user not recognized as nickname's owner
-NickServ- 2 - user recognized as owner via access list only
-NickServ- 3 - user recognized as owner via password identification

syntax: /ns status nick
Hmm i shall think on about it. Help still needed tho !
Posted By: DaveC Re: Variables and things - 24/01/05 06:44 PM
why not just have them message you the request with a code word on the end so u know its really them ?
Posted By: Angrycat Re: Variables and things - 24/01/05 06:49 PM
Well too be honest I had not considered that. It is a good idea.

Sadly the chances of them keeping it secure are slim to none,

I am drifting along the road of

// !news system

on *:text:*-NickServ- STATUS angrycat 3*

kind of thing.

Just trying to get my head around messaging NickServ with the $nick, reading the response and then activating or denying the news.
Posted By: JoeDaddy Re: Variables and things - 24/01/05 07:07 PM
You could also check their whois for
angrycat has identified for this nick
a lot of networks have that .. maybe yours too ?
Posted By: Angrycat Re: Variables and things - 24/01/05 07:10 PM
So far i have done this

Code:
 
// !news system
on *:text:!news:#: { msg NickServ status $nick } if
(on *:text:*-NickServ- STATUS 3*) then ($istok(%friend,$nick,32)) { msg $nick %news } 
else { msg $nick test %ID }
 


That is a logical lay out, and obviously doesnt work, I am just working on a proper soloution atm, help as always - appreciated.
Posted By: DaveC Re: Variables and things - 25/01/05 12:03 AM
Code:
on *:TEXT:!news:#: {
  if ($istok(%friend,$nick,32) {
    msg NickServ status $nick
    set -u5 %friend.news $true
  }
}
on *:NOTICE:STATUS * 3: {
  if ((%friend.news) && ($nick == Nickserv) && ($istok(%friend,$2,32)) && ($3- == 3)) {
    msg $2 %news
  }
}


When they text !news, you request the neckserv to tell u there status, you also set a flag that falls after 5 seconds that you have done one of these.
When (if) nickserv replies, u see if there is the flag up, and the nick is in your list, and its just "status nick 3"
The last one "&& ($3- == 3)" I added becuase i cant remember how to make it match one word between STATUS & 3 in the ON *:NOTICE (sorry had a late night)
Posted By: Iori Re: Variables and things - 25/01/05 02:31 PM
Quote:
i cant remember how to make it match one word between STATUS & 3 in the ON *:NOTICE (sorry had a late night)


Er yep musta been a late one, that is how you match one word, & = 1 word. laugh
  • on *:notice:STATUS & 3:{
Posted By: Angrycat Re: Variables and things - 25/01/05 03:40 PM
Thanks laugh
Posted By: Angrycat Re: Variables and things - 25/01/05 05:20 PM
* /if: invalid format (line 15, script.ini)

confused
Posted By: Iori Re: Variables and things - 25/01/05 05:26 PM
Code:
on *:text:!news:#:{
  if ($istok(%friend,$nick,32)[color:red])[/color] {
    msg NickServ status $nick
    set -u5 %friend.news $true
  }
}
on *:notice:STATUS & 3:[color:red]?:[/color]{
  if ((%friend.news) && ($nick == Nickserv) && ($istok(%friend,$2,32))) {
    msg $2 %news
  }
}
Posted By: Angrycat Re: Variables and things - 25/01/05 05:51 PM
ok this is not producing any errors and it is msg'ing nicvserv fine, and getting the response fine.

however it is not messaging the news.
Code:
 
%getnews !news
%news NEWS NEWS NEWS | Server back up sometime today | Town meeting likely | Xplict loves pie | Don't Reply to this |
%ID Please identify with the server before requesting news.  Syntax:  /msg NickServ Identify <PASSWORD>  If you have already identified then you are not on the access list for todays news.
%friend icedevil tsakos


there are my global variables
Posted By: Iori Re: Variables and things - 25/01/05 06:11 PM
Whoops sorry, see the edit above in the notice event, I just copied Daves code without looking, apparently blush
Posted By: Angrycat Re: Variables and things - 25/01/05 06:16 PM
I
LOVE
YOU

Thanks a million to everyone who helped me with this.

cool
Posted By: DaveC Re: Variables and things - 25/01/05 09:32 PM
%getnews !news
%news NEWS NEWS NEWS | Server back up sometime today | Town meeting likely | Xplict loves pie | Don't Reply to this |
%ID Please identify with the server before requesting news. Syntax: /msg NickServ Identify <PASSWORD> If you have already identified then you are not on the access list for todays news.
%friend icedevil tsakos[/code]

I adjusted the code to cover sending the %ID out if your not voiced. It sends %ID if u are in the %friend list but not a 3, So you might want to remove the last sentence on the %ID I dont know?!?!?

Code:
 
on *:text:%getnews:#:{
  if ($istok(%friend,$nick,32)) {
    msg NickServ status $nick
    set -u5 %friend.news $true
  }
}
on *:notice:STATUS &amp; &amp;:?:{
  if ((%friend.news) &amp;&amp; ($nick == Nickserv) &amp;&amp; ($istok(%friend,$2,32))) {
    if ($3 == 3) { msg $2 %news }
    else         { msg $2 %ID }
  }
}


Thanks Iori for fixing my typoes, I thought it was & but was getting tired and didnt want to risk putting it in on a guess, Oh and yes it was a rather hard night out.
Posted By: Angrycat Re: Variables and things - 25/01/05 10:15 PM
Thanks Dave ,

that was extremely helpful indeed.

now i am working on letting users add news to the string, but am researching if i can use sequencial variables and display the whole sequence (i,.e a user !addnews today is a good day. | then the tect is written to a new variable in sequence and !news returns the whole sequence.

The problems i forsee is a huge amount of data i have to manually remove = pain.

The other thing is to have the news somehow tagged on the end. maybe when the user !add new today is a nice day, the script calls the current version and adds the text on the end with some kind of delimiter.

And finally a !delete news function - which thankfully I think i can manage on my own.

If anyone wants to have a crack at this - as per usual - it is always appreciated, but I will slog on with it and see what happens.

Thanks again !
Posted By: DaveC Re: Variables and things - 25/01/05 11:44 PM
well this addition well cause it to become a bit more complex, I suggest using a NEWS.TXT file rather than multiple varables and, since to get ride of old news u can just edit the NEW.TXT file. To send them the contents of the file is simple use /PLAY


Also this well cause problems in that yuou must confirm all users who add news are also registered nicks. so the ON NOTIOCE needs to know what event tripped the check and what to do if the user comes back as registered,

However i have another solution for you
set %addnews !addnews

Code:
on *:text:%getnews:#:{
  if ($istok(%friend,$nick,32)) {
    var %ticks = $ticks
    .timer.kill.getnews. [ $+ [ $nick $+ . $+ [ %ticks ] ] ]  1 5 .timer.getnews. [ $+ [ $nick $+ . $+ [ %ticks ] ] ] off
    ;
    ;
    .timer.getnews. [ $+ [ $nick $+ . $+ [ %ticks ] ] ]       1 6 play $nick NEWS.TXT 1000
    ;^ this plays the news.txt to the $nick in 6 seconds time
  }
}
on *:text:%addnews:#:{
  if ($istok(%friend,$nick,32)) {
    var %ticks = $ticks
    .timer.kill.addnews. [ $+ [ $nick $+ . $+ [ %ticks ] ] ]  1 5 .timer.addnews. [ $+ [ $nick $+ . $+ [ %ticks ] ] ] off
    ;
    ;
    .timer.addnews. [ $+ [ $nick $+ . $+ [ %ticks ] ] ]       1 6 write NEWS.TXT $2-
    ;^ this adds news to the NEWS.TXT file in 6 seconds
  }
}
on *:notice:STATUS &amp; &amp;:?:{
  if ((%friend.news) &amp;&amp; ($nick == Nickserv) &amp;&amp; ($istok(%friend,$2,32))) {
    if ($3 == 3) { .timer.kill.*. [ $+ [ $2 $+ . $+ * ] ] off } 
    else         { msg $2 %ID }
  }
}


ok what i have done here is on each text event i start two timers, the 1st one kills the second one before it can run, the 2nd one is what ever the event is to do (assuming the user is registered), BUT as i said the 1st one well kill it before it can, So how does it work?
Well the reply of the nickserv if the user is registered, well kill the 1st timer, which well of course allow the second timer to run.

This way the on notice nickserv doesnt need to know what event tripped it, it just destroys the kill timers. allowing the event to progress to completion.
Posted By: DaveC Re: Variables and things - 26/01/05 02:46 AM
Code:
on *:text:%addnews:#:{
  if ($istok(%friend,$nick,32)) {
    var %ticks = $ticks
    .timer.kill.addnews. [ $+ [ $nick $+ . $+ [ %ticks ] ] ]  1 5 .timer.addnews. [ $+ [ $nick $+ . $+ [ %ticks ] ] ] off
    ;
    ;
    set -u7 %news. [ $+ [ $nick $+ . $+ [ %ticks ] ] ] $2-
    .timer.addnews. [ $+ [ $nick $+ . $+ [ %ticks ] ] ]       1 6 write NEWS.TXT % $+ news. [ $+ [ $nick $+ . $+ [ %ticks ] ] ]
    ;^ this adds news to the NEWS.TXT file in 6 seconds
  }
}


Just thought about this, and the above code is safer as $2- well be preservered in the variable, this closes a security gap with passing unknown contents in a timers parameters.
Posted By: FiberOPtics Re: Variables and things - 26/01/05 02:55 AM
Aww Dave, those eval brackets are evil.

var %a = $nick $+ $ticks

.timer.kill.addnews. $+ %a ...
...
set -u7 %news. $+ %a $2-

Good call on the escaping of that $2- string, it's something many people don't consider.
Posted By: DaveC Re: Variables and things - 26/01/05 03:29 AM
yeah I know i dont need em on alot of them (actually i think it might have been all of them), and i considered not putting them in, but i just find, if i do it the same way everywhere (ie: have them) then it all works, better to have to many than to have to few I say, and yes they are evil!

I actually find this harder to read myself

Code:
on *:text:%getnews:#:{
  if ($istok(%friend,$nick,32)) {
    var %ticks = $ticks
    .timer.kill.getnews. $+ $nick $+ . $+ %ticks  1 5 .timer.getnews. $+ $nick $+ . $+ %ticks off
    ;
    ;
    .timer.getnews. $+ $nick $+ . $+ %ticks       1 6 play $nick NEWS.TXT 1000
    ;^ this plays the news.txt to the $nick in 6 seconds time
  }
}
on *:text:%addnews:#:{
  if ($istok(%friend,$nick,32)) {
    var %ticks = $ticks
    .timer.kill.addnews. $+ $nick $+ . $+ %ticks  1 5 .timer.addnews. $+ $nick $+ . $+ %ticks off
    ;
    ;
    set -u7 %news. $+ $nick $+ . $+ %ticks $2-
    .timer.addnews. $+ $nick $+ . $+ %ticks       1 6 write NEWS.TXT % $+ news. $+ $nick $+ . $+ %ticks
    ;^ this adds news to the NEWS.TXT file in 6 seconds
  }
}
on *:notice:STATUS &amp; &amp;:?:{
  if ((%friend.news) &amp;&amp; ($nick == Nickserv) &amp;&amp; ($istok(%friend,$2,32))) {
    if ($3 == 3) { .timer.kill.*. $+ $2 $+ . $+ * off } 
    else         { msg $2 %ID }
  }
}


Attn : Angrycat : try that or the other one before it, DONT use the one without the SET -u7 in the ON TEXT addnews either way.
And incase its hard to see what im doing im naming the timers such as...
Timer.addnews.Bobby.1660420408 & Timer.kill.addnews.Bobby.1660420408, the last number is $ticks (ticks since OS started), this within normal ircing well make it a unique timer name.
Thus the kill timers are unique and well kill there unique event timer, pretty crazy system but i felt it was a little simpler than having to spool & despool events, which can get harder if say three different nicks all went !addnews blah blah and then !news at the same time.
Posted By: FiberOPtics Re: Variables and things - 26/01/05 11:34 AM
My point is not only the fact that the eval brackets are obsolete, but that you can put $nick $+ $ticks in a var, and shorten your code incredibly, and also increasing readability.

Though each has his own methods, so nvm smile

It's the difference between:

.timerbla $+ $nick $+ %ticks ..... timerbla $+ $nick $+ %ticks
set -u7 %something. $+ $nick $+ %ticks
.othertimer $+ $nick $+ %ticks

vs.

.timerbla $+ %a ..... timerbla $+ %a
set -u7 %something. $+ %a
.othertimer $+ %a

Greets
Posted By: DaveC Re: Variables and things - 26/01/05 03:14 PM
Quote:
My point is not only the fact that the eval brackets are obsolete, but that you can put $nick $+ $ticks in a var, and shorten your code incredibly, and also increasing readability.


Oh my I missunder stood that half of your message altogther, I thought you were just saying something about Telling me I didnt need the . (dots) between each section of the timer name and variable names, I thought "ok yeah I know i dont, but i like em since it lets you visually breakup the name if u list the timers or have -s on the sets. I totally understand now, your meaning jam all my repeating sections into a var and just refrence that, most correct, Im just lazy in I made the first timer, then i just pasted the code over and over for each one. Its much more efficient to modelize it into one occurance.
Posted By: FiberOPtics Re: Variables and things - 26/01/05 03:19 PM
Quote:
your meaning jam all my repeating sections into a var and just refrence that

Yep, that was what I meant. Cya!
© mIRC Discussion Forums