#![allow(non_snake_case)] use crate::Context; use crate::Error; use poise::command; use serde_json::json; use std::env; use crate::utils::*; #[command(prefix_command, slash_command, hide_in_help, ephemeral, 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; Ok(()) } #[command(prefix_command, slash_command, hide_in_help, ephemeral, owners_only)] pub async fn setsubmissionchannel(ctx: Context<'_>) -> Result<(), Error> { let mut guild_data = get_guild_data(); let guild = ctx.guild_id().unwrap().as_u64().to_string(); let channel = ctx.channel_id().as_u64().to_string(); if guild_data.contains_key(&guild) { let mut current_guild_data = guild_data[&guild].as_object().unwrap().clone(); if current_guild_data.contains_key("submissionChannel") { current_guild_data["submissionChannel"] = channel.into(); } else { current_guild_data.insert(String::from("submissionChannel"), channel.into()); } guild_data[&guild] = current_guild_data.into(); } else { 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() )) .await?; Ok(()) } #[command(prefix_command, slash_command, hide_in_help, ephemeral, owners_only)] pub async fn setsuggestionchannel(ctx: Context<'_>) -> Result<(), Error> { let channel = ctx.channel_id().as_u64().to_string(); let message = format!("Submission channel set to <#{}>.", channel); let mut guild_data = get_guild_data(); if guild_data.contains_key("submissionChannel") { guild_data["suggestionChannel"] = channel.into(); } else { guild_data.insert(String::from("suggestionChannel"), channel.into()); } set_guild_data(guild_data); ctx.say(message).await?; Ok(()) } #[command(prefix_command, slash_command, hide_in_help, ephemeral, owners_only)] #[allow(non_snake_case)] pub async fn setannouncementrole( ctx: Context<'_>, #[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(); if guild_data.contains_key(&guild) { let mut current_guild_data = guild_data[&guild].as_object().unwrap().clone(); if current_guild_data.contains_key("announcementRole") { current_guild_data["announcementRole"] = role.into(); } else { current_guild_data.insert(String::from("announcementRole"), role.into()); } guild_data[&guild] = current_guild_data.into(); } else { guild_data.insert(guild, json!({ "announcementRole": role })); } set_guild_data(guild_data); ctx.say("Announcement role set.").await?; Ok(()) } #[command(prefix_command, slash_command, hide_in_help, ephemeral, owners_only)] pub async fn announce( ctx: Context<'_>, #[description = "Announcement text"] announcement: String, ) -> Result<(), Error> { send(ctx, &announcement, true, false).await } #[command(prefix_command, slash_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 . 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. ().", n = challenge_number, th = match challenge_number % 10 { 1 => "ˢᵗ", 2 => "ⁿᵈ", 3 => "ʳᵈ", _ => "ᵗʰ" }, p = env::var("PREFIX").unwrap() ); send(ctx, &message, true, false).await?; ctx.say("Announced!").await?; Ok(()) }