cargo fmt
This commit is contained in:
parent
9e9eb48025
commit
6aff34ceab
6 changed files with 178 additions and 153 deletions
|
@ -12,19 +12,25 @@ use std::fs::File;
|
|||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
#[command(prefix_command, slash_command, description_localized("en-US", "View the latest handwriting challenge info."))]
|
||||
#[command(
|
||||
prefix_command,
|
||||
slash_command,
|
||||
description_localized("en-US", "View the latest handwriting challenge info.")
|
||||
)]
|
||||
pub async fn challenge(ctx: Context<'_>) -> Result<(), Error> {
|
||||
ctx.say(
|
||||
format!(
|
||||
"Tegaki Tuesday #{n}: <https://tegakituesday.com/{n}>",
|
||||
n = get_challenge_number()
|
||||
),
|
||||
)
|
||||
ctx.say(format!(
|
||||
"Tegaki Tuesday #{n}: <https://tegakituesday.com/{n}>",
|
||||
n = get_challenge_number()
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command(prefix_command, broadcast_typing, description_localized("en-US", "Submit to the latest handwriting challenge."))]
|
||||
#[command(
|
||||
prefix_command,
|
||||
broadcast_typing,
|
||||
description_localized("en-US", "Submit to the latest handwriting challenge.")
|
||||
)]
|
||||
pub async fn submit(ctx: PrefixContext<'_>) -> Result<(), Error> {
|
||||
// TODO: The code for this command needs to be refactored,
|
||||
// there are large duplicated sections that need to be merged somehow.
|
||||
|
@ -36,24 +42,32 @@ pub async fn submit(ctx: PrefixContext<'_>) -> Result<(), Error> {
|
|||
.unwrap()
|
||||
.contains_key("submissionChannel")
|
||||
{
|
||||
ctx.msg.reply(&ctx.discord.http, "Submissions aren't enabled for this server yet.").await?;
|
||||
ctx.msg
|
||||
.reply(
|
||||
&ctx.discord.http,
|
||||
"Submissions aren't enabled for this server yet.",
|
||||
)
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
let current_guild_data = &guild_data[&guild].as_object().unwrap();
|
||||
let submission_channel = current_guild_data["submissionChannel"].as_str().unwrap();
|
||||
if submission_channel != ctx.msg.channel_id.as_u64().to_string() {
|
||||
ctx.msg.reply(
|
||||
&ctx.discord.http,
|
||||
format!(
|
||||
"Sorry, submissions aren't permitted here. Please go to <#{}>. Thanks!",
|
||||
guild
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
ctx.msg
|
||||
.reply(
|
||||
&ctx.discord.http,
|
||||
format!(
|
||||
"Sorry, submissions aren't permitted here. Please go to <#{}>. Thanks!",
|
||||
guild
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
if ctx.msg.attachments.len() == 0 {
|
||||
ctx.msg.reply(&ctx.discord.http, "Please attach at least one image.").await?;
|
||||
ctx.msg
|
||||
.reply(&ctx.discord.http, "Please attach at least one image.")
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
let challenge_number = get_challenge_number();
|
||||
|
@ -170,7 +184,11 @@ pub async fn submit(ctx: PrefixContext<'_>) -> Result<(), Error> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[command(prefix_command, slash_command, description_localized("en-US", "List images in your current submission, if available."))]
|
||||
#[command(
|
||||
prefix_command,
|
||||
slash_command,
|
||||
description_localized("en-US", "List images in your current submission, if available.")
|
||||
)]
|
||||
pub async fn images(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let submission_data = get_current_submission_data();
|
||||
let images: Vec<String> = {
|
||||
|
@ -187,12 +205,10 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> {
|
|||
};
|
||||
let challenge_number = get_challenge_number();
|
||||
if images.len() == 0 {
|
||||
ctx.say(
|
||||
format!(
|
||||
"You haven't submitted anything for Tegaki Tuesday #{}.",
|
||||
challenge_number
|
||||
),
|
||||
)
|
||||
ctx.say(format!(
|
||||
"You haven't submitted anything for Tegaki Tuesday #{}.",
|
||||
challenge_number
|
||||
))
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -212,13 +228,18 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[command(prefix_command, slash_command, description_localized("en-US", "Delete images from your current submission using image numbers from the images command."))]
|
||||
pub async fn imagedelete(
|
||||
ctx: Context<'_>,
|
||||
number: i32,
|
||||
) -> Result<(), Error> {
|
||||
#[command(
|
||||
prefix_command,
|
||||
slash_command,
|
||||
description_localized(
|
||||
"en-US",
|
||||
"Delete images from your current submission using image numbers from the images command."
|
||||
)
|
||||
)]
|
||||
pub async fn imagedelete(ctx: Context<'_>, number: i32) -> Result<(), Error> {
|
||||
if number < 1 {
|
||||
ctx.say("That isn't a valid image number. Image numbers start at 1.").await?;
|
||||
ctx.say("That isn't a valid image number. Image numbers start at 1.")
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
let challenge_number = get_challenge_number();
|
||||
|
@ -230,23 +251,21 @@ pub async fn imagedelete(
|
|||
let mut images = submission["images"].as_array().unwrap().clone();
|
||||
let image_count = images.len();
|
||||
if image_count < number.try_into().unwrap() {
|
||||
ctx.say(
|
||||
if image_count == 0 {
|
||||
// This is an edge case that should never happen.
|
||||
// In this scenario, there is submission data with an empty image list.
|
||||
// Submission data should be deleted uppon imageDelete if there are no images remaining.
|
||||
format!(
|
||||
"You haven't submitted anything for Tegaki Tuesday #{}.",
|
||||
challenge_number
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"That image number doesn't exist, you only have {} image{}.",
|
||||
image_count,
|
||||
if image_count == 1 { "" } else { "s" }
|
||||
)
|
||||
},
|
||||
)
|
||||
ctx.say(if image_count == 0 {
|
||||
// This is an edge case that should never happen.
|
||||
// In this scenario, there is submission data with an empty image list.
|
||||
// Submission data should be deleted uppon imageDelete if there are no images remaining.
|
||||
format!(
|
||||
"You haven't submitted anything for Tegaki Tuesday #{}.",
|
||||
challenge_number
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"That image number doesn't exist, you only have {} image{}.",
|
||||
image_count,
|
||||
if image_count == 1 { "" } else { "s" }
|
||||
)
|
||||
})
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -304,22 +323,22 @@ pub async fn imagedelete(
|
|||
ctx.say(message).await?;
|
||||
return Ok(());
|
||||
}
|
||||
ctx.say(
|
||||
format!(
|
||||
"You haven't submitted anything for Tegaki Tuesday #{}.",
|
||||
challenge_number
|
||||
),
|
||||
)
|
||||
ctx.say(format!(
|
||||
"You haven't submitted anything for Tegaki Tuesday #{}.",
|
||||
challenge_number
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// TODO: make also slash command
|
||||
#[command(prefix_command, description_localized("en-US", "Make a suggestion for future challenge prompts!"))]
|
||||
#[command(
|
||||
prefix_command,
|
||||
description_localized("en-US", "Make a suggestion for future challenge prompts!")
|
||||
)]
|
||||
pub async fn suggest(
|
||||
ctx: PrefixContext<'_>,
|
||||
#[description = "Suggestion text. Please include passage and source."]
|
||||
suggestion: String,
|
||||
#[description = "Suggestion text. Please include passage and source."] suggestion: String,
|
||||
) -> Result<(), Error> {
|
||||
let guild_data = get_guild_data();
|
||||
let channel = serenity::ChannelId(
|
||||
|
@ -332,7 +351,9 @@ pub async fn suggest(
|
|||
// User::accent_colour is only available via the REST API
|
||||
// If we just do msg.author.accent_colour here, we will get None
|
||||
let author = &ctx.msg.author;
|
||||
let accent_color = ctx.discord.http
|
||||
let accent_color = ctx
|
||||
.discord
|
||||
.http
|
||||
.get_user(*author.id.as_u64())
|
||||
.await
|
||||
.unwrap()
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
use crate::utils::*;
|
||||
|
||||
use crate::serenity;
|
||||
use crate::Error;
|
||||
use crate::Context;
|
||||
use crate::Error;
|
||||
use poise::command;
|
||||
|
||||
#[command(slash_command, prefix_command, description_localized("en-US", "Get category info and links to Jisho for character(s), with stroke order for single characters."))]
|
||||
pub async fn i(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Input kanji to get info for"]
|
||||
input: String,
|
||||
#[description = "Input kanji to get info for"] input: String,
|
||||
) -> Result<(), Error> {
|
||||
let chars = input.chars();
|
||||
let mut message = String::from("");
|
||||
|
@ -46,47 +45,55 @@ pub async fn i(
|
|||
));
|
||||
}
|
||||
ctx.send(|m| {
|
||||
m.allowed_mentions(|am| {
|
||||
am.empty_parse();
|
||||
am
|
||||
});
|
||||
m.embed(|e| {
|
||||
e.title(input);
|
||||
e.description(message);
|
||||
let mut author = serenity::builder::CreateEmbedAuthor::default();
|
||||
author
|
||||
.icon_url("https://raw.githubusercontent.com/ElnuDev/ji-chan/main/ji-chan.png")
|
||||
.name("字ちゃん")
|
||||
.url("https://github.com/ElnuDev/ji-chan");
|
||||
e.set_author(author);
|
||||
e.color(serenity::utils::Colour::from_rgb(251, 73, 52));
|
||||
if found_chars.len() == 1 {
|
||||
e.thumbnail(get_so_diagram(found_chars[0]));
|
||||
}
|
||||
e
|
||||
});
|
||||
m
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
m.allowed_mentions(|am| {
|
||||
am.empty_parse();
|
||||
am
|
||||
});
|
||||
m.embed(|e| {
|
||||
e.title(input);
|
||||
e.description(message);
|
||||
let mut author = serenity::builder::CreateEmbedAuthor::default();
|
||||
author
|
||||
.icon_url("https://raw.githubusercontent.com/ElnuDev/ji-chan/main/ji-chan.png")
|
||||
.name("字ちゃん")
|
||||
.url("https://github.com/ElnuDev/ji-chan");
|
||||
e.set_author(author);
|
||||
e.color(serenity::utils::Colour::from_rgb(251, 73, 52));
|
||||
if found_chars.len() == 1 {
|
||||
e.thumbnail(get_so_diagram(found_chars[0]));
|
||||
}
|
||||
e
|
||||
});
|
||||
m
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command(slash_command, prefix_command, description_localized("en-US", "Random Jōyō kanji"))]
|
||||
pub async fn joyo(
|
||||
ctx: Context<'_>,
|
||||
) -> Result<(), Error> {
|
||||
#[command(
|
||||
slash_command,
|
||||
prefix_command,
|
||||
description_localized("en-US", "Random Jōyō kanji")
|
||||
)]
|
||||
pub async fn joyo(ctx: Context<'_>) -> Result<(), Error> {
|
||||
random_kanji("JOYO", ctx, None).await
|
||||
}
|
||||
|
||||
#[command(slash_command, prefix_command, description_localized("en-US", "Random Jinmeiyō kanji"))]
|
||||
pub async fn jinmeiyo(
|
||||
ctx: Context<'_>,
|
||||
)-> Result<(), Error> {
|
||||
#[command(
|
||||
slash_command,
|
||||
prefix_command,
|
||||
description_localized("en-US", "Random Jinmeiyō kanji")
|
||||
)]
|
||||
pub async fn jinmeiyo(ctx: Context<'_>) -> Result<(), Error> {
|
||||
random_kanji("JINMEIYO", ctx, None).await
|
||||
}
|
||||
|
||||
#[command(slash_command, prefix_command, description_localized("en-US", "Random Kyōiku kanji"))]
|
||||
#[command(
|
||||
slash_command,
|
||||
prefix_command,
|
||||
description_localized("en-US", "Random Kyōiku kanji")
|
||||
)]
|
||||
pub async fn kyoiku(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Kyōiku subcategory. GRADE1, GRADE2, GRADE3, GRADE4, GRADE5, GRADE6, or ALL."]
|
||||
|
@ -95,29 +102,38 @@ pub async fn kyoiku(
|
|||
random_kanji("KYOIKU", ctx, subcategory).await
|
||||
}
|
||||
|
||||
#[command(slash_command, prefix_command, description_localized("en-US", "Random JLPT kanji"))]
|
||||
#[command(
|
||||
slash_command,
|
||||
prefix_command,
|
||||
description_localized("en-US", "Random JLPT kanji")
|
||||
)]
|
||||
pub async fn jlpt(
|
||||
ctx: Context<'_>,
|
||||
#[description = "JLPT subcategory. N1, N2, N3, N4, N5, or ALL"]
|
||||
subcategory: Option<String>
|
||||
#[description = "JLPT subcategory. N1, N2, N3, N4, N5, or ALL"] subcategory: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
random_kanji("JLPT", ctx, subcategory).await
|
||||
}
|
||||
|
||||
#[command(slash_command, prefix_command, description_localized("en-US", "Random Hyōgai kanji"))]
|
||||
#[command(
|
||||
slash_command,
|
||||
prefix_command,
|
||||
description_localized("en-US", "Random Hyōgai kanji")
|
||||
)]
|
||||
pub async fn hyogai(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Hyōgai subcategory. ELEMENTS, MAIN, or ALL."]
|
||||
subcategory: Option<String>,
|
||||
#[description = "Hyōgai subcategory. ELEMENTS, MAIN, or ALL."] subcategory: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
random_kanji("HYOGAI", ctx, subcategory).await
|
||||
}
|
||||
|
||||
#[command(slash_command, prefix_command, description_localized("en-US", "Get stroke order diagrams for character(s), maximum 4"))]
|
||||
#[command(
|
||||
slash_command,
|
||||
prefix_command,
|
||||
description_localized("en-US", "Get stroke order diagrams for character(s), maximum 4")
|
||||
)]
|
||||
pub async fn so(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Input characters to get stroke order for"]
|
||||
text: String,
|
||||
#[description = "Input characters to get stroke order for"] text: String,
|
||||
) -> Result<(), Error> {
|
||||
const MAX_CHARS: i32 = 4;
|
||||
let mut displayed_characters: Vec<char> = Vec::new();
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
use crate::Error;
|
||||
use crate::Context;
|
||||
use crate::Error;
|
||||
use poise::command;
|
||||
|
||||
use std::env;
|
||||
|
||||
// TODO: Implement proper help text for command-specific help,
|
||||
// see https://github.com/kangalioo/poise/blob/90ac24a8ef621ec6dc3fc452762dc9cfa144f693/examples/framework_usage/main.rs#L18-L38
|
||||
#[command(prefix_command, slash_command, description_localized("en-US", "Get help for the 字ちゃん Tegaki Tuesday bot"))]
|
||||
#[command(
|
||||
prefix_command,
|
||||
slash_command,
|
||||
description_localized("en-US", "Get help for the 字ちゃん Tegaki Tuesday bot")
|
||||
)]
|
||||
pub async fn help(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let p = env::var("PREFIX").unwrap();
|
||||
let message = format!(
|
||||
|
|
|
@ -12,7 +12,12 @@ use crate::utils::*;
|
|||
#[command(prefix_command, hide_in_help, owners_only)]
|
||||
pub async fn sleep(ctx: Context<'_>) -> Result<(), crate::Error> {
|
||||
ctx.say("Good night!").await?;
|
||||
ctx.framework().shard_manager.lock().await.shutdown_all().await;
|
||||
ctx.framework()
|
||||
.shard_manager
|
||||
.lock()
|
||||
.await
|
||||
.shutdown_all()
|
||||
.await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -33,13 +38,11 @@ pub async fn setsubmissionchannel(ctx: Context<'_>) -> Result<(), Error> {
|
|||
guild_data.insert(guild, json!({ "submissionChannel": channel }));
|
||||
}
|
||||
set_guild_data(guild_data);
|
||||
ctx.say(
|
||||
format!(
|
||||
"Submission channel for **{}** set to <#{}>.",
|
||||
ctx.guild().unwrap().name,
|
||||
ctx.channel_id()
|
||||
),
|
||||
)
|
||||
ctx.say(format!(
|
||||
"Submission channel for **{}** set to <#{}>.",
|
||||
ctx.guild().unwrap().name,
|
||||
ctx.channel_id()
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -63,8 +66,7 @@ pub async fn setsuggestionchannel(ctx: Context<'_>) -> Result<(), Error> {
|
|||
#[allow(non_snake_case)]
|
||||
pub async fn setannouncementrole(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Announcement role ID"]
|
||||
role: u64,
|
||||
#[description = "Announcement role ID"] role: u64,
|
||||
) -> Result<(), Error> {
|
||||
let mut guild_data = get_guild_data();
|
||||
let guild = ctx.guild_id().unwrap().as_u64().to_string();
|
||||
|
@ -87,8 +89,7 @@ pub async fn setannouncementrole(
|
|||
#[command(prefix_command, hide_in_help, owners_only)]
|
||||
pub async fn announce(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Announcement text"]
|
||||
announcement: String,
|
||||
#[description = "Announcement text"] announcement: String,
|
||||
) -> Result<(), Error> {
|
||||
send(ctx, &announcement, true, false).await
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue