mIRC Home    About    Download    Register    News    Help

Print Thread
#92377 01/08/04 07:48 PM
Joined: Aug 2004
Posts: 26
D
Danko Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2004
Posts: 26
Hello.

I have a bot msging a channel with random news. Basicly it looks something like this;

[ Here's the shocking news! You wont't live long bleh bleh ]

(The color in black are random sentences from time to time)

Basicly what i want to do is to echo ONLY the blue part (ctrl-k + 12).. How do i do this?

Here's the echo script i'm using btw;

Code:
on *:text:*:#mychan:{
  if $network == IrcNet {
    set -u %relayto $1-
    scid -at1 checknets
  }
}
alias -l checknets {
  if $network == UnderNet && $me ison #MyOtherChan {
    msg #MyOtherChan  %relayto
  }
}

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Try this:

Code:
on *:text:*:#mychan:{
  if $network == IrcNet {
    set -u %relayto $1-
    scid -at1 checknets
  }
}
alias -l checknets {
  if $network == UnderNet && $me ison #MyOtherChan {
    [color:red]!.echo -q $regex(check_nets, %relayto, ^.+\x0312(.+)\]$)[/color]
    msg #MyOtherChan [color:red]$$regml(check_nets, 1)[/color]
  }
} 


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Aug 2004
Posts: 26
D
Danko Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2004
Posts: 26
Thanx, worked great. smile

Would you mind to explain what the added code does, and how it works?

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
I'm afraid can't give you a complete description of how the code works because it uses a regular expression. Regular expressions are basically a very powerful syntax used to match and capture text in a dynamic way. They're a very complex subject, there are dozens of books and technical manuals written on them, so it's beyond my abilities to explain them here properly. For a more detailed description see Wikipedia.

Anyway, as for the rest of the code:

[color:blue]!.echo -q $regex(check_nets, %relayto, ^.+\x0312(.+)\]$)
msg #MyOtherChan $$regml(check_nets, 1)[/color]
- Well I guess you already know what the echo command does so I'll skip that. The ! prefix forces mIRC to use the built-in echo command and not use any aliases you might have defined - this is just a general precaution I take, it's not really specific to the task at hand. The -q switch means that the echo will be quiet (not echo anything) if the . prefix has been used (which it has). It might seem completely useless at first to have an echo command that doesn't actually echo anything, but it means that you can call identifiers and then ignore their results.

!.echo -q [color:blue]$regex(check_nets, %relayto, ^.+\x0312(.+)\]$)
msg #MyOtherChan $$regml(check_nets, 1)[/color]
- $regex is the identifier that utilises the regular expression I was talking about. The check_nets parameter is just a name for the regular expression that I can refer to later to get the results of what it captured (the text you want to /msg). %relayto is the input for the regular expression, so if you ever want to change what you input just edit this parameter. ^.+\x0312(.+)\]$ is the regular expression itself, the part that does most of the work but that I can't explain so I won't try to.

!.echo -q $regex(check_nets, %relayto, ^.+\x0312(.+)\]$)
msg #MyOtherChan [color:blue]$$regml(check_nets, 1)
[/color]
- $regml is the identifier which is used to return the results of a previous call to $regex. I've used a double $$ so that if the regex didn't match anything (ie. if the %relayto variable wasn't in the format you expected) it won't cause an error. The check_nets is of course the name of the regular expression used earlier, the 1 simply means it will return the first (and in this case only) captured text.


Spelling mistakes, grammatical errors, and stupid comments are intentional.

Link Copied to Clipboard