Added reply to all functionality.

This commit is contained in:
Storm Dragon
2025-07-26 11:39:50 -04:00
parent 1f62effe0b
commit 3d5119bbd4
+76 -1
View File
@@ -2652,8 +2652,10 @@ Example:
/boost a5 - boosts post a5
/vote a5 2 - vote for option 2 on poll in post a5
/vote a5 1,3 - vote for options 1 and 3 (if multiple choice)
/replyall a5 message - reply to all users mentioned in post a5
/ra a5 message - same as /replyall (shorter alias)
Abbreviations: /re, /th, /url, /del
Abbreviations: /re, /th, /url, /del, /ra
Menu codes wrap around at end.
Note: /reply, /delete and /url work for direct message menu codes too!
@@ -3659,6 +3661,13 @@ EOF
return &vote_on_poll($post_code, $choices);
}
# reply to all mentioned users
if (m#^/(replyall|ra|replytoall)\s+([a-z]\d+)\s+(.+)$#i) {
my $post_code = $2;
my $reply_text = $3;
return &reply_to_all($post_code, $reply_text);
}
# follow and leave users
if (m#^/(follow|leave|unfollow) \@?([^\s/]+)$#) {
my $m = $1;
@@ -4117,6 +4126,72 @@ sub vote_on_poll {
}
}
# reply to all users mentioned in a post
sub reply_to_all {
my $post_code = shift;
my $reply_text = shift;
# Find the post by its menu code
my $post_ref = &findtarget($post_code);
unless ($post_ref) {
print $stdout "-- no such post: $post_code\n";
return 0;
}
# Get the post content and author
my $post_content = $post_ref->{'text'} || '';
my $post_author = $post_ref->{'user'}->{'acct'} || $post_ref->{'user'}->{'screen_name'} || '';
# Set up reply-to ID
my $in_reply_to = $post_ref->{'id_str'} || $post_ref->{'id'};
# Extract all @mentions from the post content using fediverse format
my %mentioned_users = ();
# Look for @user@domain format (full fediverse mentions)
while ($post_content =~ m/(@\w+@[\w\.-]+)/g) {
my $mention = $1;
# Don't mention ourselves or the original author
unless (lc($mention) eq lc("\@$whoami") || lc($mention) eq lc("\@$post_author")) {
$mentioned_users{lc($mention)} = $mention;
}
}
# Also look for @user format (local mentions) and convert to full format
while ($post_content =~ m/(@\w+)(?!@)/g) {
my $local_mention = $1;
# Don't mention ourselves or the original author
unless (lc($local_mention) eq lc("\@$whoami") || lc($local_mention) eq lc("\@$post_author")) {
# For local mentions, we need to determine the domain
# Check if the post has mentions array with full acct info
if (exists($post_ref->{'mentions'}) && ref($post_ref->{'mentions'}) eq 'ARRAY') {
foreach my $mention_obj (@{$post_ref->{'mentions'}}) {
my $username = $mention_obj->{'username'} || '';
my $acct = $mention_obj->{'acct'} || '';
if (lc($local_mention) eq lc("\@$username") && $acct) {
$mentioned_users{lc("\@$acct")} = "\@$acct";
last;
}
}
}
}
}
# Build the reply text with all mentions
my $mentions_text = '';
if (%mentioned_users) {
$mentions_text = join(' ', values %mentioned_users) . ' ';
}
# Construct the full reply: @author mentions reply_text
my $full_reply = "\@$post_author $mentions_text$reply_text";
print $stdout "-- replying to all: $full_reply\n" if ($verbose);
# Use the existing post sending mechanism
return &common_split_post($full_reply, $in_reply_to, undef);
}
# helper functions for the command line processor.
sub add_history {
my $h = shift;