update serenity and songbird

This commit is contained in:
mii
2022-11-02 14:38:56 +00:00
parent ddab474d67
commit af01576a99
9 changed files with 40 additions and 55 deletions

View File

@ -21,11 +21,11 @@ version = "0.8"
features = ["serde", "v4"] features = ["serde", "v4"]
[dependencies.songbird] [dependencies.songbird]
version = "0.2.0" version = "0.3.0"
features = ["builtin-queue"] features = ["builtin-queue"]
[dependencies.serenity] [dependencies.serenity]
version = "0.10.9" version = "0.11.5"
features = ["builder", "cache", "client", "gateway", "model", "utils", "unstable_discord_api", "collector", "rustls_backend", "framework", "voice"] features = ["builder", "cache", "client", "gateway", "model", "utils", "unstable_discord_api", "collector", "rustls_backend", "framework", "voice"]

View File

@ -1,7 +1,6 @@
use serenity::{ use serenity::{
model::prelude::{ model::prelude::interaction::{
application_command::ApplicationCommandInteraction, application_command::ApplicationCommandInteraction, MessageFlags,
InteractionApplicationCommandCallbackDataFlags,
}, },
prelude::Context, prelude::Context,
}; };
@ -81,7 +80,7 @@ pub async fn config_command(
}) })
}) })
}) })
.flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
}) })
}) })
.await?; .await?;

View File

@ -1,7 +1,7 @@
use serenity::{ use serenity::{
model::prelude::{ model::prelude::{
application_command::ApplicationCommandInteraction, interaction::{application_command::ApplicationCommandInteraction, MessageFlags},
InteractionApplicationCommandCallbackDataFlags, UserId, UserId,
}, },
prelude::Context, prelude::Context,
}; };
@ -17,20 +17,20 @@ pub async fn setup_command(
.create_interaction_response(&ctx.http, |f| { .create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.content("このコマンドはサーバーでのみ使用可能です.") d.content("このコマンドはサーバーでのみ使用可能です.")
.flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
}) })
}) })
.await?; .await?;
return Ok(()); return Ok(());
} }
let guild = command.guild_id.unwrap().to_guild_cached(&ctx.cache).await; let guild = command.guild_id.unwrap().to_guild_cached(&ctx.cache);
if let None = guild { if let None = guild {
command command
.create_interaction_response(&ctx.http, |f| { .create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.content("ギルドキャッシュを取得できませんでした.") d.content("ギルドキャッシュを取得できませんでした.")
.flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
}) })
}) })
.await?; .await?;
@ -48,7 +48,7 @@ pub async fn setup_command(
.create_interaction_response(&ctx.http, |f| { .create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.content("ボイスチャンネルに参加してから実行してください.") d.content("ボイスチャンネルに参加してから実行してください.")
.flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
}) })
}) })
.await?; .await?;
@ -77,7 +77,7 @@ pub async fn setup_command(
.create_interaction_response(&ctx.http, |f| { .create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.content("すでにセットアップしています.") d.content("すでにセットアップしています.")
.flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
}) })
}) })
.await?; .await?;
@ -99,7 +99,7 @@ pub async fn setup_command(
command.create_interaction_response(&ctx.http, |f| { command.create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.create_embed(|e| { d.embed(|e| {
e.title("読み上げ (Serenity)") e.title("読み上げ (Serenity)")
.field("クレジット", "```\n四国めたん  ずんだもん\n春日部つむぎ 雨晴はう\n波音リツ   玄野武宏\n白上虎太郎  青山龍星\n冥鳴ひまり  九州そら\nモチノ・キョウコ```", false) .field("クレジット", "```\n四国めたん  ずんだもん\n春日部つむぎ 雨晴はう\n波音リツ   玄野武宏\n白上虎太郎  青山龍星\n冥鳴ひまり  九州そら\nモチノ・キョウコ```", false)
.field("設定コマンド", "`/config`", false) .field("設定コマンド", "`/config`", false)

View File

@ -1,7 +1,7 @@
use serenity::{ use serenity::{
model::prelude::{ model::prelude::{
application_command::ApplicationCommandInteraction, interaction::{application_command::ApplicationCommandInteraction, MessageFlags},
InteractionApplicationCommandCallbackDataFlags, UserId, UserId,
}, },
prelude::Context, prelude::Context,
}; };
@ -17,20 +17,20 @@ pub async fn stop_command(
.create_interaction_response(&ctx.http, |f| { .create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.content("このコマンドはサーバーでのみ使用可能です.") d.content("このコマンドはサーバーでのみ使用可能です.")
.flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
}) })
}) })
.await?; .await?;
return Ok(()); return Ok(());
} }
let guild = command.guild_id.unwrap().to_guild_cached(&ctx.cache).await; let guild = command.guild_id.unwrap().to_guild_cached(&ctx.cache);
if let None = guild { if let None = guild {
command command
.create_interaction_response(&ctx.http, |f| { .create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.content("ギルドキャッシュを取得できませんでした.") d.content("ギルドキャッシュを取得できませんでした.")
.flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
}) })
}) })
.await?; .await?;
@ -48,7 +48,7 @@ pub async fn stop_command(
.create_interaction_response(&ctx.http, |f| { .create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.content("ボイスチャンネルに参加してから実行してください.") d.content("ボイスチャンネルに参加してから実行してください.")
.flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
}) })
}) })
.await?; .await?;
@ -75,7 +75,7 @@ pub async fn stop_command(
.create_interaction_response(&ctx.http, |f| { .create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.content("すでに停止しています") d.content("すでに停止しています")
.flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
}) })
}) })
.await?; .await?;

