This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ttytter-r2a.pl
75 lines (63 loc) · 2.21 KB
/
ttytter-r2a.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
###################
#
# ttytter-r2a.pl -- a TTYtter extension
#
# Copyright (C) 2011 by Ben Cotton
#
# See README.txt for more information
#
# Licensed under GNU Public License v2.0. See LICENSE for full text.
#
###################
$TTYtter_R2A_VERSION='1.0.1';
$addaction = sub {
my @command = split(/ /,$_,3);
# Check to see what command was given
if ( ( lc($command[0]) eq '/replyall' ) ||
( lc($command[0]) eq '/ra' ) ||
( lc($command[0]) eq '/replytoall' ) ) {
# Get information about the tweet
my $tweet_id = $command[1];
my $tweet = &get_tweet($tweet_id);
my $witty_reply = $command[2];
# Is the witty reply empty? Don't tweet it, that's obnoxious.
if ( $witty_reply eq '' ) {
print $stdout "-- There is no message here. Are you drunk?\n";
return 1;
}
# Check that the tweet exists. If not, it will be hard to reply to it.
if (!$tweet->{'id_str'}) {
print $stdout "-- You have to wait for that tweet to exist!\n";
return 1;
}
# Who sent the tweet that we're replying to?
$screen_name = &descape($tweet->{'user'}->{'screen_name'});
# Who is mentioned in the tweet?
my $reply_tweet = $tweet->{'text'};
my $mentioned;
# We iterate over the string because I can't think of a better way
while ( $reply_tweet =~ m/(@\w+)/g ) {
# Save the lowercased name in a variable to avoid multiple lc
# invokations and to make the m// below cleaner.
my $reply_target = lc($1);
# Don't add yourself to the reply list, or the person you're
# replying to, since they'll be added anyway
# Also try to filter out duplicate references to the same user
unless ( ( $reply_target eq lc("\@$whoami") ) ||
( $reply_target eq lc("\@$screen_name") ) ||
( $mentioned =~ m/$reply_target/ ) ) {
$mentioned .= "$reply_target ";
}
}
# We're replying, so we'd better act like it
$in_reply_to = $tweet->{'id_str'};
# Prepend the tweet with the names to mention
$witty_reply = "\@$screen_name $mentioned $witty_reply";
&common_split_post($witty_reply, $in_reply_to, undef);
# All done!
return 1;
}
# You didn't ask to reply to all. Tell TTYtter that we don't want to deal
# with this input.
return 0;
};