Compare commits
3 commits
58dbb425ba
...
74b0e6141a
Author | SHA1 | Date | |
---|---|---|---|
74b0e6141a | |||
ac7909da8d | |||
6a0a99c193 |
2 changed files with 26 additions and 15 deletions
|
@ -125,10 +125,9 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|||
}
|
||||
requires_rebuild = true;
|
||||
let file_name = format!(
|
||||
"{}-{}-{}-{}{}.{}",
|
||||
"{}-{}-{}{}.{}",
|
||||
i + 1,
|
||||
slugify(&author.name),
|
||||
author.discriminator,
|
||||
timestamp,
|
||||
if i == 0 {
|
||||
"".to_owned()
|
||||
|
@ -149,18 +148,11 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|||
break;
|
||||
}
|
||||
}
|
||||
let username = if author.discriminator == 0 { // new usernames
|
||||
author.name.clone()
|
||||
} else {
|
||||
format!("{}#{}", author.name, author.discriminator)
|
||||
};
|
||||
let username = author.username();
|
||||
let username = &username;
|
||||
if !existing_submitter {
|
||||
let mut submitter_data = Map::new();
|
||||
submitter_data.insert(
|
||||
String::from("username"),
|
||||
username.clone().into(),
|
||||
);
|
||||
submitter_data.insert(String::from("username"), username.clone().into());
|
||||
let mut images: Vec<String> = Vec::new();
|
||||
for (i, attachment) in attachments.iter().enumerate() {
|
||||
let extension;
|
||||
|
@ -470,7 +462,6 @@ pub async fn suggest(
|
|||
am
|
||||
});
|
||||
m.embed(|e| {
|
||||
let username = format!("{}#{}", author.name, author.discriminator);
|
||||
e.title("New suggestion");
|
||||
e.description(if let Context::Prefix(ctx) = ctx {
|
||||
format!("{suggestion}\n\n[See original message]({})", ctx.msg.link(),)
|
||||
|
@ -480,7 +471,7 @@ pub async fn suggest(
|
|||
let mut embed_author = serenity::builder::CreateEmbedAuthor::default();
|
||||
embed_author
|
||||
.icon_url(get_avatar(author))
|
||||
.name(username)
|
||||
.name(author.username())
|
||||
.url(format!("https://discord.com/users/{}", author.id));
|
||||
e.set_author(embed_author);
|
||||
if let Some(accent_color) = accent_color {
|
||||
|
|
24
src/utils.rs
24
src/utils.rs
|
@ -13,6 +13,19 @@ use std::io::Read;
|
|||
use std::io::Write;
|
||||
use std::process::Command;
|
||||
|
||||
pub trait User {
|
||||
fn username(&self) -> String;
|
||||
}
|
||||
|
||||
impl User for serenity::User {
|
||||
fn username(&self) -> String {
|
||||
if self.discriminator == 0 {
|
||||
return self.name.clone();
|
||||
}
|
||||
format!("{}#{}", self.name, self.discriminator)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_challenge_number() -> i32 {
|
||||
let challenge_dir = format!("{}/content/challenges", env::var("HUGO").unwrap());
|
||||
let paths = fs::read_dir(challenge_dir).unwrap();
|
||||
|
@ -375,7 +388,10 @@ pub async fn leaderboard(ctx: &Context<'_>) -> Result<(), Error> {
|
|||
let mut top_submitters: Vec<(&String, &u32)> = submission_counts.iter().collect();
|
||||
top_submitters.sort_by(|a, b| b.1.cmp(a.1));
|
||||
let mut leaderboard_html = String::from("<table id=\"leaderboard\">");
|
||||
for (i, (id, count)) in top_submitters[0..std::cmp::min(top_submitters.len(), 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 user = serenity::UserId(id.parse::<u64>().unwrap())
|
||||
.to_user(&ctx.serenity_context().http)
|
||||
|
@ -386,8 +402,12 @@ pub async fn leaderboard(ctx: &Context<'_>) -> Result<(), Error> {
|
|||
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}"));
|
||||
// New usernames have #0000 discriminator
|
||||
// Can't use User trait user.display_name() because of muted span
|
||||
if discriminator != 0 {
|
||||
leaderboard_html.push_str(&format!("<span class=\"muted\">#{:0>4}</span>", discriminator));
|
||||
leaderboard_html.push_str(&format!(
|
||||
"<span class=\"muted\">#{:0>4}</span>",
|
||||
discriminator
|
||||
));
|
||||
}
|
||||
leaderboard_html.push_str(&format!("</span></a></td><td>{count}</td></tr>"));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue