diff --git a/README.md b/README.md index 5bb2fce..8260749 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # DIDgeridoo 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. diff --git a/src/main.rs b/src/main.rs index 98a92c2..ae8d496 100644 --- a/src/main.rs +++ b/src/main.rs @@ -106,7 +106,7 @@ async fn name(ctx: &Context, msg: &Message) -> CommandResult { #[command] 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!( msg.reply(&ctx, "You don’t have the permission to do that") .await @@ -122,8 +122,23 @@ async fn inbox(ctx: &Context, msg: &Message) -> CommandResult { ); return Ok(()); } - let output = messages.into_iter().join("\n"); - send_or_log!(msg.reply(&ctx, output).await); + for message in &messages { + 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 { send_or_log!(msg.reply(&ctx, "Kein Name für die Abfrage.").await); }