fixes in help cmd, make everything use markdown

master
Ondřej Hruška 3 years ago
parent 63c4c5f2e8
commit 4ddc26c6ca
Signed by untrusted user: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      README.md
  2. 2
      locales/en.json
  3. 20
      src/group_handler/handle_mention.rs
  4. 21
      src/store/group_config.rs

@ -79,6 +79,7 @@ The locale file looks like this (excerpt):
} }
``` ```
- All messages can use markdown formatting.
- Words in curly braces (`{}`) are substitution tokens. These must be preserved in all translations. - Words in curly braces (`{}`) are substitution tokens. These must be preserved in all translations.
- Pay attention to line endings and blank lines (`\n`). Some messages from the locale file are combined to form the - Pay attention to line endings and blank lines (`\n`). Some messages from the locale file are combined to form the
final post, leaving out newlines can result in a mangled output. final post, leaving out newlines can result in a mangled output.

@ -11,7 +11,7 @@
"help_membership_member": "*You are a member.*", "help_membership_member": "*You are a member.*",
"help_membership_guest_closed": "*You are not a member, ask one of the admins to add you.*", "help_membership_guest_closed": "*You are not a member, ask one of the admins to add you.*",
"help_membership_guest_open": "*You are not a member, follow or use /join to join the group.*", "help_membership_guest_open": "*You are not a member, follow or use /join to join the group.*",
"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", "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",
"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", "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",
"help_member_commands": "\n`/admins` - show group admins\n`/undo` - un-boost your post (use in a reply)", "help_member_commands": "\n`/admins` - show group admins\n`/undo` - un-boost your post (use in a reply)",
"cmd_leave_ok": "You're no longer a group member. Unfollow the group user to stop receiving group messages.", "cmd_leave_ok": "You're no longer a group member. Unfollow the group user to stop receiving group messages.",

