# 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.1.3",
summary => "Anything you type (that is in tags) will betranslated to leetspeak and then sent.",
description => "Anything you type (that is in tags) 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",
);
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;
# 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 sending_im_msg_cb {
my ($account, $who, $msg) = @_;
$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) {
my $reg = qr{
<leet> # -- Pidgin converts <> to html
(.+?) # Stuff to be leet'd
</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--;
}