@ -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! (
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,13 +42,19 @@ 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 . msg
. reply (
& ctx . discord . http ,
format! (
"Sorry, submissions aren't permitted here. Please go to <#{}>. Thanks!" ,
@ -53,7 +65,9 @@ pub async fn submit(ctx: PrefixContext<'_>) -> Result<(), Error> {
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! (
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,8 +251,7 @@ 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 {
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.
@ -245,8 +265,7 @@ pub async fn imagedelete(
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! (
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 ( )