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
}