add missing trans, untested!

This commit is contained in:
Ondřej Hruška 2021-10-09 21:49:26 +02:00
parent bd47a004bf
commit 239e15afdd
3 changed files with 139 additions and 111 deletions

View file

@ -1,18 +1,56 @@
{ {
"welcome_public": "@{user} Welcome to the group! The group user will now follow you back to complete the sign-up.\nTo share a post, @ the group user or use a group hashtag.\n\nUse /help for more info.", "welcome_public": "Welcome to the group! The group user will now follow you back to complete the sign-up.\nTo share a post, @ the group user or use a group hashtag.\n\nUse /help for more info.",
"welcome_member_only": "@{user} Welcome to the group! This group has posting restricted to members.\nIf you'd like to join, please ask one of the group admins:\n{admins}", "welcome_member_only": "Welcome to the group! This group has posting restricted to members.\nIf you'd like to join, please ask one of the group admins:\n{admins}",
"welcome_join_cmd": "Welcome to the group! The group user will now follow you to complete the sign-up. Make sure you follow back to receive shared posts!\n\nUse /help for more info.", "welcome_join_cmd": "Welcome to the group! The group user will now follow you to complete the sign-up. Make sure you follow back to receive shared posts!\n\nUse /help for more info.",
"welcome_closed": "Sorry, this group is closed to new sign-ups.\nPlease ask one of the group admins to add you:", "welcome_closed": "Sorry, this group is closed to new sign-ups.\nPlease ask one of the group admins to add you:\n",
"user_list_member": "- {user}", "user_list_entry": "- {user}\n",
"user_list_admin": "- {user} [admin]", "user_list_entry_admin": "- {user} [admin]\n",
"help_admin_commands": "\n**Admin commands:**\n`/ping` - check the group works\n`/add user` - add a member (user@domain)\n`/remove user` - remove a member\n`/add #hashtag` - add a group hashtag\n`/remove #hashtag` - remove a group hashtag\n`/undo` - un-boost a replied-to post, delete an announcement\n`/ban x` - ban a user or server\n`/unban x` - lift a ban\n`/admin user` - grant admin rights\n`/deadmin user` - revoke admin rights\n`/closegroup` - make member-only\n`/opengroup` - make public-access\n`/announce x` - make a public announcement", "help_group_info_closed": "This is a member-only group. {membership}\n",
"cmd_leave_resp": "You're no longer a group member. Unfollow the group user to stop receiving group messages.", "help_group_info_open": "This is a public-access group. {membership}\n",
"member_list_heading": "Group members:", "help_membership_admin": "*You are an admin.*",
"admin_list_heading": "Group admins:", "help_membership_member": "*You are a member.*",
"tag_list_heading": "Group tags:", "help_membership_guest_closed": "*You are not a member, ask one of the admins to add you.*",
"tag_list_entry": "- {tag}", "help_membership_guest_open": "*You are not a member, follow or use /join to join the group.*",
"cmd_close_resp": "Group changed to member-only", "help_admin_commands": "\n\n**Admin commands:**\n`/ping` - check the group works\n`/members - show group members / admins\n`/add user` - add a member (user@domain)\n`/remove user` - remove a member\n`/add #hashtag` - add a group hashtag\n`/remove #hashtag` - remove a group hashtag\n`/undo` - un-boost a replied-to post, delete an announcement\n`/ban x` - ban a user or server\n`/unban x` - lift a ban\n`/admin user` - grant admin rights\n`/deadmin user` - revoke admin rights\n`/closegroup` - make member-only\n`/opengroup` - make public-access\n`/announce x` - make a public announcement",
"cmd_close_resp_noaction": "No action, group is member-only already", "help_basic_commands": "To share a post, @ the group user or use a group hashtag.\n\n**Supported commands:**\n`/boost`, `/b` - boost the replied-to post into the group\n`/ignore`, `/i` - make the group ignore the post\n`/tags` - show group hashtags\n`/join` - (re-)join the group\n`/leave` - leave the group\n`/optout` - forbid sharing of your posts",
"cmd_open_resp": "Group changed to open-access", "help_member_commands": "\n`/admins` - show group admins\n`/undo` - un-boost your post (use in a reply)",
"cmd_open_resp_noaction": "No action, group is open-access already", "cmd_leave_ok": "You're no longer a group member. Unfollow the group user to stop receiving group messages.",
"member_list_heading": "Group members:\n",
"admin_list_heading": "Group admins:\n",
"tag_list_heading": "Group tags:\n",
"tag_list_entry": "- {tag}\n",
"cmd_error": "Command failed: {cause}",
"cmd_close_ok": "Group changed to member-only",
"cmd_close_fail_already": "No action, group is member-only already",
"cmd_open_ok": "Group changed to open-access",
"cmd_open_fail_already": "No action, group is open-access already",
"cmd_optout_fail_admin_cant": "Group admins can't opt-out.",
"cmd_optout_fail_member_cant": "Group members can't opt-out. You have to leave first.",
"cmd_optout_ok": "Your posts will no longer be shared to the group.",
"cmd_optin_fail_admin_cant": "Opt-in has no effect for admins.",
"cmd_optin_fail_member_cant": "Opt-in has no effect for members.",
"cmd_optin_ok": "Your posts can now be shared to the group.",
"cmd_ban_user_ok": "User {user} banned from group!",
"cmd_ban_user_fail_already": "No action, user {user} is already banned",
"cmd_unban_user_ok": "User {user} un-banned!",
"cmd_unban_user_fail_already": "No action, user {user} is not banned",
"cmd_ban_server_ok": "Server {server} banned from group!",
"cmd_ban_server_fail_already": "No action, server {server} already banned",
"cmd_unban_server_ok": "Server {server} un-banned!",
"cmd_unban_server_fail_already": "No action, server {server} is not banned",
"cmd_add_user_ok": "User {user} added to the group!",
"cmd_remove_user_ok": "User {user} removed from the group.",
"cmd_add_tag_ok": "Tag #{tag} added to the group!",
"cmd_add_tag_fail_already": "No action, #{tag} is already a group tag",
"cmd_remove_tag_ok": "Tag #{tag} removed from the group!",
"cmd_remove_tag_fail_already": "No action, #{tag} is not a group tag",
"cmd_admin_ok": "User {user} is now a group admin!",
"cmd_admin_fail_already": "No action, user {user} is a group admin already",
"cmd_unadmin_ok": "User {user} is no longer a group admin!",
"cmd_unadmin_fail_already": "No action, user {user} is not a group admin",
"mention_prefix": "@{user} ",
"group_announcement": "**📢Group announcement**\n{message}",
"ping_response": "pong, this is fedigroups service v{version}"
} }

