mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 12:26:10 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
6946ddc9f1
|
|||
|
21fe190921
|
|||
|
4a0184811e
|
|||
|
70c249787c
|
79
Cargo.lock
generated
79
Cargo.lock
generated
@@ -340,6 +340,41 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc5d6b04b3fd0ba9926f945895de7d806260a2d7431ba82e7edaecb043c4c6b8"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.20.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.20.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dashmap"
|
||||
version = "5.5.3"
|
||||
@@ -785,6 +820,12 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.5.0"
|
||||
@@ -892,10 +933,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lyra"
|
||||
version = "0.1.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"dotenv",
|
||||
"openssl",
|
||||
"poise",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"serenity",
|
||||
@@ -1247,6 +1289,35 @@ dependencies = [
|
||||
"pnet_base",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "poise"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1819d5a45e3590ef33754abce46432570c54a120798bdbf893112b4211fa09a6"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"derivative",
|
||||
"futures-util",
|
||||
"parking_lot",
|
||||
"poise_macros",
|
||||
"regex",
|
||||
"serenity",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "poise_macros"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fa2c123c961e78315cd3deac7663177f12be4460f5440dbf62a7ed37b1effea"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "poly1305"
|
||||
version = "0.8.0"
|
||||
@@ -1976,6 +2047,12 @@ version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.5.0"
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
[package]
|
||||
name = "lyra"
|
||||
version = "0.1.0"
|
||||
version = "0.3.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
dotenv = "0.15.0"
|
||||
openssl = { version = "0.10.63", features = ["vendored"] }
|
||||
poise = "0.6.1"
|
||||
regex = "1.10.3"
|
||||
reqwest = "0.11.23"
|
||||
serenity = { version = "0.12.0", features = ["cache", "framework", "standard_framework", "voice"] }
|
||||
|
||||
3
scripts/cross-build.sh
Normal file
3
scripts/cross-build.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
cross build -r --target aarch64-unknown-linux-gnu
|
||||
3
scripts/launch.sh
Normal file
3
scripts/launch.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
nohup ./lyra > lyra.log 2> lyra.err < /dev/null &
|
||||
@@ -1,10 +1,10 @@
|
||||
use serenity::{all::Message, client::Context, framework::standard::{macros::command, CommandResult}};
|
||||
use crate::{Context, Error};
|
||||
|
||||
use crate::commands::misc::check_msg;
|
||||
#[poise::command(prefix_command, slash_command)]
|
||||
pub async fn kashi(ctx: Context<'_>) -> Result<(), Error> {
|
||||
|
||||
#[command]
|
||||
async fn kashi(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
check_msg(msg.reply(ctx, "Kashi lyrics platform integration").await);
|
||||
let response = format!("Kashi platform is currently under construction!");
|
||||
ctx.say(response).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -27,7 +27,15 @@ async fn deafen(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
|
||||
if handler.is_deaf() {
|
||||
check_msg(msg.channel_id.say(&ctx.http, "Already deafened").await);
|
||||
if let Err(err) = handler.deafen(false).await {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, format!("Failed: {:?}", err))
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
check_msg(msg.channel_id.say(&ctx.http, "Undeafened").await);
|
||||
} else {
|
||||
if let Err(err) = handler.deafen(true).await {
|
||||
check_msg(
|
||||
|
||||
@@ -9,15 +9,8 @@ use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier};
|
||||
#[command]
|
||||
#[only_in(guilds)]
|
||||
async fn join(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let (guild_id, channel_id) = {
|
||||
let guild = msg.guild(&ctx.cache).unwrap();
|
||||
let channel_id = guild
|
||||
.voice_states
|
||||
.get(&msg.author.id)
|
||||
.and_then(|voice_state| voice_state.channel_id);
|
||||
|
||||
(guild.id, channel_id)
|
||||
};
|
||||
let guild_id = msg.guild_id.unwrap();
|
||||
let channel_id = msg.guild(&ctx.cache).unwrap().voice_states.get(&msg.author.id).and_then(|voice_state| voice_state.channel_id);
|
||||
|
||||
let connect_to = match channel_id {
|
||||
Some(channel) => channel,
|
||||
|
||||
83
src/commands/music/loopcurrent.rs
Normal file
83
src/commands/music/loopcurrent.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use serenity::framework::standard::macros::command;
|
||||
use serenity::framework::standard::{Args, CommandResult};
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
use songbird::tracks::LoopState;
|
||||
|
||||
use crate::commands::misc::check_msg;
|
||||
|
||||
#[command]
|
||||
#[aliases(loop)]
|
||||
#[only_in(guilds)]
|
||||
async fn loopcurrent(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
let guild_id = msg.guild_id.unwrap();
|
||||
|
||||
let manager = songbird::get(ctx)
|
||||
.await
|
||||
.expect("Client placed at init")
|
||||
.clone();
|
||||
|
||||
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let handler = handler_lock.lock().await;
|
||||
let queue = handler.queue();
|
||||
|
||||
let track = queue.current().unwrap().get_info().await;
|
||||
let is_looped = track.unwrap().loops;
|
||||
|
||||
|
||||
let count = match args.single::<usize>() {
|
||||
Ok(count) => count,
|
||||
Err(_) => 100,
|
||||
};
|
||||
|
||||
match is_looped {
|
||||
LoopState::Infinite => {
|
||||
let _ = queue.current().unwrap().disable_loop();
|
||||
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(
|
||||
&ctx.http,
|
||||
format!("Song unlooped."),
|
||||
)
|
||||
.await,
|
||||
);
|
||||
}
|
||||
LoopState::Finite(_) => {
|
||||
if count < 100 {
|
||||
let _ = queue.current().unwrap().loop_for(count);
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(
|
||||
&ctx.http,
|
||||
format!("Song looped forever (a very long time)."),
|
||||
)
|
||||
.await,
|
||||
)
|
||||
}
|
||||
else {
|
||||
let _ = queue.current().unwrap().enable_loop();
|
||||
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(
|
||||
&ctx.http,
|
||||
format!("Song looped {} times.", count),
|
||||
)
|
||||
.await,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, "Not in a voice channel to play in")
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -7,5 +7,6 @@ pub mod play;
|
||||
pub mod queue;
|
||||
pub mod skip;
|
||||
pub mod stop;
|
||||
pub mod undeafen;
|
||||
pub mod unmute;
|
||||
pub mod loopcurrent;
|
||||
pub mod pause;
|
||||
pub mod resume;
|
||||
|
||||
@@ -27,7 +27,15 @@ async fn mute(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
|
||||
if handler.is_mute() {
|
||||
check_msg(msg.channel_id.say(&ctx.http, "Already muted").await);
|
||||
if let Err(e) = handler.mute(false).await {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, format!("failed: {:?}", e))
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
check_msg(msg.channel_id.say(&ctx.http, "Unmuted").await);
|
||||
} else {
|
||||
if let Err(err) = handler.mute(true).await {
|
||||
check_msg(
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::commands::misc::check_msg;
|
||||
|
||||
#[command]
|
||||
#[only_in(guilds)]
|
||||
async fn undeafen(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
async fn pause(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let guild_id = msg.guild_id.unwrap();
|
||||
|
||||
let manager = songbird::get(ctx)
|
||||
@@ -16,20 +16,22 @@ async fn undeafen(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
.clone();
|
||||
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
if let Err(e) = handler.deafen(false).await {
|
||||
let handler = handler_lock.lock().await;
|
||||
let queue = handler.queue();
|
||||
let _ = queue.pause();
|
||||
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, format!("Failed: {:?}", e))
|
||||
.say(
|
||||
&ctx.http,
|
||||
format!("Song paused."),
|
||||
)
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
check_msg(msg.channel_id.say(&ctx.http, "Undeafened").await);
|
||||
} else {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, "Not in a voice channel to undeafen in")
|
||||
.say(&ctx.http, "Not in a voice channel to play in")
|
||||
.await,
|
||||
);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ use serenity::framework::standard::{Args, CommandResult};
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
use reqwest::Client as HttpClient;
|
||||
use songbird::input::YoutubeDl;
|
||||
use songbird::input::{Compose, YoutubeDl};
|
||||
use songbird::events::TrackEvent;
|
||||
|
||||
use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier};
|
||||
@@ -31,17 +31,10 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
}
|
||||
};
|
||||
|
||||
let do_search = !url.starts_with("http");
|
||||
let is_search = !url.starts_with("http");
|
||||
|
||||
let (guild_id, channel_id) = {
|
||||
let guild = msg.guild(&ctx.cache).unwrap();
|
||||
let channel_id = guild
|
||||
.voice_states
|
||||
.get(&msg.author.id)
|
||||
.and_then(|voice_state| voice_state.channel_id);
|
||||
|
||||
(guild.id, channel_id)
|
||||
};
|
||||
let guild_id = msg.guild_id.unwrap();
|
||||
let channel_id = msg.guild(&ctx.cache).unwrap().voice_states.get(&msg.author.id).and_then(|voice_state| voice_state.channel_id);
|
||||
|
||||
let connect_to = match channel_id {
|
||||
Some(channel) => channel,
|
||||
@@ -67,19 +60,21 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
if let Ok(handler_lock) = manager.join(guild_id, connect_to).await {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
|
||||
// if let Err(err) = handler.deafen(true).await {println!("Failed to deafen: {:?}", err)};
|
||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||
|
||||
let src = if do_search {
|
||||
YoutubeDl::new_ytdl_like("yt-dlp", http_client, url)
|
||||
let mut src = if is_search {
|
||||
println!("ytsearch:{}", url);
|
||||
YoutubeDl::new_ytdl_like("yt-dlp", http_client, format!("ytsearch:{}", args.clone().message()))
|
||||
} else {
|
||||
YoutubeDl::new(http_client, url)
|
||||
YoutubeDl::new_ytdl_like("yt-dlp", http_client, url)
|
||||
};
|
||||
|
||||
let _ = handler.enqueue_input(src.clone().into()).await;
|
||||
|
||||
// let _ = handler.play_input(src.clone().into());
|
||||
let metadata = src.aux_metadata().await.unwrap();
|
||||
|
||||
check_msg(msg.channel_id.say(&ctx.http, "Playing song").await);
|
||||
check_msg(msg.channel_id.say(&ctx.http, format!("Playing song: {}", metadata.title.unwrap())).await);
|
||||
} else {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
|
||||
@@ -3,10 +3,46 @@ use serenity::framework::standard::CommandResult;
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
// use crate::commands::misc::check_msg;
|
||||
use crate::commands::misc::check_msg;
|
||||
|
||||
#[command]
|
||||
#[only_in(guilds)]
|
||||
async fn queue(_ctx: &Context, _msg: &Message) -> CommandResult {
|
||||
async fn queue(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let guild_id = msg.guild_id.unwrap();
|
||||
|
||||
let manager = songbird::get(ctx)
|
||||
.await
|
||||
.expect("Client placed at init")
|
||||
.clone();
|
||||
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let handler = handler_lock.lock().await;
|
||||
let queue = handler.queue();
|
||||
let mut queue_res = String::from("Queue: \n");
|
||||
|
||||
for (i, song) in queue.current_queue().iter().enumerate() {
|
||||
queue_res.push_str(&format!(
|
||||
"{}. {} - {}\n",
|
||||
i + 1,
|
||||
song.uuid(),
|
||||
"Artist"
|
||||
// song.metadata().artist.clone().unwrap_or_else(|| String::from("Unknown"))
|
||||
));
|
||||
}
|
||||
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, queue_res)
|
||||
.await,
|
||||
);
|
||||
|
||||
} else {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, "Not in a voice channel!")
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use crate::commands::misc::check_msg;
|
||||
|
||||
#[command]
|
||||
#[only_in(guilds)]
|
||||
async fn unmute(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
async fn resume(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let guild_id = msg.guild_id.unwrap();
|
||||
|
||||
let manager = songbird::get(ctx)
|
||||
@@ -16,20 +16,22 @@ async fn unmute(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
.clone();
|
||||
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
if let Err(e) = handler.mute(false).await {
|
||||
let handler = handler_lock.lock().await;
|
||||
let queue = handler.queue();
|
||||
let _ = queue.resume();
|
||||
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, format!("Failed: {:?}", e))
|
||||
.say(
|
||||
&ctx.http,
|
||||
format!("Song resumed."),
|
||||
)
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
check_msg(msg.channel_id.say(&ctx.http, "Unmuted").await);
|
||||
} else {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, "Not in a voice channel to unmute in")
|
||||
.say(&ctx.http, "Not in a voice channel to play in")
|
||||
.await,
|
||||
);
|
||||
}
|
||||
@@ -3,10 +3,38 @@ use serenity::framework::standard::CommandResult;
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
// use crate::commands::misc::check_msg;
|
||||
use crate::commands::misc::check_msg;
|
||||
|
||||
#[command]
|
||||
#[only_in(guilds)]
|
||||
async fn skip(_ctx: &Context, _msg: &Message) -> CommandResult {
|
||||
async fn skip(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let guild_id = msg.guild_id.unwrap();
|
||||
|
||||
let manager = songbird::get(ctx)
|
||||
.await
|
||||
.expect("Client placed at init")
|
||||
.clone();
|
||||
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let handler = handler_lock.lock().await;
|
||||
let queue = handler.queue();
|
||||
let _ = queue.skip();
|
||||
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(
|
||||
&ctx.http,
|
||||
format!("Song skipped: {} in queue.", queue.len()),
|
||||
)
|
||||
.await,
|
||||
);
|
||||
} else {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, "Not in a voice channel to play in")
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -16,22 +16,15 @@ async fn stop(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
.clone();
|
||||
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
let _queue = handler.queue();
|
||||
|
||||
if let Err(e) = handler.deafen(false).await {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, format!("Failed: {:?}", e))
|
||||
.await,
|
||||
);
|
||||
}
|
||||
let handler = handler_lock.lock().await;
|
||||
let queue = handler.queue();
|
||||
queue.stop();
|
||||
|
||||
check_msg(msg.channel_id.say(&ctx.http, "Playback stopped!").await);
|
||||
} else {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, "Not in a voice channel to undeafen in")
|
||||
.say(&ctx.http, "Not in a voice channel!")
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
use crate::{Context, Error};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use serenity::{all::Message, client::Context, framework::standard::{macros::command, CommandResult}};
|
||||
#[poise::command(prefix_command, slash_command)]
|
||||
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let system_now = SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap().as_millis() as i64;
|
||||
|
||||
use crate::commands::misc::check_msg;
|
||||
let message_now = ctx.created_at().timestamp_millis();
|
||||
|
||||
#[command]
|
||||
async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let system_now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis() as i64;
|
||||
let message_now = msg.timestamp.timestamp_millis();
|
||||
|
||||
// println!("System Time: {} ||| Message Time: {}", system_now, message_now);
|
||||
|
||||
check_msg(msg.reply(ctx, format!("Pong! (latency: {} ms)", system_now - message_now)).await);
|
||||
let response = format!("Pong! (latency: {} ms)", system_now - message_now);
|
||||
ctx.say(response).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
168
src/main.rs
168
src/main.rs
@@ -1,27 +1,13 @@
|
||||
use serenity::gateway::ActivityData;
|
||||
use serenity::model::prelude::Message;
|
||||
use songbird::SerenityInit;
|
||||
|
||||
use reqwest::Client as HttpClient;
|
||||
|
||||
use serenity::client::Context;
|
||||
|
||||
use serenity::{
|
||||
async_trait,
|
||||
client::{Client, EventHandler},
|
||||
framework::{
|
||||
standard::{macros::group, macros::hook, Configuration},
|
||||
StandardFramework,
|
||||
},
|
||||
model::gateway::Ready,
|
||||
prelude::GatewayIntents,
|
||||
};
|
||||
|
||||
use tracing::info;
|
||||
use poise::serenity_prelude::{self as serenity, ActivityData};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tracing::{info, warn, error};
|
||||
|
||||
mod commands;
|
||||
|
||||
// music management commands
|
||||
// commands: music
|
||||
use crate::commands::music::deafen::*;
|
||||
use crate::commands::music::join::*;
|
||||
use crate::commands::music::leave::*;
|
||||
@@ -30,60 +16,134 @@ use crate::commands::music::play::*;
|
||||
use crate::commands::music::queue::*;
|
||||
use crate::commands::music::skip::*;
|
||||
use crate::commands::music::stop::*;
|
||||
use crate::commands::music::undeafen::*;
|
||||
use crate::commands::music::unmute::*;
|
||||
use crate::commands::music::loopcurrent::*;
|
||||
use crate::commands::music::pause::*;
|
||||
use crate::commands::music::resume::*;
|
||||
|
||||
// tools
|
||||
// commands: tools
|
||||
use crate::commands::tools::ping::*;
|
||||
|
||||
// kashi
|
||||
// commands: kashi
|
||||
use crate::commands::kashi::kashi::*;
|
||||
|
||||
struct Handler;
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||
info!("{} [{}] connected successfully!", ready.user.name, ready.user.id);
|
||||
let prefix = std::env::var("PREFIX").expect("Environment variable `PREFIX` not found!");
|
||||
ctx.set_activity(Some(ActivityData::listening(prefix + "help")));
|
||||
pub struct Data;
|
||||
|
||||
async fn on_error(error: poise::FrameworkError<'_, Data, Error>) {
|
||||
match error {
|
||||
poise::FrameworkError::Setup { error, .. } => panic!("Failed to start bot {:?}", error),
|
||||
poise::FrameworkError::Command { error, ctx, .. } => {
|
||||
warn!("Error in command `{}`: {:?}", ctx.command().name, error);
|
||||
}
|
||||
error => {
|
||||
if let Err(e) = poise::builtins::on_error(error).await {
|
||||
error!("Error while handling error: {}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[hook]
|
||||
async fn before(_: &Context, msg: &Message, command_name: &str) -> bool {
|
||||
info!(
|
||||
"Received command [{}] from user [{}]",
|
||||
command_name, msg.author.name
|
||||
);
|
||||
true
|
||||
// this is for debug only
|
||||
#[poise::command(prefix_command)]
|
||||
pub async fn register(ctx: Context<'_>) -> Result<(), Error> {
|
||||
poise::builtins::register_application_commands_buttons(ctx).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[group]
|
||||
#[commands(
|
||||
join, deafen, leave, mute, play, unmute, undeafen, ping, kashi, queue, stop, skip
|
||||
)]
|
||||
struct General;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dotenv::dotenv().expect("Failed to load .env file.");
|
||||
// logger and dotenv initialization
|
||||
tracing_subscriber::fmt::init();
|
||||
dotenv::dotenv().expect("Failed to load .env file.");
|
||||
|
||||
let token =
|
||||
std::env::var("DISCORD_TOKEN").expect("Environment variable `DISCORD_TOKEN` not found!");
|
||||
let token = std::env::var("DISCORD_TOKEN").expect("Environment variable `DISCORD_TOKEN` not found!");
|
||||
let prefix = std::env::var("PREFIX").expect("Environment variable `PREFIX` not found!");
|
||||
|
||||
let framework = StandardFramework::new().before(before).group(&GENERAL_GROUP);
|
||||
framework.configure(Configuration::new().prefix(prefix));
|
||||
let commands = vec![
|
||||
// commands: music
|
||||
deafen(),
|
||||
join(),
|
||||
leave(),
|
||||
loopcurrent(),
|
||||
mute(),
|
||||
pause(),
|
||||
play(),
|
||||
queue(),
|
||||
resume(),
|
||||
skip(),
|
||||
stop(),
|
||||
// commands: tools
|
||||
ping(),
|
||||
// commands: kashi
|
||||
kashi(),
|
||||
// commands: debug
|
||||
register(),
|
||||
];
|
||||
|
||||
let intents = GatewayIntents::non_privileged() | GatewayIntents::MESSAGE_CONTENT;
|
||||
let options = poise::FrameworkOptions {
|
||||
commands,
|
||||
prefix_options: poise::PrefixFrameworkOptions {
|
||||
prefix: Some(prefix.to_string().into()),
|
||||
edit_tracker: Some(Arc::new(poise::EditTracker::for_timespan(
|
||||
Duration::from_secs(3600),
|
||||
))),
|
||||
additional_prefixes: vec![],
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
let mut client = Client::builder(&token, intents)
|
||||
on_error: |error| Box::pin(on_error(error)),
|
||||
|
||||
pre_command: |ctx| {
|
||||
Box::pin(async move {
|
||||
info!("Executing command {}...", ctx.command().qualified_name);
|
||||
})
|
||||
},
|
||||
|
||||
post_command: |ctx| {
|
||||
Box::pin(async move {
|
||||
info!("Executed command {}!", ctx.command().qualified_name);
|
||||
})
|
||||
},
|
||||
|
||||
command_check: Some(|ctx| {
|
||||
Box::pin(async move {
|
||||
if ctx.author().id == 123456789 {
|
||||
return Ok(false);
|
||||
}
|
||||
Ok(true)
|
||||
})
|
||||
}),
|
||||
|
||||
skip_checks_for_owners: false,
|
||||
event_handler: |_ctx, event, _framework, _data| {
|
||||
Box::pin(async move {
|
||||
info!("Got an event in event handler: {:?}", event.snake_case_name());
|
||||
Ok(())
|
||||
})
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
.setup(move |ctx, ready, _framework| {
|
||||
Box::pin(async move {
|
||||
info!("{} [{}] connected successfully!", ready.user.name, ready.user.id);
|
||||
ctx.set_activity(Some(ActivityData::listening(prefix + "help")));
|
||||
// poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
|
||||
Ok(Data {})
|
||||
})
|
||||
})
|
||||
.options(options)
|
||||
.build();
|
||||
|
||||
let intents = serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
|
||||
|
||||
let mut client = serenity::ClientBuilder::new(token, intents)
|
||||
.framework(framework)
|
||||
.register_songbird()
|
||||
.event_handler(Handler)
|
||||
.type_map_insert::<HttpKey>(HttpClient::new())
|
||||
.await
|
||||
.expect("Error creating client");
|
||||
|
||||
@@ -91,9 +151,9 @@ async fn main() {
|
||||
let _ = client
|
||||
.start()
|
||||
.await
|
||||
.map_err(|why| println!("Client ended: {:?}", why));
|
||||
.map_err(|why| error!("Client ended: {:?}", why));
|
||||
});
|
||||
|
||||
let _signal_err = tokio::signal::ctrl_c().await;
|
||||
println!("Recieved Ctrl-C, shutting down.");
|
||||
warn!("Recieved Ctrl-C, shutting down.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user