1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use super::dependencies::*;
pub struct Text(pub Locale);
impl Text {
fn data(&self) -> &ParsedData { self.0.get_data() }
pub fn alphabet(&self, lower_case: bool) -> &Vec<String> {
match lower_case {
true => &self.data().text.alphabet.lowercase,
false => &self.data().text.alphabet.uppercase,
}
}
pub fn level(&self) -> &str {
get_random_element(self.data().text.level.iter())
}
pub fn text(&self, quantity: usize) -> String {
get_random_elements(self.data().text.text.iter(), quantity)
.iter().join(" ")
}
pub fn sentence(&self) -> String {
self.text(1)
}
pub fn title(&self) -> String {
self.text(1)
}
pub fn words(&self, quantity: usize) -> Vec<&String> {
get_random_elements(self.data().text.words.normal.iter(), quantity)
}
pub fn word(&self) -> &str {
self.words(1).first().unwrap()
}
pub fn swear_word(&self) -> &str {
get_random_element(self.data().text.words.bad.iter())
}
pub fn quote(&self) -> &str {
get_random_element(self.data().text.quotes.iter())
}
pub fn answer(&self) -> &str {
get_random_element(self.data().text.answers.iter())
}
pub fn color(&self) -> &str {
get_random_element(self.data().text.color.iter())
}
pub fn hex_color(safe: bool) -> String {
match safe {
true => get_random_element(SAFE_COLORS.iter()).to_string(),
false => format!("#{:#06x}", randint(0x000000, 0xFFFFFF)),
}
}
pub fn rgb_color(safe: bool) -> (u8, u8, u8) {
let color = Self::hex_color(safe).replacen("#", "", 1);
(
u8::from_str_radix(&color[0..2], 16).expect("Cant convert RGB hex to u8 tuple!"),
u8::from_str_radix(&color[2..4], 16).expect("Cant convert RGB hex to u8 tuple!"),
u8::from_str_radix(&color[4..6], 16).expect("Cant convert RGB hex to u8 tuple!"),
)
}
}