From 1357d2c17c2b77d68068799c10c1621592948c67 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 21 Aug 2021 11:45:07 +0200 Subject: [PATCH] Update rich interactions and add owners to several menus Signed-off-by: trivernis --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/commands/misc/inspirobot.rs | 2 +- src/commands/misc/media.rs | 2 +- src/commands/misc/xkcd.rs | 2 +- src/commands/weeb/theme.rs | 2 +- src/messages/gifs.rs | 4 +++- src/messages/inspirobot.rs | 9 +++++++-- src/messages/theme.rs | 4 +++- src/messages/xkcd.rs | 4 +++- 10 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 031c102..292b24e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2208,9 +2208,9 @@ dependencies = [ [[package]] name = "serenity-rich-interaction" -version = "0.2.3" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8151b0ce52fdbcc8834a0b6788ff67baf83dea37a4050462c2b5ae2621b87821" +checksum = "9e29c534ec1387d4a0849587494e03acfb9780335468d9936f19af00f5fd0178" dependencies = [ "futures", "log 0.4.14", diff --git a/Cargo.toml b/Cargo.toml index 07a80b8..8cf306d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ panic = 'abort' [dependencies] bot-database = {path="./bot-database"} bot-coreutils = {path="./bot-coreutils"} -serenity-rich-interaction = "0.2.2" +serenity-rich-interaction = "0.2.5" serenity = "0.10.5" dotenv = "0.15.0" tokio = { version = "1.4.0", features = ["macros", "rt-multi-thread"] } diff --git a/src/commands/misc/inspirobot.rs b/src/commands/misc/inspirobot.rs index 209ad83..7b8b5e2 100644 --- a/src/commands/misc/inspirobot.rs +++ b/src/commands/misc/inspirobot.rs @@ -10,7 +10,7 @@ use serenity::model::channel::Message; #[aliases("inspireme", "inspire-me", "inspiro")] #[bucket("general")] async fn inspirobot(ctx: &Context, msg: &Message) -> CommandResult { - create_inspirobot_menu(ctx, msg.channel_id).await?; + create_inspirobot_menu(ctx, msg.channel_id, msg.author.id).await?; Ok(()) } diff --git a/src/commands/misc/media.rs b/src/commands/misc/media.rs index a4597af..3f85781 100644 --- a/src/commands/misc/media.rs +++ b/src/commands/misc/media.rs @@ -12,7 +12,7 @@ use serenity::model::channel::Message; async fn media(ctx: &Context, msg: &Message) -> CommandResult { let database = get_database_from_context(ctx).await; let gifs = database.get_all_media().await?; - create_media_menu(ctx, msg.channel_id, gifs).await?; + create_media_menu(ctx, msg.channel_id, gifs, msg.author.id).await?; Ok(()) } diff --git a/src/commands/misc/xkcd.rs b/src/commands/misc/xkcd.rs index c267fc7..3156eb6 100644 --- a/src/commands/misc/xkcd.rs +++ b/src/commands/misc/xkcd.rs @@ -29,7 +29,7 @@ async fn xkcd(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { vec![xkcd_search::get_latest_comic().await?] }; - create_xkcd_menu(ctx, msg.channel_id, comics).await?; + create_xkcd_menu(ctx, msg.channel_id, comics, msg.author.id).await?; Ok(()) } diff --git a/src/commands/weeb/theme.rs b/src/commands/weeb/theme.rs index 84fb763..019b6cd 100644 --- a/src/commands/weeb/theme.rs +++ b/src/commands/weeb/theme.rs @@ -25,7 +25,7 @@ async fn theme(ctx: &Context, msg: &Message, args: Args) -> CommandResult { }) .await?; } else { - create_theme_menu(ctx, msg.channel_id, entries).await?; + create_theme_menu(ctx, msg.channel_id, entries, msg.author.id).await?; } } else { EphemeralMessage::create(&ctx.http, msg.channel_id, MEDIUM_TIMEOUT, |c| { diff --git a/src/messages/gifs.rs b/src/messages/gifs.rs index c6c7c94..97c9717 100644 --- a/src/messages/gifs.rs +++ b/src/messages/gifs.rs @@ -2,7 +2,7 @@ use crate::utils::error::BotResult; use bot_database::models::Media; use serenity::builder::CreateMessage; use serenity::client::Context; -use serenity::model::id::ChannelId; +use serenity::model::id::{ChannelId, UserId}; use serenity_rich_interaction::menu::{MenuBuilder, Page}; use std::time::Duration; @@ -11,6 +11,7 @@ pub async fn create_media_menu( ctx: &Context, channel_id: ChannelId, media: Vec, + owner: UserId, ) -> BotResult<()> { let total_pages = (media.len() as f32 / 10.0).ceil() as usize; let pages: Vec = media @@ -23,6 +24,7 @@ pub async fn create_media_menu( .timeout(Duration::from_secs(120)) .add_pages(pages) .show_help() + .owner(owner) .build(ctx, channel_id) .await?; diff --git a/src/messages/inspirobot.rs b/src/messages/inspirobot.rs index 98ab969..87090ec 100644 --- a/src/messages/inspirobot.rs +++ b/src/messages/inspirobot.rs @@ -2,7 +2,7 @@ use crate::providers::music::inspirobot::get_inspirobot_image; use crate::utils::error::BotResult; use serenity::builder::CreateMessage; use serenity::client::Context; -use serenity::model::id::ChannelId; +use serenity::model::id::{ChannelId, UserId}; use serenity_rich_interaction::core::EXTRA_LONG_TIMEOUT; use serenity_rich_interaction::menu::{ close_menu, display_page, MenuBuilder, Page, CLOSE_MENU_EMOJI, @@ -10,7 +10,11 @@ use serenity_rich_interaction::menu::{ static REFRESH_EMOJI: &str = "🔄"; -pub async fn create_inspirobot_menu(ctx: &Context, channel_id: ChannelId) -> BotResult<()> { +pub async fn create_inspirobot_menu( + ctx: &Context, + channel_id: ChannelId, + owner: UserId, +) -> BotResult<()> { MenuBuilder::default() .add_control(0, REFRESH_EMOJI, |ctx, menu, _r| { Box::pin(async move { @@ -30,6 +34,7 @@ pub async fn create_inspirobot_menu(ctx: &Context, channel_id: ChannelId) -> Bot Ok(message) }) })) + .owner(owner) .timeout(EXTRA_LONG_TIMEOUT) .build(ctx, channel_id) .await?; diff --git a/src/messages/theme.rs b/src/messages/theme.rs index 317a165..5dbea60 100644 --- a/src/messages/theme.rs +++ b/src/messages/theme.rs @@ -2,7 +2,7 @@ use crate::utils::error::BotResult; use animethemes_rs::models::{ThemeEntry, ThemeType}; use serenity::builder::CreateMessage; use serenity::client::Context; -use serenity::model::id::ChannelId; +use serenity::model::id::{ChannelId, UserId}; use serenity_rich_interaction::core::EXTRA_LONG_TIMEOUT; use serenity_rich_interaction::menu::{MenuBuilder, Page}; @@ -11,6 +11,7 @@ pub async fn create_theme_menu( ctx: &Context, channel_id: ChannelId, mut entries: Vec, + owner: UserId, ) -> BotResult<()> { let nsfw = ctx.http.get_channel(channel_id.0).await?.is_nsfw(); entries.sort_by_key(|t| { @@ -40,6 +41,7 @@ pub async fn create_theme_menu( .map(create_theme_page), ) .timeout(EXTRA_LONG_TIMEOUT) + .owner(owner) .build(ctx, channel_id) .await?; diff --git a/src/messages/xkcd.rs b/src/messages/xkcd.rs index 9dc3434..4a3bf91 100644 --- a/src/messages/xkcd.rs +++ b/src/messages/xkcd.rs @@ -1,7 +1,7 @@ use crate::utils::error::BotResult; use serenity::builder::CreateMessage; use serenity::client::Context; -use serenity::model::id::ChannelId; +use serenity::model::id::{ChannelId, UserId}; use serenity_rich_interaction::core::LONG_TIMEOUT; use serenity_rich_interaction::menu::{MenuBuilder, Page}; use xkcd_search::Comic; @@ -11,6 +11,7 @@ pub async fn create_xkcd_menu( ctx: &Context, channel_id: ChannelId, comics: Vec, + owner: UserId, ) -> BotResult<()> { let mut builder = if comics.len() > 1 { MenuBuilder::new_paginator() @@ -25,6 +26,7 @@ pub async fn create_xkcd_menu( builder .add_pages(comics.into_iter().map(|c| create_xkcd_page(c))) .timeout(LONG_TIMEOUT) + .owner(owner) .build(ctx, channel_id) .await?;