Support threads
This commit is contained in:
parent
b21fcc65f3
commit
55e2c428e2
|
@ -10,7 +10,7 @@ edition = "2018"
|
|||
music = ["serenity/voice", "songbird"]
|
||||
|
||||
[dependencies]
|
||||
serenity = { version = "0.10", features = ["unstable_discord_api"] }
|
||||
serenity = { version = "0.10.9", features = ["unstable_discord_api"] }
|
||||
toml = "0.5"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
reqwest = "0.11"
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
use crate::{api, data::ShardManagerContainer};
|
||||
use futures::StreamExt;
|
||||
use log::error;
|
||||
use serenity::{
|
||||
client::bridge::gateway::ShardId,
|
||||
framework::standard::{
|
||||
use serenity::{client::bridge::gateway::ShardId, framework::standard::{
|
||||
macros::{command, group},
|
||||
ArgError, Args, CommandResult,
|
||||
},
|
||||
http::CacheHttp,
|
||||
model::prelude::*,
|
||||
prelude::*,
|
||||
};
|
||||
}, http::CacheHttp, model::{interactions::message_component::ButtonStyle, prelude::*}, prelude::*};
|
||||
|
||||
#[group]
|
||||
#[commands(
|
||||
|
|
|
@ -4,9 +4,12 @@ use serenity::{
|
|||
model::{
|
||||
guild::Member,
|
||||
interactions::{
|
||||
ApplicationCommandInteractionData, Interaction,
|
||||
InteractionApplicationCommandCallbackDataFlags, InteractionData,
|
||||
InteractionResponseType, MessageComponent,
|
||||
application_command::{
|
||||
ApplicationCommandInteraction, ApplicationCommandInteractionData,
|
||||
},
|
||||
message_component::{MessageComponentInteraction, MessageComponentInteractionData},
|
||||
Interaction, InteractionApplicationCommandCallbackDataFlags, InteractionResponseType,
|
||||
MessageInteraction,
|
||||
},
|
||||
Permissions,
|
||||
},
|
||||
|
@ -15,13 +18,12 @@ use serenity::{
|
|||
use crate::{data::GuildOptionsKey, utils::message::embed_author};
|
||||
|
||||
pub(crate) async fn handle_interaction(ctx: &Context, interaction: &Interaction) -> CommandResult {
|
||||
let data = interaction.data.as_ref().ok_or("Failed to get data")?;
|
||||
|
||||
match data {
|
||||
InteractionData::ApplicationCommand(app) => {
|
||||
command(ctx, &interaction, &app).await?;
|
||||
match interaction {
|
||||
Interaction::ApplicationCommand(app) => {
|
||||
command(ctx, &app, &app.data).await?;
|
||||
}
|
||||
InteractionData::MessageComponent(msg) => message_interact(ctx, interaction, msg).await?,
|
||||
Interaction::MessageComponent(msg) => message_interact(ctx, msg, &msg.data).await?,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -29,7 +31,7 @@ pub(crate) async fn handle_interaction(ctx: &Context, interaction: &Interaction)
|
|||
|
||||
async fn command(
|
||||
ctx: &Context,
|
||||
interaction: &Interaction,
|
||||
interaction: &ApplicationCommandInteraction,
|
||||
data: &ApplicationCommandInteractionData,
|
||||
) -> CommandResult {
|
||||
let name = &data.name;
|
||||
|
@ -76,7 +78,7 @@ async fn command(
|
|||
|
||||
async fn goulag(
|
||||
ctx: &Context,
|
||||
interaction: &Interaction,
|
||||
interaction: &ApplicationCommandInteraction,
|
||||
data: &ApplicationCommandInteractionData,
|
||||
guild_id: u64,
|
||||
author: &Member,
|
||||
|
@ -152,8 +154,8 @@ async fn goulag(
|
|||
|
||||
async fn message_interact(
|
||||
ctx: &Context,
|
||||
interaction: &Interaction,
|
||||
msg_interaction: &MessageComponent,
|
||||
interaction: &MessageComponentInteraction,
|
||||
msg_interaction: &MessageComponentInteractionData,
|
||||
) -> CommandResult {
|
||||
match msg_interaction.custom_id.as_str() {
|
||||
"gulag_button" => {
|
||||
|
|
|
@ -6,7 +6,7 @@ use serenity::{
|
|||
channel::{Message, ReactionType},
|
||||
guild::{Member, PartialMember},
|
||||
id::GuildId,
|
||||
interactions::ButtonStyle,
|
||||
interactions::message_component::ButtonStyle,
|
||||
Permissions,
|
||||
},
|
||||
};
|
||||
|
@ -135,6 +135,7 @@ impl<'a> CreateMessageExt for CreateMessage<'a> {
|
|||
}
|
||||
|
||||
fn add_music_buttons<'b>(&'b mut self) -> &'b mut Self {
|
||||
return self;
|
||||
self.components(|comp| {
|
||||
comp.create_action_row(|row| {
|
||||
row.create_button(|but| {
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -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) {
|
||||
if let Err(e) = interaction::handle_interaction(&ctx, &interaction).await {
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue