Split longer messages
This commit is contained in:
parent
e0015323a0
commit
4eaae45f5f
|
@ -1,3 +1,3 @@
|
||||||
# DIDgeridoo
|
# DIDgeridoo
|
||||||
A bot for people with dissociative identity disorder.
|
A bot for people with dissociative identity disorder.
|
||||||
Currently only does and logs name changes.
|
Currently only does and logs name changes and has basic inbox functionality for a single user per instance.
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -106,7 +106,7 @@ async fn name(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
async fn inbox(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn inbox(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
if msg.author.id != INBOX_OWNER {
|
if msg.author.id != INBOX_OWNER || !msg.is_private() {
|
||||||
send_or_log!(
|
send_or_log!(
|
||||||
msg.reply(&ctx, "You don’t have the permission to do that")
|
msg.reply(&ctx, "You don’t have the permission to do that")
|
||||||
.await
|
.await
|
||||||
|
@ -122,8 +122,23 @@ async fn inbox(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let output = messages.into_iter().join("\n");
|
for message in &messages {
|
||||||
send_or_log!(msg.reply(&ctx, output).await);
|
let content = message.to_string();
|
||||||
|
// Since we’re prepending a name (and later a time) to the message,
|
||||||
|
// it could go over the limit of 2000 characters.
|
||||||
|
// There is some leniency in the numbers here because unicode codepoints are meh.
|
||||||
|
if content.len() > 1900 {
|
||||||
|
let (first, second) = content.split_at(1500);
|
||||||
|
send_or_log!(msg.channel_id.say(&ctx, &first).await);
|
||||||
|
send_or_log!(msg.channel_id.say(&ctx, &second).await);
|
||||||
|
} else {
|
||||||
|
send_or_log!(msg.channel_id.say(&ctx, &content).await);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{:?}", messages); // paranoia for now so the messages aren’t lost
|
||||||
|
if let Err(e) = INBOX.clear_messages(name) {
|
||||||
|
eprintln!("Could not clear inbox of user {} because {}", name, e);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
send_or_log!(msg.reply(&ctx, "Kein Name für die Abfrage.").await);
|
send_or_log!(msg.reply(&ctx, "Kein Name für die Abfrage.").await);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user