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.

replace letters with accent in string map

General support and discussion of Eggdrop bots.
Post Reply
d
doni
Voice
Posts: 18
Joined: Tue Aug 21, 2018 4:13 am

replace letters with accent in string map

Post by doni »

Hi guys
I would like to replace these letters with accent in this way with string map in
à-> à or a'
ù -> ù or u'
ì -> ì or i'
è -> è or e'
ò -> ò or o'

Someone can help me please? Thanks

Code: Select all

#
Last edited by doni on Tue Jun 18, 2024 2:19 am, edited 1 time in total.
D
DasBrain
Voice
Posts: 19
Joined: Thu Apr 08, 2021 12:31 pm

Re: replace letters with accent in string map

Post by DasBrain »

I think you want [encoding convertfrom utf-8] instead.
d
doni
Voice
Posts: 18
Joined: Tue Aug 21, 2018 4:13 am

Re: replace letters with accent in string map

Post by doni »

can you explain me how do it?
D
DasBrain
Voice
Posts: 19
Joined: Thu Apr 08, 2021 12:31 pm

Re: replace letters with accent in string map

Post by DasBrain »

Okay, the reason you get those characters is that the result is encoded as utf-8.
To fix it, put the result of http::data through encoding convertfrom utf-8.

Code: Select all

###########################################################
#
#    Oroscopo 1.5 tcl for eggdrop (22/03/2012)
#    by lnx85 at #lnxlabs on SimosNap IRC Network (irc.simosnap.com)
#    E-mail: lnx85@lnxlabs.it
#
#    Per attivare lo script è necessario impostare il flag "+oroscopo" al canale 
#    (.chanset #chan +oroscopo)
#
###########################################################

### GLOBALS ###
set oroscopo(version) 1.5
set ::http::defaultCharset utf-8
package require http
http::config -useragent "Mozilla/1.0"
### END GLOBALS ###

### FLAGS ###
setudef flag oroscopo
### END FLAGS###

### BINDS ###
bind pub - !oroscopo oroscopo:request
bind msgm - * oroscopo:pvt:request
### END BINDS ###

### PROCS ###
proc strlastpos { string char {max 0} } {
	if { $max == 0} { set max [ string length $string ] }
	if { [ string length $string ] <= $max } { return [ string length $string ] }
	for { set i 0 } { $i < $max } { incr i } {
		if { [ string index $string [ expr $max - $i ] ] == $char } {
			return [ expr $max - $i ]
		}
	}
	return $max
}

proc max:privmsg:chars { target } {
	return [ expr 500 - 1 - [ string length $::nick ] - 30 - [ string length $target ] - 2 ]
}

proc oroscopo:pvt:request { nick uhost hand arg } {
	set arg [ lindex $arg 0 ]
	if { [ lsearch -exact {ariete toro gemelli cancro leone vergine bilancia scorpione sagittario capricorno acquario pesci} [ string tolower $arg ] ] == -1 } { return }
	regsub -all -- " " $arg "%20" args
	set url "http://it.horoscopofree.com/rss/horoscopofree-it.rss"
	set http [ http::geturl $url ]
	set html [encoding convertfrom utf-8 [ http::data $http ]]
	http::cleanup $http
	set flag 0
	if { [ regexp -nocase -all -- "<item>\[^<\]*<title>($arg)</title>\[^<\]*<link>\[^<\]*</link>\[^<\]*<guid \[^<\]*</guid>\[^<\]*<description><!\[^a-z\]CDATA\[^a-z\](\[^<\]*?)" $html all segno testo ] } {
		set testosegno [lindex $testo [lsearch -exact $segno $args]]
		set risposta "\037OROSCOPO\037 \002::\002 \037[ string toupper $args ]\037 $testo"
		set flag 1
	}
	if { $flag == 0 } {
		putserv "PRIVMSG $nick :\037OROSCOPO\037 \002::\002 \037[strupr $arg]\037 Segno zodiacale non trovato"
	} else {
		set max_chars [ max:privmsg:chars $nick ]
		while { [ string length $risposta ] > 0 } {
			set limit [ strlastpos $risposta " " $max_chars ]
			set risptemp [ string range $risposta 0 $limit ]
			set risposta [ string range $risposta $limit end ]
			if { [ string length $risposta ] != 0 } {
				putserv "PRIVMSG $nick :$risptemp ..."
			} else {
				putserv "PRIVMSG $nick :$risptemp"
			}
		}
	}
}

proc oroscopo:request { nick uhost hand chan arg } {
	if { [ lsearch -exact [ channel info $chan ] "+oroscopo" ] == -1 } { return }
	putlog "OROSCOPO :: request \"!oroscopo $arg\" from $nick!$uhost on $chan"
	if { $arg == "" || $arg == "help" } {
		 putserv "NOTICE $nick :\037OROSCOPO\037 \002::\002 \037HELP\037 Mostra l'oroscopo per un dato segno zodiacale\037Utilizzo:\037 !oroscopo segno"
		 return
	}
	regsub -all -- " " $arg "%20" args
	set url "http://it.horoscopofree.com/rss/horoscopofree-it.rss"
	set http [ http::geturl $url ]
	set html [encoding convertfrom utf-8 [ http::data $http ]]
	http::cleanup $http
	set flag 0
	if { [ regexp -nocase -all -- "<item>\[^<\]*<title>($arg)</title>\[^<\]*<link>\[^<\]*</link>\[^<\]*<guid \[^<\]*</guid>\[^<\]*<description><!\[^a-z\]CDATA\[^a-z\](\[^<\]*?)" $html all segno testo ] } {
		set testosegno [lindex $testo [lsearch -exact $segno $args]]
		set risposta "\037OROSCOPO\037 \002::\002 \037[ string toupper $args ]\037 $testo"
		set flag 1
	}
	if { $flag == 0 } {
		putserv "PRIVMSG $chan :\037OROSCOPO\037 \002::\002 \037[strupr $arg]\037 Segno zodiacale non trovato"
	} else {
		set max_chars [ max:privmsg:chars $chan ]
		while { [ string length $risposta ] > 0 } {
			set limit [ strlastpos $risposta " " $max_chars ]
			set risptemp [ string range $risposta 0 $limit ]
			set risposta [ string range $risposta $limit end ]
			if { [ string length $risposta ] != 0 } {
				putserv "PRIVMSG $chan :$risptemp ..."
			} else {
				putserv "PRIVMSG $chan :$risptemp"
			}
		}
	}
}
### END PROCS ###

### INITIAL ###
putlog "\037OROSCOPO\037 \002::\002 \037LOADED\037 version $oroscopo(version) by lnx85"
You also want to use http::cleanup to release the resources for the http request, otherwise it will leak memory.
I added the relevant lines to your code.
d
doni
Voice
Posts: 18
Joined: Tue Aug 21, 2018 4:13 am

Re: replace letters with accent in string map

Post by doni »

Great! Thanks!!!
Post Reply