View File

@ -8,8 +8,10 @@ use serenity::{
async_trait, async_trait,
client::{Context, EventHandler}, client::{Context, EventHandler},
model::{ model::{
channel::Message, gateway::Ready, id::GuildId, interactions::Interaction, channel::Message,
prelude::InteractionApplicationCommandCallbackDataFlags, voice::VoiceState, gateway::Ready,
prelude::interaction::{Interaction, MessageFlags},
voice::VoiceState,
}, },
}; };
@ -94,16 +96,14 @@ impl EventHandler for Handler {
message_component.create_interaction_response(&ctx.http, |f| { message_component.create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.content("設定しました\nこの音声を使うにはAPIをGoogleからVOICEVOXに変更する必要があります。") d.content("設定しました\nこの音声を使うにはAPIをGoogleからVOICEVOXに変更する必要があります。")
.flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
}) })
}).await.unwrap(); }).await.unwrap();
} else { } else {
message_component message_component
.create_interaction_response(&ctx.http, |f| { .create_interaction_response(&ctx.http, |f| {
f.interaction_response_data(|d| { f.interaction_response_data(|d| {
d.content("設定しました").flags( d.content("設定しました").flags(MessageFlags::EPHEMERAL)
InteractionApplicationCommandCallbackDataFlags::EPHEMERAL,
)
}) })
}) })
.await .await
@ -114,13 +114,7 @@ impl EventHandler for Handler {
} }
} }
async fn voice_state_update( async fn voice_state_update(&self, ctx: Context, old: Option<VoiceState>, new: VoiceState) {
&self, events::voice_state_update::voice_state_update(ctx, old, new).await
ctx: Context,
guild_id: Option<GuildId>,
old: Option<VoiceState>,
new: VoiceState,
) {
events::voice_state_update::voice_state_update(ctx, guild_id, old, new).await
} }
} }

View File

