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

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Replace

Post by Fire-Fox »

Hi,

Does anyone have a script that does the following:

1: some text like -> 'I liek your hat'
2: then you should be able to do :

Code: Select all

s/liek/like
and it will write the same text as you did before but with the right word in bold like :

Code: Select all

I [b]like[/b] your hat
I have tried with help from chatGPT but it does not work

Code: Select all

# Define the event handler for channel messages
proc on_message {nick user host channel message} {
    # Debugging output for received message
    putquick "PRIVMSG $channel :Received message: $message"
    
    # Define the pattern for the replacement command
    if {[regexp {^s/(\S+)/(\S+)/\s*(.*)} $message match wrong_word correct_word text]} {
        # Debugging output to check matched groups
        putquick "PRIVMSG $channel :Pattern matched: wrong_word=$wrong_word, correct_word=$correct_word, text=$text"
        
        # Check if the text is not empty
        if {[string length $text] > 0} {
            # Debugging output before replacement
            putquick "PRIVMSG $channel :Text before replacement: $text"
            
            # Replace the wrong word with the correct word in the text
            set corrected_message [string map [list $wrong_word $correct_word] $text]

            # Debugging output after replacement
            putquick "PRIVMSG $channel :Text after replacement: $corrected_message"
            
            # Send the corrected message back to the channel
            putquick "PRIVMSG $channel :$corrected_message"
        } else {
            # Debugging message if text is empty
            putquick "PRIVMSG $channel :No text to process after replacement."
        }
    } else {
        # Debugging message if pattern did not match
        putquick "PRIVMSG $channel :Pattern did not match. Ensure message format is: s/word1/word2 message"
    }
}
putlog "Replace Words Script - Loaded"
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: Replace

Post by CrazyCat »

Try "Erratum".
Explanation page (in french): https://boulets.eggdrop.fr/tcl/scripts/Erratum.html
Direct download (I haven't re-add the script in the database after my HD crash): https://scripts.eggdrop.fr/uploads/2020 ... _v1_02.zip
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Re: Replace

Post by Fire-Fox »

Thanks it does work. I have a small change I would like you to help me with :)

Instead of :

Code: Select all

!erratum

could it be done so it uses

Code: Select all

s/
also this :

Code: Select all

::erratum::display_output help PRIVMSG $chan "${::erratum::prefix}[::tcl::string::map {"\177\177" "" "\177" "\002"} $memorized_line]"
from what I can read it handles this :

Code: Select all

variable prefix "Correction: "
from the erratum.cfg. could that be made so that I can do:

Code: Select all

NICK would have said:
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: Replace

Post by CrazyCat »

Well, you can change "!erratum" with "s/" but you'll have to keep a space between the command and the arguments.
If you don't want to, you'll need to modify the bind and the process procedure to work with pubm and not pub.

And to change the prefix to add the nick, the proc must also been modified to use [format] on the prefix.

It's possible to do that but I've a lack of time and the creator of the script is actually no more involved in tcl (peharps he'll be back some day)

P.S.: the official link (https://scripts.eggdrop.fr/details-Erratum-s231.html) is available again
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Re: Replace

Post by Fire-Fox »

Okay,

I tryed, I gave up :)
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: Replace

Post by CrazyCat »

I promise nothing, but if I find a little time to spend on it this week-end, I'll try to do that :)
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Re: Replace

Post by Fire-Fox »

8)
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: Replace

Post by CrazyCat »

Ok, I did the first part with a small hack :)

Replace the user_msg_listen proc with:
proc ::erratum::user_msg_listen {nick host hand chan text} {
	if {!([channel get $chan erratum])} then {
      return
   } elseif {([::tcl::string::match -nocase "$::erratum::erratum_cmd*" $text])} {
		::erratum::process $nick $host $hand $chan [string range $text [string length $::erratum::erratum_cmd] end]
	} else {
		::tcl::dict::lappend ::erratum::memory $chan "<$nick> $text"
		if { [llength [::tcl::dict::get $::erratum::memory $chan]] > $::erratum::max_memory } {
			::tcl::dict::set ::erratum::memory $chan [lreplace [::tcl::dict::get $::erratum::memory $chan] 0 0]
		}
	}
}
With that, you can use the replace by two ways:

Code: Select all

s/old/new
s/ old/new
Think to change erratum_cmd to "s/" in erratum.cfg
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Re: Replace

Post by Fire-Fox »

Thanks. It works :)

Small issue

Code: Select all

~Flame:  s/ red/røde                               
Error : No match found.                                           
Error : No match found. 
It kinda works but:

Code: Select all

~Flame: s/ bar/bare
Correction : <Flame> testerbare
Correction : <Flame> testerbaree

Code: Select all

~Flame: s/bar/bare
Correction : <OldBoys> Correction : <Flame> testerbareee
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: Replace

Post by CrazyCat »

Did you restart the eggdrop (not rehash, restart) after having changed the script ?
Looks like a side-effect, I'll look further
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Re: Replace

Post by Fire-Fox »

Yes I did a restart :) I always do when loading new scripts :)
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: Replace

Post by CrazyCat »

I understood the trouble:
Comment the following line at the end of the script:
bind pub $::erratum::erratum_auth $::erratum::erratum_cmd ::erratum::process
This bind made the process proc called twice
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Re: Replace

Post by Fire-Fox »

Hi,

I'll do that right away

Something did it do :)

Code: Select all

~Flame: tester bare lieg                                                                                                                                                                  
~Flame: s/lieg/lige                                                                                                                                                                       
&OldBoys: Correction : <Flame> tester bare lige 
kinda missing a 'space'

Code: Select all

~Flame: tester bare lieg                                                                                                                                                                  
~Flame: s/ lieg/lige                                                                                                                                                           
&OldBoys: Correction : <Flame> tester barelige 
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: Replace

Post by CrazyCat »

Replace the following line
::erratum::process $nick $host $hand $chan [string range $text [string length $::erratum::erratum_cmd] end]
with
::erratum::process $nick $host $hand $chan [string trimleft [string range $text [string length $::erratum::erratum_cmd] end]]
User avatar
Fire-Fox
Master
Posts: 299
Joined: Sat Sep 23, 2006 9:01 pm
Location: /dev/null

Re: Replace

Post by Fire-Fox »

Thanks, that did it :)

how hard is the format text stuff?

I mean the correction to

instead of

Code: Select all

Correction : <nick> text
to

Code: Select all

<nick> meant to say : text
Fixed with :

From

Code: Select all

::erratum::display_output help PRIVMSG $chan "${::erratum::prefix}[::tcl::string::map {"\177\177" "" "\177" "\002"} $memorized_line]"
To

Code: Select all

::erratum::display_output help PRIVMSG $chan "$nick ${::erratum::prefix}[::tcl::string::map {"\177\177" "" "\177" "\002"} $memorized_line]"
and in the erratum.cfg

changed this line

Code: Select all

variable prefix "something"
GreatZ
Fire-Fox | Denmark

Scripts: Relay | Store Text | TvMaze
Post Reply