update poise

This commit is contained in:
jude 2023-06-18 10:47:31 +01:00
parent c8c1a171d4
commit a66db37b33
9 changed files with 63 additions and 59 deletions

8
Cargo.lock generated
View File

@ -1967,9 +1967,9 @@ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]]
name = "poise"
version = "0.4.1"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aee439543df35482730552e7c9ed0c45a5f1d521548e6c0249967c4ba8828f60"
checksum = "6d591af1c934c29adda172665f69b837e642d4fee85598baffb95dd98110467d"
dependencies = [
"async-trait",
"derivative",
@ -1986,9 +1986,9 @@ dependencies = [
[[package]]
name = "poise_macros"
version = "0.4.0"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d21213ff7aeef5ab69729a5cddfb351a84a9bf3dadf9f470032440d43746c2"
checksum = "40270099e1527efae99fdc0609d397e76310b529d4980ad38ab14d81803ca0fa"
dependencies = [
"darling",
"proc-macro2",

View File

@ -1,13 +1,13 @@
[package]
name = "reminder-rs"
version = "1.6.13"
version = "1.6.14"
authors = ["Jude Southworth <judesouthworth@pm.me>"]
edition = "2021"
license = "AGPL-3.0 only"
description = "Reminder Bot for Discord, now in Rust"
[dependencies]
poise = "0.4"
poise = "0.5.5"
dotenv = "0.15"
tokio = { version = "1", features = ["process", "full"] }
reqwest = "0.11"

View File

@ -6,8 +6,8 @@ use crate::{models::CtxData, Context, Error, THEME_COLOR};
fn footer(
ctx: Context<'_>,
) -> impl FnOnce(&mut serenity::CreateEmbedFooter) -> &mut serenity::CreateEmbedFooter {
let shard_count = ctx.discord().cache.shard_count();
let shard = ctx.discord().shard_id;
let shard_count = ctx.serenity_context().cache.shard_count();
let shard = ctx.serenity_context().shard_id;
move |f| {
f.text(format!(

View File

@ -2,6 +2,7 @@ use std::{collections::HashSet, string::ToString};
use chrono::{DateTime, NaiveDateTime, Utc};
use chrono_tz::Tz;
use log::warn;
use num_integer::Integer;
use poise::{
serenity_prelude::{
@ -215,7 +216,7 @@ pub async fn look(
}),
};
let channel_opt = ctx.channel_id().to_channel_cached(&ctx.discord());
let channel_opt = ctx.channel_id().to_channel_cached(&ctx);
let channel_id = if let Some(Channel::Guild(channel)) = channel_opt {
if Some(channel.guild_id) == ctx.guild_id() {
@ -227,12 +228,11 @@ pub async fn look(
ctx.channel_id()
};
let channel_name =
if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx.discord()) {
Some(channel.name)
} else {
None
};
let channel_name = if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx) {
Some(channel.name)
} else {
None
};
let reminders = Reminder::from_channel(&ctx.data().database, channel_id, &flags).await;
@ -294,8 +294,7 @@ pub async fn delete(ctx: Context<'_>) -> Result<(), Error> {
let timezone = ctx.timezone().await;
let reminders =
Reminder::from_guild(&ctx.discord(), &ctx.data().database, ctx.guild_id(), ctx.author().id)
.await;
Reminder::from_guild(&ctx, &ctx.data().database, ctx.guild_id(), ctx.author().id).await;
let resp = show_delete_page(&reminders, 0, timezone);
@ -585,19 +584,31 @@ pub async fn multiline(
timezone: Option<String>,
) -> Result<(), Error> {
let tz = timezone.map(|t| t.parse::<Tz>().ok()).flatten();
let data = ContentModal::execute(ctx).await?;
let data_opt = ContentModal::execute(ctx).await?;
create_reminder(
Context::Application(ctx),
time,
data.content,
channels,
interval,
expires,
tts,
tz,
)
.await
match data_opt {
Some(data) => {
create_reminder(
Context::Application(ctx),
time,
data.content,
channels,
interval,
expires,
tts,
tz,
)
.await
}
None => {
warn!("Unexpected None encountered in /multiline");
Ok(Context::Application(ctx)
.send(|m| m.content("Unexpected error.").ephemeral(true))
.await
.map(|_| ())?)
}
}
}
/// Create a reminder. Press "+4 more" for other options. Use "/multiline" for multiline content.
@ -681,9 +692,9 @@ async fn create_reminder(
};
let (processed_interval, processed_expires) = if let Some(repeat) = &interval {
if check_subscription(&ctx.discord(), ctx.author().id).await
if check_subscription(&ctx, ctx.author().id).await
|| (ctx.guild_id().is_some()
&& check_guild_subscription(&ctx.discord(), ctx.guild_id().unwrap()).await)
&& check_guild_subscription(&ctx, ctx.guild_id().unwrap()).await)
{
(
parse_duration(repeat)

View File

@ -47,21 +47,19 @@ async fn macro_check(ctx: Context<'_>) -> bool {
async fn check_self_permissions(ctx: Context<'_>) -> bool {
if let Some(guild) = ctx.guild() {
let user_id = ctx.discord().cache.current_user_id();
let user_id = ctx.serenity_context().cache.current_user_id();
let manage_webhooks = guild
.member_permissions(&ctx.discord(), user_id)
.await
.map_or(false, |p| p.manage_webhooks());
let manage_webhooks =
guild.member_permissions(&ctx, user_id).await.map_or(false, |p| p.manage_webhooks());
let (view_channel, send_messages, embed_links) = ctx
.channel_id()
.to_channel(&ctx.discord())
.to_channel(&ctx)
.await
.ok()
.and_then(|c| {
if let Channel::Guild(channel) = c {
let perms = channel.permissions_for_user(&ctx.discord(), user_id).ok()?;
let perms = channel.permissions_for_user(&ctx, user_id).ok()?;
Some((perms.view_channel(), perms.send_messages(), perms.embed_links()))
} else {

View File

@ -175,7 +175,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
],
allowed_mentions: None,
command_check: Some(|ctx| Box::pin(all_checks(ctx))),
listener: |ctx, event, _framework, data| Box::pin(listener(ctx, event, data)),
event_handler: |ctx, event, _framework, data| Box::pin(listener(ctx, event, data)),
..Default::default()
};
@ -201,7 +201,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
poise::Framework::builder()
.token(discord_token)
.user_data_setup(move |ctx, _bot, framework| {
.setup(move |ctx, _bot, framework| {
Box::pin(async move {
register_application_commands(ctx, framework, None).await.unwrap();

View File

@ -31,11 +31,12 @@ pub trait CtxData {
#[async_trait]
impl CtxData for Context<'_> {
async fn user_data<U: Into<UserId> + Send>(&self, user_id: U) -> Result<UserData, Error> {
UserData::from_user(user_id, &self.discord(), &self.data().database).await
UserData::from_user(user_id, &self.serenity_context(), &self.data().database).await
}
async fn author_data(&self) -> Result<UserData, Error> {
UserData::from_user(&self.author().id, &self.discord(), &self.data().database).await
UserData::from_user(&self.author().id, &self.serenity_context(), &self.data().database)
.await
}
async fn guild_data(&self) -> Option<Result<GuildData, Error>> {
@ -52,18 +53,18 @@ impl CtxData for Context<'_> {
async fn channel_data(&self) -> Result<ChannelData, Box<dyn std::error::Error + Sync + Send>> {
// If we're in a thread, get the parent channel.
let recv_channel = self.channel_id().to_channel(&self.discord()).await?;
let recv_channel = self.channel_id().to_channel(&self).await?;
let channel = match recv_channel.guild() {
Some(guild_channel) => {
if guild_channel.kind == ChannelType::PublicThread {
guild_channel.parent_id.unwrap().to_channel_cached(&self.discord()).unwrap()
guild_channel.parent_id.unwrap().to_channel_cached(&self).unwrap()
} else {
self.channel_id().to_channel_cached(&self.discord()).unwrap()
self.channel_id().to_channel_cached(&self).unwrap()
}
}
None => self.channel_id().to_channel_cached(&self.discord()).unwrap(),
None => self.channel_id().to_channel_cached(&self).unwrap(),
};
ChannelData::from_channel(&channel, &self.data().database).await

View File

@ -230,17 +230,17 @@ impl<'a> MultiReminderBuilder<'a> {
let thread_id = None;
let db_channel_id = match scope {
ReminderScope::User(user_id) => {
if let Ok(user) = UserId(user_id).to_user(&self.ctx.discord()).await {
if let Ok(user) = UserId(user_id).to_user(&self.ctx).await {
let user_data = UserData::from_user(
&user,
&self.ctx.discord(),
&self.ctx.serenity_context(),
&self.ctx.data().database,
)
.await
.unwrap();
if let Some(guild_id) = self.guild_id {
if guild_id.member(&self.ctx.discord(), user).await.is_err() {
if guild_id.member(&self.ctx, user).await.is_err() {
Err(ReminderError::InvalidTag)
} else if self.set_by.map_or(true, |i| i != user_data.id)
&& !user_data.allowed_dm
@ -257,8 +257,7 @@ impl<'a> MultiReminderBuilder<'a> {
}
}
ReminderScope::Channel(channel_id) => {
let channel =
ChannelId(channel_id).to_channel(&self.ctx.discord()).await.unwrap();
let channel = ChannelId(channel_id).to_channel(&self.ctx).await.unwrap();
if let Some(mut guild_channel) = channel.clone().guild() {
if Some(guild_channel.guild_id) != self.guild_id {
@ -271,7 +270,7 @@ impl<'a> MultiReminderBuilder<'a> {
let parent = guild_channel
.parent_id
.unwrap()
.to_channel(&self.ctx.discord())
.to_channel(&self.ctx)
.await
.unwrap();
guild_channel = parent.clone().guild().unwrap();
@ -287,12 +286,7 @@ impl<'a> MultiReminderBuilder<'a> {
if channel_data.webhook_id.is_none()
|| channel_data.webhook_token.is_none()
{
match create_webhook(
&self.ctx.discord(),
guild_channel,
"Reminder",
)
.await
match create_webhook(&self.ctx, guild_channel, "Reminder").await
{
Ok(webhook) => {
channel_data.webhook_id =

View File

@ -83,7 +83,7 @@ pub fn send_as_initial_response(
components,
ephemeral,
allowed_mentions,
reference_message: _, // can't reply to a message in interactions
reply: _,
} = data;
if let Some(content) = content {