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 = "3.0.6"
version = "3.1.0"
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 = "6.0.6", features = ["serde", "influxdb"] }
factorion-lib = { path = "../factorion-lib", version = "7.0.0", 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 = "6.0.7"
version = "6.1.0"
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 = "6.0.6", features = ["serde", "influxdb"]}
factorion-lib = {path = "../factorion-lib", version = "7.0.0", 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.145"
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 = "6.0.6"
version = "7.0.0"
edition = "2024"
description = "A library used to create bots to recognize and calculate factorials and related concepts"
license = "MIT"
Expand Down
40 changes: 39 additions & 1 deletion factorion-lib/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub struct Status {
pub reply_would_be_too_long: bool,
pub factorials_found: bool,
pub limit_hit: bool,
pub nested_used: bool,
}

impl_all_bitwise!(Status {
Expand All @@ -93,6 +94,7 @@ impl_all_bitwise!(Status {
reply_would_be_too_long,
factorials_found,
limit_hit,
nested_used,
});
#[allow(dead_code)]
impl Status {
Expand All @@ -104,6 +106,7 @@ impl Status {
reply_would_be_too_long: false,
factorials_found: false,
limit_hit: false,
nested_used: false,
};
pub const ALREADY_REPLIED_OR_REJECTED: Self = Self {
already_replied_or_rejected: true,
Expand Down Expand Up @@ -133,6 +136,10 @@ impl Status {
limit_hit: true,
..Self::NONE
};
pub const NESTED_USED: Self = Self {
nested_used: true,
..Self::NONE
};
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default, PartialOrd, Ord)]
Expand Down Expand Up @@ -217,7 +224,10 @@ impl Commands {
steps: Self::contains_command_format(text, "steps")
|| Self::contains_command_format(text, "all"),
nested: Self::contains_command_format(text, "nest")
|| Self::contains_command_format(text, "nested"),
|| Self::contains_command_format(text, "nested")
|| Self::contains_command_format(text, "no multi")
|| Self::contains_command_format(text, "no\\_multi")
|| Self::contains_command_format(text, "no_multi"),
termial: Self::contains_command_format(text, "termial")
|| Self::contains_command_format(text, "triangle"),
no_note: Self::contains_command_format(text, "no note")
Expand Down Expand Up @@ -299,6 +309,13 @@ impl<Meta> CommentConstructed<Meta> {
(Commands::from_comment_text(comment_text) | pre_commands) & command_overrides;

let mut status: Status = Default::default();
if Commands::contains_command_format(comment_text, "nest")
|| Commands::contains_command_format(comment_text, "nested")
|| Commands::contains_command_format(comment_text, "no_nest")
|| Commands::contains_command_format(comment_text, "no\\_nest")
{
status.nested_used = true;
}

let text = if Self::might_have_factorial(comment_text) {
comment_text.to_owned()
Expand Down Expand Up @@ -695,6 +712,14 @@ impl<Meta> CommentCalculated<Meta> {
too_big_number: &Integer,
) -> bool {
let multiple = self.calculation_list.len() > 1;
if self.status.nested_used {
let _ = note.write_str(locale.notes.nested_used
.as_ref()
.map(AsRef::as_ref)
.unwrap_or("The command \"nested\" is now \"no_multi\", which is way more clear in what it means. I'll ignore the former at some point in the future.")
);
let _ = note.write_str("\n\n");
}
if !self.commands.no_note {
if self.status.limit_hit {
let _ = note.write_str(
Expand Down Expand Up @@ -933,4 +958,17 @@ mod tests {
"I can only write out numbers in english, so I will do that.\n\nFakultät von one ist one \n\n\n*^(Dieser Kommentar wurde automatisch geschrieben | [Quelltext](http://f.r0.fyi))*"
);
}

#[test]
fn test_nested_used_note() {
let consts = Consts::default();
let comment = Comment::new("n!!!!! !nested", (), Commands::NONE, MAX_LENGTH, "en")
.extract(&consts)
.calc(&consts);
let reply = comment.get_reply(&consts);
assert_eq!(
reply,
"The command \"nested\" is now \"no_multi\", which is way more clear in what it means. I'll ignore the former at some point in the future.\n\n\n*^(This action was performed by a bot | [Source code](http://f.r0.fyi))*"
);
}
}
3 changes: 2 additions & 1 deletion factorion-lib/src/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"too_big_mult": "Wenn ich die Zahlen ausschreiben würde, wäre der Kommentar zu lang. Also muss ich die wissenschaftliche Schreibweise nutzen.",
"remove": "Wenn ich alle Zahlen angeben würde, wäre der Kommentar zu lang. Also muss ich welche rausnehmen.",
"tetration": "Das ist so groß, dass selbst der Zehn-hoch-Turm nicht mehr in den Kommentar passt. Also muss ich tetrieren.",
"no_post": "Sorry, die Antwort für all das wäre einfach _zu_ lang. Ich probier lieber nicht das zu schicken lmao",
"no_post": "Sorry, die Antwort für all das wäre einfach _zu_ lang. Ich probier lieber nicht das zu schicken lmao.",
"limit_hit": "I habe mich genug wiederholt, das werde ich nicht nochmal berechnen.",
"write_out_unsupported": "Ich kann nur in Englisch Zahlen ausschreiben, also werde ich das tun.",
"nested_used": "Der Command \"nested\" ist jetzt \"no_multi\", was um einiges verständlicher ist. Ich werde ersteres irgendwann ignorieren.",
"mention": "Hey {mention}!"
},
"format": {
Expand Down
1 change: 1 addition & 0 deletions factorion-lib/src/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"no_post": "Sorry, but the reply text for all those numbers would be _really_ long, so I'd rather not even try posting lmao",
"limit_hit": "I have repeated myself enough, I won't do that calculation again.",
"write_out_unsupported": "I can only write out numbers in english, so I will do that.",
"nested_used": "The command \"nested\" is now \"no_multi\", which is way more clear in what it means. I'll ignore the former at some point in the future.",
"mention": "Hey {mention}!"
},
"format": {
Expand Down
1 change: 1 addition & 0 deletions factorion-lib/src/en_fuck.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"no_post": "Sorry, but the reply text for all those numbers would be _really_ fucking long, so I'd rather not even try posting lmao",
"limit_hit": "I have repeated myself enough, I won't do that fucking calculation again.",
"write_out_unsupported": "I can only write out numbers in english, so I will do that.",
"nested_used": "The command \"nested\" is now \"no_multi\", which is way more fucking clear in what it means. I won't give a fuck about the former at some point in the future.",
"mention": "Hey {mention}!"
},
"format": {
Expand Down
27 changes: 24 additions & 3 deletions factorion-lib/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,27 @@ pub fn get_all() -> impl Iterator<Item = (&'static str, Locale<'static>)> {
.into_iter()
}

#[derive(Debug, Clone)]
/// Represents the whole locale.
/// Create by deserializing or intializing as a Struct, sperading with default.
///
/// Note regarding non_exhaustive: Additions will always be Option and will so default to None, causing a sensible fallback.
/// (also not break serialization format in many cases like json)
///
/// Note on Default: It is derived, so any strings will be empty and booleans will be false. So all non-option fields should be overridden/supplied.
///
/// For further information about the fields (as json serialization), read [../Locales.md]
#[derive(Debug, Clone, Default)]
#[cfg_attr(any(feature = "serde", test), derive(Serialize, Deserialize))]
#[non_exhaustive]
pub struct Locale<'a> {
pub bot_disclaimer: Cow<'a, str>,
pub notes: Notes<'a>,
pub format: Format<'a>,
}
#[derive(Debug, Clone)]

#[derive(Debug, Clone, Default)]
#[cfg_attr(any(feature = "serde", test), derive(Serialize, Deserialize))]
#[non_exhaustive]
pub struct Notes<'a> {
pub tower: Cow<'a, str>,
pub tower_mult: Cow<'a, str>,
Expand All @@ -72,10 +84,12 @@ pub struct Notes<'a> {
pub mention: Cow<'a, str>,
pub limit_hit: Option<Cow<'a, str>>,
pub write_out_unsupported: Option<Cow<'a, str>>,
pub nested_used: Option<Cow<'a, str>>,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
#[cfg_attr(any(feature = "serde", test), derive(Serialize, Deserialize))]
#[non_exhaustive]
pub struct Format<'a> {
pub capitalize_calc: bool,
pub termial: Cow<'a, str>,
Expand All @@ -98,6 +112,13 @@ pub struct Format<'a> {

#[derive(Debug, Clone)]
#[cfg_attr(any(feature = "serde", test), derive(Serialize, Deserialize))]
#[non_exhaustive]
pub struct NumFormat {
pub decimal: char,
}

impl Default for NumFormat {
fn default() -> Self {
NumFormat { decimal: '.' }
}
}
4 changes: 2 additions & 2 deletions factorion-lib/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ full_reply_tests!(
"Termial of 2 is 3 \n\n\n*^(This action was performed by a bot | [Source code](http://f.r0.fyi))*",
),
test_command_nest: (
"9!!!!?? !nest",
"9!!!!?? !no_multi",
Commands::TERMIAL,
"en",
"That is so large, that I can't even give the number of digits of it, so I have to make a power of ten tower.\n\nTermial of termial of factorial of factorial of factorial of factorial of 9 has on the order of 10^(2.993960567614282167996111938338 × 10^1859939) digits \n\n\n*^(This action was performed by a bot | [Source code](http://f.r0.fyi))*",
Expand All @@ -685,7 +685,7 @@ full_reply_tests!(
"Factorial of 10939742352358 is approximately 4.451909479489793754826968519779 × 10^137892308399887 \n\n\n*^(This action was performed by a bot | [Source code](http://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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!no_multi ",
Commands::NONE,
"en",
"All that of 9 has on the order of ^(628)10 digits \n\n\n*^(This action was performed by a bot | [Source code](http://f.r0.fyi))*",
Expand Down
Loading