Mirc code to Spell check before adding variable - mirc

on *:text:#btag*:#: {
if ( ## isin $2 ] {
Set %Tag. [ $+ [ $nick ] ] $2 {
Describe # $nick Has saved their Battletag
}
else {
Describe # $nick $+ , Please enter your real Btag
}
}
This is the code I have.
What I require is for the Code to Look at the text and only save it as a variable if it contains the symbol (#) hash tag.
I am finding this hard to code as the Hashtag (#) is part of the Coding language...
Lmk what you guys can do for me

'#' char in mIRC remote code is evaluate as the channel the event fired from.
When you want to express explicitly the Hash tag character you should use $chr(35), 35 is the hashtag ascii number.
The code below will check:
If in any channel a user wrote #btag some-text-contains-#-char
and if so, it will save inside the tag-user variable the word that contained #hash tag.
Then will send him has saved...
Else will send him Nick, Please enter..
Code
on *:text:#btag*:#: {
if ($chr(35) isin $2) {
set %Tag. [ $+ [ $nick ] ] $2
Describe # $nick Has saved their Battletag
}
else {
Describe # $nick $+ , Please enter your real Btag
}
}
The code isn't perfect and will work also, when a user will write the following lines:
#btagBLA some-text-contains-#-char
#btagSOMETEXT some-text-contains-#-char
And so on.. To solve it, you should change event definition to
on *:text:#btag *:#: {

The $chr() function is what you need. It accepts the ASCII value of a character and generates the character in question. So, for example, /echo -a $chr(35) would echo a pound sign (i.e. a hash tag).
You may also want to look at $asc() which will give you the ASCII code of the character you type. Or you could search online for "ASCII table".
Both functions should be adequately explained in the mIRC help file - or at least they were when I last used it.

Related

Mirc script to find exact match in customer list

I am using this to find customer name in text file. Names are each on a separate line. I need to find exact name. If searching for Nick specifically it should find Nick only but my code will say found even if only Nickolson is in te list.
On*:text:*!Customer*:#: {
if ($read(system\Customer.txt,$2)) {
.msg $chan $2 Customer found in list! | halt }
else { .msg $chan 4 $2 Customer not found in list. | halt }
}
You have to loop through every matching line and see if the line is an exact match
Something like this
On*:text:*!Custodsddmer*:#: {
var %nick
; loop over all lines that contains nick
while ($read(customer.txt, nw, *nick*, $calc($readn + 1))) {
; check if the line is an exact match
if ($v1 == nick) {
%nick = $v1
; stop the loop because a result is found
break;
}
}
if (%nick == $null) {
.msg $chan 4 $2 Customer not found in list.
}
else{
.msg $chan $2 Customer found in list!
}
You can find more here: https://en.wikichip.org/wiki/mirc/text_files#Iterating_Over_Matches
If you're looking for exact match in a new line separate list, then you can use the 'w' switch without using wildcard '*' character.
From mIRC documentation
$read(filename, [ntswrp], [matchtext], [N])
Scans the file info.txt for a line beginning with the word mirc and
returns the text following the match value. //echo $read(help.txt, w,
*help*)
Because we don't want the wildcard matching, but a exact match, we would use:
$read(customers.txt, w, Nick)
Complete Code:
ON *:TEXT:!Customer *:#: {
var %foundInTheList = $read(system\Customer.txt, w, $2)
if (%foundInTheList) {
.msg # $2 Customer found in list!
}
else {
.msg 4 # $2 Customer not found in list.
}
}
Few remarks on Original code
Halting
halt should only use when you forcibly want to stop any future processing to take place. In most cases, you can avoid it, by writing you code flow in a way it will behave like that without explicitly using halting.
It will also resolve new problems that may arise, in case you will want to add new code, but you will wonder why it isn't executing.. because of the darn now forgotten halt command.
This will also improve you debugging, in the case it will not make you wonder on another flow exit, without you knowing.
Readability
if (..) {
.... }
else { .. }
When considering many lines of codes inside the first { } it will make it hard to notice the else (or elseif) because mIRC remote parser will put on the same identification as the else line also the line above it, which contains the closing } code. You should almost always few extra code in case of readability, especially which it costs new nothing!, as i remember new lines are free of charge.
So be sure the to have the rule of thump of every command in a new line. (that includes the closing bracket)
Matching Text
On*:text:*!Customer*:#: {
The above code has critical problem, and bug.
Critical: Will not work, because on*:text contains no space between on and *:text
Bug: !Customer will match EVERYTHING-BEFORE!customerANDAFTER <NICK>, which is clearly not desired behavior. What you want is :!Customer *: will only match if the first word was !customer and you must enter at least another text, because I've used [SPACE]*.

On Text while in private query?

i was wondering how to get my remotes scripts to work in private queries rather than a channel, thank you!
example:
on $*:text:*abc*:"username": { msg "username" you whispered, $2 . }
From here: http://en.wikichip.org/wiki/mirc/on_event#Target
The target parameter of the event defines the locations of where the
event can be triggered from. For example, the on text event can be
triggered by a channel message or by a query.
? - defines query location
# - defines channel location
* - defines both query and channel locations
%var - A variable containing a channel or a list of channels is also
acceptable
In your example you would do:
on *:text:*abc*:?: { if ($nick == NAME) { msg $nick you whispered, $2 . } }

Stuck trying to write script to register username with tilte

