-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.rs
More file actions
36 lines (29 loc) · 889 Bytes
/
add.rs
File metadata and controls
36 lines (29 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use anyhow::Result;
use poise::serenity_prelude as serenity;
use crate::{Context, Message, check, database, util};
/// Add one or more candidate IDs to the candidates database from a text file.
#[tracing::instrument]
#[poise::command(
slash_command,
prefix_command,
ephemeral,
check = "check::is_moderator"
)]
pub async fn add(
ctx: Context<'_>,
#[description = "Text file with candidate IDs (one per line, UTF‑8)"] id: serenity::Attachment,
) -> Result<()> {
let pool = &ctx.data().pool;
let id = id.download().await?;
let id = String::from_utf8(id)?;
for id in id.lines() {
if util::is_valid_id(id) {
continue;
}
ctx.reply(Message::InvalidId).await?;
return Ok(());
}
database::candidate::add(id.trim().lines(), pool).await?;
ctx.reply(Message::CandidateAdded).await?;
Ok(())
}