Compare commits

...

9 Commits

@ -1,3 +1,4 @@
DOMAIN=tegakituesday.com
DISCORD_TOKEN= DISCORD_TOKEN=
PREFIX="-h " PREFIX="-h "
HUGO=/path/to/hugo HUGO=/path/to/hugo

@ -0,0 +1 @@
use nix

834
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -15,7 +15,7 @@ reqwest = "0.11"
slug = "0.1" slug = "0.1"
unicode_hfwidth = "0.2" unicode_hfwidth = "0.2"
fs_extra = "1.2" fs_extra = "1.2"
poise = "0.4" poise = "0.5.5"
[dependencies.tokio] [dependencies.tokio]
version = "1.0" version = "1.0"

@ -0,0 +1,21 @@
# <shell.nix>
{ pkgs ? import <nixpkgs> {}}:
let
rust_overlay = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz");
pkgs = import <nixpkgs> { overlays = [ rust_overlay ]; };
ruststable = (pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
];
});
in
pkgs.mkShell {
buildInputs = with pkgs; [
ruststable
rust-analyzer
bacon
pkg-config
openssl
];
}

@ -2,8 +2,8 @@ use crate::utils::*;
use serde_json::Map; use serde_json::Map;
use crate::serenity; use crate::serenity;
use crate::Error;
use crate::Context; use crate::Context;
use crate::Error;
use poise::command; use poise::command;
use slug::slugify; use slug::slugify;
@ -20,7 +20,8 @@ use std::path::Path;
)] )]
pub async fn challenge(ctx: Context<'_>) -> Result<(), Error> { pub async fn challenge(ctx: Context<'_>) -> Result<(), Error> {
ctx.say(format!( ctx.say(format!(
"Tegaki Tuesday #{n}: <https://tegakituesday.com/{n}>", "Tegaki Tuesday #{n}: <https://{domain}/{n}>",
domain = get_domain(),
n = get_challenge_number() n = get_challenge_number()
)) ))
.await?; .await?;
@ -40,9 +41,12 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
match ctx { match ctx {
Context::Application(_) => ctx.defer_ephemeral().await?, Context::Application(_) => ctx.defer_ephemeral().await?,
Context::Prefix(ctx) => { Context::Prefix(ctx) => {
if ctx.msg.attachments.len() == 0 { if ctx.msg.attachments.is_empty() {
ctx.msg ctx.msg
.reply(&ctx.discord.http, "Please attach at least one image.") .reply(
&ctx.serenity_context.http,
"Please attach at least one image.",
)
.await?; .await?;
return Ok(()); return Ok(());
} }
@ -74,7 +78,10 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
let challenge_number = get_challenge_number(); let challenge_number = get_challenge_number();
let submission_images_dir = get_submission_images_dir(); let submission_images_dir = get_submission_images_dir();
let timestamp = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_millis(); let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_millis();
// Ensure that submission_images_dir exists // Ensure that submission_images_dir exists
let path = Path::new(&submission_images_dir); let path = Path::new(&submission_images_dir);
@ -92,9 +99,15 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
let author = ctx.author(); let author = ctx.author();
let mut submitted_images = Vec::new(); let mut submitted_images = Vec::new();
for submission in submission_data.iter_mut() { for submission in submission_data.iter_mut() {
if is_matching_submission(&submission, author) { if is_matching_submission(submission, author) {
existing_submitter = true; existing_submitter = true;
let mut images: Vec<String> = submission["images"].as_array_mut().unwrap().clone().iter().map(|value| value.as_str().unwrap().to_owned()).collect(); let mut images: Vec<String> = submission["images"]
.as_array_mut()
.unwrap()
.clone()
.iter()
.map(|value| value.as_str().unwrap().to_owned())
.collect();
for (i, attachment) in attachments.iter().enumerate() { for (i, attachment) in attachments.iter().enumerate() {
let extension; let extension;
if let Some(content_type) = &attachment.content_type { if let Some(content_type) = &attachment.content_type {
@ -117,10 +130,14 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
slugify(&author.name), slugify(&author.name),
author.discriminator, author.discriminator,
timestamp, timestamp,
if i == 0 { "".to_owned() } else { format!("-{}", i + 1) }, if i == 0 {
"".to_owned()
} else {
format!("-{}", i + 1)
},
extension extension
); );
images.push(file_name.clone().into()); images.push(file_name.clone());
let image = reqwest::get(&attachment.url).await?.bytes().await?; let image = reqwest::get(&attachment.url).await?.bytes().await?;
let mut image_file = let mut image_file =
File::create(format!("{}/{}", submission_images_dir, file_name))?; File::create(format!("{}/{}", submission_images_dir, file_name))?;
@ -161,10 +178,14 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
slugify(&author.name), slugify(&author.name),
author.discriminator, author.discriminator,
timestamp, timestamp,
if i == 0 { "".to_owned() } else { format!("-{}", i + 1) }, if i == 0 {
"".to_owned()
} else {
format!("-{}", i + 1)
},
extension extension
); );
images.push(file_name.clone().into()); images.push(file_name.clone());
let image = reqwest::get(&attachment.url).await?.bytes().await?; let image = reqwest::get(&attachment.url).await?.bytes().await?;
let mut image_file = File::create(format!("{}/{}", submission_images_dir, file_name))?; let mut image_file = File::create(format!("{}/{}", submission_images_dir, file_name))?;
image_file.write_all(&image)?; image_file.write_all(&image)?;
@ -178,11 +199,15 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
set_submission_data(submission_data); set_submission_data(submission_data);
let mut message = String::new(); let mut message = String::new();
if requires_rebuild { if requires_rebuild {
let thank_you = &format!("Thank you for submitting! You can view your submission at <https://tegakituesday.com/{}>", challenge_number); let thank_you = &format!(
"Thank you for submitting! You can view your submission at <https://{domain}/{}>",
challenge_number,
domain = get_domain()
);
let mut repost_here = true; let mut repost_here = true;
match ctx { match ctx {
Context::Application(_) => message.push_str(thank_you), Context::Application(_) => message.push_str(thank_you),
Context::Prefix(ctx) => match ctx.msg.delete(&ctx.discord.http).await { Context::Prefix(ctx) => match ctx.msg.delete(&ctx.serenity_context.http).await {
Ok(_) => {} Ok(_) => {}
// don't repost image on this server if no manage messages perm // don't repost image on this server if no manage messages perm
// (if we can't delete user's image it'll be displayed twice) // (if we can't delete user's image it'll be displayed twice)
@ -202,7 +227,8 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
let invite = if data.contains_key("invite") { let invite = if data.contains_key("invite") {
Some(data["invite"].as_str().unwrap()) Some(data["invite"].as_str().unwrap())
} else { } else {
None }; None
};
for image in submitted_images.iter() { for image in submitted_images.iter() {
for (other_guild_id, data) in guild_data.iter() { for (other_guild_id, data) in guild_data.iter() {
let here = other_guild_id.eq(&ctx.guild_id().unwrap().as_u64().to_string()); let here = other_guild_id.eq(&ctx.guild_id().unwrap().as_u64().to_string());
@ -221,39 +247,48 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
.unwrap(), .unwrap(),
); );
let accent_color = ctx let accent_color = ctx
.discord() .serenity_context()
.http .http
.get_user(*author.id.as_u64()) .get_user(*author.id.as_u64())
.await .await
.unwrap() .unwrap()
.accent_colour; .accent_colour;
channel.send_message(&ctx.discord().http, |m| { channel
m.embed(|e| { .send_message(&ctx.serenity_context().http, |m| {
let username = format!("{}#{}", author.name, author.discriminator); m.embed(|e| {
let n = get_challenge_number(); let username = format!("{}#{}", author.name, author.discriminator);
let mut description = format!("New submission to [Tegaki Tuesday #{n}](https://tegakituesday.com/{n})!"); let domain = get_domain();
if !here { let n = get_challenge_number();
description.push_str(&if let Some(invite) = invite { let mut description = format!(
format!("\nCrossposted from [{}](https://discord.gg/{invite})", guild.name) "New submission to [Tegaki Tuesday #{n}](https://{domain}/{n})!"
} else { );
format!("\nCrossposted from {}", guild.name) if !here {
}); description.push_str(&if let Some(invite) = invite {
}; format!(
e.description(description); "\nCrossposted from [{}](https://discord.gg/{invite})",
let mut embed_author = serenity::builder::CreateEmbedAuthor::default(); guild.name
embed_author )
.icon_url(get_avatar(&author)) } else {
.name(username) format!("\nCrossposted from {}", guild.name)
.url(format!("https://discord.com/users/{}", author.id)); });
e.set_author(embed_author); };
e.image(format!("https://tegakituesday.com/{n}/{image}#{timestamp}")); e.description(description);
if let Some(accent_color) = accent_color { let mut embed_author = serenity::builder::CreateEmbedAuthor::default();
e.color(accent_color); embed_author
} .icon_url(get_avatar(author))
e .name(username)
}); .url(format!("https://discord.com/users/{}", author.id));
m e.set_author(embed_author);
}).await.unwrap(); e.image(format!("https://{domain}/{n}/{image}"));
if let Some(accent_color) = accent_color {
e.color(accent_color);
}
e
});
m
})
.await
.unwrap();
} }
} }
} else if invalid_types { } else if invalid_types {
@ -276,7 +311,7 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> {
let images: Vec<String> = { let images: Vec<String> = {
let mut images = Vec::new(); let mut images = Vec::new();
for submission in submission_data.iter() { for submission in submission_data.iter() {
if is_matching_submission(&submission, &ctx.author()) { if is_matching_submission(submission, ctx.author()) {
for image in submission["images"].as_array().unwrap().iter() { for image in submission["images"].as_array().unwrap().iter() {
images.push(String::from(image.as_str().unwrap())); images.push(String::from(image.as_str().unwrap()));
} }
@ -286,7 +321,7 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> {
images images
}; };
let challenge_number = get_challenge_number(); let challenge_number = get_challenge_number();
if images.len() == 0 { if images.is_empty() {
ctx.say(format!( ctx.say(format!(
"You haven't submitted anything for Tegaki Tuesday #{}.", "You haven't submitted anything for Tegaki Tuesday #{}.",
challenge_number challenge_number
@ -294,16 +329,17 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> {
.await?; .await?;
return Ok(()); return Ok(());
} }
let mut message = String::from(format!( let mut message = format!(
"Your submission images for Tegaki Tuesday #{}:\n", "Your submission images for Tegaki Tuesday #{}:\n",
challenge_number challenge_number
)); );
for (i, image) in images.iter().enumerate() { for (i, image) in images.iter().enumerate() {
message.push_str(&format!( message.push_str(&format!(
"{}<https://tegakituesday.com/{}/{}>\n", "{}<https://{domain}/{}/{}>\n",
to_fullwidth(&(i + 1).to_string()), to_fullwidth(&(i + 1).to_string()),
challenge_number, challenge_number,
image image,
domain = get_domain()
)); ));
} }
ctx.say(message).await?; ctx.say(message).await?;
@ -332,7 +368,7 @@ pub async fn imagedelete(ctx: Context<'_>, number: i32) -> Result<(), Error> {
let challenge_number = get_challenge_number(); let challenge_number = get_challenge_number();
let mut submission_data = get_current_submission_data(); let mut submission_data = get_current_submission_data();
for (i, submission) in submission_data.iter_mut().enumerate() { for (i, submission) in submission_data.iter_mut().enumerate() {
if !is_matching_submission(&submission, &ctx.author()) { if !is_matching_submission(submission, ctx.author()) {
continue; continue;
} }
let mut images = submission["images"].as_array().unwrap().clone(); let mut images = submission["images"].as_array().unwrap().clone();
@ -366,7 +402,7 @@ pub async fn imagedelete(ctx: Context<'_>, number: i32) -> Result<(), Error> {
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => (), Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => (),
Err(_) => panic!("Failed to remove file"), Err(_) => panic!("Failed to remove file"),
}; };
let mut message = String::from(format!("Deleted **{}** from your submission.", image)); let mut message = format!("Deleted **{}** from your submission.", image);
if images.len() == 1 { if images.len() == 1 {
message.push_str(" As there are no more images left attached to your submission, it has been deleted."); message.push_str(" As there are no more images left attached to your submission, it has been deleted.");
submission_data.remove(i); submission_data.remove(i);
@ -397,7 +433,8 @@ pub async fn imagedelete(ctx: Context<'_>, number: i32) -> Result<(), Error> {
pub async fn suggest( pub async fn suggest(
ctx: Context<'_>, ctx: Context<'_>,
#[rest] #[rest]
#[description = "Suggestion text. Please include passage and source."] suggestion: String, #[description = "Suggestion text. Please include passage and source."]
suggestion: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
let guild_data = get_guild_data(); let guild_data = get_guild_data();
let channel = serenity::ChannelId( let channel = serenity::ChannelId(
@ -411,14 +448,14 @@ pub async fn suggest(
// If we just do msg.author.accent_colour here, we will get None // If we just do msg.author.accent_colour here, we will get None
let author = &ctx.author(); let author = &ctx.author();
let accent_color = ctx let accent_color = ctx
.discord() .serenity_context()
.http .http
.get_user(*author.id.as_u64()) .get_user(*author.id.as_u64())
.await .await
.unwrap() .unwrap()
.accent_colour; .accent_colour;
channel channel
.send_message(&ctx.discord().http, |m| { .send_message(&ctx.serenity_context().http, |m| {
m.allowed_mentions(|am| { m.allowed_mentions(|am| {
am.empty_parse(); am.empty_parse();
am am
@ -427,16 +464,13 @@ pub async fn suggest(
let username = format!("{}#{}", author.name, author.discriminator); let username = format!("{}#{}", author.name, author.discriminator);
e.title("New suggestion"); e.title("New suggestion");
e.description(if let Context::Prefix(ctx) = ctx { e.description(if let Context::Prefix(ctx) = ctx {
format!( format!("{suggestion}\n\n[See original message]({})", ctx.msg.link(),)
"{suggestion}\n\n[See original message]({})",
ctx.msg.link(),
)
} else { } else {
suggestion suggestion
}); });
let mut embed_author = serenity::builder::CreateEmbedAuthor::default(); let mut embed_author = serenity::builder::CreateEmbedAuthor::default();
embed_author embed_author
.icon_url(get_avatar(&author)) .icon_url(get_avatar(author))
.name(username) .name(username)
.url(format!("https://discord.com/users/{}", author.id)); .url(format!("https://discord.com/users/{}", author.id));
e.set_author(embed_author); e.set_author(embed_author);

@ -21,7 +21,7 @@ pub async fn i(
} }
let kanji_info = get_kanji_info(character); let kanji_info = get_kanji_info(character);
covered_chars.push(character); covered_chars.push(character);
if kanji_info.len() == 0 { if kanji_info.is_empty() {
skipped_chars += 1; skipped_chars += 1;
continue; continue;
} }
@ -34,7 +34,7 @@ pub async fn i(
message = format!( message = format!(
"Found {} kanji{}\n{}", "Found {} kanji{}\n{}",
found_chars.len(), found_chars.len(),
if found_chars.len() == 0 { "." } else { ":" }, if found_chars.is_empty() { "." } else { ":" },
message message
); );
if skipped_chars > 0 { if skipped_chars > 0 {
@ -54,9 +54,9 @@ pub async fn i(
e.description(message); e.description(message);
let mut author = serenity::builder::CreateEmbedAuthor::default(); let mut author = serenity::builder::CreateEmbedAuthor::default();
author author
.icon_url("https://raw.githubusercontent.com/ElnuDev/ji-chan/main/ji-chan.png") .icon_url("https://git.elnu.com/tegakituesday/ji-chan/raw/branch/main/ji-chan.png")
.name("字ちゃん") .name("字ちゃん")
.url("https://github.com/ElnuDev/ji-chan"); .url("https://git.elnu.com/tegakituesday/ji-chan");
e.set_author(author); e.set_author(author);
e.color(serenity::utils::Colour::from_rgb(251, 73, 52)); e.color(serenity::utils::Colour::from_rgb(251, 73, 52));
if found_chars.len() == 1 { if found_chars.len() == 1 {
@ -142,7 +142,7 @@ pub async fn so(
if displayed_character_count >= MAX_CHARS { if displayed_character_count >= MAX_CHARS {
ctx.channel_id() ctx.channel_id()
.say( .say(
&ctx.discord().http, &ctx.serenity_context().http,
":warning: Maximum number of stroke order diagrams per command reached.", ":warning: Maximum number of stroke order diagrams per command reached.",
) )
.await?; .await?;

@ -1,3 +1,4 @@
use crate::utils::get_domain;
use crate::Context; use crate::Context;
use crate::Error; use crate::Error;
use poise::command; use poise::command;
@ -13,10 +14,9 @@ use std::env;
description_localized("en-US", "Get help for the 字ちゃん Tegaki Tuesday bot") description_localized("en-US", "Get help for the 字ちゃん Tegaki Tuesday bot")
)] )]
pub async fn help(ctx: Context<'_>) -> Result<(), Error> { pub async fn help(ctx: Context<'_>) -> Result<(), Error> {
let p = env::var("PREFIX").unwrap();
let message = format!( let message = format!(
"<:jichan:943336845637480478> Hello! I'm (Ji-chan), the Tegaki Tuesday bot (and mascot!). "<:jichan:943336845637480478> Hello! I'm (Ji-chan), the Tegaki Tuesday bot (and mascot!).
For more information about the challenge, check out the website at <https://tegakituesday.com> For more information about the challenge, check out the website at <https://{domain}>
__**Tegaki Tuesday **__ __**Tegaki Tuesday **__
:ballot_box: `{p}submit` Submit to the latest handwriting challenge. :ballot_box: `{p}submit` Submit to the latest handwriting challenge.
@ -32,7 +32,9 @@ __**Kanji 漢字**__
:game_die: `{p}joyo` Random Jōyō kanji :game_die: `{p}joyo` Random Jōyō kanji
:game_die: `{p}kyoiku <grade|all>` Random Kyōiku kanji :game_die: `{p}kyoiku <grade|all>` Random Kyōiku kanji
:game_die: `{p}jlpt <level|all>` Random JLPT kanji :game_die: `{p}jlpt <level|all>` Random JLPT kanji
:game_die: `{p}hyogai <group|all>` Random Hyōgai kanji" :game_die: `{p}hyogai <group|all>` Random Hyōgai kanji",
p = env::var("PREFIX").unwrap(),
domain = get_domain(),
); );
ctx.say(message).await?; ctx.say(message).await?;
Ok(()) Ok(())

@ -97,9 +97,10 @@ pub async fn announce(
#[command(prefix_command, hide_in_help, ephemeral, owners_only)] #[command(prefix_command, hide_in_help, ephemeral, owners_only)]
pub async fn announcechallenge(ctx: Context<'_>) -> Result<(), Error> { pub async fn announcechallenge(ctx: Context<'_>) -> Result<(), Error> {
let challenge_number = get_challenge_number(); let challenge_number = get_challenge_number();
let message = format!("Welcome to the **{n}{th}** weekly **Tegaki Tuesday** () handwriting challenge! :pen_fountain: The prompt is available in both Japanese and English on the website at <https://tegakituesday.com/{n}>. let message = format!("Welcome to the **{n}{th}** weekly **Tegaki Tuesday** () handwriting challenge! :pen_fountain: The prompt is available in both Japanese and English on the website at <https://{domain}/{n}>.
You can make submissions in both languages, but please submit in your target language first. Submissions can be submitted by uploading the image to this channel along with the `{p}submit` command. By submitting, you agree to having your work posted to the website under the Attribution-ShareAlike 4.0 Unported (CC BY-SA 4.0) license, attributed to your Discord account. (<https://creativecommons.org/licenses/by-sa/4.0>).", You can make submissions in both languages, but please submit in your target language first. Submissions can be submitted by uploading the image to this channel along with the `{p}submit` command. By submitting, you agree to having your work posted to the website under the Attribution-ShareAlike 4.0 Unported (CC BY-SA 4.0) license, attributed to your Discord account. (<https://creativecommons.org/licenses/by-sa/4.0>).",
domain = get_domain(),
n = challenge_number, n = challenge_number,
th = match challenge_number % 10 { th = match challenge_number % 10 {
1 => "ˢᵗ", 1 => "ˢᵗ",

@ -71,7 +71,7 @@ async fn main() {
| GatewayIntents::MESSAGE_CONTENT | GatewayIntents::MESSAGE_CONTENT
| GatewayIntents::GUILDS, | GatewayIntents::GUILDS,
) )
.user_data_setup(move |_ctx, _ready, _framework| Box::pin(async move { Ok(Data {}) })); .setup(move |_ctx, _ready, _framework| Box::pin(async move { Ok(Data {}) }));
framework.run().await.unwrap(); framework.run().await.unwrap();
} }

@ -34,6 +34,10 @@ pub fn get_challenge_number() -> i32 {
max max
} }
pub fn get_domain() -> String {
env::var("DOMAIN").unwrap()
}
pub fn get_hugo_path() -> String { pub fn get_hugo_path() -> String {
env::var("HUGO").unwrap() env::var("HUGO").unwrap()
} }
@ -175,7 +179,7 @@ pub async fn send(ctx: Context<'_>, message: &str, ping: bool, pin: bool) -> Res
)); ));
} }
message_to_send.push_str(message); message_to_send.push_str(message);
let ctx = ctx.discord(); let ctx = ctx.serenity_context();
let sent_message = channel let sent_message = channel
.send_message(&ctx.http, |e| { .send_message(&ctx.http, |e| {
e.content(message_to_send); e.content(message_to_send);
@ -186,10 +190,7 @@ pub async fn send(ctx: Context<'_>, message: &str, ping: bool, pin: bool) -> Res
if pin { if pin {
// No need to do anything on error, // No need to do anything on error,
// it just means we don't have pin permissions // it just means we don't have pin permissions
match sent_message.pin(&ctx.http).await { let _ = sent_message.pin(&ctx.http).await;
Ok(_) => (),
Err(_) => (),
};
} }
// announcements_count += 1; // announcements_count += 1;
} }
@ -210,8 +211,8 @@ pub fn random_from_string(string: &str) -> char {
pub fn get_so_diagram(kanji: char) -> String { pub fn get_so_diagram(kanji: char) -> String {
format!( format!(
"https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/{}.gif", "https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/{:x}.gif",
format!("{:x}", kanji as i32) kanji as i32
) )
} }
@ -224,7 +225,7 @@ pub async fn display_kanji(ctx: Context<'_>, kanji: char, comment: &str) -> Resu
let link_validated = response != reqwest::StatusCode::NOT_FOUND; let link_validated = response != reqwest::StatusCode::NOT_FOUND;
ctx.channel_id() ctx.channel_id()
.say( .say(
&ctx.discord().http, &ctx.serenity_context().http,
if link_validated { if link_validated {
&url &url
} else { } else {
@ -328,11 +329,11 @@ pub async fn random_kanji(
.choose(&mut rand::thread_rng()) .choose(&mut rand::thread_rng())
.unwrap(); .unwrap();
let list = subcategories[subcategory_key].as_str().unwrap(); let list = subcategories[subcategory_key].as_str().unwrap();
let kanji = random_from_string(&list); let kanji = random_from_string(list);
display_kanji(ctx, kanji, &format!(", **{}**", subcategory_key)).await?; display_kanji(ctx, kanji, &format!(", **{}**", subcategory_key)).await?;
} else if subcategories.contains_key(&subcategory) { } else if subcategories.contains_key(&subcategory) {
let list = list[&subcategory].as_str().unwrap(); let list = list[&subcategory].as_str().unwrap();
let kanji = random_from_string(&list); let kanji = random_from_string(list);
display_kanji(ctx, kanji, "").await?; display_kanji(ctx, kanji, "").await?;
} else { } else {
let message = format!( let message = format!(
@ -373,7 +374,7 @@ pub async fn leaderboard(ctx: &Context<'_>) -> Result<(), Error> {
for (i, (id, count)) in top_submitters[0..LENGTH].iter().enumerate() { for (i, (id, count)) in top_submitters[0..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.discord().http) .to_user(&ctx.serenity_context().http)
.await?; .await?;
let avatar = get_avatar(&user); let avatar = get_avatar(&user);
let profile = format!("https://discord.com/users/{id}"); let profile = format!("https://discord.com/users/{id}");

Loading…
Cancel
Save