diff --git a/Cargo.lock b/Cargo.lock
index 1881ab1..0c49f32 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -399,7 +399,7 @@ dependencies = [
[[package]]
name = "factorion-bot-discord"
-version = "2.2.4"
+version = "2.2.5"
dependencies = [
"anyhow",
"dotenvy",
@@ -414,7 +414,7 @@ dependencies = [
[[package]]
name = "factorion-bot-reddit"
-version = "5.3.4"
+version = "5.3.5"
dependencies = [
"anyhow",
"base64 0.22.1",
@@ -434,7 +434,7 @@ dependencies = [
[[package]]
name = "factorion-lib"
-version = "4.2.4"
+version = "4.2.5"
dependencies = [
"arbtest",
"chrono",
diff --git a/factorion-bot-discord/Cargo.toml b/factorion-bot-discord/Cargo.toml
index 6bbf6d9..9543ab1 100644
--- a/factorion-bot-discord/Cargo.toml
+++ b/factorion-bot-discord/Cargo.toml
@@ -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"
@@ -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"
diff --git a/factorion-bot-reddit/Cargo.toml b/factorion-bot-reddit/Cargo.toml
index 95ce976..1930c21 100644
--- a/factorion-bot-reddit/Cargo.toml
+++ b/factorion-bot-reddit/Cargo.toml
@@ -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"
@@ -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"
diff --git a/factorion-lib/Cargo.toml b/factorion-lib/Cargo.toml
index 0c4e76f..d17ed7f 100644
--- a/factorion-lib/Cargo.toml
+++ b/factorion-lib/Cargo.toml
@@ -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"
diff --git a/factorion-lib/src/calculation_results.rs b/factorion-lib/src/calculation_results.rs
index 85ee49c..7702771 100644
--- a/factorion-lib/src/calculation_results.rs
+++ b/factorion-lib/src/calculation_results.rs
@@ -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();
@@ -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();
diff --git a/factorion-lib/src/comment.rs b/factorion-lib/src/comment.rs
index 13d3122..e3227a7 100644
--- a/factorion-lib/src/comment.rs
+++ b/factorion-lib/src/comment.rs
@@ -629,6 +629,27 @@ impl CommentCalculated {
});
}
+ // 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";
@@ -640,7 +661,7 @@ impl CommentCalculated {
let _ = fact.format(
&mut res,
true,
- false,
+ !self.commands.steps,
too_big_number,
consts,
&locale.format(),
@@ -658,33 +679,14 @@ impl CommentCalculated {
// 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() {
diff --git a/factorion-lib/tests/integration.rs b/factorion-lib/tests/integration.rs
index e6bba3d..6642b4a 100644
--- a/factorion-lib/tests/integration.rs
+++ b/factorion-lib/tests/integration.rs
@@ -1713,6 +1713,25 @@ fn test_separators() {
)
}
+#[test]
+fn test_all_that_on_multiple_calcs() {
+ let consts = Consts::default();
+ let comment = Comment::new(
+ "(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((9999999999999999999999999!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!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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();