bind pub - -check isnumber
proc isnumber { nick host hand chan text} {
set text [split $text]
set fbid [lindex $text 1]
if ([isnum $fbid]) {
putquick "PRIVMSG #kesh :I got a number "
} else {
putquick "PRIVMSG #kesh :That was not a number "
}
}
proc isnum {string} {if {([string compare $string ""]) && (![regexp {[^0-9]} $string])} then {return 1};return 0}
I have tried this, but never seems to pick up a number, any help please ?
That regexp is not good as it will return 0 cos of ^ and without it would return 1 if string has a number from 0 to 9 in it, else will return 1 cos of ^ and without it would return 0 if there isn't a number from 0 to 9 in it. To make it work only when only a number from 0 to 9 is found this will do it:
proc isnumber {nick uhost hand chan text} {
set text [split $text]
set fbid [lindex $text 1]
if {[regexp {^[0-9]+$} $fbid]} {
putquick "PRIVMSG #kesh :I got a number "
} else {
putquick "PRIVMSG #kesh :That was not a number "
}
}
Once the game is over, the king and the pawn go back in the same box.
% set text "bla"
foo
% regexp {^[0-9]+$} $text
0
% set text "bla 1"
foo 1
% regexp {^[0-9]+$} $text
0
% set text "1"
1
% regexp {^[0-9]+$} $text
1
% set text "1 "
1
% regexp {^[0-9]+$} $text
0
as you can notice the regexp will return 1 only when the $text variable only contains a number without spaces.
The fbid is the second argument in your -check command. Do you give it two arguments or just one? If just one then replace 1 with 0 in the set fbid line.
Once the game is over, the king and the pawn go back in the same box.
proc isnumber {nick uhost hand chan text} {
set text [split $text]
set fbid [lindex $text 1]
if {[string is integer -strict $fbid] == 0 } {
putquick "PRIVMSG #kesh :That was not a number "
} else {
putquick "PRIVMSG #kesh :I got a number "
}
}
proc isnumber {nick uhost hand chan text} {
if {![scan $text {%d} number]} {
puthelp "PRIVMSG #kesh :I got a number"
} else {
puthelp "PRIVMSG #kesh :That was not a number"
}
}
that will work for a decimal integer.
Anyway, that regexp dose a better job as it returns 1 only if the $text is a valid number without any spaces before or after a valid decimal integer number.