Skip to content

Instantly share code, notes, and snippets.

@drags
Created November 7, 2011 08:42
Show Gist options
  • Save drags/1344472 to your computer and use it in GitHub Desktop.
Save drags/1344472 to your computer and use it in GitHub Desktop.
my ($kernel, $heap, $command, $target) = @_[KERNEL, HEAP, ARG0, ARG1];
$kernel->post('logger','log',"Got to offerbot area",$heap->{'username'}) if $config{'debug'} >=2;
my (@arg) = split / /, $command;
# setup prox table now, so table can access unmolested @arg
my @proc;
@proc = (
{ 'cmdmatch' => 'refresh|up|update',
'exec' => sub { $kernel->yield('twitter_timeline'); $kernel->yield('twitter_direct_messages') },
'help' => "![update|up|refresh] - Updates the #twitter stream immediately.",
},
{ 'cmdmatch' => 'tweet|t',
'argmatch' => '\S+.',
'exec' => sub {
my ($cmd, @msg) = @_;
$kernel->yield('twitter_post_tweet', '#twitter', join(" ",@msg)) },
'help' => "![tweet|t] <text of tweet> - Posts the given text as an update to your feed.",
},
{ 'cmdmatch' => 'retweet|rt',
'argmatch' => '[0-9a-f]{3}\b',
'exec' => sub {
my ($cmd, $rt_id) = @_;
$kernel->yield('twitter_retweet_tweet',$rt_id);
},
'twid' => 1,
'help' => "![retweet|rt] <tweed-id> - Posts a retweet. tweet-id is the 3 digit code preceding the tweet.",
},
{ 'cmdmatch' => 'reply|re',
'argmatch' => '[0-9a-f]{3}\s+.*',
'exec' => sub {
my ($cmd, $rt_id, @msg) = @_;
$kernel->yield('twitter_reply_to_tweet',$rt_id,join(" ",@msg));
},
'twid' => 1,
'help' => "![reply|re] <tweet-id> <message text> - Replies to a tweet. tweet-id is a the 3 digit code preceding the tweet.",
},
{ 'cmdmatch' => 'save',
'exec' => sub {
if (my $st = $kernel->call($_[SESSION], 'save_config')) {
$kernel->yield('user_msg','PRIVMSG',"tircdbot","#twitter","User configuration stored successfully");
} else{
$kernel->yield('user_msg','PRIVMSG',"tircdbot","#twitter","Error - User configuration storage failed.");
}
},
'help' => '!save - Saves twitter-username specific configuration immediately.',
},
# arg should be limited to 15char, but some UNs are grandfathered to be longer.
{ 'cmdmatch' => 'add|invite|follow',
'argmatch' => '\w',
'exec' => sub {
my ($cmd, $add_user) = @_;
my $data = { 'params' => [$add_user, '#twitter'] };
$kernel->yield('INVITE', $data);
},
'help' => '![add|invite|follow] <username> - Begin following the specified twitter username.',
},
{ 'cmdmatch' => 'remove|kick|unfollow',
'argmatch' => '\w',
'exec' => sub {
my ($cmd, $del_user) = @_;
my $data = { 'params' => [ '#twitter', $del_user ] };
$kernel->yield('KICK', $data);
},
'help' => '![remove|kick|unfollow] <username> - Remove the username from the list of people your account follows.',
},
{ 'cmdmatch' => 'h|help',
'exec' => sub {
$kernel->yield('user_msg','PRIVMSG',"tircdbot","#twitter","Tircd Command List");
$kernel->yield('user_msg','PRIVMSG',"tircdbot","#twitter","Commands listed in [abc|a] form mean that 'a' is an alias for 'abc'");
for (@proc) {
$kernel->yield('user_msg','PRIVMSG',"tircdbot","#twitter",$_->{'help'});
}
},
'help' => "!help - Shows this help message.",
},
);
# compare command to cmdmatch, verify args against argmatch, convert short tweet-ids into real tweeit-ids, do something
for my $p (@proc) {
my ($cmdmatch, $argmatch) = ($p->{'cmdmatch'},$p->{'argmatch'});
print "Trying to match $cmdmatch\n";
if ($arg[0] =~ m/^\s*!($cmdmatch)\b/i) {
print "Matched command $cmdmatch\n";
my $c = join(" ",@arg);
if ($c =~ /^\s*!($cmdmatch)\s*($argmatch)/) {
# convert tweet-id short hash to actual id
if ($p->{'twid'}) {
my $tw_id = $heap->{'timeline_ticker'}->{$arg[1]};
unless ($tw_id) {
$kernel->yield('user_msg','PRIVMSG',"tircdbot","#twitter","Tweet id of: " . $arg[1] . " was not found.");
return;
}
$arg[1] = $tw_id;
}
print "Trying to run exec\n";
&{$p->{'exec'}}(@arg);
return;
} else {
$kernel->yield('user_msg','PRIVMSG',$heap->{'username'},"#twitter",$p->{'help'});
return;
}
last;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment