mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 18:55:44 -04:00
Add translation API
This commit is contained in:
parent
47430f6e8e
commit
ef2f7491fd
3 changed files with 117 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
etc/bing_secret.txt
|
87
plugins/badfactstemp.pm
Normal file
87
plugins/badfactstemp.pm
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
package Bot::BB3::Plugin::BadfactsTemp;
|
||||||
|
use strict;
|
||||||
|
no warnings 'void';
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my( $class ) = @_;
|
||||||
|
my $self = bless {}, $class;
|
||||||
|
$self->{name} = 'badfactstemp';
|
||||||
|
$self->{opts} = {
|
||||||
|
handler => 1,
|
||||||
|
command => 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub command {
|
||||||
|
my ($self, $said, $pm) = @_;
|
||||||
|
|
||||||
|
# Always require this to be addressed, regardless of plugin config
|
||||||
|
if ($said->{addressed}) {
|
||||||
|
my $body = $said->{body};
|
||||||
|
|
||||||
|
if ($body =~ /^#(?<channel>\S+)\s+(?:(?<command>forget|learn|relearn|literal|revert|revisions|search|protect|unprotect|substitue|macro)\s+)?(?<fact>.*?)$/) {
|
||||||
|
my ($command, $channel, $fact) = @+{qw/command channel fact/};
|
||||||
|
|
||||||
|
my $realfact = ($command?"$command ":"")."__${channel}_$fact";
|
||||||
|
|
||||||
|
return ('handled', $realfact);
|
||||||
|
} else {
|
||||||
|
return ('handled', "helptexthere");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub handle {
|
||||||
|
my ($self, $said, $pm) = @_;
|
||||||
|
|
||||||
|
if ($said->{body} =~ /^!(?<fact>[^@].*?)(?:\s@\s*(?<user>\S*))?$/ ||
|
||||||
|
$said->{body} =~ /^!@(?<user>\S+)\s+(?<fact>.+)$/) {
|
||||||
|
my $fact = $+{fact};
|
||||||
|
my $user = $+{user};
|
||||||
|
|
||||||
|
# TODO HACK XXX bad hack to prevent noise until better way is decided
|
||||||
|
return ('', 'handled') if $fact =~ /^regex\s/;
|
||||||
|
|
||||||
|
my ($s, $r) = runfacts($fact, $said, $pm);
|
||||||
|
if ($s) {
|
||||||
|
$r = "$user: $r" if $user;
|
||||||
|
$r = "\0".$r;
|
||||||
|
return ($r, 'handled');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub runfacts {
|
||||||
|
my( $body, $_said, $pm ) = @_;
|
||||||
|
|
||||||
|
my $said = {%$_said};
|
||||||
|
|
||||||
|
my $plugin = $pm->get_plugin( 'fact' );
|
||||||
|
|
||||||
|
$said->{body} = $body;
|
||||||
|
$said->{recommended_args} = [ split /\s+/, $body ];
|
||||||
|
$said->{command_match} = 'fact';
|
||||||
|
$said->{addressed} = 1;
|
||||||
|
|
||||||
|
local $@;
|
||||||
|
my( $status, $results ) = eval { $plugin->command( $said, $pm ) };
|
||||||
|
my $err = $@;
|
||||||
|
|
||||||
|
warn $err if $err;
|
||||||
|
|
||||||
|
if( $err ) { return( 0, "Failed to execute plugin: facts because $err" ); }
|
||||||
|
else { return( 1, $results ) }
|
||||||
|
}
|
||||||
|
|
||||||
|
"Bot::BB3::Plugin::BadfactsTemp";
|
||||||
|
|
||||||
|
__DATA__
|
||||||
|
Supports calling factoids outside of addressed commands using special syntax. Contact simcop2387 to ask about having it enabled for your channel.
|
29
plugins/translate.pm
Normal file
29
plugins/translate.pm
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Bing::Translate;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return sub {
|
||||||
|
my( $said ) = @_;
|
||||||
|
|
||||||
|
open(my $fh, "<etc/bing_secret.txt") or die "Couldn't read $!";
|
||||||
|
my $cid = "Perlbot";
|
||||||
|
my $secret = <$fh>;
|
||||||
|
chomp $secret;
|
||||||
|
close($fh);
|
||||||
|
|
||||||
|
my $tro = Bing::Translate->new($cid, $secret);
|
||||||
|
|
||||||
|
if ($said->{body} =~ /^\s*(?<from>\S+)\s+(?<to>\S+)\s+(?<text>.*)$/) {
|
||||||
|
# print $secret;
|
||||||
|
print $tro->translate($+{text}, $+{from}, $+{to});
|
||||||
|
} else {
|
||||||
|
print "help text";
|
||||||
|
}
|
||||||
|
|
||||||
|
return('handled');
|
||||||
|
}
|
||||||
|
|
||||||
|
__DATA__
|
||||||
|
translate <from> <to> <text> - Translate using the Bing Translation API.
|
Loading…
Add table
Reference in a new issue