-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.rs
More file actions
118 lines (100 loc) · 3.27 KB
/
score.rs
File metadata and controls
118 lines (100 loc) · 3.27 KB
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
use crate::bot_types::{_Context as Context, Error};
use crate::bot_utils::{get_plus_two_received, get_top_scores, get_user_info_score};
use std::fmt::{Display, Formatter, Result as fmtResult};
/**
Struct used for displaying Information
**/
pub struct UserInfo {
pub(crate) user_name: String,
pub(crate) score: i64,
}
impl Display for UserInfo {
fn fmt(&self, f: &mut Formatter) -> fmtResult {
writeln!(f, "**{}** — **{}** ", self.user_name, self.score)
}
}
pub(crate) struct UserInfoVec(pub Vec<UserInfo>);
impl Display for UserInfoVec {
fn fmt(&self, f: &mut Formatter) -> fmtResult {
let mut comma_seperated = String::new();
for val in &self.0[0..self.0.len() - 1] {
comma_seperated.push_str(val.user_name.to_string().as_str());
comma_seperated.push_str(val.score.to_string().as_str());
comma_seperated.push_str(", ");
}
comma_seperated.push_str(&self.0[self.0.len() - 1].to_string());
write!(f, "{}", comma_seperated)
}
}
/**
Returns the Top Scoring User.
**/
#[poise::command(prefix_command)]
pub async fn top(ctx: Context<'_>) -> Result<(), Error> {
let top_scores = get_top_scores(1).await;
let mut reply_string = String::new();
for (i, value) in top_scores.0.iter().enumerate() {
reply_string.push_str(&format!("{}. {}", i + 1, value));
}
if let Err(why) = ctx.reply(reply_string).await {
println!("Error sending message: {:?}", why);
}
Ok(())
}
/**
Returns the top 10 scoring users.
**/
#[poise::command(prefix_command, aliases("board", "leaderboard", "lb"))]
pub async fn leader(ctx: Context<'_>) -> Result<(), Error> {
let top_scores = get_top_scores(10).await;
let mut reply_string = String::from("🏆 **Leaderboard** 🏆\n\n");
for (i, value) in top_scores.0.iter().enumerate() {
let place = match i {
0 => "🥇",
1 => "🥈",
2 => "🥉",
_ => "🔹",
};
reply_string.push_str(&format!(
"{} **#{}** — {} — **{}** \n",
place,
i + 1,
value.user_name,
value.score
));
}
if let Err(why) = ctx.reply(reply_string).await {
println!("Error sending message: {:?}", why);
}
Ok(())
}
/**
Returns the score of a specific user.
**/
#[poise::command(prefix_command)]
pub async fn score(ctx: Context<'_>) -> Result<(), Error> {
let msg = ctx.channel_id().message(&ctx.http(), ctx.id()).await?;
let search_user = if msg.referenced_message.is_none() {
msg.author.id
} else {
msg.referenced_message.clone().unwrap().author.id
};
let return_user = get_user_info_score(search_user.to_string().as_str()).await;
if let Err(why) = ctx.reply(return_user.to_string()).await {
println!("Error sending message: {:?}", why);
}
Ok(())
}
/**
Returns the users +2 count
**/
#[poise::command(prefix_command, aliases("balance", "bank"))]
pub async fn wallet(ctx: Context<'_>) -> Result<(), Error> {
let number_of_plus_twos = get_plus_two_received(ctx.author().id.to_string())
.await
.unwrap();
ctx.reply(format!("Current Balance: {}", number_of_plus_twos))
.await
.expect("Error: Getting current Balance.");
Ok(())
}