mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 12:26:10 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
a27e95a88d
|
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -933,7 +933,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lyra"
|
name = "lyra"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"openssl",
|
"openssl",
|
||||||
@@ -2338,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",
|
||||||
|
|||||||
12
Cargo.toml
12
Cargo.toml
@@ -1,7 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lyra"
|
name = "lyra"
|
||||||
version = "0.3.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"
|
||||||
@@ -12,7 +20,7 @@ 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.
|
||||||
|
|||||||
0
scripts/cross-build.sh
Normal file → Executable file
0
scripts/cross-build.sh
Normal file → Executable file
2
scripts/launch.sh
Normal file → Executable file
2
scripts/launch.sh
Normal file → Executable file
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
nohup ./lyra > lyra.log 2> lyra.err < /dev/null &
|
nohup ../lyra > lyra.log 2> lyra.err < /dev/null &
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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(());
|
||||||
}
|
}
|
||||||
@@ -28,24 +22,16 @@ async fn deafen(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
|
|
||||||
if handler.is_deaf() {
|
if handler.is_deaf() {
|
||||||
if let Err(err) = handler.deafen(false).await {
|
if let Err(err) = handler.deafen(false).await {
|
||||||
check_msg(
|
ctx.say(format!("Failed: {:?}", err)).await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, format!("Failed: {:?}", err))
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Undeafened").await);
|
ctx.say("Undeafened").await?;
|
||||||
} else {
|
} else {
|
||||||
if let Err(err) = handler.deafen(true).await {
|
if let Err(err) = handler.deafen(true).await {
|
||||||
check_msg(
|
ctx.say(format!("Failed: {:?}", err)).await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, format!("Failed: {:?}", err))
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Deafened").await);
|
ctx.say("Deafened").await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,29 +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 = 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 {
|
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 {
|
||||||
@@ -31,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,83 +0,0 @@
|
|||||||
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,6 +7,6 @@ pub mod play;
|
|||||||
pub mod queue;
|
pub mod queue;
|
||||||
pub mod skip;
|
pub mod skip;
|
||||||
pub mod stop;
|
pub mod stop;
|
||||||
pub mod loopcurrent;
|
pub mod repeat;
|
||||||
pub mod pause;
|
pub mod pause;
|
||||||
pub mod resume;
|
pub mod resume;
|
||||||
|
|||||||
@@ -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(());
|
||||||
}
|
}
|
||||||
@@ -28,24 +22,16 @@ async fn mute(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
|
|
||||||
if handler.is_mute() {
|
if handler.is_mute() {
|
||||||
if let Err(e) = handler.mute(false).await {
|
if let Err(e) = handler.mute(false).await {
|
||||||
check_msg(
|
ctx.say(format!("failed: {:?}", e)).await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, format!("failed: {:?}", e))
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Unmuted").await);
|
ctx.say("Unmuted").await?;
|
||||||
} else {
|
} else {
|
||||||
if let Err(err) = handler.mute(true).await {
|
if let Err(err) = handler.mute(true).await {
|
||||||
check_msg(
|
ctx.say(format!("Failed: {:?}", err)).await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, format!("Failed: {:?}", err))
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Muted").await);
|
ctx.say("Muted").await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
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 pause(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
#[command]
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn pause(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) {
|
||||||
@@ -20,20 +14,9 @@ async fn pause(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
let _ = queue.pause();
|
let _ = queue.pause();
|
||||||
|
|
||||||
check_msg(
|
ctx.say(format!("Song paused.")).await?;
|
||||||
msg.channel_id
|
|
||||||
.say(
|
|
||||||
&ctx.http,
|
|
||||||
format!("Song paused."),
|
|
||||||
)
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
check_msg(
|
ctx.say("Not in a voice channel to play in").await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, "Not in a voice channel to play in")
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,58 +1,35 @@
|
|||||||
use serenity::framework::standard::macros::command;
|
use crate::{Context, Error};
|
||||||
use serenity::framework::standard::{Args, CommandResult};
|
|
||||||
use serenity::model::prelude::*;
|
|
||||||
use serenity::prelude::*;
|
|
||||||
use reqwest::Client as HttpClient;
|
|
||||||
use songbird::input::{Compose, YoutubeDl};
|
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;
|
|
||||||
|
|
||||||
impl TypeMapKey for HttpKey {
|
|
||||||
type Value = HttpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[command]
|
|
||||||
#[aliases(p)]
|
|
||||||
#[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(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
#[poise::command(prefix_command, slash_command)]
|
||||||
|
pub async fn play(ctx: Context<'_>, url: String) -> Result<(), Error> {
|
||||||
let is_search = !url.starts_with("http");
|
let is_search = !url.starts_with("http");
|
||||||
|
|
||||||
let guild_id = msg.guild_id.unwrap();
|
let guild_id = ctx.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 channel_id = ctx.guild().unwrap().voice_states.get(&ctx.author().id).and_then(|voice_state| voice_state.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();
|
||||||
@@ -65,22 +42,18 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
|||||||
|
|
||||||
let mut src = if is_search {
|
let mut src = if is_search {
|
||||||
println!("ytsearch:{}", url);
|
println!("ytsearch:{}", url);
|
||||||
YoutubeDl::new_ytdl_like("yt-dlp", http_client, format!("ytsearch:{}", args.clone().message()))
|
YoutubeDl::new_ytdl_like("yt-dlp", http_client, format!("ytsearch:{}", url))
|
||||||
} else {
|
} else {
|
||||||
YoutubeDl::new_ytdl_like("yt-dlp", http_client, url)
|
YoutubeDl::new_ytdl_like("yt-dlp", http_client, url)
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = handler.enqueue_input(src.clone().into()).await;
|
let _ = handler.enqueue_input(src.clone().into()).await;
|
||||||
|
|
||||||
let metadata = src.aux_metadata().await.unwrap();
|
let _metadata = src.aux_metadata().await.unwrap();
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, format!("Playing song: {}", metadata.title.unwrap())).await);
|
// ctx.say(format!("Playing song: {}", metadata.title.unwrap())).await?;
|
||||||
} else {
|
} else {
|
||||||
check_msg(
|
ctx.say("Not in a voice channel to play in").await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, "Not in a voice channel to play in")
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
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();
|
||||||
|
|
||||||
#[command]
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn queue(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) {
|
||||||
@@ -30,18 +24,10 @@ async fn queue(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
check_msg(
|
ctx.say(queue_res).await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, queue_res)
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
check_msg(
|
ctx.say("Not in a voice channel!").await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, "Not in a voice channel!")
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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(())
|
||||||
|
}
|
||||||
@@ -1,18 +1,12 @@
|
|||||||
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 resume(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
#[command]
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn resume(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) {
|
||||||
@@ -20,20 +14,9 @@ async fn resume(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
let _ = queue.resume();
|
let _ = queue.resume();
|
||||||
|
|
||||||
check_msg(
|
ctx.say(format!("Song resumed.")).await?;
|
||||||
msg.channel_id
|
|
||||||
.say(
|
|
||||||
&ctx.http,
|
|
||||||
format!("Song resumed."),
|
|
||||||
)
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
check_msg(
|
ctx.say("Not in a voice channel to play in").await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, "Not in a voice channel to play in")
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
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();
|
||||||
|
|
||||||
#[command]
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
#[only_in(guilds)]
|
|
||||||
async fn skip(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) {
|
||||||
@@ -20,20 +14,9 @@ async fn skip(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
let _ = queue.skip();
|
let _ = queue.skip();
|
||||||
|
|
||||||
check_msg(
|
ctx.say(format!("Song skipped: {} in queue.", queue.len())).await?;
|
||||||
msg.channel_id
|
|
||||||
.say(
|
|
||||||
&ctx.http,
|
|
||||||
format!("Song skipped: {} in queue.", queue.len()),
|
|
||||||
)
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
check_msg(
|
ctx.say("Not in a voice channel to play in").await?;
|
||||||
msg.channel_id
|
|
||||||
.say(&ctx.http, "Not in a voice channel to play in")
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
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) {
|
||||||
@@ -20,13 +14,9 @@ async fn stop(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
queue.stop();
|
queue.stop();
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Playback stopped!").await);
|
ctx.say("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!")
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
10
src/main.rs
10
src/main.rs
@@ -4,9 +4,14 @@ use poise::serenity_prelude::{self as serenity, ActivityData};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing::{info, warn, error};
|
use tracing::{info, warn, error};
|
||||||
|
use reqwest::Client as HttpClient;
|
||||||
|
|
||||||
|
mod http;
|
||||||
mod commands;
|
mod commands;
|
||||||
|
|
||||||
|
// http typemap for handling requests
|
||||||
|
use crate::http::HttpKey;
|
||||||
|
|
||||||
// commands: music
|
// commands: music
|
||||||
use crate::commands::music::deafen::*;
|
use crate::commands::music::deafen::*;
|
||||||
use crate::commands::music::join::*;
|
use crate::commands::music::join::*;
|
||||||
@@ -16,7 +21,7 @@ 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::loopcurrent::*;
|
use crate::commands::music::repeat::*;
|
||||||
use crate::commands::music::pause::*;
|
use crate::commands::music::pause::*;
|
||||||
use crate::commands::music::resume::*;
|
use crate::commands::music::resume::*;
|
||||||
|
|
||||||
@@ -66,7 +71,7 @@ async fn main() {
|
|||||||
deafen(),
|
deafen(),
|
||||||
join(),
|
join(),
|
||||||
leave(),
|
leave(),
|
||||||
loopcurrent(),
|
repeat(),
|
||||||
mute(),
|
mute(),
|
||||||
pause(),
|
pause(),
|
||||||
play(),
|
play(),
|
||||||
@@ -144,6 +149,7 @@ async fn main() {
|
|||||||
let mut client = serenity::ClientBuilder::new(token, intents)
|
let mut client = serenity::ClientBuilder::new(token, intents)
|
||||||
.framework(framework)
|
.framework(framework)
|
||||||
.register_songbird()
|
.register_songbird()
|
||||||
|
.type_map_insert::<HttpKey>(HttpClient::new())
|
||||||
.await
|
.await
|
||||||
.expect("Error creating client");
|
.expect("Error creating client");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user