@ -30,7 +30,6 @@ pub struct ProcessMention<'a> {
replies: String, replies: String,
announcements: String, announcements: String,
do_boost_prev_post: bool, do_boost_prev_post: bool,
want_markdown: bool,
} }
impl<'a> ProcessMention<'a> { impl<'a> ProcessMention<'a> {
@ -134,7 +133,6 @@ impl<'a> ProcessMention<'a> {
replies: String::new(), replies: String::new(),
announcements: String::new(), announcements: String::new(),
do_boost_prev_post: false, do_boost_prev_post: false,
want_markdown: false,
group_acct, group_acct,
status_acct, status_acct,
status, status,
@ -271,9 +269,7 @@ impl<'a> ProcessMention<'a> {
let mut msg = std::mem::take(&mut self.replies); let mut msg = std::mem::take(&mut self.replies);
debug!("r={}", msg); debug!("r={}", msg);
if self.want_markdown { apply_trailing_hashtag_pleroma_bug_workaround(&mut msg);
apply_trailing_hashtag_pleroma_bug_workaround(&mut msg);
}
let mention = crate::tr!(self, "mention_prefix", 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?;
@ -283,9 +279,7 @@ impl<'a> ProcessMention<'a> {
let mut msg = std::mem::take(&mut self.announcements); let mut msg = std::mem::take(&mut self.announcements);
debug!("a={}", msg); debug!("a={}", msg);
if self.want_markdown { apply_trailing_hashtag_pleroma_bug_workaround(&mut msg);
apply_trailing_hashtag_pleroma_bug_workaround(&mut msg);
}
let msg = crate::tr!(self, "group_announcement", message = &msg); let msg = crate::tr!(self, "group_announcement", message = &msg);
self.send_announcement_multipart(&msg).await?; self.send_announcement_multipart(&msg).await?;
@ -301,11 +295,7 @@ impl<'a> ProcessMention<'a> {
for p in parts { for p in parts {
if let Ok(post) = StatusBuilder::new() if let Ok(post) = StatusBuilder::new()
.status(p) .status(p)
.content_type(if self.want_markdown { .content_type("text/markdown")
"text/markdown"
} else {
"text/plain"
})
.in_reply_to(&parent) .in_reply_to(&parent)
.visibility(Visibility::Direct) .visibility(Visibility::Direct)
.build() .build()
@ -647,8 +637,6 @@ impl<'a> ProcessMention<'a> {
} }
async fn cmd_help(&mut self) { async fn cmd_help(&mut self) {
self.want_markdown = true;
let membership_line = if self.is_admin { let membership_line = if self.is_admin {
crate::tr!(self, "help_membership_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) {
@ -677,7 +665,6 @@ impl<'a> ProcessMention<'a> {
} }
async fn cmd_list_members(&mut self) { async fn cmd_list_members(&mut self) {
self.want_markdown = true;
if self.is_admin { if self.is_admin {
self.add_reply(crate::tr!(self, "member_list_heading")); self.add_reply(crate::tr!(self, "member_list_heading"));
self.append_member_list_to_reply(); self.append_member_list_to_reply();
@ -689,7 +676,6 @@ impl<'a> ProcessMention<'a> {
async fn cmd_list_tags(&mut self) { async fn cmd_list_tags(&mut self) {
self.add_reply(crate::tr!(self, "tag_list_heading")); self.add_reply(crate::tr!(self, "tag_list_heading"));
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();

@ -583,6 +583,15 @@ mod tests {
use crate::error::GroupError; use crate::error::GroupError;
use crate::store::group_config::{acct_to_server, GroupConfig}; use crate::store::group_config::{acct_to_server, GroupConfig};
fn empty_group_config() -> GroupConfig {
GroupConfig {
config: Default::default(),
control: Default::default(),
state: Default::default(),
_group_tr: Default::default()
}
}
#[test] #[test]
fn test_acct_to_server() { fn test_acct_to_server() {
assert_eq!("pikachu.rocks", acct_to_server("raichu@pikachu.rocks")); assert_eq!("pikachu.rocks", acct_to_server("raichu@pikachu.rocks"));
@ -592,7 +601,7 @@ mod tests {
#[test] #[test]
fn test_default_rules() { fn test_default_rules() {
let group = GroupConfig::default(); let group = empty_group_config();
assert!(!group.is_member_only()); assert!(!group.is_member_only());
assert!(!group.is_member("piggo@piggo.space")); assert!(!group.is_member("piggo@piggo.space"));
assert!(!group.is_admin("piggo@piggo.space")); assert!(!group.is_admin("piggo@piggo.space"));
@ -601,7 +610,7 @@ mod tests {
#[test] #[test]
fn test_member_only() { fn test_member_only() {
let mut group = GroupConfig::default(); let mut group = empty_group_config();
assert!(group.can_write("piggo@piggo.space"), "rando can write in public group"); assert!(group.can_write("piggo@piggo.space"), "rando can write in public group");
group.set_member_only(true); group.set_member_only(true);
@ -638,7 +647,7 @@ mod tests {
#[test] #[test]
fn test_banned_users() { fn test_banned_users() {
// Banning single user // Banning single user
let mut group = GroupConfig::default(); let mut group = empty_group_config();
group.ban_user("piggo@piggo.space", true).unwrap(); group.ban_user("piggo@piggo.space", true).unwrap();
assert!(!group.can_write("piggo@piggo.space"), "banned user can't post"); assert!(!group.can_write("piggo@piggo.space"), "banned user can't post");
group.ban_user("piggo@piggo.space", false).unwrap(); group.ban_user("piggo@piggo.space", false).unwrap();
@ -648,7 +657,7 @@ mod tests {
#[test] #[test]
fn test_banned_members() { fn test_banned_members() {
// Banning single user // Banning single user
let mut group = GroupConfig::default(); let mut group = empty_group_config();
group.set_member_only(true); group.set_member_only(true);
group.set_member("piggo@piggo.space", true).unwrap(); group.set_member("piggo@piggo.space", true).unwrap();
@ -669,7 +678,7 @@ mod tests {
#[test] #[test]
fn test_server_ban() { fn test_server_ban() {
let mut group = GroupConfig::default(); let mut group = empty_group_config();
assert!(group.can_write("hitler@nazi.camp"), "randos can write"); assert!(group.can_write("hitler@nazi.camp"), "randos can write");
group.ban_server("nazi.camp", true).unwrap(); group.ban_server("nazi.camp", true).unwrap();
@ -689,7 +698,7 @@ mod tests {
#[test] #[test]
fn test_sanity() { fn test_sanity() {
let mut group = GroupConfig::default(); let mut group = empty_group_config();
group.set_admin("piggo@piggo.space", true).unwrap(); group.set_admin("piggo@piggo.space", true).unwrap();
assert_eq!( assert_eq!(

Loading…
Cancel
Save