@ -7,7 +7,7 @@ pub async fn message(ctx: Context, message: Message) {
return; return;
} }
let guild_id = message.guild(&ctx.cache).await; let guild_id = message.guild(&ctx.cache);
if let None = guild_id { if let None = guild_id {
return; return;

View File

@ -1,12 +1,12 @@
use serenity::{ use serenity::{
model::prelude::{application_command::ApplicationCommand, Ready}, model::prelude::{command::Command, Ready},
prelude::Context, prelude::Context,
}; };
pub async fn ready(ctx: Context, ready: Ready) { pub async fn ready(ctx: Context, ready: Ready) {
println!("{} is connected!", ready.user.name); println!("{} is connected!", ready.user.name);
let _ = ApplicationCommand::set_global_application_commands(&ctx.http, |commands| { let _ = Command::set_global_application_commands(&ctx.http, |commands| {
commands.create_application_command(|command| command.name("stop").description("Stop tts")); commands.create_application_command(|command| command.name("stop").description("Stop tts"));
commands commands
.create_application_command(|command| command.name("setup").description("Setup tts")); .create_application_command(|command| command.name("setup").description("Setup tts"));

View File

@ -1,8 +1,3 @@
use serenity::{
model::{prelude::GuildId, voice::VoiceState},
prelude::Context,
};
use crate::{ use crate::{
data::TTSData, data::TTSData,
implement::{ implement::{
@ -11,17 +6,15 @@ use crate::{
}, },
tts::message::AnnounceMessage, tts::message::AnnounceMessage,
}; };
use serenity::{model::voice::VoiceState, prelude::Context};
pub async fn voice_state_update( pub async fn voice_state_update(ctx: Context, old: Option<VoiceState>, new: VoiceState) {
ctx: Context,
guild_id: Option<GuildId>,
old: Option<VoiceState>,
new: VoiceState,
) {
if new.member.clone().unwrap().user.bot { if new.member.clone().unwrap().user.bot {
return; return;
} }
let guild_id = guild_id.unwrap(); let guild_id = new
.guild_id
.unwrap_or(old.clone().unwrap().guild_id.unwrap());
let storage_lock = { let storage_lock = {
let data_read = ctx.data.read().await; let data_read = ctx.data.read().await;

View File

@ -14,10 +14,10 @@ use data::{DatabaseClientData, TTSClientData, TTSData};
use database::database::Database; use database::database::Database;
use event_handler::Handler; use event_handler::Handler;
use serenity::{ use serenity::{
client::{bridge::gateway::GatewayIntents, Client}, client::Client,
framework::StandardFramework, framework::StandardFramework,
futures::lock::Mutex, futures::lock::Mutex,
prelude::RwLock, prelude::{GatewayIntents, RwLock},
}; };
use tts::{gcp_tts::gcp_tts::TTS, voicevox::voicevox::VOICEVOX}; use tts::{gcp_tts::gcp_tts::TTS, voicevox::voicevox::VOICEVOX};
@ -34,11 +34,10 @@ use songbird::SerenityInit;
async fn create_client(prefix: &str, token: &str, id: u64) -> Result<Client, serenity::Error> { async fn create_client(prefix: &str, token: &str, id: u64) -> Result<Client, serenity::Error> {
let framework = StandardFramework::new().configure(|c| c.with_whitespace(true).prefix(prefix)); let framework = StandardFramework::new().configure(|c| c.with_whitespace(true).prefix(prefix));
Client::builder(token) Client::builder(token, GatewayIntents::all())
.event_handler(Handler) .event_handler(Handler)
.application_id(id) .application_id(id)
.framework(framework) .framework(framework)
.intents(GatewayIntents::all())
.register_songbird() .register_songbird()
.await .await
} }
@ -75,7 +74,7 @@ async fn main() {
// Create GCP TTS client // Create GCP TTS client
let tts = match TTS::new("./credentials.json".to_string()).await { let tts = match TTS::new("./credentials.json".to_string()).await {
Ok(tts) => tts, Ok(tts) => tts,
Err(err) => panic!("{}", err), Err(err) => panic!("GCP init error: {}", err),
}; };
let voicevox = VOICEVOX::new(config.voicevox_key); let voicevox = VOICEVOX::new(config.voicevox_key);