Update: Added some things, removed some things, the new version is a reply to this node.
Well, I was very excited when I learned that Pidgin accepts plugins written in Perl. (This is my 3rd plugin, the first two being far from complete.) I was not so excited to learn that the best documentation they have is for C (which I do not know). That being said, if there are better ways to do something, please let me know.
I tried to keep the lines to 80 columns (which, before previewing, I thought PM used to keep code tags from being too long. I now realize that the limit is less than 80 characters.)~
# English 2 13375p34k
# TODO (in order of importance)
# Convert & (and such) to & (and such).
# Set up preferences to allow user customization of the substitutio
+ns
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.1.3",
summary => "Anything you type (that is in <leet></leet> tags) will
+ betranslated to leetspeak and then sent.",
description => "Anything you type (that is in <leet></leet> tags)
+will be translated to leetspeak and then sent. I use the Acme::LeetSp
+eak module (which does all the work :)). Please note that Pidgin conv
+erts '&' 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",
);
my $pathname = '/plugins/core/eng21337';
my $catchloop = 0; # Used to stop infinite loop below (there is probab
+ly 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;
# 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 l
+oaded\n");
}
sub plugin_unload {
Purple::Debug::info("eng21337", "plugin_load() - eng21137 plugin l
+oaded\n");
}
sub sending_im_msg_cb {
my ($account, $who, $msg) = @_;
$catchloop++;
# Everytime I send() something from this subroutine (sending_im_ms
+g_cb)
# this subroutine gets called again (because I am send()ing someth
+ing)
# 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 p
+rocess.
# 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) {
my $reg = qr{
<leet> # <leet> -- Pidgin converts <>
+ to html
(.+?) # Stuff to be leet'd
</leet> # </leet>
}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--;
}
Put it in your ~/.purple/plugins folder (create if necessary), restart Pidgin, and enable it through Tools->Plugins.
Oh, and, to use it, just put any text you want turned into leetspeak between <leet></leet> tags.
Thanks to jdporter for the <leet></leet> tags suggestion. Thanks to the author of Acme::LeetSpeak for obvious reasons. (Make sure to download that module, by the way.)
Also, plans for eng2LOLCAT have been made: .oO( I think 3 or 4 substitutions and a download of Acme::LOLCAT will be all that is needed :P )
And you didn't even know bears could type.