mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 20:36:10 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
3b0121699f
|
|||
|
a27e95a88d
|
|||
|
6946ddc9f1
|
|||
|
21fe190921
|
|||
|
4a0184811e
|
|||
|
70c249787c
|
80
Cargo.lock
generated
80
Cargo.lock
generated
@@ -340,6 +340,41 @@ dependencies = [
|
|||||||
"zeroize",
|
"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]]
|
[[package]]
|
||||||
name = "dashmap"
|
name = "dashmap"
|
||||||
version = "5.5.3"
|
version = "5.5.3"
|
||||||
@@ -785,6 +820,12 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ident_case"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "idna"
|
name = "idna"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -892,10 +933,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lyra"
|
name = "lyra"
|
||||||
version = "0.1.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"openssl",
|
"openssl",
|
||||||
|
"poise",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serenity",
|
"serenity",
|
||||||
@@ -1247,6 +1289,35 @@ dependencies = [
|
|||||||
"pnet_base",
|
"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]]
|
[[package]]
|
||||||
name = "poly1305"
|
name = "poly1305"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
@@ -1976,6 +2047,12 @@ version = "0.2.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82"
|
checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "subtle"
|
name = "subtle"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
@@ -2261,6 +2338,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
|
"parking_lot",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"signal-hook-registry",
|
"signal-hook-registry",
|
||||||
"socket2",
|
"socket2",
|
||||||
|
|||||||
13
Cargo.toml
13
Cargo.toml
@@ -1,17 +1,26 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lyra"
|
name = "lyra"
|
||||||
version = "0.1.0"
|
version = "0.4.0"
|
||||||
|
authors = ["Michał Czyż <mike@c2yz.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
description = "A featureful Discord bot written in Rust."
|
||||||
|
documentation = "https://lyra.c2yz.com/docs"
|
||||||
|
readme = "README.md"
|
||||||
|
homepage = "https://lyra.c2yz.com"
|
||||||
|
license-file = "LICENSE.md"
|
||||||
|
keywords = ["discord", "bot", "rust", "music", "featureful"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
openssl = { version = "0.10.63", features = ["vendored"] }
|
openssl = { version = "0.10.63", features = ["vendored"] }
|
||||||
|
poise = "0.6.1"
|
||||||
regex = "1.10.3"
|
regex = "1.10.3"
|
||||||
reqwest = "0.11.23"
|
reqwest = "0.11.23"
|
||||||
serenity = { version = "0.12.0", features = ["cache", "framework", "standard_framework", "voice"] }
|
serenity = { version = "0.12.0", features = ["cache", "framework", "standard_framework", "voice"] }
|
||||||
songbird = { version = "0.4.0", features = ["builtin-queue", "serenity"] }
|
songbird = { version = "0.4.0", features = ["builtin-queue", "serenity"] }
|
||||||
symphonia = "0.5.3"
|
symphonia = "0.5.3"
|
||||||
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread", "signal"] }
|
tokio = { version = "1.35.1", features = ["macros", "full", "signal"] }
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-futures = "0.2.5"
|
tracing-futures = "0.2.5"
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = "0.3.18"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# License
|
# License
|
||||||
|
|
||||||
Copyright(c) Michał Czyż 2024
|
Copyright (C) 2024 Michał Czyż
|
||||||
|
|
||||||
[Currently] All Rights Reserved.
|
All Rights Reserved.
|
||||||
|
|
||||||
|
This build is private and shall not be distributed nor modified without permission.
|
||||||
|
|||||||
3
scripts/cross-build.sh
Executable file
3
scripts/cross-build.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cross build -r --target aarch64-unknown-linux-gnu
|
||||||
3
scripts/launch.sh
Executable file
3
scripts/launch.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
nohup ../lyra > lyra.log 2> lyra.err < /dev/null &
|
||||||
3
src/commands.rs
Normal file
3
src/commands.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod kashi;
|
||||||
|
pub mod music;
|
||||||
|
pub mod tools;
|
||||||
3
src/commands/kashi.rs
Normal file
3
src/commands/kashi.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod kashi;
|
||||||
|
|
||||||
|
pub use kashi::kashi;
|
||||||
@@ -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]
|
let response = format!("Kashi platform is currently under construction!");
|
||||||
async fn kashi(ctx: &Context, msg: &Message) -> CommandResult {
|
ctx.say(response).await?;
|
||||||
check_msg(msg.reply(ctx, "Kashi lyrics platform integration").await);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
pub mod kashi;
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
use serenity::model::channel::Message;
|
|
||||||
use serenity::Result as SerenityResult;
|
|
||||||
|
|
||||||
pub fn check_msg(result: SerenityResult<Message>) {
|
|
||||||
if let Err(why) = result {
|
|
||||||
println!("Error sending message: {:?}", why);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
pub mod kashi;
|
pub mod kashi;
|
||||||
pub mod misc;
|
|
||||||
pub mod music;
|
pub mod music;
|
||||||
pub mod tools;
|
pub mod tools;
|
||||||
|
|||||||
24
src/commands/music.rs
Normal file
24
src/commands/music.rs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
pub mod deafen;
|
||||||
|
pub mod join;
|
||||||
|
pub mod leave;
|
||||||
|
pub mod misc;
|
||||||
|
pub mod mute;
|
||||||
|
pub mod pause;
|
||||||
|
pub mod play;
|
||||||
|
pub mod queue;
|
||||||
|
pub mod repeat;
|
||||||
|
pub mod resume;
|
||||||
|
pub mod skip;
|
||||||
|
pub mod stop;
|
||||||
|
|
||||||
|
pub use deafen::deafen;
|
||||||
|
pub use join::join;
|
||||||
|
pub use leave::leave;
|
||||||
|
pub use mute::mute;
|
||||||
|
pub use pause::pause;
|
||||||
|
pub use play::play;
|
||||||
|
pub use queue::queue;
|
||||||
|
pub use repeat::repeat;
|
||||||
|
pub use resume::resume;
|
||||||
|
pub use skip::skip;
|
||||||
|
pub use stop::stop;
|
||||||
@@ -1,24 +1,18 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
use crate::{Context, Error};
|
||||||
use serenity::framework::standard::CommandResult;
|
|
||||||
use serenity::model::prelude::*;
|
|
||||||
use serenity::prelude::*;
|
|
||||||
|
|
||||||
use crate::commands::misc::check_msg;
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn deafen(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
#[command]
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn deafen(ctx: &Context, msg: &Message) -> CommandResult {
|
|
||||||
let guild_id = msg.guild_id.unwrap();
|
|
||||||
|
|
||||||
let manager = songbird::get(ctx)
|
|
||||||
.await
|
.await
|
||||||
.expect("Client placed at init")
|
.expect("Songbird client placed at init")
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
let handler_lock = match manager.get(guild_id) {
|
let handler_lock = match manager.get(guild_id) {
|
||||||
Some(handler) => handler,
|
Some(handler) => handler,
|
||||||
None => {
|
None => {
|
||||||
check_msg(msg.reply(ctx, "Not in a voice channel").await);
|
ctx.say("Not in a voice channel").await?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -27,17 +21,17 @@ async fn deafen(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
let mut handler = handler_lock.lock().await;
|
let mut handler = handler_lock.lock().await;
|
||||||
|
|
||||||
if handler.is_deaf() {
|
if handler.is_deaf() {
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Already deafened").await);
|
if let Err(err) = handler.deafen(false).await {
|
||||||
} else {
|
ctx.say(format!("Failed: {:?}", err)).await?;
|
||||||
if let Err(err) = handler.deafen(true).await {
|
|
||||||
check_msg(
|
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, format!("Failed: {:?}", err))
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Deafened").await);
|
ctx.say("Undeafened").await?;
|
||||||
|
} else {
|
||||||
|
if let Err(err) = handler.deafen(true).await {
|
||||||
|
ctx.say(format!("Failed: {:?}", err)).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.say("Deafened").await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,36 +1,23 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
use crate::{Context, Error};
|
||||||
use serenity::framework::standard::CommandResult;
|
use songbird::TrackEvent;
|
||||||
use serenity::model::prelude::*;
|
use crate::commands::music::misc::TrackErrorNotifier;
|
||||||
use serenity::prelude::*;
|
|
||||||
use songbird::events::TrackEvent;
|
|
||||||
|
|
||||||
use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier};
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn join(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
#[command]
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
#[only_in(guilds)]
|
let channel_id = ctx.guild().unwrap().voice_states.get(&ctx.author().id).and_then(|voice_state| voice_state.channel_id);
|
||||||
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 connect_to = match channel_id {
|
let connect_to = match channel_id {
|
||||||
Some(channel) => channel,
|
Some(channel) => channel,
|
||||||
None => {
|
None => {
|
||||||
check_msg(msg.reply(ctx, "Not in a voice channel").await);
|
ctx.say("Not in a voice channel").await?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let manager = songbird::get(ctx)
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
.await
|
.await
|
||||||
.expect("Songbird Voice placed at init")
|
.expect("Songbird client placed at init")
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
if let Ok(handler_lock) = manager.join(guild_id, connect_to).await {
|
if let Ok(handler_lock) = manager.join(guild_id, connect_to).await {
|
||||||
@@ -38,5 +25,7 @@ async fn join(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.say("Joined the voice channel").await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1,36 +1,24 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
use crate::{Context, Error};
|
||||||
use serenity::framework::standard::CommandResult;
|
|
||||||
use serenity::model::prelude::*;
|
|
||||||
use serenity::prelude::*;
|
|
||||||
|
|
||||||
use crate::commands::misc::check_msg;
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn leave(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
#[command]
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
#[aliases(q)]
|
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
|
|
||||||
let guild_id = msg.guild_id.unwrap();
|
|
||||||
|
|
||||||
let manager = songbird::get(ctx)
|
|
||||||
.await
|
.await
|
||||||
.expect("Client placed in at init")
|
.expect("Songbird client placed at init")
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
let has_handler = manager.get(guild_id).is_some();
|
if !manager.get(guild_id).is_some() {
|
||||||
|
ctx.say("Not in a voice channel").await?;
|
||||||
if has_handler {
|
return Ok(())
|
||||||
if let Err(err) = manager.remove(guild_id).await {
|
|
||||||
check_msg(
|
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, format!("Failed: {:?}", err))
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Left voice channel").await);
|
|
||||||
} else {
|
|
||||||
check_msg(msg.reply(ctx, "Not in a voice channel").await);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Err(err) = manager.remove(guild_id).await {
|
||||||
|
ctx.say(format!("Failed: {:?}", err)).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.say("Left voice channel").await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
pub mod deafen;
|
|
||||||
pub mod join;
|
|
||||||
pub mod leave;
|
|
||||||
pub mod misc;
|
|
||||||
pub mod mute;
|
|
||||||
pub mod play;
|
|
||||||
pub mod queue;
|
|
||||||
pub mod skip;
|
|
||||||
pub mod stop;
|
|
||||||
pub mod undeafen;
|
|
||||||
pub mod unmute;
|
|
||||||
@@ -1,24 +1,18 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
use crate::{Context, Error};
|
||||||
use serenity::framework::standard::CommandResult;
|
|
||||||
use serenity::model::prelude::*;
|
|
||||||
use serenity::prelude::*;
|
|
||||||
|
|
||||||
use crate::commands::misc::check_msg;
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn mute(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
#[command]
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn mute(ctx: &Context, msg: &Message) -> CommandResult {
|
|
||||||
let guild_id = msg.guild_id.unwrap();
|
|
||||||
|
|
||||||
let manager = songbird::get(ctx)
|
|
||||||
.await
|
.await
|
||||||
.expect("Client placed at init")
|
.expect("Songbird client placed at init")
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
let handler_lock = match manager.get(guild_id) {
|
let handler_lock = match manager.get(guild_id) {
|
||||||
Some(handler) => handler,
|
Some(handler) => handler,
|
||||||
None => {
|
None => {
|
||||||
check_msg(msg.reply(ctx, "Not in a voice channel").await);
|
ctx.say("Not in a voice channel").await?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -27,17 +21,17 @@ async fn mute(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
let mut handler = handler_lock.lock().await;
|
let mut handler = handler_lock.lock().await;
|
||||||
|
|
||||||
if handler.is_mute() {
|
if handler.is_mute() {
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Already muted").await);
|
if let Err(e) = handler.mute(false).await {
|
||||||
} else {
|
ctx.say(format!("failed: {:?}", e)).await?;
|
||||||
if let Err(err) = handler.mute(true).await {
|
|
||||||
check_msg(
|
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, format!("Failed: {:?}", err))
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Muted").await);
|
ctx.say("Unmuted").await?;
|
||||||
|
} else {
|
||||||
|
if let Err(err) = handler.mute(true).await {
|
||||||
|
ctx.say(format!("Failed: {:?}", err)).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.say("Muted").await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
23
src/commands/music/pause.rs
Normal file
23
src/commands/music/pause.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
use crate::{Context, Error};
|
||||||
|
|
||||||
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn pause(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
|
.await
|
||||||
|
.expect("Songbird 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.pause();
|
||||||
|
|
||||||
|
ctx.say(format!("Song paused.")).await?;
|
||||||
|
} else {
|
||||||
|
ctx.say("Not in a voice channel to play in").await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,65 +1,59 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
use crate::{Context, Error};
|
||||||
use serenity::framework::standard::{Args, CommandResult};
|
|
||||||
use serenity::model::prelude::*;
|
use fancy_regex::Regex;
|
||||||
use serenity::prelude::*;
|
use regex::Regex as Regex_Classic;
|
||||||
use reqwest::Client as HttpClient;
|
use std::process::Command;
|
||||||
use songbird::input::YoutubeDl;
|
use std::time::Duration;
|
||||||
|
use poise::CreateReply;
|
||||||
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
|
use poise::serenity_prelude::Colour;
|
||||||
|
use poise::serenity_prelude::model::Timestamp;
|
||||||
|
use serenity::builder::CreateEmbedAuthor;
|
||||||
|
use serenity::builder::CreateEmbedFooter;
|
||||||
|
use songbird::input::AuxMetadata;
|
||||||
|
use songbird::input::{Compose, YoutubeDl};
|
||||||
use songbird::events::TrackEvent;
|
use songbird::events::TrackEvent;
|
||||||
|
|
||||||
use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier};
|
use crate::commands::music::misc::TrackErrorNotifier;
|
||||||
|
use crate::http::HttpKey;
|
||||||
|
|
||||||
pub struct HttpKey;
|
#[poise::command(
|
||||||
|
prefix_command,
|
||||||
|
slash_command,
|
||||||
|
aliases("p", "enqueue")
|
||||||
|
)]
|
||||||
|
pub async fn play(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Provide a query or an url"] #[rest] mut song: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let regex_spotify = Regex::new(r"https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-)+)(?:(?=\?)(?:[?&]foo=(\d*)(?=[&#]|$)|(?![?&]foo=)[^#])+)?(?=#|$)").unwrap();
|
||||||
|
let regex_youtube = Regex_Classic::new(r#""url": "(https://www.youtube.com/watch\?v=[A-Za-z0-9]{11})""#).unwrap();
|
||||||
|
let regex_youtube_playlist = Regex::new(r"^((?:https?:)\/\/)?((?:www|m)\.)?((?:youtube\.com)).*(youtu.be\/|list=)([^#&?]*).*").unwrap();
|
||||||
|
|
||||||
impl TypeMapKey for HttpKey {
|
let is_playlist = regex_youtube_playlist.is_match(&song).unwrap();
|
||||||
type Value = HttpClient;
|
let is_spotify = regex_spotify.is_match(&song).unwrap();
|
||||||
}
|
let is_query = !song.starts_with("http");
|
||||||
|
|
||||||
#[command]
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
#[aliases(p)]
|
let channel_id = ctx.guild().unwrap().voice_states.get(&ctx.author().id).and_then(|voice_state| voice_state.channel_id);
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
|
||||||
let url = match args.single::<String>() {
|
|
||||||
Ok(url) => url,
|
|
||||||
Err(_) => {
|
|
||||||
check_msg(
|
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, "Must provide a URL to a video or audio")
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let do_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 connect_to = match channel_id {
|
let connect_to = match channel_id {
|
||||||
Some(channel) => channel,
|
Some(channel) => channel,
|
||||||
None => {
|
None => {
|
||||||
check_msg(msg.reply(ctx, "Not in a voice channel").await);
|
ctx.say("Not in a voice channel").await?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let http_client = {
|
let http_client = {
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.serenity_context().data.read().await;
|
||||||
data.get::<HttpKey>()
|
data.get::<HttpKey>()
|
||||||
.cloned()
|
.cloned()
|
||||||
.expect("Guaranteed to exist in the typemap.")
|
.expect("Guaranteed to exist in the typemap.")
|
||||||
};
|
};
|
||||||
|
|
||||||
let manager = songbird::get(ctx)
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
.await
|
.await
|
||||||
.expect("Songbird Voice placed at init")
|
.expect("Songbird Voice placed at init")
|
||||||
.clone();
|
.clone();
|
||||||
@@ -69,24 +63,98 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
|||||||
|
|
||||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||||
|
|
||||||
let src = if do_search {
|
if is_playlist {
|
||||||
YoutubeDl::new_ytdl_like("yt-dlp", http_client, url)
|
let raw_list = Command::new("yt-dlp")
|
||||||
|
.args(["-j", "--flat-playlist", &song])
|
||||||
|
.output()
|
||||||
|
.expect("failed to execute process")
|
||||||
|
.stdout;
|
||||||
|
|
||||||
|
let list = String::from_utf8(raw_list.clone()).expect("Invalid UTF-8");
|
||||||
|
|
||||||
|
let urls: Vec<String> = regex_youtube.captures_iter(&list).map(|capture| capture[1].to_string()).collect();
|
||||||
|
|
||||||
|
let mut sources: Vec<YoutubeDl> = vec![];
|
||||||
|
|
||||||
|
for url in urls {
|
||||||
|
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client.clone(), url);
|
||||||
|
let _ = handler.enqueue_input(src.clone().into()).await;
|
||||||
|
sources.push(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
let embed = generate_playlist_embed(ctx, sources).await;
|
||||||
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
|
ctx.send(response).await?;
|
||||||
} else {
|
} else {
|
||||||
YoutubeDl::new(http_client, url)
|
if is_spotify {
|
||||||
};
|
let exec = format!("node ./src/spotify --url {}", song);
|
||||||
|
let query = Command::new("sh").arg("-c").arg(exec).output().expect("failed to execute process").stdout;
|
||||||
|
let query_str = String::from_utf8(query.clone()).expect("Invalid UTF-8");
|
||||||
|
song = format!("ytsearch:{}", query_str.to_string());
|
||||||
|
|
||||||
let _ = handler.enqueue_input(src.clone().into()).await;
|
}
|
||||||
|
|
||||||
// let _ = handler.play_input(src.clone().into());
|
if is_query {
|
||||||
|
song = format!("ytsearch:{}", song);
|
||||||
|
}
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Playing song").await);
|
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client, song);
|
||||||
} else {
|
let _ = handler.enqueue_input(src.clone().into()).await;
|
||||||
check_msg(
|
|
||||||
msg.channel_id
|
let embed = generate_embed(ctx, src).await;
|
||||||
.say(&ctx.http, "Not in a voice channel to play in")
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
.await,
|
ctx.send(response).await?;
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn generate_embed(ctx: Context<'_>, src: YoutubeDl) -> Result<CreateEmbed, Error> {
|
||||||
|
let metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
|
let AuxMetadata {title, thumbnail, source_url, artist, duration, ..} = metadata;
|
||||||
|
let timestamp = Timestamp::now();
|
||||||
|
let duration_minutes = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() / 60;
|
||||||
|
let duration_seconds = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() % 60;
|
||||||
|
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(CreateEmbedAuthor::new("Track enqueued").icon_url(ctx.author().clone().face()))
|
||||||
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
|
.title(title.unwrap())
|
||||||
|
.url(source_url.unwrap())
|
||||||
|
.thumbnail(thumbnail.unwrap_or(ctx.cache().current_user().face()))
|
||||||
|
.field("Artist", artist.unwrap_or("Unknown Artist".to_string()), true)
|
||||||
|
.field("Duration", format!("{:02}:{:02}", duration_minutes, duration_seconds), true)
|
||||||
|
.field("DJ", ctx.author().name.clone(), true)
|
||||||
|
.timestamp(timestamp)
|
||||||
|
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
||||||
|
|
||||||
|
Ok(embed)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn generate_playlist_embed(ctx: Context<'_>, sources: Vec<YoutubeDl>) -> Result<CreateEmbed, Error> {
|
||||||
|
let src = sources.get(0).unwrap();
|
||||||
|
|
||||||
|
let metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
|
let AuxMetadata {title, thumbnail, source_url, artist, duration, ..} = metadata;
|
||||||
|
let timestamp = Timestamp::now();
|
||||||
|
let duration_minutes = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() / 60;
|
||||||
|
let duration_seconds = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() % 60;
|
||||||
|
|
||||||
|
let description = format!("Enqueued tracks: {}", sources.len() - 1);
|
||||||
|
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(CreateEmbedAuthor::new("Playlist enqueued").icon_url(ctx.author().clone().face()))
|
||||||
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
|
.title(title.unwrap())
|
||||||
|
.url(source_url.unwrap())
|
||||||
|
.thumbnail(thumbnail.unwrap_or(ctx.cache().current_user().face()))
|
||||||
|
.field("Artist", artist.unwrap_or("Unknown Artist".to_string()), true)
|
||||||
|
.field("Duration", format!("{:02}:{:02}", duration_minutes, duration_seconds), true)
|
||||||
|
.field("DJ", ctx.author().name.clone(), true)
|
||||||
|
.description(description)
|
||||||
|
.timestamp(timestamp)
|
||||||
|
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
||||||
|
|
||||||
|
Ok(embed)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,34 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
use crate::{Context, Error};
|
||||||
use serenity::framework::standard::CommandResult;
|
|
||||||
use serenity::model::prelude::*;
|
|
||||||
use serenity::prelude::*;
|
|
||||||
|
|
||||||
// use crate::commands::misc::check_msg;
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn queue(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
|
.await
|
||||||
|
.expect("Songbird 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"))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.say(queue_res).await?;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ctx.say("Not in a voice channel!").await?;
|
||||||
|
}
|
||||||
|
|
||||||
#[command]
|
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn queue(_ctx: &Context, _msg: &Message) -> CommandResult {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
43
src/commands/music/repeat.rs
Normal file
43
src/commands/music/repeat.rs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
use crate::{Context, Error};
|
||||||
|
use songbird::tracks::LoopState;
|
||||||
|
|
||||||
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn repeat(ctx: Context<'_>, times: usize) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
|
.await
|
||||||
|
.expect("Songbird 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;
|
||||||
|
|
||||||
|
match is_looped {
|
||||||
|
LoopState::Infinite => {
|
||||||
|
let _ = queue.current().unwrap().disable_loop();
|
||||||
|
|
||||||
|
ctx.say("Song unlooped.").await?;
|
||||||
|
}
|
||||||
|
LoopState::Finite(_) => {
|
||||||
|
if times < 100 {
|
||||||
|
let _ = queue.current().unwrap().loop_for(times);
|
||||||
|
ctx.say("Song looped forever (a very long time)").await?;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let _ = queue.current().unwrap().enable_loop();
|
||||||
|
ctx.say(format!("Song looped {} times.", times)).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.say("Not in a voice channel to play in").await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
23
src/commands/music/resume.rs
Normal file
23
src/commands/music/resume.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
use crate::{Context, Error};
|
||||||
|
|
||||||
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn resume(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
|
.await
|
||||||
|
.expect("Songbird 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.resume();
|
||||||
|
|
||||||
|
ctx.say(format!("Song resumed.")).await?;
|
||||||
|
} else {
|
||||||
|
ctx.say("Not in a voice channel to play in").await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,12 +1,23 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
use crate::{Context, Error};
|
||||||
use serenity::framework::standard::CommandResult;
|
|
||||||
use serenity::model::prelude::*;
|
|
||||||
use serenity::prelude::*;
|
|
||||||
|
|
||||||
// use crate::commands::misc::check_msg;
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn skip(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
|
.await
|
||||||
|
.expect("Songbird 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();
|
||||||
|
|
||||||
|
ctx.say(format!("Song skipped: {} in queue.", queue.len())).await?;
|
||||||
|
} else {
|
||||||
|
ctx.say("Not in a voice channel to play in").await?;
|
||||||
|
}
|
||||||
|
|
||||||
#[command]
|
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn skip(_ctx: &Context, _msg: &Message) -> CommandResult {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1,39 +1,22 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
use crate::{Context, Error};
|
||||||
use serenity::framework::standard::CommandResult;
|
|
||||||
use serenity::model::prelude::*;
|
|
||||||
use serenity::prelude::*;
|
|
||||||
|
|
||||||
use crate::commands::misc::check_msg;
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn stop(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
#[command]
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn stop(ctx: &Context, msg: &Message) -> CommandResult {
|
|
||||||
let guild_id = msg.guild_id.unwrap();
|
|
||||||
|
|
||||||
let manager = songbird::get(ctx)
|
|
||||||
.await
|
.await
|
||||||
.expect("Client placed at init")
|
.expect("Songbird client placed at init")
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
if let Some(handler_lock) = manager.get(guild_id) {
|
if let Some(handler_lock) = manager.get(guild_id) {
|
||||||
let mut handler = handler_lock.lock().await;
|
let handler = handler_lock.lock().await;
|
||||||
let _queue = handler.queue();
|
let queue = handler.queue();
|
||||||
|
queue.stop();
|
||||||
|
|
||||||
if let Err(e) = handler.deafen(false).await {
|
ctx.say("Playback stopped!").await?;
|
||||||
check_msg(
|
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, format!("Failed: {:?}", e))
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Playback stopped!").await);
|
|
||||||
} else {
|
} else {
|
||||||
check_msg(
|
ctx.say("Not in a voice channel!").await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, "Not in a voice channel to undeafen in")
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
|
||||||
use serenity::framework::standard::CommandResult;
|
|
||||||
use serenity::model::prelude::*;
|
|
||||||
use serenity::prelude::*;
|
|
||||||
|
|
||||||
use crate::commands::misc::check_msg;
|
|
||||||
|
|
||||||
#[command]
|
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn undeafen(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 mut handler = handler_lock.lock().await;
|
|
||||||
if let Err(e) = handler.deafen(false).await {
|
|
||||||
check_msg(
|
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, format!("Failed: {:?}", e))
|
|
||||||
.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")
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
|
||||||
use serenity::framework::standard::CommandResult;
|
|
||||||
use serenity::model::prelude::*;
|
|
||||||
use serenity::prelude::*;
|
|
||||||
|
|
||||||
use crate::commands::misc::check_msg;
|
|
||||||
|
|
||||||
#[command]
|
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn unmute(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 mut handler = handler_lock.lock().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 {
|
|
||||||
check_msg(
|
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, "Not in a voice channel to unmute in")
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
5
src/commands/tools.rs
Normal file
5
src/commands/tools.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod ping;
|
||||||
|
pub mod register;
|
||||||
|
|
||||||
|
pub use ping::ping;
|
||||||
|
pub use register::register;
|
||||||
@@ -1 +0,0 @@
|
|||||||
pub mod ping;
|
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
|
use crate::{Context, Error};
|
||||||
use std::time::SystemTime;
|
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]
|
let response = format!("Pong! (latency: {} ms)", system_now - message_now);
|
||||||
async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
|
ctx.say(response).await?;
|
||||||
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);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
12
src/commands/tools/register.rs
Normal file
12
src/commands/tools/register.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use crate::{Context, Error};
|
||||||
|
|
||||||
|
#[poise::command(prefix_command, check = "check")]
|
||||||
|
pub async fn register(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
poise::builtins::register_application_commands_buttons(ctx).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn check(ctx: Context<'_>) -> Result<bool, Error> {
|
||||||
|
let owner = std::env::var("OWNER_ID").expect("Environment variable `OWNER_ID` not found");
|
||||||
|
Ok(ctx.author().id.to_string() == owner)
|
||||||
|
}
|
||||||
8
src/http.rs
Normal file
8
src/http.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
use reqwest::Client as HttpClient;
|
||||||
|
use poise::serenity_prelude::prelude::TypeMapKey;
|
||||||
|
|
||||||
|
pub struct HttpKey;
|
||||||
|
|
||||||
|
impl TypeMapKey for HttpKey {
|
||||||
|
type Value = HttpClient;
|
||||||
|
}
|
||||||
170
src/main.rs
170
src/main.rs
@@ -1,27 +1,18 @@
|
|||||||
use serenity::gateway::ActivityData;
|
|
||||||
use serenity::model::prelude::Message;
|
|
||||||
use songbird::SerenityInit;
|
use songbird::SerenityInit;
|
||||||
|
|
||||||
|
use poise::serenity_prelude::{self as serenity, ActivityData};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
use tracing::{info, warn, error};
|
||||||
use reqwest::Client as HttpClient;
|
use reqwest::Client as HttpClient;
|
||||||
|
|
||||||
use serenity::client::Context;
|
mod http;
|
||||||
|
|
||||||
use serenity::{
|
|
||||||
async_trait,
|
|
||||||
client::{Client, EventHandler},
|
|
||||||
framework::{
|
|
||||||
standard::{macros::group, macros::hook, Configuration},
|
|
||||||
StandardFramework,
|
|
||||||
},
|
|
||||||
model::gateway::Ready,
|
|
||||||
prelude::GatewayIntents,
|
|
||||||
};
|
|
||||||
|
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
|
|
||||||
// music management commands
|
// http typemap for handling requests
|
||||||
|
use crate::http::HttpKey;
|
||||||
|
|
||||||
|
// commands: music
|
||||||
use crate::commands::music::deafen::*;
|
use crate::commands::music::deafen::*;
|
||||||
use crate::commands::music::join::*;
|
use crate::commands::music::join::*;
|
||||||
use crate::commands::music::leave::*;
|
use crate::commands::music::leave::*;
|
||||||
@@ -30,59 +21,134 @@ use crate::commands::music::play::*;
|
|||||||
use crate::commands::music::queue::*;
|
use crate::commands::music::queue::*;
|
||||||
use crate::commands::music::skip::*;
|
use crate::commands::music::skip::*;
|
||||||
use crate::commands::music::stop::*;
|
use crate::commands::music::stop::*;
|
||||||
use crate::commands::music::undeafen::*;
|
use crate::commands::music::repeat::*;
|
||||||
use crate::commands::music::unmute::*;
|
use crate::commands::music::pause::*;
|
||||||
|
use crate::commands::music::resume::*;
|
||||||
|
|
||||||
// tools
|
// commands: tools
|
||||||
use crate::commands::tools::ping::*;
|
use crate::commands::tools::ping::*;
|
||||||
|
|
||||||
// kashi
|
// commands: kashi
|
||||||
use crate::commands::kashi::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]
|
pub struct Data;
|
||||||
impl EventHandler for Handler {
|
|
||||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
async fn on_error(error: poise::FrameworkError<'_, Data, Error>) {
|
||||||
info!("{} [{}] connected successfully!", ready.user.name, ready.user.id);
|
match error {
|
||||||
let prefix = std::env::var("PREFIX").expect("Environment variable `PREFIX` not found!");
|
poise::FrameworkError::Setup { error, .. } => panic!("Failed to start bot {:?}", error),
|
||||||
ctx.set_activity(Some(ActivityData::listening(prefix + "help")));
|
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]
|
// this is for debug only
|
||||||
async fn before(_: &Context, msg: &Message, command_name: &str) -> bool {
|
#[poise::command(prefix_command)]
|
||||||
info!(
|
pub async fn register(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
"Received command [{}] from user [{}]",
|
poise::builtins::register_application_commands_buttons(ctx).await?;
|
||||||
command_name, msg.author.name
|
Ok(())
|
||||||
);
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[group]
|
|
||||||
#[commands(
|
|
||||||
join, deafen, leave, mute, play, unmute, undeafen, ping, kashi, queue, stop, skip
|
|
||||||
)]
|
|
||||||
struct General;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
dotenv::dotenv().expect("Failed to load .env file.");
|
// logger and dotenv initialization
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
dotenv::dotenv().expect("Failed to load .env file.");
|
||||||
|
|
||||||
let token =
|
let token = std::env::var("DISCORD_TOKEN").expect("Environment variable `DISCORD_TOKEN` not found!");
|
||||||
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 prefix = std::env::var("PREFIX").expect("Environment variable `PREFIX` not found!");
|
||||||
|
|
||||||
let framework = StandardFramework::new().before(before).group(&GENERAL_GROUP);
|
let commands = vec![
|
||||||
framework.configure(Configuration::new().prefix(prefix));
|
// commands: music
|
||||||
|
deafen(),
|
||||||
|
join(),
|
||||||
|
leave(),
|
||||||
|
repeat(),
|
||||||
|
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)
|
.framework(framework)
|
||||||
.register_songbird()
|
.register_songbird()
|
||||||
.event_handler(Handler)
|
|
||||||
.type_map_insert::<HttpKey>(HttpClient::new())
|
.type_map_insert::<HttpKey>(HttpClient::new())
|
||||||
.await
|
.await
|
||||||
.expect("Error creating client");
|
.expect("Error creating client");
|
||||||
@@ -91,9 +157,9 @@ async fn main() {
|
|||||||
let _ = client
|
let _ = client
|
||||||
.start()
|
.start()
|
||||||
.await
|
.await
|
||||||
.map_err(|why| println!("Client ended: {:?}", why));
|
.map_err(|why| error!("Client ended: {:?}", why));
|
||||||
});
|
});
|
||||||
|
|
||||||
let _signal_err = tokio::signal::ctrl_c().await;
|
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