Case Insensitive Replace

By gooshie on Apr 24, 2010

Makes Xchat's Auto Replace case insensitive. This snippet was written at the request of Cracker200. One big problem is that lines are not added to the input box history. Xchat seems to lack a method to do this easily. I will keep looking at ways to resolve this issue but in the meantime I have posted this snippet. Use command /replace to update the script after making changes to Auto Replace List.

Image

# Name:     replace-1.2.pl
# Version:  1.2
# Author:   gooshie <http://www.hawkee.com/profile/58973/>
# Date:     2010-04-26
# Description:  Makes the Auto Replace Case Insensitive

# Version History at end of file

# No changes needed within this file

# NOTE: After making changes within Auto Replace List
#   use /replace to force script to apply changes.

# KNOWN BUGS: Lines are not added to input box history.

use strict;
use warnings;
use Xchat qw(:all);

hook_print ("Key Press",sub {
    return EAT_NONE unless (($_[0][0]=~/^65293|65421$/)&&($_[0][1]=~/^0|2|16|18$/));
    my($cmd,$cc)=('say',get_prefs('input_command_char'));$_=get_info('inputbox');
    if(substr($_,0,4) eq $cc.'me '){$_=substr($_,4,length($_));$cmd='action'}
    elsif(substr($_,0,1) eq $cc){$_=substr($_,1,length($_));$cmd=()}
    if(($cmd)&&($_)){command("$cmd ".replace($_)."")}
    elsif($_=~/^replace\b/i){&get_conf;prnt('Updated with Replace List')}
    elsif($_){command("$_")}
    command("settext");
    return EAT_ALL;
});

my %replace;
sub replace {
    my($words,@words)=();my@word=split/\s+/,$_[0];
    foreach $_(@word){
        if($replace{lc($_)}){push(@words,"$replace{lc($_)}")}
        else{push(@words,"$_")}
    }
    foreach $_(@words){
        if(!$words){$words="$_"}
        else{$words="$words "."$_"}
    }
    return $words;
}

&get_conf;
sub get_conf {
    open CONF,"<".get_info('xchatdir')."/replace.conf" or die $!;
    my($key,$value);%replace=();
    while(<CONF>){
        chomp($_);
        if($_=~/^NAME (.+)/){$key=lc($1);$value=()}
        elsif($_=~/^CMD (.+)/){$value=$1}
        else{($key,$value)=()}
        if(($key)&&($value)){$replace{$key}="$value"}
    }
    close(CONF);
}

my($name,$version)=('Case Insensitive Replace','1.2');
register($name,$version,'Makes the Auto Replace Case Insensitive');
prnt("$name $version Loaded");

__END__

Version History:
0.1  2010-04-24 Initial Code
1.0  2010-04-25 Cleaned up code, reluctantly released
1.1  2010-04-26 Added /replace command to update script after changes to auto replace list.
1.2  2010-04-26 Improved key press sub input command character code and reading of auto replace list.

Comments

Sign in to comment.
D2K7   -  May 09, 2010

Thank You gooshie :D
The basic xchat word replacer got right on my nerves, so I stopped using it which got me banned a lot lol.

 Respond  
gooshie   -  Apr 25, 2010

Hawkee
Yes, thanks, it works now like it did before. This is good also for when I want to show an image that is small enough that it fits in the description area and thus would not need to be hyperlinked to show it's fullsize version. By the way, I also noticed the addition/improvements to the script upload section/feature. I hope in the future when I have something of that size to make use of this feature. Thanks again for all your help.

 Respond  
Hawkee   -  Apr 25, 2010

I just realized there was a more severe bug that was causing none of the extensions to show up. It's now been corrected. Sorry!

 Respond  
Hawkee   -  Apr 25, 2010

It checked for jpeg, gif and png in the past, so I had to add jpg which was overlooked.

 Respond  
gooshie   -  Apr 25, 2010

Hawkee
Good, glad you found it, did you check it for .gif and .png as they did the same thing?

 Respond  
Hawkee   -  Apr 25, 2010

Aha! I see the problem. There was a bug in appending .jpg to image uploads. The bbcode parser requires an image extension, so that's why it's not showing up. You may upload the image again and it should have the .jpg extension and work as expected. Thanks for catching this.

 Respond  
gooshie   -  Apr 25, 2010

Hawkee
I just tried it again and it still is not working. It shows up in listings but does not evaluate within the snippet itself. I went through this when I posted my first xchat snippet and thought it was because I was using an image.png but even after I changed to image.gif and image.jpg it still did not work. Then I noticed that before the url for the image included the file extension whereas now it does not. To compensate I used the screenshot feature but did not like it as well so I settled on setting the font to size=1 and color=white in bbcode. I leave it here now without the bbcode font markup so you can see it.

 Respond  
Hawkee   -  Apr 25, 2010

The [img] tag does still work in the description. It looks like you put size=1 and color=white around it, so that's why its not showing up.

We do have icons for script uploads, but I felt it wasn't necessary for code snippets. I'll have to consider it. If you do have some more involved code that requires multiple documents you might want to consider posting them as scripts.

 Respond  
gooshie   -  Apr 25, 2010

Hawkee
Because, you changed the code so when I put a bbcode image tag it does not evaluate and display the image within the snippet (but still displays in the listing). I like the look of my snippet listings when they have an 'icon' for each snippet. If you will notice I used to use one mIRC 'icon' image for all my mIRC scripts unless I had another image I specifically wanted to associate with that snippet. With this new change the only option is to use the screenshot thing which can not be set to an image previously uploaded and also has the disadvantage of being hyperlinked to the screenshot image which in this case would be just a waste of a click/time/bandwidth. Previously when I used an image as just an icon I would not hyperlink the image back to the image file. I was thinking an option like the screenshot thing you now have but for setting an icon would be helpful if it allowed choosing from a hawkee list of icons or user's previously uploaded images or uploading a new image. These 'icons' would NOT be hyperlinked back to their image file. If no icon was selected it could default to the present behavior. If you did choose to add this 'icon' feature maybe have it appear in the snippet below the title and to the left of Average Score in addition to it showing up in listings. But, maybe I am the only one that would use it. By the way, I noticed also the change in the 'Tags' with making it comma separated values which of course allows Tags to be multiple words now. Good job and thanks for providing such a fun site.

 Respond  
Hawkee   -  Apr 25, 2010

Why the hidden image in your description?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.