Compare commits
3 commits
1dfa68452b
...
5e6bb8f2d0
Author | SHA1 | Date | |
---|---|---|---|
5e6bb8f2d0 | |||
31adf7efe8 | |||
ab30279375 |
2 changed files with 19 additions and 6 deletions
|
@ -149,11 +149,17 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let username = if author.discriminator == 0 { // new usernames
|
||||||
|
author.name.clone()
|
||||||
|
} else {
|
||||||
|
format!("{}#{}", author.name, author.discriminator)
|
||||||
|
};
|
||||||
|
let username = &username;
|
||||||
if !existing_submitter {
|
if !existing_submitter {
|
||||||
let mut submitter_data = Map::new();
|
let mut submitter_data = Map::new();
|
||||||
submitter_data.insert(
|
submitter_data.insert(
|
||||||
String::from("username"),
|
String::from("username"),
|
||||||
format!("{}#{}", author.name, author.discriminator).into(),
|
username.clone().into(),
|
||||||
);
|
);
|
||||||
let mut images: Vec<String> = Vec::new();
|
let mut images: Vec<String> = Vec::new();
|
||||||
for (i, attachment) in attachments.iter().enumerate() {
|
for (i, attachment) in attachments.iter().enumerate() {
|
||||||
|
@ -173,10 +179,9 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
||||||
}
|
}
|
||||||
requires_rebuild = true;
|
requires_rebuild = true;
|
||||||
let file_name = format!(
|
let file_name = format!(
|
||||||
"{}-{}-{}-{}{}.{}",
|
"{}-{}-{}{}.{}",
|
||||||
submission_data.len() + 1,
|
submission_data.len() + 1,
|
||||||
slugify(&author.name),
|
slugify(&author.name),
|
||||||
author.discriminator,
|
|
||||||
timestamp,
|
timestamp,
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
"".to_owned()
|
"".to_owned()
|
||||||
|
@ -256,7 +261,6 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
||||||
channel
|
channel
|
||||||
.send_message(&ctx.serenity_context().http, |m| {
|
.send_message(&ctx.serenity_context().http, |m| {
|
||||||
m.embed(|e| {
|
m.embed(|e| {
|
||||||
let username = format!("{}#{}", author.name, author.discriminator);
|
|
||||||
let domain = get_domain();
|
let domain = get_domain();
|
||||||
let n = get_challenge_number();
|
let n = get_challenge_number();
|
||||||
let mut description = format!(
|
let mut description = format!(
|
||||||
|
|
13
src/utils.rs
13
src/utils.rs
|
@ -67,6 +67,10 @@ pub fn get_submission_data(challenge: i32) -> Vec<Value> {
|
||||||
json
|
json
|
||||||
}
|
}
|
||||||
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => {
|
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => {
|
||||||
|
// Create parent directory if not exists
|
||||||
|
if let Some(parent_dir) = std::path::Path::new(&submission_data_path).parent() {
|
||||||
|
fs::create_dir_all(parent_dir).unwrap();
|
||||||
|
}
|
||||||
let mut file = File::create(&submission_data_path).unwrap();
|
let mut file = File::create(&submission_data_path).unwrap();
|
||||||
file.write_all(b"[]").unwrap();
|
file.write_all(b"[]").unwrap();
|
||||||
file.flush().unwrap();
|
file.flush().unwrap();
|
||||||
|
@ -371,7 +375,7 @@ pub async fn leaderboard(ctx: &Context<'_>) -> Result<(), Error> {
|
||||||
let mut top_submitters: Vec<(&String, &u32)> = submission_counts.iter().collect();
|
let mut top_submitters: Vec<(&String, &u32)> = submission_counts.iter().collect();
|
||||||
top_submitters.sort_by(|a, b| b.1.cmp(a.1));
|
top_submitters.sort_by(|a, b| b.1.cmp(a.1));
|
||||||
let mut leaderboard_html = String::from("<table id=\"leaderboard\">");
|
let mut leaderboard_html = String::from("<table id=\"leaderboard\">");
|
||||||
for (i, (id, count)) in top_submitters[0..LENGTH].iter().enumerate() {
|
for (i, (id, count)) in top_submitters[0..std::cmp::min(top_submitters.len(), LENGTH)].iter().enumerate() {
|
||||||
let place = i + 1;
|
let place = i + 1;
|
||||||
let user = serenity::UserId(id.parse::<u64>().unwrap())
|
let user = serenity::UserId(id.parse::<u64>().unwrap())
|
||||||
.to_user(&ctx.serenity_context().http)
|
.to_user(&ctx.serenity_context().http)
|
||||||
|
@ -380,7 +384,12 @@ pub async fn leaderboard(ctx: &Context<'_>) -> Result<(), Error> {
|
||||||
let profile = format!("https://discord.com/users/{id}");
|
let profile = format!("https://discord.com/users/{id}");
|
||||||
let name = &user.name;
|
let name = &user.name;
|
||||||
let discriminator = user.discriminator;
|
let discriminator = user.discriminator;
|
||||||
leaderboard_html.push_str(&format!("<tr><td>{place}</td><td><a href=\"{profile}\" target=\"_blank\" class=\"no-underline\"><img src=\"{avatar}\" onerror=\"this.src='/default.png'\"> <span class=\"underline\">{name}<span class=\"muted\">#{:0>4}</span></span></a></td><td>{count}</td></tr>", discriminator));
|
leaderboard_html.push_str(&format!("<tr><td>{place}</td><td><a href=\"{profile}\" target=\"_blank\" class=\"no-underline\"><img src=\"{avatar}\" onerror=\"this.src='/default.png'\"> <span class=\"underline\">{name}"));
|
||||||
|
// New usernames have #0000 discriminator
|
||||||
|
if discriminator != 0 {
|
||||||
|
leaderboard_html.push_str(&format!("<span class=\"muted\">#{:0>4}</span>", discriminator));
|
||||||
|
}
|
||||||
|
leaderboard_html.push_str(&format!("</span></a></td><td>{count}</td></tr>"));
|
||||||
}
|
}
|
||||||
leaderboard_html.push_str("</table>");
|
leaderboard_html.push_str("</table>");
|
||||||
let mut file = std::fs::OpenOptions::new()
|
let mut file = std::fs::OpenOptions::new()
|
||||||
|
|
Loading…
Add table
Reference in a new issue