Skip to content

Commit c810038

Browse files
authored
Merge pull request #330 from Aras14HD/simplify-locale
2 parents 648012f + 9ec2e8a commit c810038

File tree

21 files changed

+626
-934
lines changed

21 files changed

+626
-934
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

factorion-bot-discord/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "factorion-bot-discord"
3-
version = "2.5.2"
3+
version = "3.0.0"
44
edition = "2024"
55
description = "factorion-bot (for factorials and related) on Discord"
66
license = "MIT"
@@ -10,7 +10,7 @@ keywords = ["factorial", "termial", "bot", "math", "discord"]
1010
categories = ["mathematics", "web-programming", "parser-implementations"]
1111

1212
[dependencies]
13-
factorion-lib = { path = "../factorion-lib", version = "5.0.2", features = ["serde", "influxdb"] }
13+
factorion-lib = { path = "../factorion-lib", version = "6.0.0", features = ["serde", "influxdb"] }
1414
serenity = { version = "0.12", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] }
1515
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "time"] }
1616
dotenvy = "^0.15.7"

factorion-bot-discord/src/discord_api.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'a> Handler<'a> {
146146
let extract_end = SystemTime::now();
147147

148148
factorion_lib::influxdb::discord::log_time_consumed(
149-
&self.influx_client,
149+
self.influx_client,
150150
extract_start,
151151
extract_end,
152152
"extract_factorials",
@@ -163,7 +163,7 @@ impl<'a> Handler<'a> {
163163
let calc_end = SystemTime::now();
164164

165165
factorion_lib::influxdb::discord::log_time_consumed(
166-
&self.influx_client,
166+
self.influx_client,
167167
calc_start,
168168
calc_end,
169169
"calculate_factorials",
@@ -208,7 +208,7 @@ impl<'a> Handler<'a> {
208208

209209
// Log the reply to InfluxDB
210210
factorion_lib::influxdb::discord::log_message_reply(
211-
&self.influx_client,
211+
self.influx_client,
212212
&msg.id.to_string(),
213213
&msg.author.name,
214214
&msg.channel_id.to_string(),
@@ -220,7 +220,7 @@ impl<'a> Handler<'a> {
220220

221221
let end = SystemTime::now();
222222
factorion_lib::influxdb::discord::log_time_consumed(
223-
&self.influx_client,
223+
self.influx_client,
224224
start,
225225
end,
226226
"process_message",

factorion-bot-discord/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
9494
std::fs::read_to_string(file.path()).unwrap().leak(),
9595
)
9696
.unwrap();
97-
locale.set_bot_disclaimer("".into());
97+
locale.bot_disclaimer = "".into();
9898
(file.file_name().into_string().unwrap(), locale)
9999
})
100100
.collect::<Box<_>>()
@@ -106,7 +106,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
106106
.unwrap_or_else(|_| {
107107
factorion_lib::locale::get_all()
108108
.map(|(k, mut v)| {
109-
v.set_bot_disclaimer("".into());
109+
v.bot_disclaimer = "".into();
110110
(k.to_owned(), v)
111111
})
112112
.collect()
@@ -124,7 +124,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
124124
info!("InfluxDB client configured. Metrics will be logged.");
125125
}
126126

127-
discord_api::start_bot(token, consts, &*INFLUX_CLIENT).await?;
127+
discord_api::start_bot(token, consts, &INFLUX_CLIENT).await?;
128128

129129
Ok(())
130130
}

factorion-bot-reddit/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "factorion-bot-reddit"
3-
version = "5.6.2"
3+
version = "6.0.0"
44
edition = "2024"
55
description = "factorion-bot (for factorials and related) on Reddit"
66
license = "MIT"
@@ -10,7 +10,7 @@ keywords = ["factorial", "termial", "bot", "math"]
1010
categories = ["mathematics", "web-programming", "parser-implementations"]
1111

1212
[dependencies]
13-
factorion-lib = {path = "../factorion-lib", version = "5.0.2", features = ["serde", "influxdb"]}
13+
factorion-lib = {path = "../factorion-lib", version = "6.0.0", features = ["serde", "influxdb"]}
1414
reqwest = { version = "0.12.28", features = ["json", "native-tls"], default-features = false }
1515
serde = { version = "1.0.219", default-features = false, features = ["derive"] }
1616
serde_json = "1.0.140"

factorion-bot-reddit/src/main.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,13 @@ fn en_str() -> &'static str {
4646
"en"
4747
}
4848

49-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
49+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default)]
5050
enum SubredditMode {
5151
All,
5252
PostOnly,
53+
#[default]
5354
None,
5455
}
55-
impl Default for SubredditMode {
56-
fn default() -> Self {
57-
Self::None
58-
}
59-
}
6056

6157
#[tokio::main]
6258
async fn main() -> Result<(), Box<dyn Error>> {
@@ -135,7 +131,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
135131
let dont_reply = dont_reply == "true";
136132

137133
let sub_entries = if let Ok(path) = std::env::var("SUBREDDITS_FILE") {
138-
if let Ok(_) = std::env::var("SUBREDDITS") {
134+
if std::env::var("SUBREDDITS").is_ok() {
139135
panic!("SUBREDDITS and SUBREDDITS_FILE can not be set simultaneusly!")
140136
}
141137
let text = std::fs::read_to_string(path).unwrap();
@@ -277,7 +273,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
277273
continue;
278274
}
279275
let Ok(mut dense_id) = u64::from_str_radix(&comment.meta.thread, 36) else {
280-
if comment.meta.thread == "" {
276+
if comment.meta.thread.is_empty() {
281277
info!("Empty thread id on comment {}", comment.meta.id);
282278
} else {
283279
warn!("Failed to make id dense {}", comment.meta.thread);
@@ -421,10 +417,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
421417
}
422418
factorion_lib::influxdb::reddit::log_comment_reply(
423419
influx_client,
424-
&comment_id,
425-
&comment_author,
426-
&comment_subreddit,
427-
&comment_locale,
420+
comment_id,
421+
comment_author,
422+
comment_subreddit,
423+
comment_locale,
428424
)
429425
.await?;
430426
}

factorion-bot-reddit/src/reddit_api.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl RedditClient {
268268

269269
reset_timer = Self::update_reset_timer(reset_timer, t);
270270

271-
if last_ids.mentions != ""
271+
if !last_ids.mentions.is_empty()
272272
&& a.len()
273273
== *COMMENT_COUNT.get().expect("Comment count uninitialized") as usize
274274
{
@@ -296,7 +296,7 @@ impl RedditClient {
296296

297297
reset_timer = Self::update_reset_timer(reset_timer, t);
298298

299-
if last_ids.comments != ""
299+
if !last_ids.comments.is_empty()
300300
&& a.len()
301301
== *COMMENT_COUNT.get().expect("Comment count uninitialized") as usize
302302
{
@@ -324,7 +324,7 @@ impl RedditClient {
324324

325325
reset_timer = Self::update_reset_timer(reset_timer, t);
326326

327-
if last_ids.posts != ""
327+
if !last_ids.posts.is_empty()
328328
&& posts.len()
329329
== *COMMENT_COUNT.get().expect("Comment count uninitialized") as usize
330330
{
@@ -859,7 +859,7 @@ impl RedditClient {
859859
error!("Failed to construct comment {comment_id}!");
860860
return None;
861861
};
862-
comment.meta.used_commands = !(comment.commands == pre_commands);
862+
comment.meta.used_commands = (comment.commands != pre_commands);
863863
if let Some((mention, commands, mention_author)) = mention_map.get(comment_id) {
864864
comment.meta.id = mention.clone();
865865
comment.commands = *commands;

factorion-lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "factorion-lib"
3-
version = "5.0.2"
3+
version = "6.0.0"
44
edition = "2024"
55
description = "A library used to create bots to recognize and calculate factorials and related concepts"
66
license = "MIT"

factorion-lib/Locales.md

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -10,80 +10,80 @@ Locales contain a few different kinds of settings:
1010
- Toggles: on is true, off is false
1111
- Map, a list of key value pairs for certain settings, used for overrides
1212

13-
## V1
13+
## Example
1414
```jsonc
1515
// Version number
16-
{ "V1":
17-
{
18-
// The little disclaimer at the end of a comment
19-
"bot_disclaimer": "This action was performed by a bot | [Source code](http://f.r0.fyi)",
20-
// The notes at the beginning of a comment
21-
"notes": {
22-
"tower": "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.",
23-
"tower_mult": "Some of these are so large, that I can't even give the number of digits of them, so I have to make a power of ten tower.",
24-
"digits": "That number is so large, that I can't even approximate it well, so I can only give you an approximation on the number of digits.",
25-
"digits_mult": "Some of these are so large, that I can't even approximate them well, so I can only give you an approximation on the number of digits.",
26-
"approx": "That is so large, that I can't calculate it, so I'll have to approximate.",
27-
"approx_mult": "Some of those are so large, that I can't calculate them, so I'll have to approximate.",
28-
"round": "I can't calculate such a large factorial of decimals. So I had to round at some point.",
29-
"round_mult": "I can't calculate that large factorials of decimals. So I had to round at some point.",
30-
"too_big": "If I post the whole number, the comment would get too long. So I had to turn it into scientific notation.",
31-
"too_big_mult": "If I post the whole numbers, the comment would get too long. So I had to turn them into scientific notation.",
32-
"remove": "If I posted all numbers, the comment would get too long. So I had to remove some of them.",
33-
"tetration": "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!",
34-
"no_post": "Sorry, but the reply text for all those numbers would be _really_ long, so I'd rather not even try posting lmao",
35-
// How to call out to a user (when mentioning them). "{mention}" is replaced by the user string formatted as a mention
36-
"mention": "Hey {mention}!"
16+
{
17+
// The little disclaimer at the end of a comment
18+
"bot_disclaimer": "This action was performed by a bot | [Source code](http://f.r0.fyi)",
19+
// The notes at the beginning of a comment
20+
"notes": {
21+
"tower": "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.",
22+
"tower_mult": "Some of these are so large, that I can't even give the number of digits of them, so I have to make a power of ten tower.",
23+
"digits": "That number is so large, that I can't even approximate it well, so I can only give you an approximation on the number of digits.",
24+
"digits_mult": "Some of these are so large, that I can't even approximate them well, so I can only give you an approximation on the number of digits.",
25+
"approx": "That is so large, that I can't calculate it, so I'll have to approximate.",
26+
"approx_mult": "Some of those are so large, that I can't calculate them, so I'll have to approximate.",
27+
"round": "I can't calculate such a large factorial of decimals. So I had to round at some point.",
28+
"round_mult": "I can't calculate that large factorials of decimals. So I had to round at some point.",
29+
"too_big": "If I post the whole number, the comment would get too long. So I had to turn it into scientific notation.",
30+
"too_big_mult": "If I post the whole numbers, the comment would get too long. So I had to turn them into scientific notation.",
31+
"remove": "If I posted all numbers, the comment would get too long. So I had to remove some of them.",
32+
"tetration": "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!",
33+
"no_post": "Sorry, but the reply text for all those numbers would be _really_ long, so I'd rather not even try posting lmao",
34+
"limit_hit": "I have repeated myself enough, I won't do that calculation again.",
35+
"write_out_unsupported": "I can only write out numbers in english, so I will do that.",
36+
// How to call out to a user (when mentioning them). "{mention}" is replaced by the user string formatted as a mention
37+
"mention": "Hey {mention}!"
38+
},
39+
// Formatting calculations
40+
"format": {
41+
// Formatting numbers
42+
"number_format": {
43+
// The number decimal separator (also used when parsing). Must be a single character
44+
"decimal": "."
3745
},
38-
// Formatting calculations
39-
"format": {
40-
// Formatting numbers
41-
"number_format": {
42-
// The number decimal separator (also used when parsing). Must be a single character
43-
"decimal": "."
44-
},
45-
// Whether to capitalize the start of the calculation word (sub, uple, termial or factorial) (ASCII only)
46-
"capitalize_calc": false,
47-
"termial": "termial",
48-
"factorial": "factorial",
49-
// What to call tuples. "{factorial}" is replaced by termial or factorial
50-
"uple": "uple-{factorial}",
51-
// What to call a subfactorial. "{factorial}" is replaced by termial (not currently) or factorial
52-
"sub": "sub{factorial}",
53-
// How to call a negative calculation. "{factorial}" is replaced by sub, uple, termial or factorial
54-
"negative": "negative {factorial}",
55-
// Overrides for individual tuples. "{factorial}" is replaced by termial or factorial
56-
"num_overrides": {
57-
"2": "double-{factorial}",
58-
"3": "triple-{factorial}"
59-
},
60-
// Turn off automatic tuple names (use overrides and numbers)
61-
"force_num": false,
62-
// How to write nested factorials. "{factorial}" is replaced by the outer calculation, "{next}" by the inner (both being negative, sub, uple, termial or factorial)
63-
"nest": "{factorial} of {next}",
64-
// How to write a calculation with an exact result. "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
65-
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
66-
"exact": "{factorial} of {number} is {result}",
67-
// How to write a calculation with a shortened result. "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
68-
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
69-
"rough": "{factorial} of {number} is roughly {result}",
70-
// How to write a calculation with an approximate result. "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
71-
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
72-
"approx": "{factorial} of {number} is approximately {result}",
73-
// How to write a calculation with a result given in approximate number of digits. "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
74-
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
75-
"digits": "{factorial} of {number} has approximately {result} digits",
76-
// How to write a calculation with a result given in a power-of-ten tower number of digits.
77-
// "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
78-
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
79-
"order": "{factorial} of {number} has on the order of {result} digits",
80-
// How to write a calculation with a result given in tetration of ten number of digits, and no calculation steps.
81-
// "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
82-
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
83-
"all_that": "All that of {number} has on the order of {result} digits",
84-
// How to write a shortened number. "{number}" is replaced by the input to the calculation
85-
"rough_number": "roughly {number}"
86-
}
46+
// Whether to capitalize the start of the calculation word (sub, uple, termial or factorial) (ASCII only)
47+
"capitalize_calc": false,
48+
"termial": "termial",
49+
"factorial": "factorial",
50+
// What to call tuples. "{factorial}" is replaced by termial or factorial
51+
"uple": "uple-{factorial}",
52+
// What to call a subfactorial. "{factorial}" is replaced by termial (not currently) or factorial
53+
"sub": "sub{factorial}",
54+
// How to call a negative calculation. "{factorial}" is replaced by sub, uple, termial or factorial
55+
"negative": "negative {factorial}",
56+
// Overrides for individual tuples. "{factorial}" is replaced by termial or factorial
57+
"num_overrides": {
58+
"2": "double-{factorial}",
59+
"3": "triple-{factorial}"
60+
},
61+
// Turn off automatic tuple names (use overrides and numbers)
62+
"force_num": false,
63+
// How to write nested factorials. "{factorial}" is replaced by the outer calculation, "{next}" by the inner (both being negative, sub, uple, termial or factorial)
64+
"nest": "{factorial} of {next}",
65+
// How to write a calculation with an exact result. "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
66+
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
67+
"exact": "{factorial} of {number} is {result}",
68+
// How to write a calculation with a shortened result. "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
69+
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
70+
"rough": "{factorial} of {number} is roughly {result}",
71+
// How to write a calculation with an approximate result. "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
72+
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
73+
"approx": "{factorial} of {number} is approximately {result}",
74+
// How to write a calculation with a result given in approximate number of digits. "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
75+
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
76+
"digits": "{factorial} of {number} has approximately {result} digits",
77+
// How to write a calculation with a result given in a power-of-ten tower number of digits.
78+
// "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
79+
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
80+
"order": "{factorial} of {number} has on the order of {result} digits",
81+
// How to write a calculation with a result given in tetration of ten number of digits, and no calculation steps.
82+
// "{factorial}" is replaced by nest, negative, sub, uple, termial or factorial,
83+
// "{number}" by the input to the calculation or rough_number and "{result}" by the result
84+
"all_that": "All that of {number} has on the order of {result} digits",
85+
// How to write a shortened number. "{number}" is replaced by the input to the calculation
86+
"rough_number": "roughly {number}"
8787
}
8888
}
8989
```

0 commit comments

Comments
 (0)