Implement domain system

main
Elnu 1 year ago
parent 60d6eff39b
commit 9857504705

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

@ -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?;
@ -178,7 +179,7 @@ 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),
@ -230,8 +231,9 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
channel.send_message(&ctx.serenity_context().http, |m| { channel.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 domain = get_domain();
let n = get_challenge_number(); 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 { if !here {
description.push_str(&if let Some(invite) = invite { description.push_str(&if let Some(invite) = invite {
format!("\nCrossposted from [{}](https://discord.gg/{invite})", guild.name) 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) .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);
e.image(format!("https://tegakituesday.com/{n}/{image}#{timestamp}")); e.image(format!("https://{domain}/{n}/{image}#{timestamp}"));
if let Some(accent_color) = accent_color { if let Some(accent_color) = accent_color {
e.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() { 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?;

@ -1,5 +1,6 @@
use crate::Context; use crate::Context;
use crate::Error; use crate::Error;
use crate::utils::get_domain;
use poise::command; use poise::command;
use std::env; use std::env;
@ -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 => "ˢᵗ",

@ -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()
} }

Loading…
Cancel
Save