Remove lavalink dependencies and update to new serenity

main
trivernis 2 years ago
parent 065fc688ad
commit 118832036e
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

1039
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -42,14 +42,11 @@ animethemes-rs = "0.4.4"
build-time = "0.1.1"
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
tracing = "0.1.34"
serenity-rich-interaction= "0.3.1"
serenity-additions = "0.3.2"
[dependencies.tokio]
version = "1.19.2"
features = ["macros", "rt-multi-thread"]
[dependencies.lavalink-rs]
git = "https://gitlab.com/vicky5124/lavalink-rs/"
rev = "2487c295"
features=["native", "serenity", "songbird", "tracing-log"]
default-features = false
[patch.crates-io]
serenity-additions = { path = "../serenity-additions" }

@ -7,8 +7,8 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.19.2", features = ["process", "io-util"] }
tokio = { version = "1.21.2", features = ["process", "io-util"] }
log = "0.4.17"
url = "2.2.2"
url = "2.3.1"
mime_guess = "2.0.4"
rand = "0.8.5"

@ -11,7 +11,7 @@ pub async fn run_command_async(command: &str, args: &[&str]) -> io::Result<Strin
let stdout = String::from_utf8_lossy(&process_output.stdout[..]);
if stderr.len() != 0 {
log::debug!("STDERR of command {}: {}", command, stderr);
log::trace!("STDERR of command {}: {}", command, stderr);
}
log::trace!("Command output is {}", stdout);

@ -8,12 +8,12 @@ edition = "2018"
[dependencies]
dotenv = "0.15.0"
chrono = "0.4.19"
thiserror = "1.0.31"
tracing = "0.1.34"
chrono = "0.4.22"
thiserror = "1.0.37"
tracing = "0.1.37"
[dependencies.sea-orm]
version = "0.9.2"
version = "0.9.3"
features = ["runtime-tokio-native-tls", "sqlx-postgres"]
[dependencies.migration]

@ -9,4 +9,5 @@ name = "migration"
path = "src/lib.rs"
[dependencies]
sea-orm-migration = "0.9.2"
sea-orm-migration = "0.9.3"
tokio = { version = "1.21.2", features = ["rt", "net", "tracing"] }

@ -1,7 +1,7 @@
use migration::Migrator;
use sea_orm_migration::prelude::*;
#[async_std::main]
#[tokio::main]
async fn main() {
cli::run_cli(Migrator).await;
}

