mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 20:36:10 +01:00
Compare commits
5 Commits
0.7.0
...
78a1937210
| Author | SHA1 | Date | |
|---|---|---|---|
|
78a1937210
|
|||
|
fc42427437
|
|||
|
9474577233
|
|||
|
b86e8b9daf
|
|||
|
ef29e5319a
|
1242
Cargo.lock
generated
1242
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
35
Cargo.toml
35
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lyra"
|
name = "lyra"
|
||||||
version = "0.7.0"
|
version = "0.8.2"
|
||||||
authors = ["Michał Czyż <mike@c2yz.com>"]
|
authors = ["Michał Czyż <mike@c2yz.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A featureful Discord bot written in Rust."
|
description = "A featureful Discord bot written in Rust."
|
||||||
@@ -15,18 +15,31 @@ keywords = ["discord", "bot", "rust", "music", "featureful"]
|
|||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
fancy-regex = "0.13.0"
|
fancy-regex = "0.13.0"
|
||||||
json = "0.12.4"
|
json = "0.12.4"
|
||||||
openssl = { version = "0.10.63", features = ["vendored"] }
|
openssl = { version = "0.10.66", features = ["vendored"] }
|
||||||
|
owoify = "0.1.5"
|
||||||
poise = "0.6.1"
|
poise = "0.6.1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
regex = "1.10.3"
|
regex = "1.10.6"
|
||||||
reqwest = { version = "0.11.23", features = ["json"]}
|
reqwest = { version = "0.11.27", features = ["json"] }
|
||||||
serde = { version = "1.0.197", features = ["derive"] }
|
serde = { version = "1.0.204", features = ["derive"] }
|
||||||
serde_json = "1.0.114"
|
serde_json = "1.0.122"
|
||||||
serenity = { version = "0.12.0", features = ["cache", "framework", "standard_framework", "voice"] }
|
serenity = { version = "0.12.2", features = [
|
||||||
songbird = { version = "0.4.0", features = ["builtin-queue", "serenity"] }
|
"cache",
|
||||||
symphonia = { version = "0.5.3", features = ["aac", "adpcm", "alac", "flac", "mpa", "isomp4"] }
|
"framework",
|
||||||
tokio = { version = "1.35.1", features = ["macros", "full", "signal"] }
|
"standard_framework",
|
||||||
|
"voice",
|
||||||
|
] }
|
||||||
|
songbird = { version = "0.4.3", features = ["builtin-queue", "serenity"] }
|
||||||
|
symphonia = { version = "0.5.4", features = [
|
||||||
|
"aac",
|
||||||
|
"adpcm",
|
||||||
|
"alac",
|
||||||
|
"flac",
|
||||||
|
"mpa",
|
||||||
|
"isomp4",
|
||||||
|
] }
|
||||||
|
tokio = { version = "1.39.2", 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"
|
||||||
url = "2.5.0"
|
url = "2.5.2"
|
||||||
|
|||||||
19
Dockerfile
19
Dockerfile
@@ -1,19 +0,0 @@
|
|||||||
FROM rust:1.71-alpine
|
|
||||||
|
|
||||||
RUN apk add --update \
|
|
||||||
alpine-sdk \
|
|
||||||
ffmpeg \
|
|
||||||
youtube-dl \
|
|
||||||
pkgconfig \
|
|
||||||
cmake \
|
|
||||||
openssl-dev \
|
|
||||||
musl-dev \
|
|
||||||
openssl
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
RUN cargo build --release
|
|
||||||
|
|
||||||
CMD ["./target/release/lyra"]
|
|
||||||
22
LICENSE.md
22
LICENSE.md
@@ -1,7 +1,21 @@
|
|||||||
# License
|
MIT License
|
||||||
|
|
||||||
Copyright (C) 2024 Michał Czyż
|
Copyright (c) 2024 Michał Czyż
|
||||||
|
|
||||||
All Rights Reserved.
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
This build is private and shall not be distributed nor modified without permission.
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|||||||
73
README.md
73
README.md
@@ -3,10 +3,79 @@
|
|||||||

|

|
||||||
|
|
||||||
Lyra is a music bot written in Rust.
|
Lyra is a music bot written in Rust.
|
||||||
More features coming soon!
|
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
## Building
|
Lyra is an open source, discord music bot written in Rust.
|
||||||
|
|
||||||
|
The idea behind this project is to allow a user to self-host one's own instance of the bot.
|
||||||
|
|
||||||
|
User no longer has to rely on 3rd parties to provide them an invite link.
|
||||||
|
|
||||||
|
The bot can be run even on a desktop or a phone because after compilation, it's just a simple binary.
|
||||||
|
|
||||||
|
As of now, the bot supports spotify url track recognition through a separate nodejs script. I plan to write the actual parser inside the bot iteself but as of now I postponed it into future release.
|
||||||
|
|
||||||
|
Slash commands are still work in progress! Currently bot is still heavily in development!
|
||||||
|
|
||||||
|
## Setting up
|
||||||
|
|
||||||
|
To compile the source code on your own, you need `rust` and `cargo`
|
||||||
|
|
||||||
|
To run a dev version use
|
||||||
|
```bash
|
||||||
|
$ cargo run
|
||||||
|
```
|
||||||
|
|
||||||
|
To build a production version use
|
||||||
|
```bash
|
||||||
|
$ cargo build --release
|
||||||
|
```
|
||||||
|
|
||||||
|
If you need an ARM version and just don't want to wait for ages for the program to compile, use
|
||||||
|
```bash
|
||||||
|
$ cross build -r --target aarch64-unknown-linux-gnu
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a program, just type
|
||||||
|
```bash
|
||||||
|
$ ./lyra
|
||||||
|
```
|
||||||
|
|
||||||
|
if you want to disown it from the shell, I recommend using the script I provided in `scripts` folder
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
|
As of now, working commands are:
|
||||||
|
|
||||||
|
```
|
||||||
|
Music:
|
||||||
|
/deafen Deafens itself while in a voice channel; aliases: deafen, undeaden, shuush
|
||||||
|
/join Joins your voice channel
|
||||||
|
/leave Leaves the voice channel; aliases: leave, qa!
|
||||||
|
/mute Mutes itself while in a voice channel; aliases: mute, unmute, shhh
|
||||||
|
/pause Pauses the currently playing song
|
||||||
|
/play Plays a song; you can search by query or paste an url; aliases: play, p, enqueue
|
||||||
|
/queue Shows next tracks in queue; aliases: queue, q
|
||||||
|
/repeat Loops currently playing song provided amount of times; aliases: repeat, loop, while, for
|
||||||
|
/resume Resumes currently paused song
|
||||||
|
/seek Seeks a track by provided seconds
|
||||||
|
/skip Skips the currently playing song
|
||||||
|
/stop Stops playback and destroys the queue; aliases: stop, end
|
||||||
|
/volume Changes output volume
|
||||||
|
/effect Plays one of available audio effects
|
||||||
|
/stream Hijacks output and plays audio; search by query or paste an url; aliases: stream, override, hijack
|
||||||
|
|
||||||
|
Tools:
|
||||||
|
/ai Asks AI
|
||||||
|
/dice Rolls a dice
|
||||||
|
/owoify Owoifies whatever you want uwu
|
||||||
|
/ping Pings you backs with a response time
|
||||||
|
/posix Prints current time in POSIX format
|
||||||
|
/qr Creates a qr code from text
|
||||||
|
/verse Reference Bible by verse
|
||||||
|
|
||||||
|
Help:
|
||||||
|
/help Prints this help message; aliases: help, huh, welp
|
||||||
|
|
||||||
|
```
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
version: '2'
|
|
||||||
|
|
||||||
services:
|
|
||||||
melvinjs:
|
|
||||||
container_name: lyra
|
|
||||||
build: .
|
|
||||||
@@ -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 &
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ pub mod queue;
|
|||||||
pub mod repeat;
|
pub mod repeat;
|
||||||
pub mod resume;
|
pub mod resume;
|
||||||
pub mod seek;
|
pub mod seek;
|
||||||
pub mod shuffle;
|
|
||||||
pub mod skip;
|
pub mod skip;
|
||||||
pub mod soundboard;
|
pub mod soundboard;
|
||||||
pub mod stop;
|
pub mod stop;
|
||||||
@@ -26,7 +25,6 @@ pub use queue::queue;
|
|||||||
pub use repeat::repeat;
|
pub use repeat::repeat;
|
||||||
pub use resume::resume;
|
pub use resume::resume;
|
||||||
pub use seek::seek;
|
pub use seek::seek;
|
||||||
pub use shuffle::shuffle;
|
|
||||||
pub use skip::skip;
|
pub use skip::skip;
|
||||||
pub use stop::stop;
|
pub use stop::stop;
|
||||||
pub use volume::volume;
|
pub use volume::volume;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ pub async fn resume(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
let _ = queue.resume();
|
let _ = queue.resume();
|
||||||
|
|
||||||
ctx.say(format!("Song resumed.")).await?;
|
|
||||||
ctx.send(
|
ctx.send(
|
||||||
CreateReply::default().embed(
|
CreateReply::default().embed(
|
||||||
embed(ctx, "Resumed!", "Currently paused song is now resumed!", "")
|
embed(ctx, "Resumed!", "Currently paused song is now resumed!", "")
|
||||||
|
|||||||
@@ -1,11 +1,51 @@
|
|||||||
use crate::{commands::embeds::embed, Context, Error};
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
/// Seeks a track by provided seconds
|
/// Seeks a track by provided seconds
|
||||||
#[poise::command(prefix_command, slash_command, category = "Music")]
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
pub async fn seek(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn seek(
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
ctx: Context<'_>,
|
||||||
|
#[description = "How many seconds shall I seek"] seek: u64,
|
||||||
|
) -> 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 seek_duration = Duration::from_secs(seek);
|
||||||
|
|
||||||
|
let track = queue.current().unwrap();
|
||||||
|
let _ = track.seek(seek_duration);
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
"Track seeked!",
|
||||||
|
&format!("Track seeked by: {} seconds", seek),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
} else {
|
||||||
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
use crate::{commands::embeds::embed, Context, Error};
|
|
||||||
use poise::CreateReply;
|
|
||||||
|
|
||||||
/// Shuffles the playlist
|
|
||||||
#[poise::command(prefix_command, slash_command, category = "Music")]
|
|
||||||
pub async fn shuffle(ctx: Context<'_>) -> Result<(), Error> {
|
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -12,8 +12,14 @@ use serenity::{
|
|||||||
};
|
};
|
||||||
use songbird::{input::AuxMetadata, tracks::TrackHandle};
|
use songbird::{input::AuxMetadata, tracks::TrackHandle};
|
||||||
|
|
||||||
/// Skips the currently playing song
|
/// Skips the currently playing song; \
|
||||||
#[poise::command(prefix_command, slash_command, category = "Music")]
|
/// aliases: skip, :skipper:
|
||||||
|
#[poise::command(
|
||||||
|
prefix_command,
|
||||||
|
slash_command,
|
||||||
|
aliases("skipper:"),
|
||||||
|
category = "Music"
|
||||||
|
)]
|
||||||
pub async fn skip(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn skip(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,117 @@
|
|||||||
use crate::{commands::embeds::embed, Context, Error};
|
use crate::{commands::embeds::error_embed, Context, Error};
|
||||||
|
|
||||||
|
use poise::serenity_prelude::model::Timestamp;
|
||||||
|
use poise::serenity_prelude::Colour;
|
||||||
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
use serenity::builder::CreateEmbedAuthor;
|
||||||
|
use serenity::builder::CreateEmbedFooter;
|
||||||
|
use songbird::events::TrackEvent;
|
||||||
|
use songbird::input::AuxMetadata;
|
||||||
|
use songbird::input::{Compose, YoutubeDl};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use crate::commands::music::notifier::TrackErrorNotifier;
|
||||||
|
use crate::http::HttpKey;
|
||||||
|
|
||||||
/// Plays one of available audio effects
|
/// Plays one of available audio effects
|
||||||
#[poise::command(prefix_command, slash_command, category = "Music")]
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
pub async fn effect(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn effect(
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "Playing an effect", "", "").await.unwrap()))
|
ctx: Context<'_>,
|
||||||
.await?;
|
#[description = "Shall output pause?"]
|
||||||
|
#[flag]
|
||||||
|
pause: bool,
|
||||||
|
#[description = "Provide a query or an url"]
|
||||||
|
#[rest]
|
||||||
|
mut song: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let is_query = !song.starts_with("http");
|
||||||
|
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
|
let http_client = {
|
||||||
|
let data = ctx.serenity_context().data.read().await;
|
||||||
|
data.get::<HttpKey>()
|
||||||
|
.cloned()
|
||||||
|
.expect("Guaranteed to exist in the typemap.")
|
||||||
|
};
|
||||||
|
|
||||||
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
|
.await
|
||||||
|
.expect("Songbird Voice placed at init")
|
||||||
|
.clone();
|
||||||
|
|
||||||
|
if pause {
|
||||||
|
if let Some(handler_lock) = manager.get(guild_id) {
|
||||||
|
let handler = handler_lock.lock().await;
|
||||||
|
let queue = handler.queue();
|
||||||
|
let _ = queue.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(handler_lock) = manager.get(guild_id) {
|
||||||
|
let mut handler = handler_lock.lock().await;
|
||||||
|
|
||||||
|
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||||
|
|
||||||
|
if is_query {
|
||||||
|
song = format!("ytsearch:{}", song);
|
||||||
|
}
|
||||||
|
|
||||||
|
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client, song);
|
||||||
|
let embed = generate_embed(ctx, src.clone()).await;
|
||||||
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
|
ctx.send(response).await?;
|
||||||
|
|
||||||
|
let _ = handler.play_input(src.clone().into());
|
||||||
|
} else {
|
||||||
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.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 description = format!("Playing now!");
|
||||||
|
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(CreateEmbedAuthor::new("Playing an effect!").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,11 +1,126 @@
|
|||||||
use crate::{commands::embeds::embed, Context, Error};
|
use crate::{commands::embeds::error_embed, Context, Error};
|
||||||
use poise::CreateReply;
|
|
||||||
|
|
||||||
/// Hijacks current audio output and plays selected audio
|
use poise::serenity_prelude::model::Timestamp;
|
||||||
#[poise::command(prefix_command, slash_command, aliases("override"), category = "Music")]
|
use poise::serenity_prelude::Colour;
|
||||||
pub async fn stream(ctx: Context<'_>) -> Result<(), Error> {
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "Playing audio", "", "").await.unwrap()))
|
use poise::CreateReply;
|
||||||
.await?;
|
use serenity::builder::CreateEmbedAuthor;
|
||||||
|
use serenity::builder::CreateEmbedFooter;
|
||||||
|
use songbird::events::TrackEvent;
|
||||||
|
use songbird::input::AuxMetadata;
|
||||||
|
use songbird::input::{Compose, YoutubeDl};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use crate::commands::music::notifier::TrackErrorNotifier;
|
||||||
|
use crate::http::HttpKey;
|
||||||
|
|
||||||
|
/// Hijacks output and plays audio; \
|
||||||
|
/// search by query or paste an url; \
|
||||||
|
/// aliases: stream, override, hijack
|
||||||
|
#[poise::command(
|
||||||
|
prefix_command,
|
||||||
|
slash_command,
|
||||||
|
aliases("override", "hijack"),
|
||||||
|
category = "Music"
|
||||||
|
)]
|
||||||
|
pub async fn stream(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Shall output pause?"]
|
||||||
|
#[flag]
|
||||||
|
pause: bool,
|
||||||
|
#[description = "Provide a query or an url"]
|
||||||
|
#[rest]
|
||||||
|
mut song: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let is_query = !song.starts_with("http");
|
||||||
|
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
|
let http_client = {
|
||||||
|
let data = ctx.serenity_context().data.read().await;
|
||||||
|
data.get::<HttpKey>()
|
||||||
|
.cloned()
|
||||||
|
.expect("Guaranteed to exist in the typemap.")
|
||||||
|
};
|
||||||
|
|
||||||
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
|
.await
|
||||||
|
.expect("Songbird Voice placed at init")
|
||||||
|
.clone();
|
||||||
|
|
||||||
|
if pause {
|
||||||
|
if let Some(handler_lock) = manager.get(guild_id) {
|
||||||
|
let handler = handler_lock.lock().await;
|
||||||
|
let queue = handler.queue();
|
||||||
|
let _ = queue.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(handler_lock) = manager.get(guild_id) {
|
||||||
|
let mut handler = handler_lock.lock().await;
|
||||||
|
|
||||||
|
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||||
|
|
||||||
|
if is_query {
|
||||||
|
song = format!("ytsearch:{}", song);
|
||||||
|
}
|
||||||
|
|
||||||
|
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client, song);
|
||||||
|
let embed = generate_embed(ctx, src.clone()).await;
|
||||||
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
|
ctx.send(response).await?;
|
||||||
|
|
||||||
|
let _ = handler.play_input(src.clone().into());
|
||||||
|
} else {
|
||||||
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.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 description = format!("Playing now!");
|
||||||
|
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(
|
||||||
|
CreateEmbedAuthor::new("Audio output hijacked!").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,11 +1,44 @@
|
|||||||
use crate::{commands::embeds::embed, Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
/// Changes output volume
|
/// Changes output volume
|
||||||
#[poise::command(prefix_command, slash_command, category = "Music")]
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
pub async fn volume(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn volume(ctx: Context<'_>, #[description = "Volume"] volume: f32) -> Result<(), Error> {
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
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();
|
||||||
|
let _ = track.set_volume(volume / 100.0);
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
"Volume changed",
|
||||||
|
"",
|
||||||
|
&format!("Set volume to {}%", volume),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
} else {
|
||||||
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,72 @@
|
|||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use url::form_urlencoded;
|
||||||
|
|
||||||
use crate::{commands::embeds::embed, Context, Error};
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
/// Explains provided query
|
/// Explains provided query
|
||||||
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
#[poise::command(prefix_command, slash_command, aliases("dict"), category = "Tools")]
|
||||||
pub async fn dictionary(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn dictionary(
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
ctx: Context<'_>,
|
||||||
.await?;
|
#[description = "Word you're looking for"]
|
||||||
|
#[rest]
|
||||||
|
word: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let data: String = form_urlencoded::byte_serialize(word.as_bytes()).collect();
|
||||||
|
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let response = client
|
||||||
|
.get(format!(
|
||||||
|
"https://api.dictionaryapi.dev/api/v2/entries/en/{}",
|
||||||
|
data
|
||||||
|
))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
match response.status() {
|
||||||
|
reqwest::StatusCode::OK => match response.json::<Vec<Word>>().await {
|
||||||
|
Ok(parsed) => {
|
||||||
|
println!("{:?}", parsed);
|
||||||
|
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
Err(err) => println!("Something is messed up! {:?}", err),
|
||||||
|
},
|
||||||
|
reqwest::StatusCode::UNAUTHORIZED => {
|
||||||
|
println!("Unauthorized.. Uoops!!");
|
||||||
|
}
|
||||||
|
error => {
|
||||||
|
println!("Something went wrong: {:?}", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
struct Definition {
|
||||||
|
definition: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
struct Meaning {
|
||||||
|
partOfSpeech: String,
|
||||||
|
definitions: Vec<Definition>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
struct Phonetic {
|
||||||
|
text: Option<String>,
|
||||||
|
audio: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
struct Word {
|
||||||
|
word: String,
|
||||||
|
phonetics: Vec<Phonetic>,
|
||||||
|
meanings: Vec<Meaning>,
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
|
use owoify::OwOifiable;
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
use crate::{commands::embeds::embed, Context, Error};
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
/// Owoifies whatever you want uwu
|
/// Owoifies whatever you want uwu
|
||||||
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
pub async fn owoify(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn owoify(
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
ctx: Context<'_>,
|
||||||
|
#[description = "Text to owoify w-woify OwO"]
|
||||||
|
#[rest]
|
||||||
|
text: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "OwO", &text.owoify(), "").await.unwrap()))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ async fn main() {
|
|||||||
music::repeat(),
|
music::repeat(),
|
||||||
music::resume(),
|
music::resume(),
|
||||||
music::seek(),
|
music::seek(),
|
||||||
music::shuffle(),
|
|
||||||
music::skip(),
|
music::skip(),
|
||||||
music::stop(),
|
music::stop(),
|
||||||
music::volume(),
|
music::volume(),
|
||||||
|
|||||||
Reference in New Issue
Block a user