|
|
|
@ -2,21 +2,25 @@ use std::cmp::Ordering; |
|
|
|
|
use std::collections::HashSet; |
|
|
|
|
use std::time::Duration; |
|
|
|
|
|
|
|
|
|
use elefren::{FediClient, SearchType, StatusBuilder}; |
|
|
|
|
use elefren::entities::account::Account; |
|
|
|
|
use elefren::entities::prelude::Status; |
|
|
|
|
use elefren::status_builder::Visibility; |
|
|
|
|
use elefren::{FediClient, SearchType, StatusBuilder}; |
|
|
|
|
|
|
|
|
|
use crate::command::{StatusCommand, RE_NOBOT_TAG}; |
|
|
|
|
use crate::command::{RE_NOBOT_TAG, StatusCommand}; |
|
|
|
|
use crate::error::GroupError; |
|
|
|
|
use crate::group_handler::GroupHandle; |
|
|
|
|
use crate::store::group_config::GroupConfig; |
|
|
|
|
use crate::store::CommonConfig; |
|
|
|
|
use crate::store::group_config::GroupConfig; |
|
|
|
|
use crate::tr::TranslationTable; |
|
|
|
|
use crate::utils; |
|
|
|
|
use crate::utils::{normalize_acct, LogError, VisExt}; |
|
|
|
|
use crate::utils::{LogError, normalize_acct, VisExt}; |
|
|
|
|
|
|
|
|
|
use crate::{grp_debug, grp_info, grp_warn}; |
|
|
|
|
use crate::{ |
|
|
|
|
grp_debug, |
|
|
|
|
grp_warn, |
|
|
|
|
grp_info |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
pub struct ProcessMention<'a> { |
|
|
|
|
status: Status, |
|
|
|
@ -47,7 +51,7 @@ impl<'a> ProcessMention<'a> { |
|
|
|
|
self.client |
|
|
|
|
.search_v2(acct, !followed, Some(SearchType::Accounts), Some(1), followed), |
|
|
|
|
) |
|
|
|
|
.await |
|
|
|
|
.await |
|
|
|
|
{ |
|
|
|
|
Err(_) => { |
|
|
|
|
grp_warn!(self, "Account lookup timeout!"); |
|
|
|
@ -94,9 +98,9 @@ impl<'a> ProcessMention<'a> { |
|
|
|
|
let mut to_add = String::new(); |
|
|
|
|
for m in members { |
|
|
|
|
to_add.push_str(&if admins.contains(&m) { |
|
|
|
|
crate::tr!(self, "user_list_entry_admin", user = m) |
|
|
|
|
crate::tr!(self, "user_list_entry_admin", user=m) |
|
|
|
|
} else { |
|
|
|
|
crate::tr!(self, "user_list_entry", user = m) |
|
|
|
|
crate::tr!(self, "user_list_entry", user=m) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
self.add_reply(&to_add); |
|
|
|
@ -145,7 +149,8 @@ impl<'a> ProcessMention<'a> { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async fn reblog_status(&self) { |
|
|
|
|
self.client.reblog(&self.status.id).await.log_error("Failed to reblog status"); |
|
|
|
|
self.client.reblog(&self.status.id) |
|
|
|
|
.await.log_error("Failed to reblog status"); |
|
|
|
|
self.delay_after_post().await; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -414,7 +419,7 @@ impl<'a> ProcessMention<'a> { |
|
|
|
|
|
|
|
|
|
async fn cmd_undo(&mut self) -> Result<(), GroupError> { |
|
|
|
|
if let (Some(ref parent_account_id), Some(ref parent_status_id)) = |
|
|
|
|
(&self.status.in_reply_to_account_id, &self.status.in_reply_to_id) |
|
|
|
|
(&self.status.in_reply_to_account_id, &self.status.in_reply_to_id) |
|
|
|
|
{ |
|
|
|
|
if parent_account_id == &self.group_account.id { |
|
|
|
|
// This is a post sent by the group user, likely an announcement.
|
|
|
|
@ -670,11 +675,7 @@ impl<'a> ProcessMention<'a> { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if self.config.is_member_only() { |
|
|
|
|
self.add_reply(crate::tr!( |
|
|
|
|
self, |
|
|
|
|
"help_group_info_closed", |
|
|
|
|
membership = &membership_line |
|
|
|
|
)); |
|
|
|
|
self.add_reply(crate::tr!(self, "help_group_info_closed", membership = &membership_line)); |
|
|
|
|
} else { |
|
|
|
|
self.add_reply(crate::tr!(self, "help_group_info_open", membership = &membership_line)); |
|
|
|
|
} |
|
|
|
@ -708,7 +709,7 @@ impl<'a> ProcessMention<'a> { |
|
|
|
|
let mut to_add = String::new(); |
|
|
|
|
|
|
|
|
|
for t in tags { |
|
|
|
|
to_add.push_str(&crate::tr!(self, "tag_list_entry", tag = t)); |
|
|
|
|
to_add.push_str(&crate::tr!(self, "tag_list_entry", tag=t)); |
|
|
|
|
} |
|
|
|
|
self.add_reply(to_add); |
|
|
|
|
} |
|
|
|
@ -773,11 +774,11 @@ impl<'a> ProcessMention<'a> { |
|
|
|
|
// Try to unfollow
|
|
|
|
|
let account = self.client.get_account(id).await?; |
|
|
|
|
let bio = utils::strip_html(&account.note); |
|
|
|
|
let normalized = normalize_acct(&account.acct, &self.group_acct)?; |
|
|
|
|
if RE_NOBOT_TAG.is_match(&bio) && !self.config.is_member(&normalized) { |
|
|
|
|
// #nobot in a non-member account
|
|
|
|
|
Err(GroupError::UserOptedOutNobot) |
|
|
|
|
if RE_NOBOT_TAG.is_match(&bio) { |
|
|
|
|
// #nobot
|
|
|
|
|
Err(GroupError::UserOptedOut) |
|
|
|
|
} else { |
|
|
|
|
let normalized = normalize_acct(&account.acct, &self.group_acct)?; |
|
|
|
|
if self.config.is_banned(&normalized) { |
|
|
|
|
Err(GroupError::UserIsBanned) |
|
|
|
|
} else if self.config.is_optout(&normalized) { |
|
|
|
|