From 9e125c87a887e393b0693c25b95c4282138be141 Mon Sep 17 00:00:00 2001 From: CircuitSacul Date: Mon, 21 Nov 2022 17:27:37 -0500 Subject: [PATCH] upgrade to twilight 0.14 --- Cargo.toml | 14 +++++++------- Dockerfile | 2 +- src/cache/cache.rs | 15 ++++----------- src/cache/models/message.rs | 2 +- src/client/bot.rs | 1 - src/core/autostar.rs | 7 +------ src/core/embedder/attachment_handle.rs | 2 +- src/core/embedder/builder.rs | 2 +- src/core/embedder/handle.rs | 3 --- src/core/embedder/image_only_embed.rs | 2 +- src/core/embedder/parser.rs | 2 +- src/core/emoji.rs | 2 +- src/core/has_image.rs | 2 +- src/core/starboard/handle.rs | 1 - src/core/starboard/reaction_events.rs | 1 - src/interactions/autocomplete/autostar_name.rs | 6 +++--- src/interactions/autocomplete/handle.rs | 1 - src/interactions/autocomplete/override_name.rs | 6 +++--- src/interactions/autocomplete/starboard_name.rs | 6 +++--- src/interactions/commands/chat/autostar/create.rs | 2 +- .../commands/chat/starboard/create.rs | 2 +- src/interactions/commands/register.rs | 2 +- src/interactions/components/dismiss.rs | 1 - src/interactions/context.rs | 5 ++--- src/owner/commands/sql.rs | 6 +----- src/utils/dm.rs | 1 - src/utils/notify.rs | 3 +-- 27 files changed, 36 insertions(+), 63 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3d09e921..8293999c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,13 +6,13 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -twilight-gateway = "0.13.0" -twilight-http = "0.13.0" -twilight-model = "0.13.0" -twilight-util = { version = "0.13.0", features = ["builder", "snowflake"] } -twilight-interactions = "0.13.0" -twilight-mention = "0.13.0" -twilight-standby = "0.13.0" +twilight-gateway = "0.14.0" +twilight-http = "0.14.0" +twilight-model = "0.14.0" +twilight-util = { version = "0.14.0", features = ["builder", "snowflake"] } +twilight-interactions = "0.14.0" +twilight-mention = "0.14.0" +twilight-standby = "0.14.0" async-trait = "0.1.56" tokio = { version = "1.19.2", features = ["full"] } diff --git a/Dockerfile b/Dockerfile index 455a3953..4d70af75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.62.0-slim-buster as builder +FROM rust:1.65.0-slim-buster as builder WORKDIR /usr/src/starboard # force cargo to update the crates.io index. diff --git a/src/cache/cache.rs b/src/cache/cache.rs index 742c8755..d5b49bf8 100644 --- a/src/cache/cache.rs +++ b/src/cache/cache.rs @@ -140,14 +140,7 @@ impl Cache { }); if must_fetch { - let channel = bot - .http - .channel(channel_id) - .exec() - .await? - .model() - .await - .unwrap(); + let channel = bot.http.channel(channel_id).await?.model().await.unwrap(); current_channel_id = channel.parent_id; } } @@ -166,7 +159,7 @@ impl Cache { user_id: Id, ) -> StarboardResult>> { if !self.users.contains_key(&user_id) { - let user_get = bot.http.user(user_id).exec().await; + let user_get = bot.http.user(user_id).await; let user = match user_get { Ok(user) => Some(Arc::new(user.model().await.unwrap().into())), Err(why) => { @@ -194,7 +187,7 @@ impl Cache { return Ok(cached.value().clone()); } - let msg = bot.http.message(channel_id, message_id).exec().await; + let msg = bot.http.message(channel_id, message_id).await; let msg = match msg { Err(why) => { if get_status(&why) == Some(404) { @@ -221,7 +214,7 @@ impl Cache { bot: &StarboardBot, channel_id: Id, ) -> StarboardResult> { - let channel = bot.http.channel(channel_id).exec().await; + let channel = bot.http.channel(channel_id).await; let channel = match channel { Ok(channel) => channel, Err(why) => { diff --git a/src/cache/models/message.rs b/src/cache/models/message.rs index e2637e5f..24a878f1 100644 --- a/src/cache/models/message.rs +++ b/src/cache/models/message.rs @@ -1,5 +1,5 @@ use twilight_model::{ - channel::{embed::Embed, Attachment, Message}, + channel::{message::embed::Embed, Attachment, Message}, id::{ marker::{MessageMarker, UserMarker}, Id, diff --git a/src/client/bot.rs b/src/client/bot.rs index c05f2b55..149d6b6c 100644 --- a/src/client/bot.rs +++ b/src/client/bot.rs @@ -113,7 +113,6 @@ impl StarboardBot { .create_message(chid.into_id()) .content(msg) .unwrap() - .exec() .await; } } diff --git a/src/core/autostar.rs b/src/core/autostar.rs index 271d6435..2f4c1f34 100644 --- a/src/core/autostar.rs +++ b/src/core/autostar.rs @@ -51,11 +51,7 @@ pub async fn handle(bot: &StarboardBot, event: &MessageCreate) -> anyhow::Result continue; } if let Status::InvalidRemove(reasons) = status { - let _ = bot - .http - .delete_message(event.channel_id, event.id) - .exec() - .await; + let _ = bot.http.delete_message(event.channel_id, event.id).await; if !event.author.bot { let message = { @@ -74,7 +70,6 @@ pub async fn handle(bot: &StarboardBot, event: &MessageCreate) -> anyhow::Result let _ = bot .http .create_reaction(event.channel_id, event.id, &emoji.reactable()) - .exec() .await; } } diff --git a/src/core/embedder/attachment_handle.rs b/src/core/embedder/attachment_handle.rs index 1a7e4da7..e26dd8c9 100644 --- a/src/core/embedder/attachment_handle.rs +++ b/src/core/embedder/attachment_handle.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; use twilight_model::{ - channel::{embed::Embed, Attachment as ReceivedAttachment}, + channel::{message::embed::Embed, Attachment as ReceivedAttachment}, http::attachment::Attachment, }; use twilight_util::builder::embed::{EmbedBuilder, ImageSource}; diff --git a/src/core/embedder/builder.rs b/src/core/embedder/builder.rs index 23a70c47..9b118953 100644 --- a/src/core/embedder/builder.rs +++ b/src/core/embedder/builder.rs @@ -1,7 +1,7 @@ use std::fmt::Write; use twilight_model::{ - channel::embed::Embed, + channel::message::embed::Embed, id::{marker::MessageMarker, Id}, util::Timestamp, }; diff --git a/src/core/embedder/handle.rs b/src/core/embedder/handle.rs index fe8994e4..e3976b8d 100644 --- a/src/core/embedder/handle.rs +++ b/src/core/embedder/handle.rs @@ -72,7 +72,6 @@ impl Embedder<'_> { .unwrap() .attachments(&attachments) .unwrap() - .exec() .await } @@ -90,7 +89,6 @@ impl Embedder<'_> { .unwrap() .embeds(Some(&built.embeds)) .unwrap() - .exec() .await } BuiltStarboardEmbed::Partial(built) => { @@ -98,7 +96,6 @@ impl Embedder<'_> { .update_message(self.config.starboard.channel_id.into_id(), message_id) .content(Some(&built.top_content)) .unwrap() - .exec() .await } } diff --git a/src/core/embedder/image_only_embed.rs b/src/core/embedder/image_only_embed.rs index 1b720383..c8ebed32 100644 --- a/src/core/embedder/image_only_embed.rs +++ b/src/core/embedder/image_only_embed.rs @@ -1,4 +1,4 @@ -use twilight_model::channel::embed::Embed; +use twilight_model::channel::message::embed::Embed; use crate::utils::gifv::get_gif_url; diff --git a/src/core/embedder/parser.rs b/src/core/embedder/parser.rs index 8c6bdc70..08915eac 100644 --- a/src/core/embedder/parser.rs +++ b/src/core/embedder/parser.rs @@ -1,4 +1,4 @@ -use twilight_model::channel::embed::Embed; +use twilight_model::channel::message::embed::Embed; use twilight_util::builder::embed::ImageSource; use crate::cache::models::message::CachedMessage; diff --git a/src/core/emoji.rs b/src/core/emoji.rs index c615686c..c1b34289 100644 --- a/src/core/emoji.rs +++ b/src/core/emoji.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use twilight_http::request::channel::reaction::RequestReactionType; use twilight_mention::Mention; use twilight_model::{ - channel::ReactionType, + channel::message::ReactionType, id::{ marker::{EmojiMarker, GuildMarker}, Id, diff --git a/src/core/has_image.rs b/src/core/has_image.rs index b5f8a405..1ea8ec7b 100644 --- a/src/core/has_image.rs +++ b/src/core/has_image.rs @@ -1,4 +1,4 @@ -use twilight_model::channel::{embed::Embed, Attachment}; +use twilight_model::channel::{message::embed::Embed, Attachment}; pub fn has_image(embeds: &Vec, attachments: &Vec) -> bool { for attachment in attachments { diff --git a/src/core/starboard/handle.rs b/src/core/starboard/handle.rs index 0fcef4ff..69549b26 100644 --- a/src/core/starboard/handle.rs +++ b/src/core/starboard/handle.rs @@ -215,7 +215,6 @@ impl<'this, 'bot> RefreshStarboard<'this, 'bot> { self.config.starboard.channel_id.into_id(), sb_msg.starboard_message_id.into_id(), ) - .exec() .await; (ret.map(|_| ()), false, true) } diff --git a/src/core/starboard/reaction_events.rs b/src/core/starboard/reaction_events.rs index 82c9521d..574f02be 100644 --- a/src/core/starboard/reaction_events.rs +++ b/src/core/starboard/reaction_events.rs @@ -116,7 +116,6 @@ pub async fn handle_reaction_add( &emoji.reactable(), event.user_id, ) - .exec() .await; Ok(()) diff --git a/src/interactions/autocomplete/autostar_name.rs b/src/interactions/autocomplete/autostar_name.rs index c7918b0a..875ccd72 100644 --- a/src/interactions/autocomplete/autostar_name.rs +++ b/src/interactions/autocomplete/autostar_name.rs @@ -1,4 +1,4 @@ -use twilight_model::application::command::CommandOptionChoice; +use twilight_model::application::command::{CommandOptionChoice, CommandOptionChoiceData}; use crate::{database::AutoStarChannel, interactions::context::CommandCtx, unwrap_id}; @@ -17,11 +17,11 @@ pub async fn autostar_name_autocomplete( let mut arr = Vec::new(); for name in names { - arr.push(CommandOptionChoice::String { + arr.push(CommandOptionChoice::String(CommandOptionChoiceData { name: name.clone(), name_localizations: None, value: name, - }); + })); } Ok(arr) diff --git a/src/interactions/autocomplete/handle.rs b/src/interactions/autocomplete/handle.rs index c09f82fc..3934431d 100644 --- a/src/interactions/autocomplete/handle.rs +++ b/src/interactions/autocomplete/handle.rs @@ -94,7 +94,6 @@ pub async fn handle_autocomplete(ctx: CommandCtx) -> anyhow::Result<()> { kind: InteractionResponseType::ApplicationCommandAutocompleteResult, }; i.create_response(ctx.interaction.id, &ctx.interaction.token, &resp) - .exec() .await?; Ok(()) diff --git a/src/interactions/autocomplete/override_name.rs b/src/interactions/autocomplete/override_name.rs index 74c662c9..e202da52 100644 --- a/src/interactions/autocomplete/override_name.rs +++ b/src/interactions/autocomplete/override_name.rs @@ -1,4 +1,4 @@ -use twilight_model::application::command::CommandOptionChoice; +use twilight_model::application::command::{CommandOptionChoice, CommandOptionChoiceData}; use crate::{database::StarboardOverride, interactions::context::CommandCtx, unwrap_id}; @@ -17,11 +17,11 @@ pub async fn override_name_autocomplete( let mut arr = Vec::new(); for name in names { - arr.push(CommandOptionChoice::String { + arr.push(CommandOptionChoice::String(CommandOptionChoiceData { name: name.clone(), name_localizations: None, value: name, - }); + })); } Ok(arr) diff --git a/src/interactions/autocomplete/starboard_name.rs b/src/interactions/autocomplete/starboard_name.rs index 2ddd1695..9f2b1964 100644 --- a/src/interactions/autocomplete/starboard_name.rs +++ b/src/interactions/autocomplete/starboard_name.rs @@ -1,4 +1,4 @@ -use twilight_model::application::command::CommandOptionChoice; +use twilight_model::application::command::{CommandOptionChoice, CommandOptionChoiceData}; use crate::{database::Starboard, interactions::context::CommandCtx, unwrap_id}; @@ -17,11 +17,11 @@ pub async fn starboard_name_autocomplete( let mut arr = Vec::new(); for name in names { - arr.push(CommandOptionChoice::String { + arr.push(CommandOptionChoice::String(CommandOptionChoiceData { name: name.clone(), name_localizations: None, value: name, - }); + })); } Ok(arr) diff --git a/src/interactions/commands/chat/autostar/create.rs b/src/interactions/commands/chat/autostar/create.rs index 3e47b053..76824e44 100644 --- a/src/interactions/commands/chat/autostar/create.rs +++ b/src/interactions/commands/chat/autostar/create.rs @@ -14,7 +14,7 @@ pub struct CreateAutoStarChannel { /// The name of the autostar channel. name: String, /// The channel to create an autostar channel in. - #[command(channel_types = "guild_text guild_news")] + #[command(channel_types = "guild_text")] channel: InteractionChannel, } diff --git a/src/interactions/commands/chat/starboard/create.rs b/src/interactions/commands/chat/starboard/create.rs index 721fa27d..0f5d1e56 100644 --- a/src/interactions/commands/chat/starboard/create.rs +++ b/src/interactions/commands/chat/starboard/create.rs @@ -14,7 +14,7 @@ pub struct CreateStarboard { /// The name of the starboard. name: String, /// The channel to create a starboard in. - #[command(channel_types = "guild_text guild_news")] + #[command(channel_types = "guild_text")] channel: InteractionChannel, } diff --git a/src/interactions/commands/register.rs b/src/interactions/commands/register.rs index 26fe305c..3df38142 100644 --- a/src/interactions/commands/register.rs +++ b/src/interactions/commands/register.rs @@ -24,7 +24,7 @@ pub async fn post_commands(bot: Arc) { chat::overrides::Overrides ); - match inter_client.set_global_commands(&commands).exec().await { + match inter_client.set_global_commands(&commands).await { Ok(_) => println!("Successfully registered commands"), Err(e) => eprintln!("Failed to register commands: {}", e), } diff --git a/src/interactions/components/dismiss.rs b/src/interactions/components/dismiss.rs index 1935e657..4f3205ae 100644 --- a/src/interactions/components/dismiss.rs +++ b/src/interactions/components/dismiss.rs @@ -7,7 +7,6 @@ pub async fn handle_dismiss(ctx: &ComponentCtx) -> anyhow::Result<()> { ctx.bot .http .delete_message(message.channel_id, message.id) - .exec() .await?; Ok(()) diff --git a/src/interactions/context.rs b/src/interactions/context.rs index 48620ef6..6b9b1126 100644 --- a/src/interactions/context.rs +++ b/src/interactions/context.rs @@ -78,19 +78,18 @@ impl Ctx { followup = followup.tts(tts); } - followup.exec().await + followup.await } else { i.create_response( self.interaction.id, &self.interaction.token, &InteractionResponse { data, kind }, ) - .exec() .await?; self.responded = true; - i.response(&self.interaction.token).exec().await + i.response(&self.interaction.token).await } } diff --git a/src/owner/commands/sql.rs b/src/owner/commands/sql.rs index 60bc6d8f..0ffbc04c 100644 --- a/src/owner/commands/sql.rs +++ b/src/owner/commands/sql.rs @@ -10,10 +10,7 @@ use twilight_model::gateway::payload::incoming::MessageCreate; use crate::{client::bot::StarboardBot, concat_format, owner::code_block::parse_code_blocks}; pub async fn run_sql(bot: &StarboardBot, event: &MessageCreate) -> anyhow::Result<()> { - bot.http - .create_typing_trigger(event.channel_id) - .exec() - .await?; + bot.http.create_typing_trigger(event.channel_id).await?; let blocks = parse_code_blocks(event.content.strip_prefix("star sql").unwrap()); let mut results = Vec::new(); @@ -74,7 +71,6 @@ pub async fn run_sql(bot: &StarboardBot, event: &MessageCreate) -> anyhow::Resul .create_message(event.channel_id) .content(&final_result) .unwrap() - .exec() .await?; Ok(()) } diff --git a/src/utils/dm.rs b/src/utils/dm.rs index cc69ccd6..e5f77283 100644 --- a/src/utils/dm.rs +++ b/src/utils/dm.rs @@ -10,7 +10,6 @@ pub async fn dm( let dm_channel = bot .http .create_private_channel(user_id) - .exec() .await? .model() .await diff --git a/src/utils/notify.rs b/src/utils/notify.rs index 64f0528d..f22b8643 100644 --- a/src/utils/notify.rs +++ b/src/utils/notify.rs @@ -1,5 +1,5 @@ use twilight_model::{ - application::component::{button::ButtonStyle, ActionRow, Button, Component}, + channel::message::component::{ActionRow, Button, ButtonStyle, Component}, id::{marker::UserMarker, Id}, }; @@ -35,6 +35,5 @@ pub async fn notify(bot: &StarboardBot, user_id: Id, message: &str) .unwrap() .components(&[comp]) .unwrap() - .exec() .await; }