Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions factorion-bot-discord/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "factorion-bot-discord"
version = "2.2.4"
version = "2.2.5"
edition = "2024"
description = "factorion-bot (for factorials and related) on Discord"
license = "MIT"
Expand All @@ -10,7 +10,7 @@ keywords = ["factorial", "termial", "bot", "math", "discord"]
categories = ["mathematics", "web-programming", "parser-implementations"]

[dependencies]
factorion-lib = { path = "../factorion-lib", version = "4.2.4", features = ["serde", "influxdb"] }
factorion-lib = { path = "../factorion-lib", version = "4.2.5", features = ["serde", "influxdb"] }
serenity = { version = "0.12", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] }
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "time"] }
dotenvy = "^0.15.7"
Expand Down
4 changes: 2 additions & 2 deletions factorion-bot-reddit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "factorion-bot-reddit"
version = "5.3.4"
version = "5.3.5"
edition = "2024"
description = "factorion-bot (for factorials and related) on Reddit"
license = "MIT"
Expand All @@ -10,7 +10,7 @@ keywords = ["factorial", "termial", "bot", "math"]
categories = ["mathematics", "web-programming", "parser-implementations"]

[dependencies]
factorion-lib = {path = "../factorion-lib", version = "4.2.4", features = ["serde", "influxdb"]}
factorion-lib = {path = "../factorion-lib", version = "4.2.5", features = ["serde", "influxdb"]}
reqwest = { version = "0.12.28", features = ["json", "native-tls"], default-features = false }
serde = { version = "1.0.219", default-features = false, features = ["derive"] }
serde_json = "1.0.140"
Expand Down
2 changes: 1 addition & 1 deletion factorion-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "factorion-lib"
version = "4.2.4"
version = "4.2.5"
edition = "2024"
description = "A library used to create bots to recognize and calculate factorials and related concepts"
license = "MIT"
Expand Down
36 changes: 21 additions & 15 deletions factorion-lib/src/calculation_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,26 @@ impl Calculation {
locale: &locale::Format<'_>,
) -> Result<(), std::fmt::Error> {
let frame_start = acc.len();
acc.write_str(match (&self.value, &self.result, agressive_shorten) {
// All that
(_, _, true) => locale.all_that(),
// on the order
(_, CalculationResult::ApproximateDigitsTower(_, _, _, _), _) => locale.order(),
// digits
(_, CalculationResult::ApproximateDigits(_, _), _) => locale.digits(),
// approximately
(Number::Float(_), _, _) | (_, CalculationResult::Approximate(_, _), _) => {
locale.approx()
}
// is
_ => locale.exact(),
})?;
acc.write_str(
match (
&self.value,
&self.result,
agressive_shorten && self.steps.len() > 1,
) {
// All that
(_, _, true) => locale.all_that(),
// on the order
(_, CalculationResult::ApproximateDigitsTower(_, _, _, _), _) => locale.order(),
// digits
(_, CalculationResult::ApproximateDigits(_, _), _) => locale.digits(),
// approximately
(Number::Float(_), _, _) | (_, CalculationResult::Approximate(_, _), _) => {
locale.approx()
}
// is
_ => locale.exact(),
},
)?;
acc.write_str(" \n\n")?;

let mut number = String::new();
Expand Down Expand Up @@ -1160,7 +1166,7 @@ mod test {
let consts = Consts::default();
let fact = Calculation {
value: 0.into(),
steps: vec![(1, false)],
steps: vec![(1, false), (1, false)],
result: CalculationResult::ApproximateDigitsTower(false, false, 9.into(), 10375.into()),
};
let mut s = String::new();
Expand Down
50 changes: 26 additions & 24 deletions factorion-lib/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,27 @@ impl<Meta> CommentCalculated<Meta> {
});
}

// If the reply was too long try agressive shortening all factorials
if reply.len() + locale.bot_disclaimer().len() + 16 > self.max_length
&& !self.commands.steps
{
let note = locale.notes().tetration().clone().into_owned() + "\n\n";
reply = self
.calculation_list
.iter()
.fold(note, |mut acc, factorial| {
let _ = factorial.format(
&mut acc,
true,
true,
too_big_number,
consts,
&locale.format(),
);
acc
});
}

// Remove factorials until we can fit them in a comment
if reply.len() + locale.bot_disclaimer().len() + 16 > self.max_length {
let note = locale.notes().remove().clone().into_owned() + "\n\n";
Expand All @@ -640,7 +661,7 @@ impl<Meta> CommentCalculated<Meta> {
let _ = fact.format(
&mut res,
true,
false,
!self.commands.steps,
too_big_number,
consts,
&locale.format(),
Expand All @@ -658,33 +679,14 @@ impl<Meta> CommentCalculated<Meta> {
// remove last factorial (probably the biggest)
factorial_list.pop();
if factorial_list.is_empty() {
if self.calculation_list.len() == 1 {
let note = locale.notes().tetration().clone().into_owned() + "\n\n";
reply =
self.calculation_list
.iter()
.fold(note, |mut acc, factorial| {
let _ = factorial.format(
&mut acc,
true,
true,
too_big_number,
consts,
&locale.format(),
);
acc
});
if reply.len() <= self.max_length {
break 'drop_last;
}
}
reply = locale.notes().no_post().to_string();
break 'drop_last;
}
}
reply = factorial_list
.iter()
.fold(note, |acc, factorial| format!("{acc}{factorial}"));
reply = factorial_list.iter().fold(note, |mut acc, factorial| {
let _ = acc.write_str(&factorial);
acc
});
}
}
if !locale.bot_disclaimer().is_empty() {
Expand Down
19 changes: 19 additions & 0 deletions factorion-lib/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,25 @@ fn test_separators() {
)
}

#[test]
fn test_all_that_on_multiple_calcs() {
let consts = Consts::default();
let comment = Comment::new(
"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((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!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!^99!",
(),
Commands::NONE,
MAX_LENGTH,
"en")
.extract(&consts)
.calc(&consts);

let reply = comment.get_reply(&consts);
assert_eq!(
reply,
"That is so large, I can't even fit it in a comment with a power of 10 tower, so I'll have to use tetration!\n\nFactorial of 99 is roughly 9.332621544394415268169923885627 × 10^155 \n\nAll that of 9999999999999999999999999 has on the order of ^(613)10 digits \n\n\n*^(This action was performed by a bot | [Source code](http://f.r0.fyi))*"
)
}

#[test]
fn test_arbitrary_comment() {
let consts = Consts::default();
Expand Down