Compare commits

..

No commits in common. "1dfa68452b063b7aa79119091e1b7209ac39d219" and "d531b91569e295937ae4c3dae3015752d38c4f87" have entirely different histories.

11 changed files with 473 additions and 586 deletions

View file

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

1
.envrc
View file

@ -1 +0,0 @@
use nix

838
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -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.5.5" poise = "0.4"
[dependencies.tokio] [dependencies.tokio]
version = "1.0" version = "1.0"

View file

@ -1,21 +0,0 @@
# <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
];
}

View file

@ -2,8 +2,8 @@ use crate::utils::*;
use serde_json::Map; use serde_json::Map;
use crate::serenity; use crate::serenity;
use crate::Context;
use crate::Error; use crate::Error;
use crate::Context;
use poise::command; use poise::command;
use slug::slugify; use slug::slugify;
@ -20,8 +20,7 @@ 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://{domain}/{n}>", "Tegaki Tuesday #{n}: <https://tegakituesday.com/{n}>",
domain = get_domain(),
n = get_challenge_number() n = get_challenge_number()
)) ))
.await?; .await?;
@ -41,12 +40,9 @@ 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.is_empty() { if ctx.msg.attachments.len() == 0 {
ctx.msg ctx.msg
.reply( .reply(&ctx.discord.http, "Please attach at least one image.")
&ctx.serenity_context.http,
"Please attach at least one image.",
)
.await?; .await?;
return Ok(()); return Ok(());
} }
@ -78,10 +74,7 @@ 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() let timestamp = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_millis();
.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);
@ -99,15 +92,9 @@ 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"] let mut images: Vec<String> = submission["images"].as_array_mut().unwrap().clone().iter().map(|value| value.as_str().unwrap().to_owned()).collect();
.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 {
@ -130,14 +117,10 @@ 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 { if i == 0 { "".to_owned() } else { format!("-{}", i + 1) },
"".to_owned()
} else {
format!("-{}", i + 1)
},
extension extension
); );
images.push(file_name.clone()); images.push(file_name.clone().into());
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))?;
@ -178,14 +161,10 @@ 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 { if i == 0 { "".to_owned() } else { format!("-{}", i + 1) },
"".to_owned()
} else {
format!("-{}", i + 1)
},
extension extension
); );
images.push(file_name.clone()); images.push(file_name.clone().into());
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)?;
@ -199,15 +178,11 @@ 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!( let thank_you = &format!("Thank you for submitting! You can view your submission at <https://tegakituesday.com/{}>", challenge_number);
"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.serenity_context.http).await { Context::Prefix(ctx) => match ctx.msg.delete(&ctx.discord.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)
@ -227,8 +202,7 @@ 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());
@ -247,48 +221,39 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
.unwrap(), .unwrap(),
); );
let accent_color = ctx let accent_color = ctx
.serenity_context() .discord()
.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.embed(|e| {
m.embed(|e| { let username = format!("{}#{}", author.name, author.discriminator);
let username = format!("{}#{}", author.name, author.discriminator); let n = get_challenge_number();
let domain = get_domain(); let mut description = format!("New submission to [Tegaki Tuesday #{n}](https://tegakituesday.com/{n})!");
let n = get_challenge_number(); if !here {
let mut description = format!( description.push_str(&if let Some(invite) = invite {
"New submission to [Tegaki Tuesday #{n}](https://{domain}/{n})!" format!("\nCrossposted from [{}](https://discord.gg/{invite})", guild.name)
); } else {
if !here { format!("\nCrossposted from {}", guild.name)
description.push_str(&if let Some(invite) = invite { });
format!( };
"\nCrossposted from [{}](https://discord.gg/{invite})", e.description(description);
guild.name let mut embed_author = serenity::builder::CreateEmbedAuthor::default();
) embed_author
} else { .icon_url(get_avatar(&author))
format!("\nCrossposted from {}", guild.name) .name(username)
}); .url(format!("https://discord.com/users/{}", author.id));
}; e.set_author(embed_author);
e.description(description); e.image(format!("https://tegakituesday.com/{n}/{image}#{timestamp}"));
let mut embed_author = serenity::builder::CreateEmbedAuthor::default(); if let Some(accent_color) = accent_color {
embed_author e.color(accent_color);
.icon_url(get_avatar(author)) }
.name(username) e
.url(format!("https://discord.com/users/{}", author.id)); });
e.set_author(embed_author); m
e.image(format!("https://{domain}/{n}/{image}")); }).await.unwrap();
if let Some(accent_color) = accent_color {
e.color(accent_color);
}
e
});
m
})
.await
.unwrap();
} }
} }
} else if invalid_types { } else if invalid_types {
@ -311,7 +276,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()));
} }
@ -321,7 +286,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.is_empty() { if images.len() == 0 {
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
@ -329,17 +294,16 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> {
.await?; .await?;
return Ok(()); return Ok(());
} }
let mut message = format!( let mut message = String::from(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://{domain}/{}/{}>\n", "{}<https://tegakituesday.com/{}/{}>\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?;
@ -368,7 +332,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();
@ -402,7 +366,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 = format!("Deleted **{}** from your submission.", image); let mut message = String::from(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);
@ -433,8 +397,7 @@ 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."] #[description = "Suggestion text. Please include passage and source."] suggestion: String,
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(
@ -448,14 +411,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
.serenity_context() .discord()
.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.serenity_context().http, |m| { .send_message(&ctx.discord().http, |m| {
m.allowed_mentions(|am| { m.allowed_mentions(|am| {
am.empty_parse(); am.empty_parse();
am am
@ -464,13 +427,16 @@ 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!("{suggestion}\n\n[See original message]({})", ctx.msg.link(),) format!(
"{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);

View file

@ -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.is_empty() { if kanji_info.len() == 0 {
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.is_empty() { "." } else { ":" }, if found_chars.len() == 0 { "." } 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://git.elnu.com/tegakituesday/ji-chan/raw/branch/main/ji-chan.png") .icon_url("https://raw.githubusercontent.com/ElnuDev/ji-chan/main/ji-chan.png")
.name("字ちゃん") .name("字ちゃん")
.url("https://git.elnu.com/tegakituesday/ji-chan"); .url("https://github.com/ElnuDev/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.serenity_context().http, &ctx.discord().http,
":warning: Maximum number of stroke order diagrams per command reached.", ":warning: Maximum number of stroke order diagrams per command reached.",
) )
.await?; .await?;

View file

@ -1,4 +1,3 @@
use crate::utils::get_domain;
use crate::Context; use crate::Context;
use crate::Error; use crate::Error;
use poise::command; use poise::command;
@ -14,9 +13,10 @@ 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://{domain}> For more information about the challenge, check out the website at <https://tegakituesday.com>
__**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,9 +32,7 @@ __**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(())

View file

@ -97,10 +97,9 @@ 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://{domain}/{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://tegakituesday.com/{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 => "ˢᵗ",

View file

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

View file

@ -34,10 +34,6 @@ 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()
} }
@ -179,7 +175,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.serenity_context(); let ctx = ctx.discord();
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);
@ -190,7 +186,10 @@ 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
let _ = sent_message.pin(&ctx.http).await; match sent_message.pin(&ctx.http).await {
Ok(_) => (),
Err(_) => (),
};
} }
// announcements_count += 1; // announcements_count += 1;
} }
@ -211,8 +210,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/{:x}.gif", "https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/{}.gif",
kanji as i32 format!("{:x}", kanji as i32)
) )
} }
@ -225,7 +224,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.serenity_context().http, &ctx.discord().http,
if link_validated { if link_validated {
&url &url
} else { } else {
@ -329,11 +328,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!(
@ -374,7 +373,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.serenity_context().http) .to_user(&ctx.discord().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}");