Skip to content

Commit

Permalink
Factoid: Truncate messages to 512 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Jokler committed Jun 27, 2020
1 parent a92e622 commit 33403d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ where

#[derive(Clone, Debug)]
struct ThreadedPlugins<C: FrippyClient> {
plugins: HashMap<String, Arc<Plugin<Client = C>>>,
plugins: HashMap<String, Arc<dyn Plugin<Client = C>>>,
}

impl<C: FrippyClient + 'static> ThreadedPlugins<C> {
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/factoid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ impl<T: Database, C: Client> Factoid<T, C> {
.get_factoid(name, idx)
.context(ErrorKind::NotFound)?;

let message = factoid.content.replace("\n", "|").replace("\r", "");
let mut message = factoid.content.replace("\n", "|").replace("\r", "");
message.truncate(512);

Ok(format!("{}: {}", factoid.name, message))
}
Expand Down Expand Up @@ -179,7 +180,7 @@ impl<T: Database, C: Client> Factoid<T, C> {
let factoid = self.factoids.read().get_factoid(&name, count - 1)?;

let content = factoid.content;
let value = if content.starts_with('>') {
let mut message = if content.starts_with('>') {
let content = String::from(&content[1..]);

if content.starts_with('>') {
Expand All @@ -197,7 +198,8 @@ impl<T: Database, C: Client> Factoid<T, C> {
content
};

Ok(value.replace("\n", "|").replace("\r", ""))
message.truncate(512);
Ok(message.replace("\n", "|").replace("\r", ""))
}
}

Expand Down

0 comments on commit 33403d0

Please sign in to comment.