# English 2 13375p34k # TODO (in order of importance) # Convert & (and such) to & (and such). # Set up preferences to allow user customization of the substitutions use warnings; use strict; use Purple; use Acme::LeetSpeak; # Who says Acme should not be used in production :P our %PLUGIN_INFO = ( perl_api_version => 2, name => "eng21337", version => "0.2.1", summary => "Translate what you type to leetspeak.", description => "Anything you type (that is (optionally) between tags (the tags are customizable, though)) will be translated to leetspeak and then sent. I use the Acme::LeetSpeak module (which does all the work :)). Please note that Pidgin converts '&' to '&' so the leetspeak of 'me&you' will be 'm3&4Mpjo0' (or something). I'll fix it in a later version ;)", author => "Marc Green", url => "http://pidgin.im", load => "plugin_load", unload => "plugin_unload", prefs_info => "prefs_info_cb", ); my $pathname = '/plugins/core/eng21337'; my $catchloop = 0; # Used to stop infinite loop below (there is probably a way # to avoid the whole thing but this works for now :P) sub plugin_init { return %PLUGIN_INFO; } sub plugin_load { my $plugin = shift; Purple::Prefs::add_none($pathname); Purple::Prefs::add_string("$pathname/leet_tag", "leet"); Purple::Prefs::add_bool("$pathname/full_leet", 1); # Everytime I send an im, call the subroutine sending_im_msg_cb my $convs_handle = Purple::Conversations::get_handle(); Purple::Signal::connect($convs_handle, "sending-im-msg", $plugin, \&sending_im_msg_cb, ''); Purple::Debug::info("eng21337", "plugin_load() - eng21137 plugin loaded\n"); } sub plugin_unload { Purple::Debug::info("eng21337", "plugin_load() - eng21137 plugin loaded\n"); } sub prefs_info_cb { my ($frame, $ppref); $frame = Purple::PluginPref::Frame->new(); $ppref = Purple::PluginPref->new_with_name_and_label("$pathname/leet_tag", "Tag used to denote what should be turned into leetspeak.\n(E.g., type 'dood' if you want to use ."); $ppref->set_type(2); $ppref->set_max_length(9); $frame->add($ppref); $ppref = Purple::PluginPref->new_with_name_and_label("$pathname/full_leet", "Always in leetspeak mode. (I.e., no tags\nneeded -- everything you type will be translated.)"); $frame->add($ppref); return $frame; } sub sending_im_msg_cb { my ($account, $who, $msg) = @_; my $leet_tag = quotemeta Purple::Prefs::get_string("$pathname/leet_tag"); my $full_leet = Purple::Prefs::get_bool("$pathname/full_leet"); $catchloop++; # Everytime I send() something from this subroutine (sending_im_msg_cb) # this subroutine gets called again (because I am send()ing something) # leading to an infinite loop. This is why I use $catchloop. I set it to 0 # earlier so when this sub is called it will increase to 1 letting the # below if statement execute. It is then set to 0 to restart the process. # This stops the infinite loop because once I call $im->send($msg), this # sub gets called again making $catchloop 2 which bypasses the if statement # including the send(). Trust me, I've done the math. if ($catchloop == 1) { # If the user wants everything translated to leetspeak, do so. # Else, just translate stuff between the tags if ($full_leet) { $msg = leet($msg); } else { my $reg = qr{ <$leet_tag> # (.+?) # Stuff to be leet'd </$leet_tag> # }x; $msg =~ s/$reg/leet($1);/ge if $msg =~ /$reg/; } # Not sure how else to get the correct im handle besides these 5 lines my $im; my @convs = Purple::get_conversations(); foreach my $conv (@convs) { $im = $conv->get_im_data() and last if $conv->get_name eq $who; } $im->send($msg); # Show *both* users the leetspeak'd message $_[2] = ''; # Prevent double messages } $catchloop--; }