serenity icon indicating copy to clipboard operation
serenity copied to clipboard

Integrated support for edit-tracking in framework

Open kangalio opened this issue 3 years ago • 2 comments

It would be amazing to have support for bot responses that dynamically adapt when users edit their command message. A feature like this is present for example in the official Rust Discord bot, and also in Ferris (the bot for the community Rust Discord). Furthermore, edit-tracking in this fashion is potentially applicable and useful to many bots with a simple command->response model.

Having integrated support for this feature in the serenity framework would be very convenient and admittedly quite cool.

Potential API design

  • Allow enabling edit-tracking for individual commands
    • Using #[track_edits] attribute on command functions
  • In serenity, store all Discord messages applicable to edit-tracking
  • When a Discord user edits a message applicable to edit-tracking, call the corresponding command function as if it were a new message
  • Allow adding a "trigger message ID" when sending a message
    • Add trigger_message(&mut self, trigger: MessageId) to CreateMessage
  • Serenity will remember all "trigger message -> response message" associations
  • When the bot attempts to send a message with a known trigger message, Serenity will edit the existing corresponding response message instead

From a user perspective, enabling edit tracking would work like this:

#[command]
async fn echo(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
    msg.channel_id.send_message(&ctx.http, |m| m.content(args.rest())).await?;
    Ok(())
}

->

#[command]
#[track_edits]
async fn echo(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
    msg.channel_id.send_message(&ctx.http, |m| m.content(args.rest()).trigger_message(msg.id)).await?;
    Ok(())
}

kangalio avatar Feb 15 '21 17:02 kangalio

Wouldn't command dispatch upon message edit as an option on the framework be more reasonable? Is there anything this would not cover for your use case?

Lakelezz avatar Feb 16 '21 05:02 Lakelezz

Command dispatch upon message edit was actually part of the API design idea, though perhaps I worded it confusingly:

When a Discord user edits a message applicable to edit-tracking, call the corresponding command function as if it were a new message

"Is there anything this would not cover for your use case?" Are you asking if the rest of the bullet points are really needed? If I'm understanding your question correctly, I'd argue yes, because without the rest of the bullet points implemented, users would have hand-roll their own system to store and edit messages.

kangalio avatar Feb 16 '21 09:02 kangalio

The standard framework is not really developed anymore, and my framework poise does have this feature so I'm gonna close this issue

kangalio avatar Sep 08 '22 08:09 kangalio