This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Need a little help

Help for those learning Tcl or writing their own scripts.
Post Reply
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Need a little help

Post by garfwen »

Hello guys

I have some channels like this:

#1.channel.PT
#2.channel.UK
#3.channel.ES
etc.

Now my question is how can i get the country in a var ?

Example:

Code: Select all

(chan == #1.channel.pt)

<nick> .language
<botnick> This channel is PT
Thnx
GaRfWeN
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

If say it is always the last two characters of the variable chan that represent the country code then you can extract it using 'string range' as follows :-

[string range $chan end-1 end]

If you are unsure of exactly what the bot knows the channel as in terms of case, I would recommend :-

[string toupper [string range $chan end-1 end]]

The following script could be used to output both the country code and the country name in a channel using the public command !locale (if it exists in the preset array).

array set varCountries {
PT "Portugal"
UK "United Kingdom"
ES "Spain"
}

bind PUB - !locale prcLocale

proc prcLocale {nick uhost hand chan text} {
global varCountries
set code [string toupper [string range $chan end-1 end]]
if {[info exists varCountries($code)]} {
putserv "PRIVMSG $chan :The channel locale is $varCountries($code) ($code)"
} else {
putserv "PRIVMSG $chan :The channel locale is unknown"
}
return 0
}
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Post by garfwen »

Thanks, it works :D
Post Reply