Working on a bot script to lookup a username on join and see if it's be regiester with a title for the channel I run. Like if my name is Ravenna. I want the bot to check if I've registered the title Mistress with the username Ravenna.
I'm extremely stuck on how to go about this, researching things haven't brought me closer to a solution
so far all I've figured out I want is
on *:JOIN:#channel {
.msg $chan $nick take time to register with me; a pm will be sent to you soon
}
Any help or a source where I can figure out how to write and read files or the snippet code I need would be appericated
I think it's the best to use ini files for this. You should have a look at this: http://en.wikichip.org/wiki/mirc/ini_files and for more on http://en.wikichip.org/wiki/mirc.
For example you have a title called Mistress, your titles.ini file would look like this:
[mistress]
Ravenna=true
[mister]
Denny=true
To read a value you can use: $readini(titles.ini,n,mistress,$nick)
And to check the value you can do:
on *:join:#channel: {
if ($readini(titles.ini,n,mistress,$nick)) {
; code here for mistress
}
elseif ($readini(titles.ini,n,mister,$nick)) {
; code here for mister
}
elseif ($readini(titles.ini,n,TITLE,$nick)) {
; code here for another title
}
else {
; code here when no title
}
}
This way you must manually add a title in your titles.ini file. So if you want to add another title you should add [TITLE] on a new line in your ini file. If you have more questions you can ask here.
If you want to register someone with a title you could make a simple on text event and add a name to the ini file with writeini titles.ini TITLE $nick true
on *:join:#Tristram_Halls: {
if ($readini(titles.ini,n,mistress,$nick)) {
.describe $chan looks up and sees Mistress $nick. "Greetings Mistress."
}
else {
.msg $chan Greetings $nick I have no record of what you are. Please take the time to register that info with me
.msg $chan $nick Please choose from one of the following titles: !Mistress
}
}
on *:text:!Mistress:#:{
/writeini [-n] titles.ini mistress $nick true
}
just testing a short code for mirc title registration. At this point nobody is in the ini file, and I've add the title [mistress] but when anybody joins the channel the bot does this rather than c
Testbot looks up and sees Mistress "Greetings Mistress."

Expect Interact and special characters

trying to create a macro program with expect to help me manage my cisco devices>
I want to keep all native cisco functions like tab complete ETC.
initially I wanted to type "!...!" where my macro is inside the bangs, my code looked like this:
interact {
-re "!(.+)!" { #find correct macro }
}
but with this method, there is no feedback to the user. what happens if they misspell? etc then they can't see their corrections with backspace.
then I started thinking about just capturing each character press and building a string
interact {
#book says backspace character
"\b" {
set command [lreplace $command end end]
}
#detect return, sending command
-re "\r" {
set command [join $command ""]
if [regexp "^!" $command] {
#send ctrl+u to erase line sent
send "\025"
findMacro $command
}
set command ""
send "\r"
}
#send tab for tab completion
"\t" { send "\t" }
-re "(.)" {
send $interact_out(1,string)
lappend command $interact_out(1,string)
}
}
but I can't "expect" the backspace. I've tried 0x08.. etc nothing is working. in the end I'm not even sure this is the way to go simply because there are to many other buttons a user could push and mess up my string I'm building.
the real solution, I think, is to wait until "\r" is pressed, and then run a regex on that line. but I'm not sure how to do that.

mIRC bot - copy/paste lines in 2 channels

I’m a noob in mirc scripting, and I need some help.
there’s 2 irc channels. let’s call then #channel1 and #channel2;
There’s 2 bots. One is mine, let’s call him “mybot” (my bot is in both channels). The other bot is from a third person, let’s call him “otherBot”;
What I need is… let me make an example to better explain.
a) in #channel1 some user type:
[14:38:48] <#someuser> !user xpto
At this time, “mybot” is in both channels. he reads the command “!user*” and copy/paste it in #channel2, where the “otherBot” will recognize the command “!user*” and will paste some information about this command.
b) so, in #channel2 it will append something like:
[14:38:50] <# mybot > !user xpto
[14:38:52] <# otherBot > User name is xpto and he likes popatos.
Now I want that “mybot” reads the information provided by the “otherBot” and then paste it on #channel1
c) so, in #channel1:
[14:38:54] <# mybot > User name is xpto and he likes popatos.
So far I have the fowling code in my remote:
on *:TEXT:!user*:#channel1 {
/msg # channel2 $1-
}
on *:TEXT:User name*:#channel2 {
if $address($nick,2) == *!*#otherBot.users.gameea {
/msg # channel1 $1-
}
}
This works fine, but have a problem: if someone else ( not “mybot” ) type “!user kakaka” in #channel2, “mybot” will also copy/paste the information provided by the “otherBot” and then paste it on #channel1. And I only want that “mybot” copy/paste only the information that “mybot” ask to “otherBot”.
A very simple (but not a particularly nice) way of doing this could be to set a global variable when someone types !user in #channel1, and check whether or not this is set in the other part which is listening on #channel2. For example:
on *:TEXT:!user *:#channel1: {
set %repeatUser 1
msg channel2 $1-
}
on *:TEXT:User name*:#channel2: {
if ($address($nick,2) == *!*#otherBot.users.gameea && %repeatUser == 1) {
unset %repeatUser
msg #channel1 $1-
}
}
This isn't a perfect solution, since if the bot says something else between the time it takes for the script to send '!user' to the other channel and for the bot to respond, then it will print out that reply instead of the one for your request, but this is only relevant if #channel2 is ridiculously busy, otherbot is very laggy, or it just so happens that both your bot and someone else type !user on #channel2 within a fraction of a second of eachother.