Update rich interactions and add owners to several menus

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/37/head
trivernis 3 years ago
parent e9adc2393d
commit 1357d2c17c
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

4
Cargo.lock generated

@ -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",

@ -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"] }

@ -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(())
}

@ -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(())
}

@ -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(())
}

@ -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| {

@ -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<Media>,
owner: UserId,
) -> BotResult<()> {
let total_pages = (media.len() as f32 / 10.0).ceil() as usize;
let pages: Vec<Page> = 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?;

@ -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?;

@ -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<ThemeEntry>,
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?;

@ -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<Comic>,
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?;

Loading…
Cancel
Save