Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to twilight 0.14 #105

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
15 changes: 4 additions & 11 deletions src/cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -166,7 +159,7 @@ impl Cache {
user_id: Id<UserMarker>,
) -> StarboardResult<Option<Arc<CachedUser>>> {
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) => {
Expand Down Expand Up @@ -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) {
Expand All @@ -221,7 +214,7 @@ impl Cache {
bot: &StarboardBot,
channel_id: Id<ChannelMarker>,
) -> StarboardResult<Option<Channel>> {
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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/cache/models/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use twilight_model::{
channel::{embed::Embed, Attachment, Message},
channel::{message::embed::Embed, Attachment, Message},
id::{
marker::{MessageMarker, UserMarker},
Id,
Expand Down
1 change: 0 additions & 1 deletion src/client/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ impl StarboardBot {
.create_message(chid.into_id())
.content(msg)
.unwrap()
.exec()
.await;
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/core/autostar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/embedder/attachment_handle.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion src/core/embedder/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Write;

use twilight_model::{
channel::embed::Embed,
channel::message::embed::Embed,
id::{marker::MessageMarker, Id},
util::Timestamp,
};
Expand Down
3 changes: 0 additions & 3 deletions src/core/embedder/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ impl Embedder<'_> {
.unwrap()
.attachments(&attachments)
.unwrap()
.exec()
.await
}

Expand All @@ -90,15 +89,13 @@ impl Embedder<'_> {
.unwrap()
.embeds(Some(&built.embeds))
.unwrap()
.exec()
.await
}
BuiltStarboardEmbed::Partial(built) => {
bot.http
.update_message(self.config.starboard.channel_id.into_id(), message_id)
.content(Some(&built.top_content))
.unwrap()
.exec()
.await
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/embedder/image_only_embed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use twilight_model::channel::embed::Embed;
use twilight_model::channel::message::embed::Embed;

use crate::utils::gifv::get_gif_url;

Expand Down
2 changes: 1 addition & 1 deletion src/core/embedder/parser.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/core/has_image.rs
Original file line number Diff line number Diff line change
@@ -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<Embed>, attachments: &Vec<Attachment>) -> bool {
for attachment in attachments {
Expand Down
1 change: 0 additions & 1 deletion src/core/starboard/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion src/core/starboard/reaction_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ pub async fn handle_reaction_add(
&emoji.reactable(),
event.user_id,
)
.exec()
.await;

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/interactions/autocomplete/autostar_name.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/interactions/autocomplete/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
6 changes: 3 additions & 3 deletions src/interactions/autocomplete/override_name.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/interactions/autocomplete/starboard_name.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/interactions/commands/chat/autostar/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion src/interactions/commands/chat/starboard/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion src/interactions/commands/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn post_commands(bot: Arc<StarboardBot>) {
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),
}
Expand Down
1 change: 0 additions & 1 deletion src/interactions/components/dismiss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
5 changes: 2 additions & 3 deletions src/interactions/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,18 @@ impl<T> Ctx<T> {
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
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/owner/commands/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(())
}
Expand Down
1 change: 0 additions & 1 deletion src/utils/dm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub async fn dm(
let dm_channel = bot
.http
.create_private_channel(user_id)
.exec()
.await?
.model()
.await
Expand Down
3 changes: 1 addition & 2 deletions src/utils/notify.rs
Original file line number Diff line number Diff line change
@@ -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},
};

Expand Down Expand Up @@ -35,6 +35,5 @@ pub async fn notify(bot: &StarboardBot, user_id: Id<UserMarker>, message: &str)
.unwrap()
.components(&[comp])
.unwrap()
.exec()
.await;
}