View file

@ -27,8 +27,8 @@ pub struct ProcessMention<'a> {
status_user_id: String, status_user_id: String,
can_write: bool, can_write: bool,
is_admin: bool, is_admin: bool,
replies: Vec<String>, replies: String,
announcements: Vec<String>, announcements: String,
do_boost_prev_post: bool, do_boost_prev_post: bool,
want_markdown: bool, want_markdown: bool,
} }
@ -78,9 +78,11 @@ impl<'a> ProcessMention<'a> {
fn append_admin_list_to_reply(&mut self) { fn append_admin_list_to_reply(&mut self) {
let mut admins = self.config.get_admins().collect::<Vec<_>>(); let mut admins = self.config.get_admins().collect::<Vec<_>>();
admins.sort(); admins.sort();
let mut to_add = String::new();
for a in admins { for a in admins {
self.replies.push(format!("- {}", a)); to_add.push_str(&crate::tr!(self, "user_list_entry", user = a));
} }
self.add_reply(&to_add);
} }
fn append_member_list_to_reply(&mut self) { fn append_member_list_to_reply(&mut self) {
@ -89,13 +91,15 @@ impl<'a> ProcessMention<'a> {
members.extend(admins.iter()); members.extend(admins.iter());
members.sort(); members.sort();
members.dedup(); members.dedup();
let mut to_add = String::new();
for m in members { for m in members {
self.replies.push(if admins.contains(&m) { to_add.push_str(&if admins.contains(&m) {
crate::tr!(self, "user_list_admin", user=m) crate::tr!(self, "user_list_entry_admin", user=m)
} else { } else {
crate::tr!(self, "user_list_member", user=m) crate::tr!(self, "user_list_entry", user=m)
}); });
} }
self.add_reply(&to_add);
} }
async fn follow_user_by_id(&self, id: &str) -> Result<(), GroupError> { async fn follow_user_by_id(&self, id: &str) -> Result<(), GroupError> {
@ -128,8 +132,8 @@ impl<'a> ProcessMention<'a> {
cc: &gh.cc, cc: &gh.cc,
can_write: gh.config.can_write(&status_acct), can_write: gh.config.can_write(&status_acct),
is_admin: gh.config.is_admin(&status_acct), is_admin: gh.config.is_admin(&status_acct),
replies: vec![], replies: String::new(),
announcements: vec![], announcements: String::new(),
do_boost_prev_post: false, do_boost_prev_post: false,
want_markdown: false, want_markdown: false,
group_acct, group_acct,
@ -142,16 +146,17 @@ impl<'a> ProcessMention<'a> {
} }
async fn reblog_status(&self) { 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; self.delay_after_post().await;
} }
fn add_reply(&mut self, line: impl AsRef<str>) { fn add_reply(&mut self, line: impl AsRef<str>) {
self.replies.push(line.as_ref().trim_matches(' ').to_string()) self.replies.push_str(line.as_ref())
} }
fn add_announcement(&mut self, line: impl AsRef<str>) { fn add_announcement(&mut self, line: impl AsRef<str>) {
self.announcements.push(line.as_ref().trim_matches(' ').to_string()) self.announcements.push_str(line.as_ref())
} }
async fn handle(mut self) -> Result<(), GroupError> { async fn handle(mut self) -> Result<(), GroupError> {
@ -166,6 +171,9 @@ impl<'a> ProcessMention<'a> {
} }
for cmd in commands { for cmd in commands {
if !self.replies.is_empty() {
self.replies.push('\n'); // make sure there's a newline between batched commands.
}
match cmd { match cmd {
StatusCommand::Undo => { StatusCommand::Undo => {
self.cmd_undo().await.log_error("Error handling undo cmd"); self.cmd_undo().await.log_error("Error handling undo cmd");
@ -213,7 +221,7 @@ impl<'a> ProcessMention<'a> {
self.cmd_grant_admin(&u).await.log_error("Error handling grant-admin cmd"); self.cmd_grant_admin(&u).await.log_error("Error handling grant-admin cmd");
} }
StatusCommand::RemoveAdmin(u) => { StatusCommand::RemoveAdmin(u) => {
self.cmd_revoke_member(&u).await.log_error("Error handling grant-admin cmd"); self.cmd_revoke_admin(&u).await.log_error("Error handling grant-admin cmd");
} }
StatusCommand::OpenGroup => { StatusCommand::OpenGroup => {
self.cmd_open_group().await; self.cmd_open_group().await;
@ -261,26 +269,26 @@ impl<'a> ProcessMention<'a> {
} }
if !self.replies.is_empty() { if !self.replies.is_empty() {
let mut msg = self.replies.join("\n"); let mut msg = std::mem::take(&mut self.replies);
debug!("r={}", msg); debug!("r={}", msg);
if self.want_markdown { if self.want_markdown {
apply_trailing_hashtag_pleroma_bug_workaround(&mut msg); apply_trailing_hashtag_pleroma_bug_workaround(&mut msg);
} }
let mention = format!("@{user} ", user = self.status_acct); let mention = crate::tr!(self, "mention_prefix", user = &self.status_acct);
self.send_reply_multipart(mention, msg).await?; self.send_reply_multipart(mention, msg).await?;
} }
if !self.announcements.is_empty() { if !self.announcements.is_empty() {
let mut msg = self.announcements.join("\n"); let mut msg = std::mem::take(&mut self.announcements);
debug!("a={}", msg); debug!("a={}", msg);
if self.want_markdown { if self.want_markdown {
apply_trailing_hashtag_pleroma_bug_workaround(&mut msg); apply_trailing_hashtag_pleroma_bug_workaround(&mut msg);
} }
let msg = format!("**📢 Group announcement**\n{msg}", msg = msg); let msg = crate::tr!(self, "group_announcement", message = &msg);
self.send_announcement_multipart(&msg).await?; self.send_announcement_multipart(&msg).await?;
} }
@ -373,23 +381,23 @@ impl<'a> ProcessMention<'a> {
async fn cmd_optout(&mut self) { async fn cmd_optout(&mut self) {
if self.is_admin { if self.is_admin {
self.add_reply("Group admins can't opt-out."); self.add_reply(crate::tr!(self, "cmd_optout_fail_admin_cant"));
} else if self.config.is_member(&self.status_acct) { } else if self.config.is_member(&self.status_acct) {
self.add_reply("Group members can't opt-out. You have to leave first."); self.add_reply(crate::tr!(self, "cmd_optout_fail_member_cant"));
} else { } else {
self.config.set_optout(&self.status_acct, true); self.config.set_optout(&self.status_acct, true);
self.add_reply("Your posts will no longer be shared to the group."); self.add_reply(crate::tr!(self, "cmd_optout_ok"));
} }
} }
async fn cmd_optin(&mut self) { async fn cmd_optin(&mut self) {
if self.is_admin { if self.is_admin {
self.add_reply("Opt-in has no effect for admins."); self.add_reply(crate::tr!(self, "cmd_optin_fail_admin_cant"));
} else if self.config.is_member(&self.status_acct) { } else if self.config.is_member(&self.status_acct) {
self.add_reply("Opt-in has no effect for members."); self.add_reply(crate::tr!(self, "cmd_optin_fail_member_cant"));
} else { } else {
self.config.set_optout(&self.status_acct, false); self.config.set_optout(&self.status_acct, false);
self.add_reply("Your posts can now be shared to the group."); self.add_reply(crate::tr!(self, "cmd_optin_ok"));
} }
} }
@ -428,15 +436,15 @@ impl<'a> ProcessMention<'a> {
if !self.config.is_banned(&u) { if !self.config.is_banned(&u) {
match self.config.ban_user(&u, true) { match self.config.ban_user(&u, true) {
Ok(_) => { Ok(_) => {
self.add_reply(format!("User {} banned from group!", u)); self.add_reply(crate::tr!(self, "cmd_ban_user_ok", user = &u));
self.unfollow_by_acct(&u).await.log_error("Failed to unfollow banned user"); self.unfollow_by_acct(&u).await.log_error("Failed to unfollow banned user");
} }
Err(e) => { Err(e) => {
self.add_reply(format!("Failed to ban user {}: {}", u, e)); self.add_reply(crate::tr!(self, "cmd_error", cause = &e.to_string()));
} }
} }
} else { } else {
self.add_reply(format!("No action, user {} is already banned", u)); self.add_reply(crate::tr!(self, "cmd_ban_user_fail_already", user = &u));
} }
} else { } else {
warn!("Ignore cmd, user not admin"); warn!("Ignore cmd, user not admin");
@ -450,15 +458,15 @@ impl<'a> ProcessMention<'a> {
if self.config.is_banned(&u) { if self.config.is_banned(&u) {
match self.config.ban_user(&u, false) { match self.config.ban_user(&u, false) {
Ok(_) => { Ok(_) => {
self.add_reply(format!("User {} un-banned!", u)); self.add_reply(crate::tr!(self, "cmd_unban_user_ok", user = &u));
// no announcement here // no announcement here
} }
Err(_) => { Err(e) => {
unreachable!() self.add_reply(crate::tr!(self, "cmd_error", cause = &e.to_string()));
} }
} }
} else { } else {
self.add_reply(format!("No action, user {} is not banned", u)); self.add_reply(crate::tr!(self, "cmd_unban_user_fail_already", user = &u));
} }
} else { } else {
warn!("Ignore cmd, user not admin"); warn!("Ignore cmd, user not admin");
@ -471,14 +479,14 @@ impl<'a> ProcessMention<'a> {
if !self.config.is_server_banned(s) { if !self.config.is_server_banned(s) {
match self.config.ban_server(s, true) { match self.config.ban_server(s, true) {
Ok(_) => { Ok(_) => {
self.add_reply(format!("Server {} banned from group!", s)); self.add_reply(crate::tr!(self, "cmd_ban_server_ok", server = s));
} }
Err(e) => { Err(e) => {
self.add_reply(format!("Failed to ban server {}: {}", s, e)); self.add_reply(crate::tr!(self, "cmd_error", cause = &e.to_string()));
} }
} }
} else { } else {
self.add_reply(format!("No action, server {} already banned", s)); self.add_reply(crate::tr!(self, "cmd_ban_server_fail_already", server = s));
} }
} else { } else {
warn!("Ignore cmd, user not admin"); warn!("Ignore cmd, user not admin");
@ -490,14 +498,14 @@ impl<'a> ProcessMention<'a> {
if self.config.is_server_banned(s) { if self.config.is_server_banned(s) {
match self.config.ban_server(s, false) { match self.config.ban_server(s, false) {
Ok(_) => { Ok(_) => {
self.add_reply(format!("Server {} un-banned!", s)); self.add_reply(crate::tr!(self, "cmd_unban_server_ok", server = s));
} }
Err(e) => { Err(e) => {
self.add_reply(format!("Unexpected error occured: {}", e)); self.add_reply(crate::tr!(self, "cmd_error", cause = &e.to_string()));
} }
} }
} else { } else {
self.add_reply(format!("No action, server {} is not banned", s)); self.add_reply(crate::tr!(self, "cmd_unban_server_fail_already", server = s));
} }
} else { } else {
warn!("Ignore cmd, user not admin"); warn!("Ignore cmd, user not admin");
@ -510,11 +518,12 @@ impl<'a> ProcessMention<'a> {
// Allow even if the user is already a member - that will trigger re-follow // Allow even if the user is already a member - that will trigger re-follow
match self.config.set_member(&u, true) { match self.config.set_member(&u, true) {
Ok(_) => { Ok(_) => {
self.add_reply(format!("User {} added to the group!", u)); self.add_reply(crate::tr!(self, "cmd_add_user_ok", user = &u));
// marked as member, now also follow the user
self.follow_by_acct(&u).await.log_error("Failed to follow"); self.follow_by_acct(&u).await.log_error("Failed to follow");
} }
Err(e) => { Err(e) => {
self.add_reply(format!("Failed to add user {} to group: {}", u, e)); self.add_reply(crate::tr!(self, "cmd_error", cause = &e.to_string()));
} }
} }
} else { } else {
@ -528,11 +537,11 @@ impl<'a> ProcessMention<'a> {
if self.is_admin { if self.is_admin {
match self.config.set_member(&u, false) { match self.config.set_member(&u, false) {
Ok(_) => { Ok(_) => {
self.add_reply(format!("User {} removed from the group.", u)); self.add_reply(crate::tr!(self, "cmd_remove_user_ok", user = &u));
self.unfollow_by_acct(&u).await.log_error("Failed to unfollow removed user"); self.unfollow_by_acct(&u).await.log_error("Failed to unfollow removed user");
} }
Err(e) => { Err(e) => {
self.add_reply(format!("Unexpected error occured: {}", e)); self.add_reply(crate::tr!(self, "cmd_error", cause = &e.to_string()));
} }
} }
} else { } else {
@ -545,9 +554,9 @@ impl<'a> ProcessMention<'a> {
if self.is_admin { if self.is_admin {
if !self.config.is_tag_followed(&tag) { if !self.config.is_tag_followed(&tag) {
self.config.add_tag(&tag); self.config.add_tag(&tag);
self.add_reply(format!("Tag \"{}\" added to the group!", tag)); self.add_reply(crate::tr!(self, "cmd_add_tag_ok", tag = &tag));
} else { } else {
self.add_reply(format!("No action, \"{}\" is already a group tag", tag)); self.add_reply(crate::tr!(self, "cmd_add_tag_fail_already", tag = &tag));
} }
} else { } else {
warn!("Ignore cmd, user not admin"); warn!("Ignore cmd, user not admin");
@ -558,9 +567,9 @@ impl<'a> ProcessMention<'a> {
if self.is_admin { if self.is_admin {
if self.config.is_tag_followed(&tag) { if self.config.is_tag_followed(&tag) {
self.config.remove_tag(&tag); self.config.remove_tag(&tag);
self.add_reply(format!("Tag \"{}\" removed from the group!", tag)); self.add_reply(crate::tr!(self, "cmd_remove_tag_ok", tag = &tag));
} else { } else {
self.add_reply(format!("No action, \"{}\" is not a group tag", tag)); self.add_reply(crate::tr!(self, "cmd_remove_tag_fail_already", tag = &tag));
} }
} else { } else {
warn!("Ignore cmd, user not admin"); warn!("Ignore cmd, user not admin");
@ -576,14 +585,14 @@ impl<'a> ProcessMention<'a> {
// try to make the config a little more sane, admins should be members // try to make the config a little more sane, admins should be members
let _ = self.config.set_member(&u, true); let _ = self.config.set_member(&u, true);
self.add_reply(format!("User {} is now a group admin!", u)); self.add_reply(crate::tr!(self, "cmd_admin_ok", user = &u));
} }
Err(e) => { Err(e) => {
self.add_reply(format!("Failed to make user {} a group admin: {}", u, e)); self.add_reply(crate::tr!(self, "cmd_error", cause = &e.to_string()));
} }
} }
} else { } else {
self.add_reply(format!("No action, \"{}\" is admin already", u)); self.add_reply(crate::tr!(self, "cmd_admin_fail_already", user = &u));
} }
} else { } else {
warn!("Ignore cmd, user not admin"); warn!("Ignore cmd, user not admin");
@ -591,20 +600,20 @@ impl<'a> ProcessMention<'a> {
Ok(()) Ok(())
} }
async fn cmd_revoke_member(&mut self, user: &str) -> Result<(), GroupError> { async fn cmd_revoke_admin(&mut self, user: &str) -> Result<(), GroupError> {
let u = normalize_acct(user, &self.group_acct)?; let u = normalize_acct(user, &self.group_acct)?;
if self.is_admin { if self.is_admin {
if self.config.is_admin(&u) { if self.config.is_admin(&u) {
match self.config.set_admin(&u, false) { match self.config.set_admin(&u, false) {
Ok(_) => { Ok(_) => {
self.add_reply(format!("User {} is no longer a group admin!", u)); self.add_reply(crate::tr!(self, "cmd_unadmin_ok", user = &u));
} }
Err(e) => { Err(e) => {
self.add_reply(format!("Failed to revoke {}'s group admin: {}", u, e)); self.add_reply(crate::tr!(self, "cmd_error", cause = &e.to_string()));
} }
} }
} else { } else {
self.add_reply(format!("No action, user {} is not admin", u)); self.add_reply(crate::tr!(self, "cmd_unadmin_fail_already", user = &u));
} }
} else { } else {
warn!("Ignore cmd, user not admin"); warn!("Ignore cmd, user not admin");
@ -618,7 +627,7 @@ impl<'a> ProcessMention<'a> {
self.config.set_member_only(false); self.config.set_member_only(false);
self.add_reply(crate::tr!(self, "cmd_open_resp")); self.add_reply(crate::tr!(self, "cmd_open_resp"));
} else { } else {
self.add_reply(crate::tr!(self, "cmd_open_resp_noaction")); self.add_reply(crate::tr!(self, "cmd_open_resp_already"));
} }
} else { } else {
warn!("Ignore cmd, user not admin"); warn!("Ignore cmd, user not admin");
@ -631,7 +640,7 @@ impl<'a> ProcessMention<'a> {
self.config.set_member_only(true); self.config.set_member_only(true);
self.add_reply(crate::tr!(self, "cmd_close_resp")); self.add_reply(crate::tr!(self, "cmd_close_resp"));
} else { } else {
self.add_reply(crate::tr!(self, "cmd_close_resp_noaction")); self.add_reply(crate::tr!(self, "cmd_close_resp_already"));
} }
} else { } else {
warn!("Ignore cmd, user not admin"); warn!("Ignore cmd, user not admin");
@ -642,44 +651,27 @@ impl<'a> ProcessMention<'a> {
self.want_markdown = true; self.want_markdown = true;
let membership_line = if self.is_admin { let membership_line = if self.is_admin {
"*You are an admin.*" crate::tr!(self, "help_membership_admin")
} else if self.config.is_member(&self.status_acct) { } else if self.config.is_member(&self.status_acct) {
"*You are a member.*" crate::tr!(self, "help_membership_member")
} else if self.config.is_member_only() { } else if self.config.is_member_only() {
"*You are not a member, ask one of the admins to add you.*" crate::tr!(self, "help_membership_guest_closed")
} else { } else {
"*You are not a member, follow or use /join to join the group.*" crate::tr!(self, "help_membership_guest_open")
}; };
if self.config.is_member_only() { if self.config.is_member_only() {
self.add_reply(format!("This is a member-only group. {}", membership_line)); self.add_reply(crate::tr!(self, "help_group_info_closed", membership = &membership_line));
} else { } else {
self.add_reply(format!("This is a public-access group. {}", membership_line)); self.add_reply(crate::tr!(self, "help_group_info_open", membership = &membership_line));
} }
self.add_reply( self.add_reply(crate::tr!(self, "help_basic_commands"));
"\
To share a post, @ the group user or use a group hashtag.\n\
\n\
**Supported commands:**\n\
`/boost`, `/b` - boost the replied-to post into the group\n\
`/ignore`, `/i` - make the group ignore the post\n\
`/tags` - show group hashtags\n\
`/join` - (re-)join the group\n\
`/leave` - leave the group\n\
`/optout` - forbid sharing of your posts",
);
if self.is_admin { if !self.is_admin {
self.add_reply("`/members`, `/who` - show group members / admins"); self.add_reply(crate::tr!(self, "help_member_commands"));
// undo is listed as an admin command
} else {
self.add_reply("`/admins` - show group admins");
self.add_reply("`/undo` - un-boost your post (use in a reply)");
} }
// XXX when used on instance with small character limit, this won't fit!
if self.is_admin { if self.is_admin {
self.add_reply(crate::tr!(self, "help_admin_commands")); self.add_reply(crate::tr!(self, "help_admin_commands"));
} }
@ -701,9 +693,13 @@ impl<'a> ProcessMention<'a> {
self.want_markdown = true; self.want_markdown = true;
let mut tags = self.config.get_tags().collect::<Vec<_>>(); let mut tags = self.config.get_tags().collect::<Vec<_>>();
tags.sort(); tags.sort();
let mut to_add = String::new();
for t in tags { for t in tags {
self.replies.push(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);
} }
async fn cmd_leave(&mut self) { async fn cmd_leave(&mut self) {
@ -742,10 +738,7 @@ impl<'a> ProcessMention<'a> {
} }
async fn cmd_ping(&mut self) { async fn cmd_ping(&mut self) {
self.add_reply(format!( self.add_reply(crate::tr!(self, "ping_response", version = env!("CARGO_PKG_VERSION")));
"pong, this is fedigroups service v{}",
env!("CARGO_PKG_VERSION")
));
} }
async fn unfollow_by_acct(&self, acct: &str) -> Result<(), GroupError> { async fn unfollow_by_acct(&self, acct: &str) -> Result<(), GroupError> {
@ -895,21 +888,21 @@ mod test {
let to_split = "foo\nbar\nbaz"; let to_split = "foo\nbar\nbaz";
let parts = super::smart_split(to_split, None, 1000); let parts = super::smart_split(to_split, None, 1000);
assert_eq!(vec!["foo\nbar\nbaz".to_string(),], parts); assert_eq!(vec!["foo\nbar\nbaz".to_string()], parts);
} }
#[test] #[test]
fn test_smart_split_nosplit_prefix() { fn test_smart_split_nosplit_prefix() {
let to_split = "foo\nbar\nbaz"; let to_split = "foo\nbar\nbaz";
let parts = super::smart_split(to_split, Some("PREFIX".to_string()), 1000); let parts = super::smart_split(to_split, Some("PREFIX".to_string()), 1000);
assert_eq!(vec!["PREFIXfoo\nbar\nbaz".to_string(),], parts); assert_eq!(vec!["PREFIXfoo\nbar\nbaz".to_string()], parts);
} }
#[test] #[test]
fn test_smart_split_prefix_each() { fn test_smart_split_prefix_each() {
let to_split = "1234\n56\n7"; let to_split = "1234\n56\n7";
let parts = super::smart_split(to_split, Some("PREFIX".to_string()), 10); let parts = super::smart_split(to_split, Some("PREFIX".to_string()), 10);
assert_eq!(vec!["PREFIX1234".to_string(), "PREFIX56\n7".to_string(),], parts); assert_eq!(vec!["PREFIX1234".to_string(), "PREFIX56\n7".to_string()], parts);
} }
#[test] #[test]
@ -951,7 +944,7 @@ mod test {
let to_split = "one two threefourfive six"; let to_split = "one two threefourfive six";
let parts = super::smart_split(to_split, None, 10); let parts = super::smart_split(to_split, None, 10);
assert_eq!( assert_eq!(
vec!["one two".to_string(), "threefourf".to_string(), "ive six".to_string(),], vec!["one two".to_string(), "threefourf".to_string(), "ive six".to_string()],
parts parts
); );
} }

View file

@ -538,18 +538,15 @@ impl GroupHandle {
let mut admins = self.config.get_admins().cloned().collect::<Vec<_>>(); let mut admins = self.config.get_admins().cloned().collect::<Vec<_>>();
admins.sort(); admins.sort();
crate::tr!(self, "welcome_member_only", crate::tr!(self, "mention_prefix", user = notif_acct)
user = notif_acct, + &crate::tr!(self, "welcome_member_only", admins = &admins.join(", "))
admins = &admins.join(", ")
)
} else { } else {
follow_back = true; follow_back = true;
self.config.set_member(notif_acct, true).log_error("Fail add a member"); self.config.set_member(notif_acct, true).log_error("Fail add a member");
crate::tr!(self, "welcome_public", crate::tr!(self, "mention_prefix", user = notif_acct)
user = notif_acct + &crate::tr!(self, "welcome_public")
)
}; };
let post = StatusBuilder::new() let post = StatusBuilder::new()