From 9857504705671cca6bf410fb5b34b3170d5dd44a Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 10 Jun 2023 12:59:29 -0700 Subject: [PATCH] Implement domain system --- .env.example | 1 + src/commands/challenge.rs | 15 +++++++++------ src/commands/meta.rs | 8 +++++--- src/commands/owner.rs | 3 ++- src/utils.rs | 4 ++++ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 4e67ce9..ab419e1 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ +DOMAIN=tegakituesday.com DISCORD_TOKEN= PREFIX="-h " HUGO=/path/to/hugo diff --git a/src/commands/challenge.rs b/src/commands/challenge.rs index 659add4..0c19009 100644 --- a/src/commands/challenge.rs +++ b/src/commands/challenge.rs @@ -20,7 +20,8 @@ use std::path::Path; )] pub async fn challenge(ctx: Context<'_>) -> Result<(), Error> { ctx.say(format!( - "Tegaki Tuesday #{n}: ", + "Tegaki Tuesday #{n}: ", + domain = get_domain(), n = get_challenge_number() )) .await?; @@ -178,7 +179,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul set_submission_data(submission_data); let mut message = String::new(); if requires_rebuild { - let thank_you = &format!("Thank you for submitting! You can view your submission at ", challenge_number); + let thank_you = &format!("Thank you for submitting! You can view your submission at ", challenge_number, domain = get_domain()); let mut repost_here = true; match ctx { Context::Application(_) => message.push_str(thank_you), @@ -230,8 +231,9 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul channel.send_message(&ctx.serenity_context().http, |m| { m.embed(|e| { let username = format!("{}#{}", author.name, author.discriminator); + let domain = get_domain(); let n = get_challenge_number(); - let mut description = format!("New submission to [Tegaki Tuesday #{n}](https://tegakituesday.com/{n})!"); + let mut description = format!("New submission to [Tegaki Tuesday #{n}](https://{domain}/{n})!"); if !here { description.push_str(&if let Some(invite) = invite { format!("\nCrossposted from [{}](https://discord.gg/{invite})", guild.name) @@ -246,7 +248,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul .name(username) .url(format!("https://discord.com/users/{}", author.id)); e.set_author(embed_author); - e.image(format!("https://tegakituesday.com/{n}/{image}#{timestamp}")); + e.image(format!("https://{domain}/{n}/{image}#{timestamp}")); if let Some(accent_color) = accent_color { e.color(accent_color); } @@ -300,10 +302,11 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> { )); for (i, image) in images.iter().enumerate() { message.push_str(&format!( - "({})\n", + "({})\n", to_fullwidth(&(i + 1).to_string()), challenge_number, - image + image, + domain = get_domain() )); } ctx.say(message).await?; diff --git a/src/commands/meta.rs b/src/commands/meta.rs index 31b41ae..9cd20ca 100644 --- a/src/commands/meta.rs +++ b/src/commands/meta.rs @@ -1,5 +1,6 @@ use crate::Context; use crate::Error; +use crate::utils::get_domain; use poise::command; use std::env; @@ -13,10 +14,9 @@ use std::env; 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!( "<:jichan:943336845637480478> Hello! I'm 字【じ】ちゃん (Ji-chan), the Tegaki Tuesday bot (and mascot!). -For more information about the challenge, check out the website at +For more information about the challenge, check out the website at __**Tegaki Tuesday 手書きの火曜日**__ :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}kyoiku ` Random Kyōiku kanji :game_die: `{p}jlpt ` Random JLPT kanji -:game_die: `{p}hyogai ` Random Hyōgai kanji" +:game_die: `{p}hyogai ` Random Hyōgai kanji", + p = env::var("PREFIX").unwrap(), + domain = get_domain(), ); ctx.say(message).await?; Ok(()) diff --git a/src/commands/owner.rs b/src/commands/owner.rs index 0f08352..7abfd61 100644 --- a/src/commands/owner.rs +++ b/src/commands/owner.rs @@ -97,9 +97,10 @@ pub async fn announce( #[command(prefix_command, hide_in_help, ephemeral, owners_only)] pub async fn announcechallenge(ctx: Context<'_>) -> Result<(), Error> { 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 . + 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 . 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. ().", + domain = get_domain(), n = challenge_number, th = match challenge_number % 10 { 1 => "ˢᵗ", diff --git a/src/utils.rs b/src/utils.rs index ab11f06..ef5f237 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -34,6 +34,10 @@ pub fn get_challenge_number() -> i32 { max } +pub fn get_domain() -> String { + env::var("DOMAIN").unwrap() +} + pub fn get_hugo_path() -> String { env::var("HUGO").unwrap() }