Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 33 additions and 30 deletions.
  1. +33 −30 lib/POE/Component/Server/Twirc.pm
View
63 lib/POE/Component/Server/Twirc.pm
@@ -6,7 +6,7 @@ use LWP::UserAgent::POE;
use POE qw(Component::Server::IRC);
use Net::Twitter;
use Email::Valid;
-use String::Truncate qw/elide/;
+use String::Truncate elide => { marker => '' };
use POE::Component::Server::Twirc::LogAppender;
use POE::Component::Server::Twirc::State;
use Encode qw/decode/;
@@ -747,10 +747,7 @@ event ircd_daemon_privmsg => sub {
return;
}
- unless ( $self->twitter(new_direct_message => { user => $target_nick, text => $text }) ) {
- # TODO what channel?
- $self->bot_says($self->irc_channel, "new_direct_message failed.");
- }
+ $self->twitter(new_direct_message => { user => $target_nick, text => $text });
};
sub friends_stale_after () { 7*24*3600 } # 1 week
@@ -972,7 +969,8 @@ sub _favorite_or_retweet {
my $link = "https://twitter.com/$$status{user}{screen_name}/status/$$status{id}";
my $text = $self->formatted_status_text($status);
- $self->bot_notice($self->irc_channel, elide(qq/$who $verb $whom "$text"/, 80) . " [$link]");
+ $self->bot_notice($self->irc_channel,
+ elide(qq/$who $verb $whom "$text"/, 80, { marker => '…"' }) . " [$link]");
}
sub on_event_block {
@@ -1061,19 +1059,33 @@ event cmd_post => sub {
$self->log->trace("[cmd_post_status]");
- my $http_urls = (my $stripped = $text) =~ s/$RE{URI}{HTTP}//g;
- my $https_urls = $stripped =~ s/$RE{URI}{HTTP}{-scheme => 'https'}//g;
-
- if ( (my $n = length($stripped) + $http_urls * 20 + $https_urls * 21 - 140) > 0 ) {
- $self->bot_says($channel, "Message not sent; $n characters too long. Limit is 140 characters.");
- return;
- }
+ return if $self->status_text_too_long($channel, $text);
my $status = $self->twitter(update => $text) || return;
$self->log->trace(" update returned $status");
};
+sub status_text_too_long {
+ my ( $self, $channel, $text ) = @_;
+
+ if ( (my $n = $self->_calc_text_length($text) - 140) > 0 ) {
+ $self->bot_says($channel, "$n characters too long.");
+ return $n;
+ }
+
+ return;
+}
+
+sub _calc_text_length {
+ my ( $self, $text ) = @_;
+
+ my $http_urls = $text =~ s/$RE{URI}{HTTP}//g;
+ my $https_urls = $text =~ s/$RE{URI}{HTTP}{-scheme => 'https'}//g;
+
+ return length($text) + $http_urls * 20 + $https_urls * 21;
+}
+
=item follow I<id>
Follow a new Twitter user, I<id>. In Twitter parlance, this creates a friendship.
@@ -1197,9 +1209,7 @@ event cmd_notify => sub {
my $method = $onoff eq 'on' ? 'enable_notifications' : 'disable_notifications';
for my $nick ( @nicks ) {
- unless ( $self->twitter($method => { id => $nick }) ) {
- $self->bot_says($channel, "notify $onoff failed for $nick");
- }
+ $self->twitter($method => { id => $nick });
}
};
@@ -1243,9 +1253,7 @@ sub _handle_favorite {
my @candidates = @{$self->stash->{candidates} || []};
if ( $index =~ /^\d+$/ && 0 < $index && $index <= @candidates ) {
- if ( $self->twitter(create_favorite => { id => $candidates[$index - 1] }) ) {
- $self->bot_notice($channel, 'favorite added');
- }
+ $self->twitter(create_favorite => { id => $candidates[$index - 1] });
$self->clear_stash;
return 1; # handled
}
@@ -1359,6 +1367,8 @@ event cmd_reply => sub {
return;
}
+ $message = "\@$nick $message";
+ return if $self->status_text_too_long($channel, $message);
$count ||= $self->favorites_count;
@@ -1371,7 +1381,6 @@ event cmd_reply => sub {
$self->stash({
handler => '_handle_reply',
candidates => [ map $_->{id_str}, @$recent ],
- recipient => $nick,
message => $message,
});
@@ -1386,16 +1395,10 @@ sub _handle_reply {
my @candidates = @{$self->stash->{candidates} || []};
if ( $index =~ /^\d+$/ && 0 < $index && $index <= @candidates ) {
- my $message = sprintf '@%s %s', @{$self->stash}{qw/recipient message/};
- if ( (my $n = length($message) - 140) > 0 ) {
- $self->bot_says($channel, "Message not sent; $n characters too long. Limit is 140 characters.");
- }
- else {
- $self->twitter(update => {
- status => $message,
- in_reply_to_status_id => $candidates[$index - 1],
- });
- }
+ $self->twitter(update => {
+ status => $self->stash->{message},
+ in_reply_to_status_id => $candidates[$index - 1],
+ });
$self->clear_stash;
return 1; # handled
}

No commit comments for this range

Something went wrong with that request. Please try again.