Support threads

This commit is contained in:
oupson 2021-08-23 18:18:22 +02:00
parent b21fcc65f3
commit 55e2c428e2
5 changed files with 31 additions and 23 deletions

View File

@ -10,7 +10,7 @@ edition = "2018"
music = ["serenity/voice", "songbird"] music = ["serenity/voice", "songbird"]
[dependencies] [dependencies]
serenity = { version = "0.10", features = ["unstable_discord_api"] } serenity = { version = "0.10.9", features = ["unstable_discord_api"] }
toml = "0.5" toml = "0.5"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
reqwest = "0.11" reqwest = "0.11"

View File

@ -1,16 +1,10 @@
use crate::{api, data::ShardManagerContainer}; use crate::{api, data::ShardManagerContainer};
use futures::StreamExt; use futures::StreamExt;
use log::error; use log::error;
use serenity::{ use serenity::{client::bridge::gateway::ShardId, framework::standard::{
client::bridge::gateway::ShardId,
framework::standard::{
macros::{command, group}, macros::{command, group},
ArgError, Args, CommandResult, ArgError, Args, CommandResult,
}, }, http::CacheHttp, model::{interactions::message_component::ButtonStyle, prelude::*}, prelude::*};
http::CacheHttp,
model::prelude::*,
prelude::*,
};
#[group] #[group]
#[commands( #[commands(

View File

@ -4,9 +4,12 @@ use serenity::{
model::{ model::{
guild::Member, guild::Member,
interactions::{ interactions::{
ApplicationCommandInteractionData, Interaction, application_command::{
InteractionApplicationCommandCallbackDataFlags, InteractionData, ApplicationCommandInteraction, ApplicationCommandInteractionData,
InteractionResponseType, MessageComponent, },
message_component::{MessageComponentInteraction, MessageComponentInteractionData},
Interaction, InteractionApplicationCommandCallbackDataFlags, InteractionResponseType,
MessageInteraction,
}, },
Permissions, Permissions,
}, },
@ -15,13 +18,12 @@ use serenity::{
use crate::{data::GuildOptionsKey, utils::message::embed_author}; use crate::{data::GuildOptionsKey, utils::message::embed_author};
pub(crate) async fn handle_interaction(ctx: &Context, interaction: &Interaction) -> CommandResult { pub(crate) async fn handle_interaction(ctx: &Context, interaction: &Interaction) -> CommandResult {
let data = interaction.data.as_ref().ok_or("Failed to get data")?; match interaction {
Interaction::ApplicationCommand(app) => {
match data { command(ctx, &app, &app.data).await?;
InteractionData::ApplicationCommand(app) => {
command(ctx, &interaction, &app).await?;
} }
InteractionData::MessageComponent(msg) => message_interact(ctx, interaction, msg).await?, Interaction::MessageComponent(msg) => message_interact(ctx, msg, &msg.data).await?,
_ => {}
} }
Ok(()) Ok(())
@ -29,7 +31,7 @@ pub(crate) async fn handle_interaction(ctx: &Context, interaction: &Interaction)
async fn command( async fn command(
ctx: &Context, ctx: &Context,
interaction: &Interaction, interaction: &ApplicationCommandInteraction,
data: &ApplicationCommandInteractionData, data: &ApplicationCommandInteractionData,
) -> CommandResult { ) -> CommandResult {
let name = &data.name; let name = &data.name;
@ -76,7 +78,7 @@ async fn command(
async fn goulag( async fn goulag(
ctx: &Context, ctx: &Context,
interaction: &Interaction, interaction: &ApplicationCommandInteraction,
data: &ApplicationCommandInteractionData, data: &ApplicationCommandInteractionData,
guild_id: u64, guild_id: u64,
author: &Member, author: &Member,
@ -152,8 +154,8 @@ async fn goulag(
async fn message_interact( async fn message_interact(
ctx: &Context, ctx: &Context,
interaction: &Interaction, interaction: &MessageComponentInteraction,
msg_interaction: &MessageComponent, msg_interaction: &MessageComponentInteractionData,
) -> CommandResult { ) -> CommandResult {
match msg_interaction.custom_id.as_str() { match msg_interaction.custom_id.as_str() {
"gulag_button" => { "gulag_button" => {

View File

@ -6,7 +6,7 @@ use serenity::{
channel::{Message, ReactionType}, channel::{Message, ReactionType},
guild::{Member, PartialMember}, guild::{Member, PartialMember},
id::GuildId, id::GuildId,
interactions::ButtonStyle, interactions::message_component::ButtonStyle,
Permissions, Permissions,
}, },
}; };
@ -135,6 +135,7 @@ impl<'a> CreateMessageExt for CreateMessage<'a> {
} }
fn add_music_buttons<'b>(&'b mut self) -> &'b mut Self { fn add_music_buttons<'b>(&'b mut self) -> &'b mut Self {
return self;
self.components(|comp| { self.components(|comp| {
comp.create_action_row(|row| { comp.create_action_row(|row| {
row.create_button(|but| { row.create_button(|but| {

View File

@ -224,11 +224,22 @@ impl EventHandler for Messages {
} }
} }
async fn channel_create(&self, _ctx: Context, channel: &GuildChannel) {
log::debug!("{:?}", channel);
}
async fn interaction_create(&self, ctx: Context, interaction: Interaction) { async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
if let Err(e) = interaction::handle_interaction(&ctx, &interaction).await { if let Err(e) = interaction::handle_interaction(&ctx, &interaction).await {
error!("While handling interaction : {}", e); error!("While handling interaction : {}", e);
} }
} }
async fn thread_create(&self, ctx: Context, thread: GuildChannel) {
if let Err(e) = thread.id.join_thread(&ctx).await {
log::error!("Failed to join thread : {}", e);
}
}
} }
async fn log_mentions(ctx: Context, new_message: &Message) -> CommandResult { async fn log_mentions(ctx: Context, new_message: &Message) -> CommandResult {