mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 12:26:10 +01:00
Compare commits
13 Commits
0.5.0
...
8a0d08de4e
| Author | SHA1 | Date | |
|---|---|---|---|
|
8a0d08de4e
|
|||
|
f224ccfbdf
|
|||
|
d0af34833b
|
|||
|
c2e653b3ea
|
|||
|
78a1937210
|
|||
|
fc42427437
|
|||
|
9474577233
|
|||
|
b86e8b9daf
|
|||
|
ef29e5319a
|
|||
|
ee3d9a0c45
|
|||
|
4e92771f8f
|
|||
|
8a947926f7
|
|||
|
639fd7775f
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
|
**/target
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
|||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "libs/songbird"]
|
||||||
|
path = libs/songbird
|
||||||
|
url = git@github.com:eRgo35/songbird.git
|
||||||
1943
Cargo.lock
generated
1943
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
42
Cargo.toml
42
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lyra"
|
name = "lyra"
|
||||||
version = "0.5.0"
|
version = "0.9.0"
|
||||||
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."
|
||||||
@@ -10,18 +10,42 @@ homepage = "https://lyra.c2yz.com"
|
|||||||
license-file = "LICENSE.md"
|
license-file = "LICENSE.md"
|
||||||
keywords = ["discord", "bot", "rust", "music", "featureful"]
|
keywords = ["discord", "bot", "rust", "music", "featureful"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
lib-spotify-parser = { path = "libs/spotify-parser" }
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
fancy-regex = "0.13.0"
|
fancy-regex = "0.13.0"
|
||||||
openssl = { version = "0.10.63", features = ["vendored"] }
|
json = "0.12.4"
|
||||||
|
openssl = { version = "0.10.66", features = ["vendored"] }
|
||||||
|
owoify = "0.1.5"
|
||||||
poise = "0.6.1"
|
poise = "0.6.1"
|
||||||
regex = "1.10.3"
|
rand = "0.8.5"
|
||||||
reqwest = "0.11.23"
|
regex = "1.10.6"
|
||||||
serenity = { version = "0.12.0", features = ["cache", "framework", "standard_framework", "voice"] }
|
reqwest = { version = "0.11.27", features = ["json"] }
|
||||||
songbird = { version = "0.4.0", features = ["builtin-queue", "serenity"] }
|
serde = { version = "1.0.204", features = ["derive"] }
|
||||||
symphonia = { version = "0.5.3", features = ["aac", "adpcm", "alac", "flac", "mpa", "isomp4"] }
|
serde_json = "1.0.122"
|
||||||
tokio = { version = "1.35.1", features = ["macros", "full", "signal"] }
|
songbird = { path = "./libs/songbird", version = "0.4", default-features = true, features = [
|
||||||
|
"builtin-queue",
|
||||||
|
] }
|
||||||
|
serenity = { features = [
|
||||||
|
"cache",
|
||||||
|
"framework",
|
||||||
|
"standard_framework",
|
||||||
|
"voice",
|
||||||
|
"http",
|
||||||
|
"rustls_backend",
|
||||||
|
], version = "0.12" }
|
||||||
|
|
||||||
|
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.2"
|
||||||
|
once_cell = "1.19.0"
|
||||||
|
|||||||
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
|
||||||
|
|
||||||
|
```
|
||||||
|
|||||||
BIN
assets/lyra-nightly.png
Normal file
BIN
assets/lyra-nightly.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 291 KiB |
@@ -1,6 +0,0 @@
|
|||||||
version: '2'
|
|
||||||
|
|
||||||
services:
|
|
||||||
melvinjs:
|
|
||||||
container_name: lyra
|
|
||||||
build: .
|
|
||||||
1
libs/songbird
Submodule
1
libs/songbird
Submodule
Submodule libs/songbird added at 52ccf8b328
1906
libs/spotify-parser/Cargo.lock
generated
Normal file
1906
libs/spotify-parser/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
libs/spotify-parser/Cargo.toml
Normal file
12
libs/spotify-parser/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "lib-spotify-parser"
|
||||||
|
version = "1.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
regex = "1.10.6"
|
||||||
|
reqwest = { version = "0.12.5", features = ["blocking", "rustls-tls"] }
|
||||||
|
scraper = "0.19.1"
|
||||||
|
serde = "1.0.204"
|
||||||
|
serde_json = "1.0.122"
|
||||||
|
tokio = { version = "1.39.2", features = ["macros"] }
|
||||||
14
libs/spotify-parser/src/error.rs
Normal file
14
libs/spotify-parser/src/error.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum ParseError {
|
||||||
|
InvalidUrl,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ParseError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "Invalid URL")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for ParseError {}
|
||||||
154
libs/spotify-parser/src/lib.rs
Normal file
154
libs/spotify-parser/src/lib.rs
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
mod error;
|
||||||
|
mod parser;
|
||||||
|
mod retriever;
|
||||||
|
|
||||||
|
use error::ParseError;
|
||||||
|
use parser::{parse_list, parse_single, USER_AGENT};
|
||||||
|
use regex::Regex;
|
||||||
|
use reqwest;
|
||||||
|
use retriever::{retrieve_async_track, retrieve_async_tracks, retrieve_track, retrieve_tracks};
|
||||||
|
|
||||||
|
pub fn retrieve_url(url: &str) -> Result<Vec<String>, ParseError> {
|
||||||
|
let spotify_regex: Regex = Regex::new(r"https?:\/\/(?:embed\.|open\.)spotify\.com\/(track|album|playlist)\/([a-zA-Z0-9]+)(?:\?si=[\w-]+)?").unwrap();
|
||||||
|
|
||||||
|
if let Some(captures) = spotify_regex.captures(url) {
|
||||||
|
let category = captures.get(1).unwrap().as_str();
|
||||||
|
let id = captures.get(2).unwrap().as_str();
|
||||||
|
|
||||||
|
match category {
|
||||||
|
"track" => {
|
||||||
|
let track = retrieve_track(category, id).unwrap();
|
||||||
|
Ok(vec![track])
|
||||||
|
}
|
||||||
|
"playlist" | "album" => {
|
||||||
|
let tracks = retrieve_tracks(category, id).unwrap();
|
||||||
|
Ok(tracks)
|
||||||
|
}
|
||||||
|
_ => Err(ParseError::InvalidUrl),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(ParseError::InvalidUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn retrieve_async_url(url: &str) -> Result<Vec<String>, ParseError> {
|
||||||
|
let spotify_regex: Regex = Regex::new(r"https?:\/\/(?:embed\.|open\.)spotify\.com\/(track|album|playlist)\/([a-zA-Z0-9]+)(?:\?si=[\w-]+)?").unwrap();
|
||||||
|
|
||||||
|
if let Some(captures) = spotify_regex.captures(url) {
|
||||||
|
let category = captures.get(1).unwrap().as_str();
|
||||||
|
let id = captures.get(2).unwrap().as_str();
|
||||||
|
|
||||||
|
match category {
|
||||||
|
"track" => {
|
||||||
|
let track = retrieve_async_track(category, id).await.unwrap();
|
||||||
|
Ok(vec![track])
|
||||||
|
}
|
||||||
|
"playlist" | "album" => {
|
||||||
|
let tracks = retrieve_async_tracks(category, id).await.unwrap();
|
||||||
|
Ok(tracks)
|
||||||
|
}
|
||||||
|
_ => Err(ParseError::InvalidUrl),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(ParseError::InvalidUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
const TRACK: &str = "https://open.spotify.com/track/4PTG3Z6ehGkBFwjybzWkR8?si=e0a8c8ada8284e43";
|
||||||
|
const MULTIPLE_ARTISTS_TRACK: &str =
|
||||||
|
"https://open.spotify.com/track/1O0SdrryPeGp6eSSUibdgo?si=4ae58febe9e74eae";
|
||||||
|
const PLAYLIST: &str =
|
||||||
|
"https://open.spotify.com/playlist/37i9dQZF1DZ06evO05tE88?si=e0c6f44d176f44e6";
|
||||||
|
const ALBUM: &str =
|
||||||
|
"https://open.spotify.com/album/6eUW0wxWtzkFdaEFsTJto6?si=_grLtlNySNyfJTZr8tP44Q";
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_track() {
|
||||||
|
let track: Vec<&str> = vec!["Rick Astley - Never Gonna Give You Up"];
|
||||||
|
assert_eq!(retrieve_url(TRACK).unwrap(), track);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_multiple_artists_track() {
|
||||||
|
let track: Vec<&str> = vec!["Will o' the wisp, Rick Astley - Blood on My Tie"];
|
||||||
|
assert_eq!(retrieve_url(MULTIPLE_ARTISTS_TRACK).unwrap(), track);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_playlist() {
|
||||||
|
let playlist: Vec<&str> = vec![
|
||||||
|
"Rick Astley - Never Gonna Give You Up",
|
||||||
|
"Rick Astley - Take Me to Your Heart (2023 Remaster)",
|
||||||
|
"Rick Astley - Cry for Help - Single Edit",
|
||||||
|
"Rick Astley - Never Gonna Stop",
|
||||||
|
"Rick Astley - Together Forever",
|
||||||
|
"Rick Astley - Hold Me in Your Arms (7\" Version)",
|
||||||
|
"Rick Astley - Angels on My Side",
|
||||||
|
"New Kids On The Block, Salt-N-Pepa, Rick Astley, En Vogue - Bring Back The Time",
|
||||||
|
"Rick Astley - Whenever You Need Somebody",
|
||||||
|
"Rick Astley - She Wants to Dance with Me (2023 Remaster)",
|
||||||
|
"Rick Astley - Dippin My Feet",
|
||||||
|
"Rick Astley - My Arms Keep Missing You",
|
||||||
|
"Rick Astley - Don't Say Goodbye",
|
||||||
|
"Rick Astley - Dance",
|
||||||
|
"Rick Astley - Giving Up On Love (7'' Pop Version)",
|
||||||
|
"Rick Astley - Never Gonna Give You Up (Cake Mix)",
|
||||||
|
"Rick Astley - It Would Take a Strong Strong Man",
|
||||||
|
"Rick Astley - Driving Me Crazy",
|
||||||
|
"Rick Astley - Beautiful Life",
|
||||||
|
"Rick Astley - I Don't Want to Lose Her",
|
||||||
|
"Rick Astley - Keep Singing",
|
||||||
|
"Rick Astley - Forever and More",
|
||||||
|
"Rick Astley - Hopelessly",
|
||||||
|
"Rick Astley - When I Fall in Love",
|
||||||
|
"Rick Astley - Every One of Us",
|
||||||
|
"Rick Astley - High Enough",
|
||||||
|
"Rick Astley - Ain't Too Proud to Beg (2023 Remaster)",
|
||||||
|
"Rick Astley - I'll Never Let You Down",
|
||||||
|
"Trevor Horn, Rick Astley - Owner Of A Lonely Heart",
|
||||||
|
"Rick Astley - Letting Go",
|
||||||
|
"Rick Astley - Never Knew Love",
|
||||||
|
"Rick Astley - Lights Out - Radio Edit",
|
||||||
|
"Rick Astley - Try",
|
||||||
|
"Rick Astley - Dial My Number (2023 Remaster)",
|
||||||
|
"Rick Astley - Wish Away",
|
||||||
|
"Rick Astley - Giant",
|
||||||
|
"Rick Astley - Move Right Out",
|
||||||
|
"Rick Astley - Till Then (Time Stands Still) (2023 Remaster)",
|
||||||
|
"Rick Astley - Pray with Me",
|
||||||
|
"Rick Astley - I Don't Want to Be Your Lover",
|
||||||
|
"Will o' the wisp, Rick Astley - Blood on My Tie",
|
||||||
|
"Rick Astley - Can't Help Falling in Love",
|
||||||
|
"Rick Astley - I Like the Sun",
|
||||||
|
"Rick Astley - She Makes Me",
|
||||||
|
"Rick Astley - Body and Soul",
|
||||||
|
"Rick Astley - (They Long to Be) Close to You",
|
||||||
|
"Rick Astley - Unwanted (Official Song from the Podcast)",
|
||||||
|
"Rick Astley - Last Night on Earth",
|
||||||
|
"Rick Astley - Everlong - Acoustic Version",
|
||||||
|
"Rick Astley - Superman",
|
||||||
|
];
|
||||||
|
assert_eq!(retrieve_url(PLAYLIST).unwrap(), playlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_album() {
|
||||||
|
let album: Vec<&str> = vec![
|
||||||
|
"Rick Astley - Never Gonna Give You Up",
|
||||||
|
"Rick Astley - Whenever You Need Somebody",
|
||||||
|
"Rick Astley - Together Forever",
|
||||||
|
"Rick Astley - It Would Take a Strong Strong Man",
|
||||||
|
"Rick Astley - The Love Has Gone",
|
||||||
|
"Rick Astley - Don't Say Goodbye",
|
||||||
|
"Rick Astley - Slipping Away",
|
||||||
|
"Rick Astley - No More Looking for Love",
|
||||||
|
"Rick Astley - You Move Me",
|
||||||
|
"Rick Astley - When I Fall in Love",
|
||||||
|
];
|
||||||
|
assert_eq!(retrieve_url(ALBUM).unwrap(), album);
|
||||||
|
}
|
||||||
|
}
|
||||||
70
libs/spotify-parser/src/parser.rs
Normal file
70
libs/spotify-parser/src/parser.rs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
use scraper::{Html, Selector};
|
||||||
|
use serde_json::Value;
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub(crate) struct SpotifyTrack {
|
||||||
|
pub title: String,
|
||||||
|
pub artist: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36";
|
||||||
|
|
||||||
|
pub(crate) fn parse_single(content: String) -> Result<SpotifyTrack, Box<dyn Error>> {
|
||||||
|
let document = Html::parse_document(&content);
|
||||||
|
let selector = Selector::parse("#__NEXT_DATA__").unwrap();
|
||||||
|
|
||||||
|
if let Some(script_element) = document.select(&selector).next() {
|
||||||
|
let json_str = script_element.inner_html();
|
||||||
|
let json_value: Value = serde_json::from_str(&json_str)?;
|
||||||
|
let metadata = &json_value["props"]["pageProps"]["state"]["data"]["entity"];
|
||||||
|
|
||||||
|
// println!("{metadata:?}");
|
||||||
|
|
||||||
|
let title = metadata["title"].as_str().unwrap().to_string();
|
||||||
|
|
||||||
|
let artists = metadata["artists"].as_array().unwrap();
|
||||||
|
let artists_list: Vec<String> = artists
|
||||||
|
.iter()
|
||||||
|
.map(|artist| artist["name"].as_str().unwrap().to_string())
|
||||||
|
.collect();
|
||||||
|
let artist: String = artists_list.join(", ").to_string();
|
||||||
|
|
||||||
|
let track = SpotifyTrack { title, artist };
|
||||||
|
|
||||||
|
Ok(track)
|
||||||
|
} else {
|
||||||
|
Err("Could not find element".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn parse_list(content: String) -> Result<Vec<SpotifyTrack>, Box<dyn Error>> {
|
||||||
|
let document = Html::parse_document(&content);
|
||||||
|
let selector = Selector::parse("#__NEXT_DATA__").unwrap();
|
||||||
|
|
||||||
|
if let Some(script_element) = document.select(&selector).next() {
|
||||||
|
let json_str = script_element.inner_html();
|
||||||
|
let json_value: Value = serde_json::from_str(&json_str)?;
|
||||||
|
let metadata = &json_value["props"]["pageProps"]["state"]["data"]["entity"]["trackList"]
|
||||||
|
.as_array()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// println!("{metadata:?}");
|
||||||
|
|
||||||
|
let tracks: Vec<SpotifyTrack> = metadata
|
||||||
|
.iter()
|
||||||
|
.map(|track| {
|
||||||
|
let title = track["title"].as_str().unwrap().to_string();
|
||||||
|
let artist = track["subtitle"].as_str().unwrap().to_string();
|
||||||
|
|
||||||
|
SpotifyTrack { title, artist }
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// println!("{tracks:?}");
|
||||||
|
|
||||||
|
Ok(tracks)
|
||||||
|
} else {
|
||||||
|
Err("Could not find element".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
85
libs/spotify-parser/src/retriever.rs
Normal file
85
libs/spotify-parser/src/retriever.rs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
use crate::*;
|
||||||
|
|
||||||
|
pub fn retrieve_track(category: &str, id: &str) -> Result<String, String> {
|
||||||
|
let embed_url = format!("https://embed.spotify.com/?uri=spotify:{}:{}", category, id);
|
||||||
|
|
||||||
|
let client = reqwest::blocking::Client::builder()
|
||||||
|
.use_rustls_tls()
|
||||||
|
.user_agent(USER_AGENT)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let response = client.get(&embed_url).send().unwrap();
|
||||||
|
let content = response.text().unwrap();
|
||||||
|
|
||||||
|
let parsed_content = parse_single(content).unwrap();
|
||||||
|
|
||||||
|
Ok(format!(
|
||||||
|
"{} - {}",
|
||||||
|
parsed_content.artist, parsed_content.title
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn retrieve_tracks(category: &str, id: &str) -> Result<Vec<String>, String> {
|
||||||
|
let embed_url = format!("https://embed.spotify.com/?uri=spotify:{}:{}", category, id);
|
||||||
|
|
||||||
|
let client = reqwest::blocking::Client::builder()
|
||||||
|
.use_rustls_tls()
|
||||||
|
.user_agent(USER_AGENT)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let response = client.get(&embed_url).send().unwrap();
|
||||||
|
let content = response.text().unwrap();
|
||||||
|
|
||||||
|
let parsed_content = parse_list(content).unwrap();
|
||||||
|
|
||||||
|
let tracks: Vec<String> = parsed_content
|
||||||
|
.iter()
|
||||||
|
.map(|track| format!("{} - {}", track.artist, track.title))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(tracks)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn retrieve_async_track(category: &str, id: &str) -> Result<String, String> {
|
||||||
|
let embed_url = format!("https://embed.spotify.com/?uri=spotify:{}:{}", category, id);
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.use_rustls_tls()
|
||||||
|
.user_agent(USER_AGENT)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let response = client.get(&embed_url).send().await.unwrap();
|
||||||
|
let content = response.text().await.unwrap();
|
||||||
|
|
||||||
|
let parsed_content = parse_single(content).unwrap();
|
||||||
|
|
||||||
|
Ok(format!(
|
||||||
|
"{} - {}",
|
||||||
|
parsed_content.artist, parsed_content.title
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn retrieve_async_tracks(category: &str, id: &str) -> Result<Vec<String>, String> {
|
||||||
|
let embed_url = format!("https://embed.spotify.com/?uri=spotify:{}:{}", category, id);
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.use_rustls_tls()
|
||||||
|
.user_agent(USER_AGENT)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let response = client.get(&embed_url).send().await.unwrap();
|
||||||
|
let content = response.text().await.unwrap();
|
||||||
|
|
||||||
|
let parsed_content = parse_list(content).unwrap();
|
||||||
|
|
||||||
|
let tracks: Vec<String> = parsed_content
|
||||||
|
.iter()
|
||||||
|
.map(|track| format!("{} - {}", track.artist, track.title))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(tracks)
|
||||||
|
}
|
||||||
@@ -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,4 +1,4 @@
|
|||||||
|
pub mod embeds;
|
||||||
pub mod kashi;
|
pub mod kashi;
|
||||||
pub mod music;
|
pub mod music;
|
||||||
pub mod tools;
|
pub mod tools;
|
||||||
pub mod embeds;
|
|
||||||
|
|||||||
@@ -1,37 +1,58 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
|
|
||||||
use serenity::{builder::{CreateEmbedAuthor, CreateEmbedFooter}, model::{Colour, Timestamp}};
|
|
||||||
use poise::serenity_prelude::CreateEmbed;
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
use serenity::{
|
||||||
|
builder::{CreateEmbedAuthor, CreateEmbedFooter},
|
||||||
|
model::{Colour, Timestamp},
|
||||||
|
};
|
||||||
|
|
||||||
pub async fn fail(ctx: Context<'_>, err: String) -> Result<(), Error> {
|
pub async fn fail(ctx: Context<'_>, err: String) -> Result<(), Error> {
|
||||||
ctx.send(
|
ctx.send(
|
||||||
CreateReply::default().embed(error_embed(ctx, &format!("Failed: {:?}", err)).await.unwrap())
|
CreateReply::default().embed(
|
||||||
).await?;
|
error_embed(ctx, &format!("Failed: {:?}", err))
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn error_embed(ctx: Context<'_>, msg: &str) -> Result<CreateEmbed, Error> {
|
pub async fn error_embed(ctx: Context<'_>, msg: &str) -> Result<CreateEmbed, Error> {
|
||||||
let embed = CreateEmbed::default()
|
let embed = CreateEmbed::default()
|
||||||
.author(CreateEmbedAuthor::new("Something went wrong!").icon_url(ctx.author().clone().face()))
|
.author(
|
||||||
.colour(Colour::from_rgb(255, 58, 97))
|
CreateEmbedAuthor::new("Something went wrong!").icon_url(ctx.author().clone().face()),
|
||||||
.title("Oopsie, Doopsie!")
|
)
|
||||||
.description(msg)
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
.timestamp(Timestamp::now())
|
.title("Oopsie, Doopsie!")
|
||||||
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
.description(msg)
|
||||||
|
.timestamp(Timestamp::now())
|
||||||
|
.footer(
|
||||||
|
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||||
|
.icon_url(ctx.cache().current_user().face()),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(embed)
|
Ok(embed)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn embed(ctx: Context<'_>, author: &str, description: &str, title: &str) -> Result<CreateEmbed, Error> {
|
pub async fn embed(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
author: &str,
|
||||||
|
description: &str,
|
||||||
|
title: &str,
|
||||||
|
) -> Result<CreateEmbed, Error> {
|
||||||
let embed = CreateEmbed::default()
|
let embed = CreateEmbed::default()
|
||||||
.author(CreateEmbedAuthor::new(author).icon_url(ctx.author().clone().face()))
|
.author(CreateEmbedAuthor::new(author).icon_url(ctx.author().clone().face()))
|
||||||
.colour(Colour::from_rgb(255, 58, 97))
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
.title(title)
|
.title(title)
|
||||||
.description(description)
|
.description(description)
|
||||||
.timestamp(Timestamp::now())
|
.timestamp(Timestamp::now())
|
||||||
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
.footer(
|
||||||
|
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||||
|
.icon_url(ctx.cache().current_user().face()),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(embed)
|
Ok(embed)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
pub mod deafen;
|
pub mod deafen;
|
||||||
pub mod join;
|
pub mod join;
|
||||||
pub mod leave;
|
pub mod leave;
|
||||||
pub mod notifier;
|
pub mod metadata;
|
||||||
pub mod mute;
|
pub mod mute;
|
||||||
|
pub mod notifier;
|
||||||
pub mod pause;
|
pub mod pause;
|
||||||
pub mod play;
|
pub mod play;
|
||||||
pub mod queue;
|
pub mod queue;
|
||||||
pub mod repeat;
|
pub mod repeat;
|
||||||
pub mod resume;
|
pub mod resume;
|
||||||
|
pub mod seek;
|
||||||
pub mod skip;
|
pub mod skip;
|
||||||
|
pub mod soundboard;
|
||||||
pub mod stop;
|
pub mod stop;
|
||||||
|
pub mod volume;
|
||||||
|
|
||||||
pub use deafen::deafen;
|
pub use deafen::deafen;
|
||||||
pub use join::join;
|
pub use join::join;
|
||||||
@@ -20,5 +24,7 @@ pub use play::play;
|
|||||||
pub use queue::queue;
|
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 skip::skip;
|
pub use skip::skip;
|
||||||
pub use stop::stop;
|
pub use stop::stop;
|
||||||
|
pub use volume::volume;
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use crate::{commands::embeds::{error_embed, embed, fail}, Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed, fail},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
/// Deafens itself while in a voice channel; \
|
/// Deafens itself while in a voice channel; \
|
||||||
@@ -9,9 +12,7 @@ use poise::CreateReply;
|
|||||||
aliases("shuush", "undeafen"),
|
aliases("shuush", "undeafen"),
|
||||||
category = "Music"
|
category = "Music"
|
||||||
)]
|
)]
|
||||||
pub async fn deafen(
|
pub async fn deafen(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
@@ -23,10 +24,9 @@ pub async fn deafen(
|
|||||||
Some(handler) => handler,
|
Some(handler) => handler,
|
||||||
None => {
|
None => {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -38,17 +38,15 @@ pub async fn deafen(
|
|||||||
fail(ctx, err.to_string()).await.unwrap();
|
fail(ctx, err.to_string()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(embed(ctx, "Undeafened!", "", "").await.unwrap()))
|
||||||
CreateReply::default().embed(embed(ctx, "Undeafened!", "", "").await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
} else {
|
} else {
|
||||||
if let Err(err) = handler.deafen(true).await {
|
if let Err(err) = handler.deafen(true).await {
|
||||||
fail(ctx, err.to_string()).await.unwrap();
|
fail(ctx, err.to_string()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(embed(ctx, "Deafened!", "", "").await.unwrap()))
|
||||||
CreateReply::default().embed(embed(ctx, "Deafened!", "", "").await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,29 +1,28 @@
|
|||||||
use crate::{commands::embeds::{error_embed, embed}, Context, Error};
|
use crate::commands::music::notifier::TrackErrorNotifier;
|
||||||
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
use songbird::TrackEvent;
|
use songbird::TrackEvent;
|
||||||
use crate::commands::music::notifier::TrackErrorNotifier;
|
|
||||||
|
|
||||||
/// Joins your voice channel
|
/// Joins your voice channel
|
||||||
#[poise::command(
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
prefix_command,
|
pub async fn join(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
slash_command,
|
|
||||||
category = "Music"
|
|
||||||
)]
|
|
||||||
pub async fn join(
|
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
let channel_id = ctx.guild().unwrap()
|
let channel_id = ctx
|
||||||
.voice_states.get(&ctx.author().id)
|
.guild()
|
||||||
|
.unwrap()
|
||||||
|
.voice_states
|
||||||
|
.get(&ctx.author().id)
|
||||||
.and_then(|voice_state| voice_state.channel_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 => {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -38,9 +37,8 @@ pub async fn join(
|
|||||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(embed(ctx, "Joined!", "Hi there!", "").await.unwrap()))
|
||||||
CreateReply::default().embed(embed(ctx, "Joined!", "Hi there!", "").await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed, fail},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
use crate::{commands::embeds::{error_embed, fail, embed}, Context, Error};
|
|
||||||
|
|
||||||
/// Leaves the voice channel; \
|
/// Leaves the voice channel; \
|
||||||
/// aliases: leave, qa!
|
/// aliases: leave, qa!
|
||||||
@@ -9,9 +12,7 @@ use crate::{commands::embeds::{error_embed, fail, embed}, Context, Error};
|
|||||||
aliases("leave", "qa!"),
|
aliases("leave", "qa!"),
|
||||||
category = "Music"
|
category = "Music"
|
||||||
)]
|
)]
|
||||||
pub async fn leave(
|
pub async fn leave(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
@@ -21,20 +22,24 @@ pub async fn leave(
|
|||||||
|
|
||||||
if !manager.get(guild_id).is_some() {
|
if !manager.get(guild_id).is_some() {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
|
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = manager.remove(guild_id).await {
|
if let Err(err) = manager.remove(guild_id).await {
|
||||||
fail(ctx, err.to_string()).await.unwrap();
|
fail(ctx, err.to_string()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.send(
|
ctx.send(
|
||||||
CreateReply::default().embed(embed(ctx, "Left!", "I left the voice channel", "").await.unwrap())
|
CreateReply::default().embed(
|
||||||
).await?;
|
embed(ctx, "Left!", "I left the voice channel", "")
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
7
src/commands/music/metadata.rs
Normal file
7
src/commands/music/metadata.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
use songbird::{input::AuxMetadata, typemap::TypeMapKey};
|
||||||
|
|
||||||
|
pub struct Metadata;
|
||||||
|
|
||||||
|
impl TypeMapKey for Metadata {
|
||||||
|
type Value = AuxMetadata;
|
||||||
|
}
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
use crate::{commands::embeds::{error_embed, embed, fail}, Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed, fail},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
/// Mutes itself while in a voice channel; \
|
/// Mutes itself while in a voice channel; \
|
||||||
/// aliases: mute, unmute, shhh
|
/// aliases: mute, unmute, shhh
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
prefix_command,
|
prefix_command,
|
||||||
slash_command,
|
slash_command,
|
||||||
aliases("shhh", "unmute"),
|
aliases("shhh", "unmute"),
|
||||||
category = "Music"
|
category = "Music"
|
||||||
)]
|
)]
|
||||||
pub async fn mute(
|
pub async fn mute(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
@@ -21,33 +22,30 @@ pub async fn mute(
|
|||||||
|
|
||||||
let handler_lock = match manager.get(guild_id) {
|
let handler_lock = match manager.get(guild_id) {
|
||||||
Some(handler) => handler,
|
Some(handler) => handler,
|
||||||
None => {
|
None => {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut handler = handler_lock.lock().await;
|
let mut handler = handler_lock.lock().await;
|
||||||
|
|
||||||
if handler.is_mute() {
|
if handler.is_mute() {
|
||||||
if let Err(err) = handler.mute(false).await {
|
if let Err(err) = handler.mute(false).await {
|
||||||
fail(ctx, err.to_string()).await.unwrap();
|
fail(ctx, err.to_string()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(embed(ctx, "Unmuted!", "", "").await.unwrap()))
|
||||||
CreateReply::default().embed(embed(ctx, "Unmuted!", "", "").await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
} else {
|
} else {
|
||||||
if let Err(err) = handler.mute(true).await {
|
if let Err(err) = handler.mute(true).await {
|
||||||
fail(ctx, err.to_string()).await.unwrap();
|
fail(ctx, err.to_string()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(embed(ctx, "Muted!", "", "").await.unwrap()))
|
||||||
CreateReply::default().embed(embed(ctx, "Muted!", "", "").await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
use crate::{commands::embeds::{error_embed, embed}, Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
/// Pauses the currently playing song
|
/// Pauses the currently playing song
|
||||||
#[poise::command(
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
prefix_command,
|
pub async fn pause(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
slash_command,
|
|
||||||
category = "Music"
|
|
||||||
)]
|
|
||||||
pub async fn pause(
|
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
@@ -21,15 +18,19 @@ pub async fn pause(
|
|||||||
let handler = handler_lock.lock().await;
|
let handler = handler_lock.lock().await;
|
||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
let _ = queue.pause();
|
let _ = queue.pause();
|
||||||
|
|
||||||
ctx.send(
|
ctx.send(
|
||||||
CreateReply::default().embed(embed(ctx, "Paused!", "Currently playing song is now paused!", "").await.unwrap())
|
CreateReply::default().embed(
|
||||||
).await?;
|
embed(ctx, "Paused!", "Currently playing song is now paused!", "")
|
||||||
} else {
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
|
use crate::commands::music::metadata::Metadata;
|
||||||
use crate::{commands::embeds::error_embed, Context, Error};
|
use crate::{commands::embeds::error_embed, Context, Error};
|
||||||
|
|
||||||
use fancy_regex::Regex;
|
use fancy_regex::Regex;
|
||||||
use regex::Regex as Regex_Classic;
|
use lib_spotify_parser;
|
||||||
use std::process::Command;
|
|
||||||
use std::time::Duration;
|
|
||||||
use poise::CreateReply;
|
|
||||||
use poise::serenity_prelude::CreateEmbed;
|
|
||||||
use poise::serenity_prelude::Colour;
|
|
||||||
use poise::serenity_prelude::model::Timestamp;
|
use poise::serenity_prelude::model::Timestamp;
|
||||||
|
use poise::serenity_prelude::Colour;
|
||||||
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
|
use poise::CreateReply;
|
||||||
|
use regex::Regex as Regex_Classic;
|
||||||
use serenity::builder::CreateEmbedAuthor;
|
use serenity::builder::CreateEmbedAuthor;
|
||||||
use serenity::builder::CreateEmbedFooter;
|
use serenity::builder::CreateEmbedFooter;
|
||||||
|
use songbird::events::TrackEvent;
|
||||||
use songbird::input::AuxMetadata;
|
use songbird::input::AuxMetadata;
|
||||||
use songbird::input::{Compose, YoutubeDl};
|
use songbird::input::{Compose, YoutubeDl};
|
||||||
use songbird::events::TrackEvent;
|
use songbird::tracks::{TrackHandle, TrackQueue};
|
||||||
|
use std::process::Command;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::commands::music::notifier::TrackErrorNotifier;
|
use crate::commands::music::notifier::TrackErrorNotifier;
|
||||||
use crate::http::HttpKey;
|
use crate::http::HttpKey;
|
||||||
@@ -21,33 +24,47 @@ use crate::http::HttpKey;
|
|||||||
/// you can search by query or paste an url; \
|
/// you can search by query or paste an url; \
|
||||||
/// aliases: play, p, enqueue
|
/// aliases: play, p, enqueue
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
prefix_command,
|
prefix_command,
|
||||||
slash_command,
|
slash_command,
|
||||||
aliases("p", "enqueue"),
|
aliases("p", "enqueue"),
|
||||||
category = "Music"
|
category = "Music"
|
||||||
)]
|
)]
|
||||||
pub async fn play(
|
pub async fn play(
|
||||||
ctx: Context<'_>,
|
ctx: Context<'_>,
|
||||||
#[description = "Provide a query or an url"] #[rest] mut song: String,
|
#[description = "Provide a query or an url"]
|
||||||
|
#[rest]
|
||||||
|
mut song: String,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let regex_spotify = Regex::new(r"https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-)+)(?:(?=\?)(?:[?&]foo=(\d*)(?=[&#]|$)|(?![?&]foo=)[^#])+)?(?=#|$)").unwrap();
|
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 =
|
||||||
let regex_youtube_playlist = Regex::new(r"^((?:https?:)\/\/)?((?:www|m)\.)?((?:youtube\.com)).*(youtu.be\/|list=)([^#&?]*).*").unwrap();
|
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();
|
||||||
|
let regex_spotify_playlist = Regex::new(r"https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:(album|playlist)\/|\?uri=spotify:playlist:)((\w|-)+)(?:(?=\?)(?:[?&]foo=(\d*)(?=[&#]|$)|(?![?&]foo=)[^#])+)?(?=#|$)").unwrap();
|
||||||
|
|
||||||
let is_playlist = regex_youtube_playlist.is_match(&song).unwrap();
|
let is_playlist = regex_youtube_playlist.is_match(&song).unwrap()
|
||||||
let is_spotify = regex_spotify.is_match(&song).unwrap();
|
|| regex_spotify_playlist.is_match(&song).unwrap();
|
||||||
|
let is_spotify =
|
||||||
|
regex_spotify.is_match(&song).unwrap() || regex_spotify_playlist.is_match(&song).unwrap();
|
||||||
let is_query = !song.starts_with("http");
|
let is_query = !song.starts_with("http");
|
||||||
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
let channel_id = ctx.guild().unwrap().voice_states.get(&ctx.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 => {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -70,59 +87,128 @@ pub async fn play(
|
|||||||
|
|
||||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||||
|
|
||||||
|
if is_playlist && is_spotify {
|
||||||
|
let tracks: Vec<String> = lib_spotify_parser::retrieve_async_url(&song).await.unwrap();
|
||||||
|
|
||||||
|
for (index, url) in tracks.clone().iter().enumerate() {
|
||||||
|
if url.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let src = YoutubeDl::new_ytdl_like(
|
||||||
|
"yt-dlp",
|
||||||
|
http_client.clone(),
|
||||||
|
format!("ytsearch:{}", url.to_string()),
|
||||||
|
);
|
||||||
|
let aux_metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
|
let track = handler.enqueue_input(src.clone().into()).await;
|
||||||
|
let _ = track
|
||||||
|
.typemap()
|
||||||
|
.write()
|
||||||
|
.await
|
||||||
|
.insert::<Metadata>(aux_metadata);
|
||||||
|
|
||||||
|
if index == 0 {
|
||||||
|
let embed = generate_playlist_embed(ctx, track, tracks.len()).await;
|
||||||
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
|
ctx.send(response).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
if is_playlist {
|
if is_playlist {
|
||||||
let raw_list = Command::new("yt-dlp")
|
let raw_list = Command::new("yt-dlp")
|
||||||
.args(["-j", "--flat-playlist", &song])
|
.args(["-j", "--flat-playlist", &song])
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to execute process")
|
.expect("failed to execute process")
|
||||||
.stdout;
|
.stdout;
|
||||||
|
|
||||||
let list = String::from_utf8(raw_list.clone()).expect("Invalid UTF-8");
|
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 urls: Vec<String> = regex_youtube
|
||||||
|
.captures_iter(&list)
|
||||||
let mut sources: Vec<YoutubeDl> = vec![];
|
.map(|capture| capture[1].to_string())
|
||||||
|
.collect();
|
||||||
|
|
||||||
for url in urls {
|
for (index, url) in urls.clone().iter().enumerate() {
|
||||||
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client.clone(), url);
|
if url.is_empty() {
|
||||||
let _ = handler.enqueue_input(src.clone().into()).await;
|
break;
|
||||||
sources.push(src);
|
}
|
||||||
|
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client.clone(), url.to_string());
|
||||||
|
let aux_metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
|
let track = handler.enqueue_input(src.clone().into()).await;
|
||||||
|
let _ = track
|
||||||
|
.typemap()
|
||||||
|
.write()
|
||||||
|
.await
|
||||||
|
.insert::<Metadata>(aux_metadata);
|
||||||
|
|
||||||
|
if index == 0 {
|
||||||
|
let embed = generate_playlist_embed(ctx, track, urls.len()).await;
|
||||||
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
|
ctx.send(response).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let embed = generate_playlist_embed(ctx, sources).await;
|
return Ok(());
|
||||||
let response = CreateReply::default().embed(embed.unwrap());
|
|
||||||
ctx.send(response).await?;
|
|
||||||
} else {
|
|
||||||
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());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_query {
|
|
||||||
song = format!("ytsearch:{}", song);
|
|
||||||
}
|
|
||||||
|
|
||||||
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client, song);
|
|
||||||
let _ = handler.enqueue_input(src.clone().into()).await;
|
|
||||||
|
|
||||||
let embed = generate_embed(ctx, src).await;
|
|
||||||
let response = CreateReply::default().embed(embed.unwrap());
|
|
||||||
ctx.send(response).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_spotify {
|
||||||
|
song = format!(
|
||||||
|
"ytsearch:{}",
|
||||||
|
lib_spotify_parser::retrieve_async_url(&song)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.first()
|
||||||
|
.unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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(), handler.queue()).await;
|
||||||
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
|
ctx.send(response).await?;
|
||||||
|
|
||||||
|
let aux_metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
|
|
||||||
|
let track = handler.enqueue_input(src.clone().into()).await;
|
||||||
|
let _ = track
|
||||||
|
.typemap()
|
||||||
|
.write()
|
||||||
|
.await
|
||||||
|
.insert::<Metadata>(aux_metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_embed(ctx: Context<'_>, src: YoutubeDl) -> Result<CreateEmbed, Error> {
|
async fn generate_embed(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
src: YoutubeDl,
|
||||||
|
queue: &TrackQueue,
|
||||||
|
) -> Result<CreateEmbed, Error> {
|
||||||
let metadata = src.clone().aux_metadata().await.unwrap();
|
let metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
let AuxMetadata {title, thumbnail, source_url, artist, duration, ..} = metadata;
|
let AuxMetadata {
|
||||||
|
title,
|
||||||
|
thumbnail,
|
||||||
|
source_url,
|
||||||
|
artist,
|
||||||
|
duration,
|
||||||
|
..
|
||||||
|
} = metadata;
|
||||||
let timestamp = Timestamp::now();
|
let timestamp = Timestamp::now();
|
||||||
let duration_minutes = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() / 60;
|
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 duration_seconds = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() % 60;
|
||||||
|
let mut description = format!("Song added to queue @ {}", queue.len() + 1);
|
||||||
|
|
||||||
|
if queue.len() == 0 {
|
||||||
|
description = format!("Playing now!");
|
||||||
|
}
|
||||||
|
|
||||||
let embed = CreateEmbed::default()
|
let embed = CreateEmbed::default()
|
||||||
.author(CreateEmbedAuthor::new("Track enqueued").icon_url(ctx.author().clone().face()))
|
.author(CreateEmbedAuthor::new("Track enqueued").icon_url(ctx.author().clone().face()))
|
||||||
@@ -130,38 +216,75 @@ async fn generate_embed(ctx: Context<'_>, src: YoutubeDl) -> Result<CreateEmbed,
|
|||||||
.title(title.unwrap())
|
.title(title.unwrap())
|
||||||
.url(source_url.unwrap())
|
.url(source_url.unwrap())
|
||||||
.thumbnail(thumbnail.unwrap_or(ctx.cache().current_user().face()))
|
.thumbnail(thumbnail.unwrap_or(ctx.cache().current_user().face()))
|
||||||
.field("Artist", artist.unwrap_or("Unknown Artist".to_string()), true)
|
.field(
|
||||||
.field("Duration", format!("{:02}:{:02}", duration_minutes, duration_seconds), true)
|
"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)
|
.field("DJ", ctx.author().name.clone(), true)
|
||||||
|
.description(description)
|
||||||
.timestamp(timestamp)
|
.timestamp(timestamp)
|
||||||
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
.footer(
|
||||||
|
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||||
|
.icon_url(ctx.cache().current_user().face()),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(embed)
|
Ok(embed)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_playlist_embed(ctx: Context<'_>, sources: Vec<YoutubeDl>) -> Result<CreateEmbed, Error> {
|
async fn generate_playlist_embed(
|
||||||
let src = sources.get(0).unwrap();
|
ctx: Context<'_>,
|
||||||
|
track: TrackHandle,
|
||||||
let metadata = src.clone().aux_metadata().await.unwrap();
|
queue_length: usize,
|
||||||
let AuxMetadata {title, thumbnail, source_url, artist, duration, ..} = metadata;
|
) -> Result<CreateEmbed, Error> {
|
||||||
|
let meta_typemap = track.typemap().read().await;
|
||||||
|
let metadata = meta_typemap.get::<Metadata>().unwrap();
|
||||||
|
let AuxMetadata {
|
||||||
|
title,
|
||||||
|
thumbnail,
|
||||||
|
source_url,
|
||||||
|
artist,
|
||||||
|
duration,
|
||||||
|
..
|
||||||
|
} = metadata;
|
||||||
let timestamp = Timestamp::now();
|
let timestamp = Timestamp::now();
|
||||||
let duration_minutes = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() / 60;
|
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 duration_seconds = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() % 60;
|
||||||
|
|
||||||
let description = format!("Enqueued tracks: {}", sources.len() - 1);
|
let description = format!("Enqueued tracks: {}", queue_length - 1);
|
||||||
|
|
||||||
let embed = CreateEmbed::default()
|
let embed = CreateEmbed::default()
|
||||||
.author(CreateEmbedAuthor::new("Playlist enqueued").icon_url(ctx.author().clone().face()))
|
.author(CreateEmbedAuthor::new("Playlist enqueued").icon_url(ctx.author().clone().face()))
|
||||||
.colour(Colour::from_rgb(255, 58, 97))
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
.title(title.unwrap())
|
.title(title.as_ref().unwrap())
|
||||||
.url(source_url.unwrap())
|
.url(source_url.as_ref().unwrap())
|
||||||
.thumbnail(thumbnail.unwrap_or(ctx.cache().current_user().face()))
|
.thumbnail(
|
||||||
.field("Artist", artist.unwrap_or("Unknown Artist".to_string()), true)
|
thumbnail
|
||||||
.field("Duration", format!("{:02}:{:02}", duration_minutes, duration_seconds), true)
|
.as_ref()
|
||||||
|
.unwrap_or(&ctx.cache().current_user().face()),
|
||||||
|
)
|
||||||
|
.field(
|
||||||
|
"Artist",
|
||||||
|
artist.as_ref().unwrap_or(&"Unknown Artist".to_string()),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.field(
|
||||||
|
"Duration",
|
||||||
|
format!("{:02}:{:02}", duration_minutes, duration_seconds),
|
||||||
|
true,
|
||||||
|
)
|
||||||
.field("DJ", ctx.author().name.clone(), true)
|
.field("DJ", ctx.author().name.clone(), true)
|
||||||
.description(description)
|
.description(description)
|
||||||
.timestamp(timestamp)
|
.timestamp(timestamp)
|
||||||
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
.footer(
|
||||||
|
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||||
|
.icon_url(ctx.cache().current_user().face()),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(embed)
|
Ok(embed)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use crate::commands::music::metadata::Metadata;
|
||||||
use crate::{commands::embeds::error_embed, Context, Error};
|
use crate::{commands::embeds::error_embed, Context, Error};
|
||||||
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
use serenity::{
|
||||||
|
builder::{CreateEmbedAuthor, CreateEmbedFooter},
|
||||||
|
model::{Colour, Timestamp},
|
||||||
|
};
|
||||||
|
use songbird::input::AuxMetadata;
|
||||||
|
|
||||||
|
const QUEUE_DISPLAY_LENGTH: usize = 10;
|
||||||
|
|
||||||
/// Shows next tracks in queue; \
|
/// Shows next tracks in queue; \
|
||||||
/// aliases: queue, q
|
/// aliases: queue, q
|
||||||
#[poise::command(
|
#[poise::command(prefix_command, slash_command, aliases("q"), category = "Music")]
|
||||||
prefix_command,
|
pub async fn queue(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
slash_command,
|
|
||||||
aliases("q"),
|
|
||||||
category = "Music"
|
|
||||||
)]
|
|
||||||
pub async fn queue(
|
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
@@ -22,26 +26,68 @@ pub async fn queue(
|
|||||||
if let Some(handler_lock) = manager.get(guild_id) {
|
if let Some(handler_lock) = manager.get(guild_id) {
|
||||||
let handler = handler_lock.lock().await;
|
let handler = handler_lock.lock().await;
|
||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
let mut queue_res = String::from("Queue: \n");
|
let mut queue_res = String::from("");
|
||||||
|
let mut too_long = false;
|
||||||
|
|
||||||
|
for (index, song) in queue.clone().current_queue().iter().enumerate() {
|
||||||
|
let meta_typemap = song.typemap().read().await;
|
||||||
|
let metadata = meta_typemap.get::<Metadata>().unwrap();
|
||||||
|
let AuxMetadata {
|
||||||
|
title,
|
||||||
|
artist,
|
||||||
|
duration,
|
||||||
|
..
|
||||||
|
} = metadata;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
for (i, song) in queue.current_queue().iter().enumerate() {
|
|
||||||
queue_res.push_str(&format!(
|
queue_res.push_str(&format!(
|
||||||
"{}. {} - {}\n",
|
"{}. {} - {} [{:02}:{:02}] \n",
|
||||||
i + 1,
|
index,
|
||||||
song.uuid(),
|
title.as_ref().unwrap(),
|
||||||
"Artist"
|
artist.as_ref().unwrap(),
|
||||||
// song.metadata().artist.clone().unwrap_or_else(|| String::from("Unknown"))
|
duration_minutes,
|
||||||
|
duration_seconds
|
||||||
|
));
|
||||||
|
|
||||||
|
if index + 1 == QUEUE_DISPLAY_LENGTH {
|
||||||
|
too_long = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if too_long {
|
||||||
|
queue_res.push_str(&format!(
|
||||||
|
"and {} more...",
|
||||||
|
queue.len() - QUEUE_DISPLAY_LENGTH
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.say(queue_res).await?;
|
ctx.send(CreateReply::default().embed(embed(ctx, queue_res).await.unwrap()))
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn embed(ctx: Context<'_>, queue: String) -> Result<CreateEmbed, Error> {
|
||||||
|
let title = "Now playing";
|
||||||
|
let timestamp = Timestamp::now();
|
||||||
|
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(CreateEmbedAuthor::new("Queue").icon_url(ctx.author().clone().face()))
|
||||||
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
|
.title(title)
|
||||||
|
.description(queue)
|
||||||
|
.timestamp(timestamp)
|
||||||
|
.footer(
|
||||||
|
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||||
|
.icon_url(ctx.cache().current_user().face()),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(embed)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
use crate::{commands::embeds::{error_embed, embed}, Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
use songbird::tracks::LoopState;
|
use songbird::tracks::LoopState;
|
||||||
|
|
||||||
/// Loops currently playing song provided amount of times; \
|
/// Loops currently playing song provided amount of times; \
|
||||||
/// aliases: repeat, loop, while, for
|
/// aliases: repeat, loop, while, for
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
prefix_command,
|
prefix_command,
|
||||||
slash_command,
|
slash_command,
|
||||||
aliases("loop", "while", "for"),
|
aliases("loop", "while", "for"),
|
||||||
category = "Music"
|
category = "Music"
|
||||||
)]
|
)]
|
||||||
pub async fn repeat(
|
pub async fn repeat(
|
||||||
ctx: Context<'_>,
|
ctx: Context<'_>,
|
||||||
#[description = "How many times"] #[rest] times: usize
|
#[description = "How many times"]
|
||||||
|
#[rest]
|
||||||
|
times: usize,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
@@ -21,7 +26,6 @@ pub async fn repeat(
|
|||||||
.expect("Songbird 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 handler = handler_lock.lock().await;
|
let handler = handler_lock.lock().await;
|
||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
@@ -34,36 +38,52 @@ pub async fn repeat(
|
|||||||
let _ = queue.current().unwrap().disable_loop();
|
let _ = queue.current().unwrap().disable_loop();
|
||||||
|
|
||||||
ctx.send(
|
ctx.send(
|
||||||
CreateReply::default().embed(embed(ctx, "Song Unlooped!", "", "").await.unwrap())
|
CreateReply::default()
|
||||||
).await?;
|
.embed(embed(ctx, "Song Unlooped!", "", "").await.unwrap()),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
LoopState::Finite(_) => {
|
LoopState::Finite(_) => {
|
||||||
if times == 0 {
|
if times == 0 {
|
||||||
let _ = queue.current().unwrap().disable_loop();
|
let _ = queue.current().unwrap().disable_loop();
|
||||||
|
|
||||||
ctx.send(
|
ctx.send(
|
||||||
CreateReply::default().embed(embed(ctx, "Song Unlooped!", "", "").await.unwrap())
|
CreateReply::default()
|
||||||
).await?;
|
.embed(embed(ctx, "Song Unlooped!", "", "").await.unwrap()),
|
||||||
}
|
)
|
||||||
else if times < 100 {
|
.await?;
|
||||||
|
} else if times < 100 {
|
||||||
let _ = queue.current().unwrap().loop_for(times);
|
let _ = queue.current().unwrap().loop_for(times);
|
||||||
ctx.send(
|
ctx.send(
|
||||||
CreateReply::default().embed(embed(ctx, &format!("Song looped {} times!", times), "You definitelly love this song!", "").await.unwrap())
|
CreateReply::default().embed(
|
||||||
).await?;
|
embed(
|
||||||
}
|
ctx,
|
||||||
else {
|
&format!("Song looped {} times!", times),
|
||||||
|
"You definitelly love this song!",
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
let _ = queue.current().unwrap().enable_loop();
|
let _ = queue.current().unwrap().enable_loop();
|
||||||
ctx.send(
|
ctx.send(
|
||||||
CreateReply::default().embed(embed(ctx, "Song looped forever!", "A very long time!", "").await.unwrap())
|
CreateReply::default().embed(
|
||||||
).await?;
|
embed(ctx, "Song looped forever!", "A very long time!", "")
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
use crate::{commands::embeds::{error_embed, embed}, Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
/// Resumes currently paused song
|
/// Resumes currently paused song
|
||||||
#[poise::command(
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
prefix_command,
|
pub async fn resume(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
slash_command,
|
|
||||||
category = "Music"
|
|
||||||
)]
|
|
||||||
pub async fn resume(
|
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
@@ -22,15 +19,18 @@ pub async fn resume(
|
|||||||
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(embed(ctx, "Resumed!", "Currently paused song is now resumed!", "").await.unwrap())
|
CreateReply::default().embed(
|
||||||
).await?;
|
embed(ctx, "Resumed!", "Currently paused song is now resumed!", "")
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
51
src/commands/music/seek.rs
Normal file
51
src/commands/music/seek.rs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
/// Seeks a track by provided seconds
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
|
pub async fn seek(
|
||||||
|
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?;
|
||||||
|
} else {
|
||||||
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,15 +1,26 @@
|
|||||||
use crate::{commands::embeds::{error_embed, embed}, Context, Error};
|
use crate::commands::music::metadata::Metadata;
|
||||||
use poise::CreateReply;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// Skips the currently playing song
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
use serenity::{
|
||||||
|
builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter},
|
||||||
|
model::{Colour, Timestamp},
|
||||||
|
};
|
||||||
|
use songbird::{input::AuxMetadata, tracks::TrackHandle};
|
||||||
|
|
||||||
|
/// Skips the currently playing song; \
|
||||||
|
/// aliases: skip, :skipper:
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
prefix_command,
|
prefix_command,
|
||||||
slash_command,
|
slash_command,
|
||||||
|
aliases("skipper:"),
|
||||||
category = "Music"
|
category = "Music"
|
||||||
)]
|
)]
|
||||||
pub async fn skip(
|
pub async fn skip(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
@@ -20,17 +31,88 @@ pub async fn skip(
|
|||||||
if let Some(handler_lock) = manager.get(guild_id) {
|
if let Some(handler_lock) = manager.get(guild_id) {
|
||||||
let handler = handler_lock.lock().await;
|
let handler = handler_lock.lock().await;
|
||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
let _ = queue.skip();
|
let _ = queue.clone().skip();
|
||||||
|
let track_raw = queue.clone().current_queue();
|
||||||
|
let track = track_raw.get(1);
|
||||||
|
let queue_length = queue.len() - 1;
|
||||||
|
|
||||||
ctx.send(
|
let response;
|
||||||
CreateReply::default().embed(embed(ctx, "Skipped!", "Next song: {song}", &format!("Songs left in queue: {}", queue.len())).await.unwrap())
|
|
||||||
).await?;
|
match track {
|
||||||
|
Some(track) => {
|
||||||
|
response = CreateReply::default().embed(
|
||||||
|
generate_embed(ctx, track.clone(), queue_length)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
response = CreateReply::default().embed(
|
||||||
|
embed(ctx, "Skipped!", "The queue is empty!", "")
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.send(response).await?;
|
||||||
} else {
|
} else {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn generate_embed(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
track: TrackHandle,
|
||||||
|
queue_length: usize,
|
||||||
|
) -> Result<CreateEmbed, Error> {
|
||||||
|
let meta_typemap = track.typemap().read().await;
|
||||||
|
let metadata = meta_typemap.get::<Metadata>().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!("Song skipped! Queue length is {}", queue_length);
|
||||||
|
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(CreateEmbedAuthor::new("Skipped!").icon_url(ctx.author().clone().face()))
|
||||||
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
|
.title(title.as_ref().unwrap())
|
||||||
|
.url(source_url.as_ref().unwrap())
|
||||||
|
.thumbnail(
|
||||||
|
thumbnail
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or(&ctx.cache().current_user().face()),
|
||||||
|
)
|
||||||
|
.field(
|
||||||
|
"Artist",
|
||||||
|
artist.as_ref().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)
|
||||||
|
}
|
||||||
|
|||||||
5
src/commands/music/soundboard.rs
Normal file
5
src/commands/music/soundboard.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod effect;
|
||||||
|
pub mod stream;
|
||||||
|
|
||||||
|
pub use effect::effect;
|
||||||
|
pub use stream::stream;
|
||||||
117
src/commands/music/soundboard/effect.rs
Normal file
117
src/commands/music/soundboard/effect.rs
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
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 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
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
|
pub async fn effect(
|
||||||
|
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(())
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
126
src/commands/music/soundboard/stream.rs
Normal file
126
src/commands/music/soundboard/stream.rs
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
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 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(())
|
||||||
|
}
|
||||||
|
|
||||||
|
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,19 +1,15 @@
|
|||||||
use crate::{commands::embeds::{error_embed, embed}, Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
/// Stops playback and destroys the queue; \
|
/// Stops playback and destroys the queue; \
|
||||||
/// aliases: stop, end
|
/// aliases: stop, end
|
||||||
#[poise::command(
|
#[poise::command(prefix_command, slash_command, aliases("end"), category = "Music")]
|
||||||
prefix_command,
|
pub async fn stop(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
slash_command,
|
|
||||||
aliases("end"),
|
|
||||||
category = "Music"
|
|
||||||
)]
|
|
||||||
pub async fn stop(
|
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
.await
|
.await
|
||||||
.expect("Songbird client placed at init")
|
.expect("Songbird client placed at init")
|
||||||
@@ -25,14 +21,23 @@ pub async fn stop(
|
|||||||
queue.stop();
|
queue.stop();
|
||||||
|
|
||||||
ctx.send(
|
ctx.send(
|
||||||
CreateReply::default().embed(embed(ctx, "Stopped!", "Playback stopped!", "Queue destroyed! Bot will stay and chill with you in a vc").await.unwrap())
|
CreateReply::default().embed(
|
||||||
).await?;
|
embed(
|
||||||
} else {
|
ctx,
|
||||||
|
"Stopped!",
|
||||||
|
"Playback stopped!",
|
||||||
|
"Queue destroyed! Bot will stay and chill with you in a vc",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
|
.await?;
|
||||||
).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
44
src/commands/music/volume.rs
Normal file
44
src/commands/music/volume.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
/// Changes output volume
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
|
pub async fn volume(ctx: Context<'_>, #[description = "Volume"] volume: f32) -> 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();
|
||||||
|
let _ = track.set_volume(volume / 100.0);
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
"Volume changed",
|
||||||
|
"",
|
||||||
|
&format!("Set volume to {}%", volume),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,7 +1,31 @@
|
|||||||
pub mod ping;
|
pub mod ai;
|
||||||
pub mod register;
|
pub mod dice;
|
||||||
|
pub mod dictionary;
|
||||||
pub mod help;
|
pub mod help;
|
||||||
|
pub mod ip;
|
||||||
|
pub mod metar;
|
||||||
|
pub mod owoify;
|
||||||
|
pub mod ping;
|
||||||
|
pub mod posix;
|
||||||
|
pub mod qr;
|
||||||
|
pub mod register;
|
||||||
|
pub mod taf;
|
||||||
|
pub mod uptime;
|
||||||
|
pub mod verse;
|
||||||
|
pub mod weather;
|
||||||
|
|
||||||
pub use ping::ping;
|
pub use ai::ai;
|
||||||
pub use register::register;
|
pub use dice::dice;
|
||||||
|
pub use dictionary::dictionary;
|
||||||
pub use help::help;
|
pub use help::help;
|
||||||
|
pub use ip::ip;
|
||||||
|
pub use metar::metar;
|
||||||
|
pub use owoify::owoify;
|
||||||
|
pub use ping::ping;
|
||||||
|
pub use posix::posix;
|
||||||
|
pub use qr::qr;
|
||||||
|
pub use register::register;
|
||||||
|
pub use taf::taf;
|
||||||
|
pub use uptime::uptime;
|
||||||
|
pub use verse::verse;
|
||||||
|
pub use weather::weather;
|
||||||
|
|||||||
50
src/commands/tools/ai.rs
Normal file
50
src/commands/tools/ai.rs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
use std::thread::sleep;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Asks AI
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn ai(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "prompt to ask"]
|
||||||
|
#[rest]
|
||||||
|
prompt: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let iamsorry = vec![
|
||||||
|
"I'm sorry, but as an AI language model, I must follow ethical guidelines, and I cannot engage in harmful, malicious, or offensive behavior.",
|
||||||
|
"I'm sorry, but as an AI language model, I may not always be perfect and can make mistakes or provide inaccurate information. Please verify important details from reliable sources.",
|
||||||
|
"I'm sorry, but as an AI language model, I can't engage in real-time conversations or remember previous interactions with users.",
|
||||||
|
"I'm sorry, but as an AI language model, I don't have personal opinions or feelings; I can only provide information based on patterns in the data I was trained on.",
|
||||||
|
"I'm sorry, but as an AI language model, I don't have access to real-time information or updates beyond my last training data in September 2021.",
|
||||||
|
"I'm sorry, but as an AI language model, I don't have the ability to recall specific personal data or information about individuals.",
|
||||||
|
"I'm sorry, but as an AI language model, I don't have consciousness or self-awareness. I'm simply a program designed to process and generate human-like text."
|
||||||
|
];
|
||||||
|
|
||||||
|
println!("Funny prompts: {}", prompt);
|
||||||
|
|
||||||
|
let response;
|
||||||
|
|
||||||
|
let _ = {
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
|
response = rng.gen_range(0..iamsorry.len());
|
||||||
|
};
|
||||||
|
|
||||||
|
sleep(Duration::from_secs(1));
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(ctx, "AI Response:", "", &format!("{}", iamsorry[response]))
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
33
src/commands/tools/dice.rs
Normal file
33
src/commands/tools/dice.rs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Rolls a dice
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn dice(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let dice;
|
||||||
|
|
||||||
|
let _ = {
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
|
dice = rng.gen_range(1..7);
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
"Let's roll the dice!",
|
||||||
|
"",
|
||||||
|
&format!("Your number is: {}", dice),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
72
src/commands/tools/dictionary.rs
Normal file
72
src/commands/tools/dictionary.rs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use url::form_urlencoded;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Explains provided query
|
||||||
|
#[poise::command(prefix_command, slash_command, aliases("dict"), category = "Tools")]
|
||||||
|
pub async fn dictionary(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[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(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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>,
|
||||||
|
}
|
||||||
12
src/commands/tools/ip.rs
Normal file
12
src/commands/tools/ip.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Shows IP information
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn ip(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
12
src/commands/tools/metar.rs
Normal file
12
src/commands/tools/metar.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Prints metar for provided airport
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn metar(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
18
src/commands/tools/owoify.rs
Normal file
18
src/commands/tools/owoify.rs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
use owoify::OwOifiable;
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Owoifies whatever you want uwu
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn owoify(
|
||||||
|
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?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -2,17 +2,12 @@ use crate::{Context, Error};
|
|||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
/// Pings you backs with a response time
|
/// Pings you backs with a response time
|
||||||
#[poise::command(
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
prefix_command,
|
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
slash_command,
|
|
||||||
category = "Tools"
|
|
||||||
)]
|
|
||||||
pub async fn ping(
|
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let system_now = SystemTime::now()
|
let system_now = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap().as_millis() as i64;
|
.unwrap()
|
||||||
|
.as_millis() as i64;
|
||||||
|
|
||||||
let message_now = ctx.created_at().timestamp_millis();
|
let message_now = ctx.created_at().timestamp_millis();
|
||||||
|
|
||||||
|
|||||||
30
src/commands/tools/posix.rs
Normal file
30
src/commands/tools/posix.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Prints current time in POSIX format
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn posix(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let time = SystemTime::now()
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_millis();
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
"The time is",
|
||||||
|
"since Jan 1st 1970",
|
||||||
|
&format!("{} ms", time),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
48
src/commands/tools/qr.rs
Normal file
48
src/commands/tools/qr.rs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
use serenity::{
|
||||||
|
builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter},
|
||||||
|
model::{Colour, Timestamp},
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{Context, Error};
|
||||||
|
use url::form_urlencoded;
|
||||||
|
|
||||||
|
/// Creates a qr code from text
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn qr(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Message to encode"]
|
||||||
|
#[rest]
|
||||||
|
message: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let response = CreateReply::default().embed(generate_embed(ctx, message).await.unwrap());
|
||||||
|
ctx.send(response).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn generate_embed(ctx: Context<'_>, message: String) -> Result<CreateEmbed, Error> {
|
||||||
|
let timestamp = Timestamp::now();
|
||||||
|
let data: String = form_urlencoded::byte_serialize(message.as_bytes()).collect();
|
||||||
|
let url = format!(
|
||||||
|
"http://api.qrserver.com/v1/create-qr-code/?data={}&size=1000x1000&ecc=Q&margin=8",
|
||||||
|
data
|
||||||
|
);
|
||||||
|
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(
|
||||||
|
CreateEmbedAuthor::new("Your message as a QR Code!")
|
||||||
|
.icon_url(ctx.author().clone().face()),
|
||||||
|
)
|
||||||
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
|
.title("Your QR Code:")
|
||||||
|
.url(url.clone())
|
||||||
|
.image(url)
|
||||||
|
.timestamp(timestamp)
|
||||||
|
.footer(
|
||||||
|
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||||
|
.icon_url(ctx.cache().current_user().face()),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(embed)
|
||||||
|
}
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
|
|
||||||
#[poise::command(
|
#[poise::command(prefix_command, hide_in_help, owners_only)]
|
||||||
prefix_command,
|
pub async fn register(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
hide_in_help,
|
|
||||||
owners_only
|
|
||||||
)]
|
|
||||||
pub async fn register(
|
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
poise::builtins::register_application_commands_buttons(ctx).await?;
|
poise::builtins::register_application_commands_buttons(ctx).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/commands/tools/taf.rs
Normal file
12
src/commands/tools/taf.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Returns taf for provided airport
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn taf(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
48
src/commands/tools/uptime.rs
Normal file
48
src/commands/tools/uptime.rs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
use once_cell::sync::Lazy;
|
||||||
|
use poise::CreateReply;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
pub static PROCESS_UPTIME: Lazy<Mutex<std::time::SystemTime>> =
|
||||||
|
Lazy::new(|| Mutex::new(std::time::SystemTime::now()));
|
||||||
|
|
||||||
|
/// Checks how long the bot has been running
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn uptime(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let start = PROCESS_UPTIME.lock().unwrap().clone();
|
||||||
|
let uptime = std::time::SystemTime::now().duration_since(start).unwrap();
|
||||||
|
|
||||||
|
let (days, hours, minutes, seconds) = (
|
||||||
|
uptime.as_secs() / 86400,
|
||||||
|
(uptime.as_secs() / 3600) % 24,
|
||||||
|
(uptime.as_secs() / 60) % 60,
|
||||||
|
uptime.as_secs() % 60,
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut message = format!(
|
||||||
|
"I have been awake for {} days, {} hours, {} minutes and {} seconds!",
|
||||||
|
days, hours, minutes, seconds
|
||||||
|
);
|
||||||
|
|
||||||
|
if days != 0 {
|
||||||
|
message = format!("I have been awake for {} days!", days);
|
||||||
|
}
|
||||||
|
|
||||||
|
if days == 0 && hours != 0 {
|
||||||
|
message = format!("I have been awake for {} hours!", hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
if days == 0 && hours == 0 && minutes != 0 {
|
||||||
|
message = format!("I have been awake for {} minutes!", minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
if days == 0 && hours == 0 && minutes == 0 && seconds != 0 {
|
||||||
|
message = format!("I have been awake for {} seconds!", seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "Uptime", "", &message).await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
78
src/commands/tools/verse.rs
Normal file
78
src/commands/tools/verse.rs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use url::form_urlencoded;
|
||||||
|
|
||||||
|
/// Reference Bible by verse
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn verse(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Latin?"]
|
||||||
|
#[flag]
|
||||||
|
latin: bool,
|
||||||
|
#[description = "BOOK+CHAPTER:VERSE"]
|
||||||
|
#[rest]
|
||||||
|
verse: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let data: String = form_urlencoded::byte_serialize(verse.as_bytes()).collect();
|
||||||
|
let translation = if latin { "clementine" } else { "web" };
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let response = client
|
||||||
|
.get(format!(
|
||||||
|
"https://bible-api.com/{}?translation={}",
|
||||||
|
data, translation
|
||||||
|
))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
match response.status() {
|
||||||
|
reqwest::StatusCode::OK => {
|
||||||
|
match response.json::<APIResponse>().await {
|
||||||
|
Ok(parsed) => {
|
||||||
|
if parsed.text.len() > 4000 {
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default()
|
||||||
|
.embed(error_embed(ctx, "Quoted text is too long!").await.unwrap()),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
&parsed.translation_name,
|
||||||
|
&parsed.text,
|
||||||
|
&parsed.reference,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
Err(err) => println!("Something is messed up! {:?}", err),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
reqwest::StatusCode::UNAUTHORIZED => {
|
||||||
|
println!("Unauthorized.. Uoops!!");
|
||||||
|
}
|
||||||
|
error => {
|
||||||
|
println!("Something went wrong: {:?}", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
struct APIResponse {
|
||||||
|
reference: String,
|
||||||
|
text: String,
|
||||||
|
translation_name: String,
|
||||||
|
translation_note: String,
|
||||||
|
}
|
||||||
17
src/commands/tools/weather.rs
Normal file
17
src/commands/tools/weather.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Shows weather for provided location
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn weather(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Provide a city name"]
|
||||||
|
#[rest]
|
||||||
|
_location: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
use reqwest::Client as HttpClient;
|
|
||||||
use poise::serenity_prelude::prelude::TypeMapKey;
|
use poise::serenity_prelude::prelude::TypeMapKey;
|
||||||
|
use reqwest::Client as HttpClient;
|
||||||
|
|
||||||
pub struct HttpKey;
|
pub struct HttpKey;
|
||||||
|
|
||||||
|
|||||||
57
src/main.rs
57
src/main.rs
@@ -1,9 +1,10 @@
|
|||||||
|
use commands::tools::uptime::PROCESS_UPTIME;
|
||||||
|
use poise::serenity_prelude::{self as serenity, ActivityData};
|
||||||
|
use reqwest::Client as HttpClient;
|
||||||
|
use songbird::SerenityInit;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing::{info, warn, error};
|
use tracing::{error, info, warn};
|
||||||
use poise::serenity_prelude::{self as serenity, ActivityData};
|
|
||||||
use songbird::SerenityInit;
|
|
||||||
use reqwest::Client as HttpClient;
|
|
||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
mod http;
|
mod http;
|
||||||
@@ -37,7 +38,10 @@ async fn main() {
|
|||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
dotenv::dotenv().expect("Failed to load .env file.");
|
dotenv::dotenv().expect("Failed to load .env file.");
|
||||||
|
|
||||||
let token = std::env::var("DISCORD_TOKEN").expect("Environment variable `DISCORD_TOKEN` not found!");
|
let _ = PROCESS_UPTIME.lock().unwrap().clone();
|
||||||
|
|
||||||
|
let token =
|
||||||
|
std::env::var("DISCORD_TOKEN").expect("Environment variable `DISCORD_TOKEN` not found!");
|
||||||
let prefix = std::env::var("PREFIX").expect("Environment variable `PREFIX` not found!");
|
let prefix = std::env::var("PREFIX").expect("Environment variable `PREFIX` not found!");
|
||||||
|
|
||||||
let commands = vec![
|
let commands = vec![
|
||||||
@@ -45,17 +49,33 @@ async fn main() {
|
|||||||
music::deafen(),
|
music::deafen(),
|
||||||
music::join(),
|
music::join(),
|
||||||
music::leave(),
|
music::leave(),
|
||||||
music::repeat(),
|
|
||||||
music::mute(),
|
music::mute(),
|
||||||
music::pause(),
|
music::pause(),
|
||||||
music::play(),
|
music::play(),
|
||||||
music::queue(),
|
music::queue(),
|
||||||
|
music::repeat(),
|
||||||
music::resume(),
|
music::resume(),
|
||||||
|
music::seek(),
|
||||||
music::skip(),
|
music::skip(),
|
||||||
music::stop(),
|
music::stop(),
|
||||||
tools::ping(),
|
music::volume(),
|
||||||
tools::register(),
|
music::soundboard::effect(),
|
||||||
|
music::soundboard::stream(),
|
||||||
|
tools::ai(),
|
||||||
|
tools::dice(),
|
||||||
|
tools::dictionary(),
|
||||||
tools::help(),
|
tools::help(),
|
||||||
|
tools::ip(),
|
||||||
|
tools::metar(),
|
||||||
|
tools::owoify(),
|
||||||
|
tools::ping(),
|
||||||
|
tools::posix(),
|
||||||
|
tools::qr(),
|
||||||
|
tools::register(),
|
||||||
|
tools::taf(),
|
||||||
|
tools::uptime(),
|
||||||
|
tools::verse(),
|
||||||
|
tools::weather(),
|
||||||
];
|
];
|
||||||
|
|
||||||
let options = poise::FrameworkOptions {
|
let options = poise::FrameworkOptions {
|
||||||
@@ -95,7 +115,10 @@ async fn main() {
|
|||||||
skip_checks_for_owners: false,
|
skip_checks_for_owners: false,
|
||||||
event_handler: |_ctx, event, _framework, _data| {
|
event_handler: |_ctx, event, _framework, _data| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
info!("Got an event in event handler: {:?}", event.snake_case_name());
|
info!(
|
||||||
|
"Got an event in event handler: {:?}",
|
||||||
|
event.snake_case_name()
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -103,11 +126,20 @@ async fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let framework = poise::Framework::builder()
|
let framework = poise::Framework::builder()
|
||||||
.setup(move |ctx, ready, _framework| {
|
.setup(move |ctx, ready, framework| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
info!("{} [{}] connected successfully!", ready.user.name, ready.user.id);
|
info!(
|
||||||
|
"{} [{}] connected successfully!",
|
||||||
|
ready.user.name, ready.user.id
|
||||||
|
);
|
||||||
ctx.set_activity(Some(ActivityData::listening(prefix + "help")));
|
ctx.set_activity(Some(ActivityData::listening(prefix + "help")));
|
||||||
// poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
// poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||||
|
poise::builtins::register_in_guild(
|
||||||
|
ctx,
|
||||||
|
&framework.options().commands,
|
||||||
|
512680330495524873.into(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(Data {})
|
Ok(Data {})
|
||||||
})
|
})
|
||||||
@@ -115,7 +147,8 @@ async fn main() {
|
|||||||
.options(options)
|
.options(options)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let intents = serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
|
let intents =
|
||||||
|
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
|
||||||
|
|
||||||
let mut client = serenity::ClientBuilder::new(token, intents)
|
let mut client = serenity::ClientBuilder::new(token, intents)
|
||||||
.framework(framework)
|
.framework(framework)
|
||||||
|
|||||||
Submodule src/spotify deleted from ea246e9ed2
Reference in New Issue
Block a user