@ -10,13 +10,13 @@ use serenity::framework::standard::{CommandResult, DispatchError};
use serenity::framework::StandardFramework;
use serenity::model::channel::Message;
use serenity::model::id::UserId;
use serenity::prelude::GatewayIntents;
use serenity::Client;
use serenity_rich_interaction::RegisterRichInteractions;
use serenity_additions::RegisterAdditions;
use songbird::SerenityInit;
use crate::commands::*;
use crate::handler::{get_raw_event_handler, Handler};
use crate::utils;
use crate::utils::context_data::{
get_database_from_context, DatabaseContainer, MusicPlayers, Store, StoreData,
};
@ -25,8 +25,8 @@ use crate::utils::error::{BotError, BotResult};
pub async fn get_client() -> BotResult<Client> {
let token = env::var("BOT_TOKEN").map_err(|_| BotError::MissingToken)?;
let database = get_database().await?;
let client = Client::builder(token)
.register_rich_interactions_with(get_raw_event_handler())
let client = Client::builder(token, GatewayIntents::all())
.register_serenity_additions_with(get_raw_event_handler())
.event_handler(Handler)
.framework(get_framework().await)
.register_songbird()
@ -34,15 +34,6 @@ pub async fn get_client() -> BotResult<Client> {
.type_map_insert::<DatabaseContainer>(database)
.type_map_insert::<MusicPlayers>(HashMap::new())
.await?;
let data = client.data.clone();
let current_application = client
.cache_and_http
.http
.get_current_application_info()
.await?;
utils::initialize_lavalink(data, current_application).await?;
Ok(client)
}
@ -124,7 +115,7 @@ async fn before_hook(ctx: &Context, msg: &Message, _: &str) -> bool {
}
#[hook]
async fn dispatch_error(ctx: &Context, msg: &Message, error: DispatchError) {
async fn dispatch_error(ctx: &Context, msg: &Message, error: DispatchError, command_name: &str) {
match error {
DispatchError::Ratelimited(info) => {
if info.is_first_try {
@ -140,13 +131,19 @@ async fn dispatch_error(ctx: &Context, msg: &Message, error: DispatchError) {
DispatchError::OnlyForDM => {
let _ = msg
.channel_id
.say(&ctx.http, "This command only works via DM")
.say(
&ctx.http,
format!("The command {command_name} only works via DM"),
)
.await;
}
DispatchError::OnlyForGuilds => {
let _ = msg
.channel_id
.say(&ctx.http, "This command only works on servers")
.say(
&ctx.http,
format!("The command {command_name} only works on servers"),
)
.await;
}
DispatchError::NotEnoughArguments { min, given } => {

@ -4,8 +4,8 @@ use serenity::client::Context;
use serenity::framework::standard::macros::command;
use serenity::framework::standard::{Args, CommandResult};
use serenity::model::channel::Message;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[description("Adds media to the database")]

@ -4,8 +4,8 @@ use serenity::framework::standard::macros::command;
use serenity::framework::standard::{Args, CommandResult};
use serenity::model::channel::Message;
use serenity::Result as SerenityResult;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[description("Clears the chat (maximum 100 messages)")]

@ -19,6 +19,7 @@ pub async fn help(
groups: &[&'static CommandGroup],
owners: HashSet<UserId>,
) -> CommandResult {
tracing::debug!("Help");
let _ = help_commands::with_embeds(ctx, msg, args, help_options, groups, owners).await;
handle_autodelete(ctx, msg).await?;
Ok(())

@ -10,7 +10,6 @@ use pain::PAIN_COMMAND;
use party::PARTY_COMMAND;
use ping::PING_COMMAND;
use qalc::QALC_COMMAND;
use reset_lavalink::RESET_LAVALINK_COMMAND;
use shutdown::SHUTDOWN_COMMAND;
use stats::STATS_COMMAND;
use time::TIME_COMMAND;
@ -28,7 +27,6 @@ mod pain;
mod party;
mod ping;
mod qalc;
mod reset_lavalink;
mod shutdown;
mod stats;
mod time;
@ -37,21 +35,7 @@ mod xkcd;
#[group]
#[commands(
ping,
stats,
shutdown,
time,
timezones,
qalc,
about,
add_media,
media,
pain,
clear,
xkcd,
fuck,
party,
inspirobot,
reset_lavalink
ping, stats, shutdown, time, timezones, qalc, about, add_media, media, pain, clear, xkcd, fuck,
party, inspirobot
)]
pub struct Misc;

@ -1,40 +0,0 @@
use serenity::client::Context;
use serenity::framework::standard::macros::command;
use serenity::framework::standard::CommandResult;
use serenity::model::channel::Message;
use crate::commands::common::handle_autodelete;
use crate::providers::music::lavalink::Lavalink;
use crate::utils::initialize_lavalink;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use std::mem;
use std::sync::Arc;
#[command]
#[description("Resets the lavalink connection")]
#[aliases("reconnect_lavalink", "reset-lavalink", "reconnect-lavalink")]
#[num_args(0)]
#[owners_only]
async fn reset_lavalink(ctx: &Context, msg: &Message) -> CommandResult {
let app_info = ctx.http.get_current_application_info().await?;
destroy_lavalink(ctx).await;
initialize_lavalink(Arc::clone(&ctx.data), app_info).await?;
EphemeralMessage::create(&ctx.http, msg.channel_id, SHORT_TIMEOUT, |m| {
m.content("Reconnected to lavalink")
})
.await?;
handle_autodelete(ctx, msg).await?;
Ok(())
}
async fn destroy_lavalink(ctx: &Context) {
let mut data = ctx.data.write().await;
{
let lava_client = data.remove::<Lavalink>().unwrap();
mem::drop(lava_client);
}
}

@ -33,7 +33,7 @@ async fn stats(ctx: &Context, msg: &Message) -> CommandResult {
let uptime = own_process.run_time();
let uptime = ChronoDuration::from_std(Duration::from_secs(uptime)).unwrap();
let total_commands_executed = database.get_total_commands_statistic().await?;
let shard_count = ctx.cache.shard_count().await;
let shard_count = ctx.cache.shard_count();
let discord_info = format!(
r#"

@ -6,8 +6,8 @@ use serenity::model::channel::Message;
use crate::commands::common::handle_autodelete;
use crate::commands::music::{get_music_player_for_guild, DJ_CHECK};
use crate::messages::music::no_voicechannel::create_no_voicechannel_message;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[only_in(guilds)]
@ -17,7 +17,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
#[bucket("general")]
#[checks(DJ)]
async fn clear_queue(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Clearing queue for guild {}", guild.id);
let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await {

@ -15,7 +15,7 @@ use crate::messages::music::now_playing::create_now_playing_msg;
#[aliases("nowplaying", "np")]
#[bucket("general")]
async fn current(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Displaying current song for queue in {}", guild.id);
let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await {

@ -1,62 +0,0 @@
use serenity::framework::standard::macros::command;
use serenity::framework::standard::{Args, CommandError, CommandResult};
use serenity::model::channel::Message;
use serenity::prelude::*;
use crate::commands::common::handle_autodelete;
use crate::commands::music::{get_music_player_for_guild, DJ_CHECK};
use crate::messages::music::no_voicechannel::create_no_voicechannel_message;
use serenity_rich_interaction::core::{MEDIUM_TIMEOUT, SHORT_TIMEOUT};
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
#[command]
#[only_in(guilds)]
#[description("Loads an equalizer preset")]
#[usage("<preset>")]
#[num_args(1)]
#[example("bass")]
#[bucket("general")]
#[checks(DJ)]
async fn equalize(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
tracing::debug!("Changing equalizer for {}", guild.id);
let preset = args.single::<String>().unwrap();
let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await {
player
} else {
return create_no_voicechannel_message(&ctx.http, msg.channel_id)
.await
.map_err(CommandError::from);
};
let bands = match preset.to_lowercase().as_str() {
"metal" => lavalink_rs::EQ_METAL,
"boost" => lavalink_rs::EQ_BOOST,
"base" => lavalink_rs::EQ_BASE,
"piano" => lavalink_rs::EQ_PIANO,
_ => {
EphemeralMessage::create(&ctx.http, msg.channel_id, MEDIUM_TIMEOUT, |m| {
m.content(format!(
"Unknown preset '{}'. Available are 'metal', 'boost', 'base' and 'piano'",
preset
))
})
.await?;
handle_autodelete(ctx, msg).await?;
return Ok(());
}
};
{
let mut player = player.lock().await;
player.equalize_all(bands).await?;
}
EphemeralMessage::create(&ctx.http, msg.channel_id, SHORT_TIMEOUT, |m| {
m.content(format!("🎛️ Changed equalizer to '{}'", preset))
})
.await?;
handle_autodelete(ctx, msg).await?;
Ok(())
}

@ -1,33 +0,0 @@
use serenity::framework::standard::macros::command;
use serenity::framework::standard::{CommandError, CommandResult};
use serenity::model::channel::Message;
use serenity::prelude::*;
use crate::commands::common::handle_autodelete;
use crate::commands::music::{get_music_player_for_guild, DJ_CHECK};
use crate::messages::music::equalizer::create_equalizer_message;
use crate::messages::music::no_voicechannel::create_no_voicechannel_message;
#[command]
#[only_in(guilds)]
#[description("Displays the equalizer for the music player")]
#[usage("")]
#[bucket("general")]
#[checks(DJ)]
async fn equalizer(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
tracing::debug!("Displaying equalizer for guild {}", guild.id);
let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await {
player
} else {
return create_no_voicechannel_message(&ctx.http, msg.channel_id)
.await
.map_err(CommandError::from);
};
create_equalizer_message(&ctx, msg.channel_id, player).await?;
handle_autodelete(ctx, msg).await?;
Ok(())
}

@ -7,8 +7,8 @@ use crate::commands::common::handle_autodelete;
use crate::commands::music::{get_channel_for_author, get_music_player_for_guild, is_dj};
use crate::providers::music::player::MusicPlayer;
use serenity::model::id::ChannelId;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[only_in(guilds)]
@ -16,7 +16,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
#[usage("")]
#[bucket("general")]
async fn join(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
let channel_id = if let Ok(arg) = args.single::<u64>() {
if is_dj(ctx, guild.id, &msg.author).await? {
ChannelId(arg)

@ -6,8 +6,8 @@ use serenity::model::channel::Message;
use crate::commands::common::handle_autodelete;
use crate::commands::music::DJ_CHECK;
use crate::utils::context_data::MusicPlayers;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[only_in(guilds)]
@ -17,13 +17,13 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
#[bucket("general")]
#[checks(DJ)]
async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Leave request received for guild {}", guild.id);
let manager = songbird::get(ctx).await.unwrap();
if let Some(handler) = manager.get(guild.id) {
let mut handler_lock = handler.lock().await;
let _ = handler_lock.leave().await;
handler_lock.leave().await?;
}
let mut data = ctx.data.write().await;

@ -13,7 +13,7 @@ use crate::messages::music::no_voicechannel::create_no_voicechannel_message;
#[usage("")]
#[bucket("general")]
async fn lyrics(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Fetching lyrics for song playing in {}", guild.id);
let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await {

@ -18,8 +18,6 @@ use youtube_metadata::get_video_information;
use clear_queue::CLEAR_QUEUE_COMMAND;
use current::CURRENT_COMMAND;
use equalize::EQUALIZE_COMMAND;
use equalizer::EQUALIZER_COMMAND;
use join::JOIN_COMMAND;
use leave::LEAVE_COMMAND;
use lyrics::LYRICS_COMMAND;
@ -43,8 +41,6 @@ use crate::utils::error::{BotError, BotResult};
mod clear_queue;
mod current;
mod equalize;
mod equalizer;
mod join;
mod leave;
mod lyrics;
@ -75,9 +71,7 @@ mod skip;
playlists,
lyrics,
move_song,
remove_song,
equalizer,
equalize
remove_song
)]
pub struct Music;
@ -257,7 +251,6 @@ pub async fn check_dj(
) -> Result<(), Reason> {
let guild = msg
.guild(&ctx.cache)
.await
.ok_or(Reason::Log("Not in a guild".to_string()))?;
if is_dj(ctx, guild.id, &msg.author)

@ -5,8 +5,8 @@ use serenity::client::Context;
use serenity::framework::standard::macros::command;
use serenity::framework::standard::{Args, CommandError, CommandResult};
use serenity::model::channel::Message;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[description("Moves a song in the queue from one position to a new one")]
@ -18,7 +18,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
#[aliases("mvs", "movesong", "move-song")]
#[checks(DJ)]
async fn move_song(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Moving song for guild {}", guild.id);
let pos1 = args.single::<usize>()?;

@ -6,8 +6,8 @@ use serenity::prelude::*;
use crate::commands::common::handle_autodelete;
use crate::commands::music::{get_music_player_for_guild, DJ_CHECK};
use crate::messages::music::no_voicechannel::create_no_voicechannel_message;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[only_in(guilds)]
@ -16,7 +16,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
#[bucket("general")]
#[checks(DJ)]
async fn pause(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Pausing playback for guild {}", guild.id);
let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await {

@ -22,7 +22,7 @@ use std::sync::Arc;
async fn play(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let query = args.message();
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Play request received for guild {}", guild.id);
let mut player = get_music_player_for_guild(ctx, guild.id).await;

@ -22,7 +22,7 @@ use std::sync::Arc;
async fn play_next(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let query = args.message();
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Playing song as next song for guild {}", guild.id);
let mut player = get_music_player_for_guild(ctx, guild.id).await;

@ -12,7 +12,7 @@ use crate::utils::context_data::get_database_from_context;
#[usage("")]
#[bucket("general")]
async fn playlists(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Displaying playlists for guild {}", guild.id);
let database = get_database_from_context(ctx).await;

@ -16,7 +16,7 @@ use crate::providers::music::queue::Song;
#[aliases("q")]
#[bucket("general")]
async fn queue(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::trace!("Displaying queue for guild {}", guild.id);
let query = args

@ -5,8 +5,8 @@ use serenity::client::Context;
use serenity::framework::standard::macros::command;
use serenity::framework::standard::{Args, CommandError, CommandResult};
use serenity::model::channel::Message;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[description("Removes a song from the queue")]
@ -18,7 +18,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
#[aliases("rms", "removesong", "remove-song")]
#[checks(DJ)]
async fn remove_song(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Moving song for guild {}", guild.id);
let pos = args.single::<usize>()?;

@ -16,7 +16,7 @@ use crate::utils::context_data::get_database_from_context;
#[bucket("general")]
#[checks(DJ)]
async fn save_playlist(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
let name: String = args.single().unwrap();
let url: &str = args.remains().unwrap();

@ -6,8 +6,8 @@ use serenity::model::channel::Message;
use crate::commands::common::handle_autodelete;
use crate::commands::music::{get_music_player_for_guild, DJ_CHECK};
use crate::messages::music::no_voicechannel::create_no_voicechannel_message;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[only_in(guilds)]
@ -17,7 +17,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
#[bucket("general")]
#[checks(DJ)]
async fn shuffle(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Shuffling queue for guild {}", guild.id);
let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await {

@ -6,8 +6,8 @@ use serenity::model::channel::Message;
use crate::commands::common::handle_autodelete;
use crate::commands::music::{get_music_player_for_guild, DJ_CHECK};
use crate::messages::music::no_voicechannel::create_no_voicechannel_message;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[only_in(guilds)]
@ -17,7 +17,7 @@ use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
#[bucket("general")]
#[checks(DJ)]
async fn skip(ctx: &Context, msg: &Message) -> CommandResult {
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Skipping song for guild {}", guild.id);
let player = if let Some(player) = get_music_player_for_guild(ctx, guild.id).await {

@ -17,7 +17,7 @@ use crate::utils::context_data::get_database_from_context;
#[bucket("general")]
async fn get(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let database = get_database_from_context(ctx).await;
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
tracing::debug!("Displaying guild setting for guild {}", guild.id);
if let Some(key) = args.single::<String>().ok() {

@ -28,7 +28,7 @@ async fn set(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
return Ok(());
}
let database = get_database_from_context(ctx).await;
let guild = msg.guild(&ctx.cache).await.unwrap();
let guild = msg.guild(&ctx.cache).unwrap();
if let Ok(value) = args.single::<String>() {
database

@ -5,8 +5,8 @@ use serenity::client::Context;
use serenity::framework::standard::macros::command;
use serenity::framework::standard::{Args, CommandResult};
use serenity::model::channel::Message;
use serenity_rich_interaction::core::MEDIUM_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::MEDIUM_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
#[command]
#[description("Query for the opening/ending/insert song of an anime")]

@ -4,7 +4,7 @@ use serenity::model::channel::GuildChannel;
use serenity::model::event::ResumedEvent;
use serenity::model::gateway::{Activity, Ready};
use serenity::model::guild::Member;
use serenity::model::id::{ChannelId, GuildId};
use serenity::model::id::ChannelId;
use serenity::model::voice::VoiceState;
use serenity::prelude::*;
@ -12,8 +12,8 @@ use crate::commands::music::get_music_player_for_guild;
use crate::utils::context_data::MusicPlayers;
use crate::utils::delete_messages_from_database;
use serenity::model::event;
use serenity_rich_interaction::events::RichEventHandler;
use serenity_rich_interaction::Result;
use serenity_additions::events::RichEventHandler;
use serenity_additions::Result;
/// Returns the raw event handler built from a rich event handler
pub fn get_raw_event_handler() -> RichEventHandler {
@ -34,8 +34,9 @@ async fn ready(ctx: &Context, _: &Ready) -> Result<()> {
tracing::info!("Ready");
delete_messages_from_database(&ctx).await?;
let prefix = std::env::var("BOT_PREFIX").unwrap_or("~!".to_string());
ctx.set_activity(Activity::listening(format!("{}help", prefix).as_str()))
ctx.set_activity(Activity::listening(format!("{prefix}help").as_str()))
.await;
tracing::info!("Fully initialized. Listening to {prefix}help");
Ok(())
}
@ -50,13 +51,12 @@ impl EventHandler for Handler {
async fn voice_state_update(
&self,
ctx: Context,
guild_id: Option<GuildId>,
old_state: Option<VoiceState>,
new_state: VoiceState,
) {
let mut member_count = None;
let guild_id = if let Some(gid) = guild_id {
let guild_id = if let Some(gid) = new_state.guild_id {
gid
} else {
return;
@ -81,7 +81,7 @@ impl EventHandler for Handler {
}
// handle disconnects
if let (Some(state), None) = (old_state, new_state.channel_id) {
let current_user = ctx.cache.current_user().await;
let current_user = ctx.cache.current_user();
if state.user_id == current_user.id {
let mut data = ctx.data.write().await;
@ -101,7 +101,7 @@ impl EventHandler for Handler {
async fn get_own_channel_member_count(ctx: &Context, channel_id: ChannelId) -> Option<usize> {
let guild_channel = get_guild_channel(ctx, channel_id).await?;
let current_user = ctx.cache.current_user().await;
let current_user = ctx.cache.current_user();
let members = guild_channel.members(&ctx).await.ok()?;
let own_channel = members
@ -119,7 +119,7 @@ async fn get_own_channel_member_count(ctx: &Context, channel_id: ChannelId) -> O
/// Returns the guild channel for a guild ID
async fn get_guild_channel(ctx: &Context, channel_id: ChannelId) -> Option<GuildChannel> {
if let Some(channel) = ctx.cache.channel(channel_id).await {
if let Some(channel) = ctx.cache.channel(channel_id) {
return channel.guild();
}
let channel = ctx.http.get_channel(channel_id.0).await.ok()?;

@ -3,7 +3,7 @@ use bot_database::models::Media;
use serenity::builder::CreateMessage;
use serenity::client::Context;
use serenity::model::id::{ChannelId, UserId};
use serenity_rich_interaction::menu::{MenuBuilder, Page};
use serenity_additions::menu::{MenuBuilder, Page};
use std::time::Duration;
/// Creates a new gifs embed

@ -3,10 +3,8 @@ use crate::utils::error::BotResult;
use serenity::builder::CreateMessage;
use serenity::client::Context;
use serenity::model::id::{ChannelId, UserId};
use serenity_rich_interaction::core::EXTRA_LONG_TIMEOUT;
use serenity_rich_interaction::menu::{
close_menu, display_page, MenuBuilder, Page, CLOSE_MENU_EMOJI,
};
use serenity_additions::core::EXTRA_LONG_TIMEOUT;
use serenity_additions::menu::{close_menu, display_page, MenuBuilder, Page, CLOSE_MENU_EMOJI};
static REFRESH_EMOJI: &str = "🔄";
@ -30,7 +28,7 @@ pub async fn create_inspirobot_menu(
Box::pin(async {
let message = create_inspirobot_page()
.await
.map_err(|e| serenity_rich_interaction::Error::Msg(format!("{}", e)))?;
.map_err(|e| serenity_additions::Error::Msg(format!("{}", e)))?;
Ok(message)
})
}))

@ -1,7 +1,7 @@
use crate::utils::context_data::get_database_from_context;
use crate::utils::error::BotResult;
use serenity::client::Context;
use serenity_rich_interaction::core::MessageHandle;
use serenity_additions::core::MessageHandle;
use std::time::{Duration, SystemTime};
pub mod gifs;

@ -1,262 +0,0 @@
use crate::commands::music::is_dj;
use crate::providers::music::player::MusicPlayer;
use crate::utils::error::BotResult;
use serenity::builder::{CreateEmbed, CreateMessage};
use serenity::client::Context;
use serenity::model::channel::Reaction;
use serenity::model::id::ChannelId;
use serenity_rich_interaction::core::EXTRA_LONG_TIMEOUT;
use serenity_rich_interaction::menu::{display_page, Menu, MenuBuilder, Page};
use serenity_rich_interaction::Result as SerenityUtilsResult;
use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::Arc;
use tokio::sync::Mutex;
use typemap_rev::TypeMapKey;
static DELETE_BUTTON: &str = "🗑️";
static NEXT_BAND_BUTTON: &str = "➡️";
static PREVIOUS_BAND_BUTTON: &str = "⬅️";
static ADD_BUTTON: &str = "";
static SUB_BUTTON: &str = "";
struct SelectedBand;
impl TypeMapKey for SelectedBand {
type Value = Arc<AtomicU8>;
}
struct Player;
impl TypeMapKey for Player {
type Value = Arc<Mutex<MusicPlayer>>;
}
/// Creates a new equalizer message
pub async fn create_equalizer_message(
ctx: &Context,
channel_id: ChannelId,
player: Arc<Mutex<MusicPlayer>>,
) -> BotResult<()> {
let selected_band = Arc::new(AtomicU8::new(0));
let selected_band_clone = Arc::clone(&selected_band);
let player_clone = Arc::clone(&player);
MenuBuilder::default()
.add_page(Page::new_builder(move || {
let player = Arc::clone(&player_clone);
let selected_band = Arc::clone(&selected_band_clone);
Box::pin(async move {
let mut page = CreateMessage::default();
let mut embed = CreateEmbed::default();
create_equalizer_embed(selected_band.load(Ordering::Relaxed), &mut embed, &player)
.await;
page.embed(|e| {
e.0.clone_from(&embed.0);
e
});
Ok(page)
})
}))
.add_control(-1, DELETE_BUTTON, |c, m, r| Box::pin(delete_menu(c, m, r)))
.add_help(DELETE_BUTTON, "Deletes this message.")
.add_control(0, PREVIOUS_BAND_BUTTON, |c, m, r| {
Box::pin(previous_band(c, m, r))
})
.add_help(PREVIOUS_BAND_BUTTON, "Selects the previous band.")
.add_control(1, NEXT_BAND_BUTTON, |c, m, r| Box::pin(next_band(c, m, r)))
.add_help(NEXT_BAND_BUTTON, "Selects the next band.")
.add_control(3, ADD_BUTTON, |c, m, r| Box::pin(add_to_band(c, m, r)))
.add_help(ADD_BUTTON, "Adds to the selected band.")
.add_control(2, SUB_BUTTON, |c, m, r| {
Box::pin(subtract_from_band(c, m, r))
})
.add_help(SUB_BUTTON, "Subtracts from the selected band")
.show_help()
.add_data::<SelectedBand>(selected_band)
.add_data::<Player>(player)
.timeout(EXTRA_LONG_TIMEOUT)
.build(ctx, channel_id)
.await?;
Ok(())
}
/// Creates a new equalizer embed
async fn create_equalizer_embed<'a>(
selected_band: u8,
embed: &'a mut CreateEmbed,
player: &Arc<Mutex<MusicPlayer>>,
) -> &'a mut CreateEmbed {
let mut description = String::new();
let bands = {
let player = player.lock().await;
player.get_equalizer().clone()
};
for i in 0..bands.len() {
if i as u8 == selected_band {
description += "⤋"
} else {
description += " ";
}
}
description += "\n";
for i in (0..11).rev() {
let eq_value = (i as f64) / 20.0 - 0.25;
for band in &bands {
if (eq_value > 0. && band >= &eq_value) || (eq_value < 0. && band <= &eq_value) {
description += "█";
} else if eq_value == 0. {
description += format!("-").as_str();
} else {
description += " ";
}
}
description += "\n";
}
for i in 0..bands.len() {
if i as u8 == selected_band {
description += "⤊"
} else {
description += " ";
}
}
embed
.title("Equalizer")
.description(format!("```\n{}\n```", description));
embed
}
/// Selects the previous band
async fn next_band(
ctx: &Context,
menu: &mut Menu<'_>,
reaction: Reaction,
) -> SerenityUtilsResult<()> {
let guild_id = reaction.guild_id.unwrap();
let user = reaction.user(&ctx).await?;
if !is_dj(ctx, guild_id, &user).await? {
return Ok(());
}
let selected_band = menu.data.get::<SelectedBand>().unwrap();
if selected_band.load(Ordering::SeqCst) >= 14 {
selected_band.store(0, Ordering::SeqCst);
} else {
selected_band.fetch_add(1, Ordering::SeqCst);
}
display_page(ctx, menu).await?;
Ok(())
}
/// Selects the previous band
async fn previous_band(
ctx: &Context,
menu: &mut Menu<'_>,
reaction: Reaction,
) -> SerenityUtilsResult<()> {
let guild_id = reaction.guild_id.unwrap();
let user = reaction.user(&ctx).await?;
if !is_dj(ctx, guild_id, &user).await? {
return Ok(());
}
let selected_band = menu.data.get::<SelectedBand>().unwrap();
if selected_band.load(Ordering::SeqCst) <= 0 {
selected_band.store(14, Ordering::SeqCst);
} else {
selected_band.fetch_sub(1, Ordering::SeqCst);
}
display_page(ctx, menu).await?;
Ok(())
}
/// Adds to the selected band
async fn add_to_band(
ctx: &Context,
menu: &mut Menu<'_>,
reaction: Reaction,
) -> SerenityUtilsResult<()> {
let guild_id = reaction.guild_id.unwrap();
let user = reaction.user(&ctx).await?;
if !is_dj(ctx, guild_id, &user).await? {
return Ok(());
}
{
let selected_band = menu
.data
.get::<SelectedBand>()
.unwrap()
.load(Ordering::Relaxed);
let player = menu.data.get::<Player>().unwrap();
let mut player = player.lock().await;
let equalizer = player.get_equalizer();
let current_value = equalizer[selected_band as usize];
if current_value < 0.25 {
player.equalize(selected_band, current_value + 0.05).await?;
}
}
display_page(ctx, menu).await?;
Ok(())
}
/// Substracts from the selected band
async fn subtract_from_band(
ctx: &Context,
menu: &mut Menu<'_>,
reaction: Reaction,
) -> SerenityUtilsResult<()> {
let guild_id = reaction.guild_id.unwrap();
let user = reaction.user(&ctx).await?;
if !is_dj(ctx, guild_id, &user).await? {
return Ok(());
}
{
let selected_band = menu
.data
.get::<SelectedBand>()
.unwrap()
.load(Ordering::Relaxed);
let player = menu.data.get::<Player>().unwrap();
let mut player = player.lock().await;
let equalizer = player.get_equalizer();
let current_value = equalizer[selected_band as usize];
if current_value > -0.25 {
player.equalize(selected_band, current_value - 0.05).await?;
}
}
display_page(ctx, menu).await?;
Ok(())
}
/// Deletes the menu
async fn delete_menu(
ctx: &Context,
menu: &mut Menu<'_>,
reaction: Reaction,
) -> SerenityUtilsResult<()> {
let guild_id = reaction.guild_id.unwrap();
let user = reaction.user(&ctx).await?;
if !is_dj(ctx, guild_id, &user).await? {
return Ok(());
}
let handle = menu.message.read().await;
ctx.http
.delete_message(handle.channel_id, handle.message_id)
.await?;
Ok(())
}

@ -1,4 +1,3 @@
pub mod equalizer;
pub mod no_voicechannel;
pub mod now_playing;
pub mod queue;

@ -1,8 +1,8 @@
use crate::utils::error::BotResult;
use serenity::http::Http;
use serenity::model::prelude::ChannelId;
use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
use std::sync::Arc;
/// Creates a not in a voicechannel message

@ -14,9 +14,9 @@ use crate::utils::error::*;
use serenity::builder::CreateMessage;
use serenity::client::Context;
use serenity::model::channel::Reaction;
use serenity_rich_interaction::core::MessageHandle;
use serenity_rich_interaction::menu::{Menu, MenuBuilder, Page};
use serenity_rich_interaction::Result as SerenityUtilsResult;
use serenity_additions::core::MessageHandle;
use serenity_additions::menu::{Menu, MenuBuilder, Page};
use serenity_additions::Result as SerenityUtilsResult;
use std::env;
use std::time::Duration;
use tokio::sync::{Mutex, RwLock};

@ -3,7 +3,7 @@ use crate::utils::error::BotResult;
use serenity::builder::CreateMessage;
use serenity::client::Context;
use serenity::model::id::ChannelId;
use serenity_rich_interaction::menu::{MenuBuilder, Page};
use serenity_additions::menu::{MenuBuilder, Page};
use std::time::Duration;
/// Creates a new queue menu

@ -8,7 +8,7 @@ use bot_coreutils::url::get_domain_for_url;
use crate::utils::error::BotResult;
use rand::prelude::SliceRandom;
use serenity_rich_interaction::menu::{MenuBuilder, Page};
use serenity_additions::menu::{MenuBuilder, Page};
use std::time::Duration;
static MAX_RESULTS: usize = 6;