feat(discord): Moved most strings to Strings
- Added Error::AccountIsSelf variant - /balance give to self now returns error
This commit is contained in:
parent
aec4ef8339
commit
787118309a
7 changed files with 247 additions and 85 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use poise::serenity_prelude::{Attachment, ComponentInteractionCollector, CreateActionRow, CreateAttachment, CreateButton, CreateMessage, EditMessage, Mentionable};
|
||||
use poise::serenity_prelude::{Attachment, ComponentInteractionCollector, CreateActionRow, CreateAttachment, CreateButton, CreateMessage, EditMessage};
|
||||
use squad_quest::SquadObject;
|
||||
|
||||
use crate::{Context, Error, account::fetch_or_init_account};
|
||||
|
|
@ -33,7 +33,7 @@ pub async fn answer(
|
|||
.find(|q| q.id == quest_id) else {
|
||||
return Err(Error::QuestNotFound(quest_id));
|
||||
};
|
||||
|
||||
|
||||
let mut files: Vec<Attachment> = Vec::new();
|
||||
for file in [file1, file2, file3] {
|
||||
if let Some(f) = file {
|
||||
|
|
@ -45,23 +45,30 @@ pub async fn answer(
|
|||
return Err(Error::NoContent);
|
||||
}
|
||||
|
||||
let text_ans = match text {
|
||||
Some(text) => format!("\n### Passed answer:\n{text}"),
|
||||
let strings = &ctx.data().strings;
|
||||
let mut formatter = strings.formatter()
|
||||
.user(ctx.author())
|
||||
.quest(quest);
|
||||
|
||||
let text_ans = match text {
|
||||
Some(text) => {
|
||||
formatter = formatter.text(text);
|
||||
formatter.fmt(&strings.answer.text)
|
||||
},
|
||||
None => String::new(),
|
||||
};
|
||||
|
||||
let attachment_notice = if files.len() == 0 { String::new() } else {
|
||||
"\nPassed answer has attachments.".to_string()
|
||||
formatter.fmt(&strings.answer.attachment_notice)
|
||||
};
|
||||
|
||||
let content = format!("## From: {user}\n\
|
||||
### Quest #{quest_id}: {quest_name}\n\
|
||||
### Expected answer:\n\
|
||||
||{quest_answer}||{text_ans}{attachment_notice}",
|
||||
user = ctx.author().mention(),
|
||||
quest_name = quest.name,
|
||||
quest_answer = quest.answer,
|
||||
);
|
||||
let content = [
|
||||
formatter.fmt(&strings.answer.from),
|
||||
formatter.fmt(&strings.answer.quest),
|
||||
formatter.fmt(&strings.answer.expected),
|
||||
text_ans,
|
||||
attachment_notice,
|
||||
].join("");
|
||||
|
||||
let mut attachments: Vec<CreateAttachment> = Vec::new();
|
||||
|
||||
|
|
@ -91,19 +98,21 @@ pub async fn answer(
|
|||
|
||||
let mut message = ans_channel.send_message(ctx, builder).await?;
|
||||
|
||||
let reply_string = "Your answer has been posted.".to_string();
|
||||
let reply_string = formatter.fmt(&strings.answer.reply.initial);
|
||||
ctx.reply(reply_string).await?;
|
||||
|
||||
if let Some(press) = ComponentInteractionCollector::new(ctx)
|
||||
.filter(move |press| press.data.custom_id.starts_with(&ctx_id.to_string()))
|
||||
.await
|
||||
{
|
||||
let admin = press.user.mention();
|
||||
let admin = press.user;
|
||||
formatter = formatter.user(&admin).text(&content);
|
||||
|
||||
let is_approved = press.data.custom_id == approve_id;
|
||||
let content = if is_approved {
|
||||
format!("{content}\nApproved by: {admin}")
|
||||
formatter.fmt(&strings.answer.accepted_by)
|
||||
} else {
|
||||
format!("~~{content}~~\nRejected by: {admin}")
|
||||
formatter.fmt(&strings.answer.rejected_by)
|
||||
};
|
||||
|
||||
let builder = EditMessage::new().content(content).components(Vec::new());
|
||||
|
|
@ -122,21 +131,15 @@ pub async fn answer(
|
|||
no_errors = false;
|
||||
};
|
||||
|
||||
formatter = formatter.current_balance(&account);
|
||||
|
||||
if no_errors {
|
||||
content = format!("Your answer to the quest #{quest_id} has been approved.\n\
|
||||
You gained {reward} points.\n\
|
||||
Your balance is now {balance} points",
|
||||
reward = quest.reward,
|
||||
balance = account.balance
|
||||
);
|
||||
content = formatter.fmt(&strings.answer.reply.accepted);
|
||||
} else {
|
||||
content = format!("Your answer to the quest #{quest_id} has been approved, \
|
||||
but some server error happened. \
|
||||
Please contact administrator for details."
|
||||
);
|
||||
content = formatter.fmt(&strings.answer.reply.error);
|
||||
}
|
||||
} else {
|
||||
content = format!("Your answer to the quest #{quest_id} has been rejected.");
|
||||
content = formatter.fmt(&strings.answer.reply.rejected);
|
||||
};
|
||||
let dm_builder = CreateMessage::new().content(content);
|
||||
ctx.author().dm(ctx, dm_builder).await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue