feat: do todos
This commit is contained in:
parent
fb14a6f9a0
commit
e5dd0206ca
4 changed files with 59 additions and 53 deletions
32
README.md
32
README.md
|
|
@ -13,8 +13,7 @@ Clone this repository with `git clone --recursive https://git.sad.ovh/sophie/cop
|
||||||
- Lots of generic MPP bot features such as following, moving between rooms, et cetera
|
- Lots of generic MPP bot features such as following, moving between rooms, et cetera
|
||||||
|
|
||||||
## Todo
|
## Todo
|
||||||
- Playlist has hardcoded Playlist
|
- No todo :3
|
||||||
- Get rid of all mentions of files.sad.ovh as it's my copyparty server, and make it customizable to other servers.
|
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
1. Requirements: Rust Nightly, should be automatically used when you do cargo run.
|
1. Requirements: Rust Nightly, should be automatically used when you do cargo run.
|
||||||
|
|
@ -24,10 +23,39 @@ Clone this repository with `git clone --recursive https://git.sad.ovh/sophie/cop
|
||||||
database {
|
database {
|
||||||
url: "postgres://user:pass@ip:port/database"
|
url: "postgres://user:pass@ip:port/database"
|
||||||
}
|
}
|
||||||
|
|
||||||
commands {
|
commands {
|
||||||
prefix: "r"
|
prefix: "r"
|
||||||
name: "Copper"
|
name: "Copper"
|
||||||
|
|
||||||
|
copyparty: "https://files.sad.ovh/public/midis"
|
||||||
|
|
||||||
|
playlists {
|
||||||
|
chill_music: [
|
||||||
|
"https://files.sad.ovh/public/midis/A/autumn_leaves2-G85.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/B/blue_bossa-kenny-dorham_dz.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/J/Jobim_Desafinado.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/J/Jobim_Wave.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/J/Jobim_corcovado.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/I/ipanema.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/J/Jobim_Meditacao2.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/S/so_what.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/T/take_five2-Gb176-davebrubeck.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/M/My_Funny_Valentine.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/A/all_the_things_you_are-2_dm.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/J/Johnny_Mathis_Misty.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/H/HOWARD.Fly me to the moon.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/R/Ray Charles - Georgia On My Mind.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/B/blue_in_green.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/S/Stella-By-Starlight-1.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/F/FITZGERALD.Summertime K.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/M/Moon River.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/A/autumn_in_new_york2-Bb84.mid",
|
||||||
|
"https://files.sad.ovh/public/midis/J/Jobim_One_Note_Samba.mid",
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client {
|
client {
|
||||||
token: "token"
|
token: "token"
|
||||||
ws: "wss://mppclone.com"
|
ws: "wss://mppclone.com"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::Configuration;
|
||||||
use crate::client::Client;
|
use crate::client::Client;
|
||||||
use crate::client::ClientEvent;
|
use crate::client::ClientEvent;
|
||||||
use crate::client::Note;
|
use crate::client::Note;
|
||||||
|
|
@ -17,11 +18,12 @@ use tokio::sync::Mutex;
|
||||||
|
|
||||||
pub struct PlayCommand {
|
pub struct PlayCommand {
|
||||||
midi_state: Arc<Mutex<MidiState>>,
|
midi_state: Arc<Mutex<MidiState>>,
|
||||||
|
conf: Configuration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlayCommand {
|
impl PlayCommand {
|
||||||
pub fn new(midi_state: Arc<Mutex<MidiState>>) -> Self {
|
pub fn new(midi_state: Arc<Mutex<MidiState>>, conf: Configuration) -> Self {
|
||||||
Self { midi_state }
|
Self { midi_state, conf }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,7 +182,7 @@ impl Command for PlayCommand {
|
||||||
filename_to_play = format!("midis/{}.mid", hashed);
|
filename_to_play = format!("midis/{}.mid", hashed);
|
||||||
filename_beautiful = first_capture.to_string();
|
filename_beautiful = first_capture.to_string();
|
||||||
|
|
||||||
let url = format!("https://files.sad.ovh/public/midis/{}", first_capture);
|
let url = format!("{}/{}", self.conf.commands.copyparty, first_capture);
|
||||||
|
|
||||||
let file_exists = tokio::fs::try_exists(&filename_to_play)
|
let file_exists = tokio::fs::try_exists(&filename_to_play)
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use crate::client::Client;
|
||||||
use crate::client::ClientEvent;
|
use crate::client::ClientEvent;
|
||||||
use crate::client::Player;
|
use crate::client::Player;
|
||||||
|
|
||||||
|
use crate::Configuration;
|
||||||
use crate::commands::Command;
|
use crate::commands::Command;
|
||||||
use crate::commands::MidiState;
|
use crate::commands::MidiState;
|
||||||
use crate::commands::argument::{ArgumentSpec, ArgumentType, ParsedArgument, ParsedArguments};
|
use crate::commands::argument::{ArgumentSpec, ArgumentType, ParsedArgument, ParsedArguments};
|
||||||
|
|
@ -15,11 +16,12 @@ use tokio::sync::Mutex;
|
||||||
|
|
||||||
pub struct PlaylistCommand {
|
pub struct PlaylistCommand {
|
||||||
midi_state: Arc<Mutex<MidiState>>,
|
midi_state: Arc<Mutex<MidiState>>,
|
||||||
|
conf: Configuration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlaylistCommand {
|
impl PlaylistCommand {
|
||||||
pub fn new(midi_state: Arc<Mutex<MidiState>>) -> Self {
|
pub fn new(midi_state: Arc<Mutex<MidiState>>, conf: Configuration) -> Self {
|
||||||
Self { midi_state }
|
Self { midi_state, conf }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,50 +61,20 @@ impl Command for PlaylistCommand {
|
||||||
let mut filename_to_play: String = "".to_string();
|
let mut filename_to_play: String = "".to_string();
|
||||||
let mut filename_beautiful: String = "".to_string();
|
let mut filename_beautiful: String = "".to_string();
|
||||||
|
|
||||||
if joined_args == "playlist_1" {
|
if self.conf.commands.playlists.contains_key(joined_args) {
|
||||||
const TRACKS: &[&str] = &[
|
let tracks_ref = self.conf.commands.playlists.get(joined_args).unwrap();
|
||||||
"A/autumn_leaves2-G85.mid",
|
for track in tracks_ref {
|
||||||
"B/blue_bossa-kenny-dorham_dz.mid",
|
|
||||||
"J/Jobim_Desafinado.mid",
|
|
||||||
"J/Jobim_Wave.mid",
|
|
||||||
"J/Jobim_corcovado.mid",
|
|
||||||
"I/ipanema.mid",
|
|
||||||
"J/Jobim_Meditacao2.mid",
|
|
||||||
"S/so_what.mid",
|
|
||||||
"T/take_five2-Gb176-davebrubeck.mid",
|
|
||||||
"M/My_Funny_Valentine.mid",
|
|
||||||
"A/all_the_things_you_are-2_dm.mid",
|
|
||||||
"J/Johnny_Mathis_Misty.mid",
|
|
||||||
"H/HOWARD.Fly me to the moon.mid",
|
|
||||||
"R/Ray Charles - Georgia On My Mind.mid",
|
|
||||||
"B/blue_in_green.mid",
|
|
||||||
"S/Stella-By-Starlight-1.mid",
|
|
||||||
"F/FITZGERALD.Summertime K.mid",
|
|
||||||
"M/Moon River.mid",
|
|
||||||
"A/autumn_in_new_york2-Bb84.mid",
|
|
||||||
"J/Jobim_One_Note_Samba.mid",
|
|
||||||
];
|
|
||||||
|
|
||||||
for track in TRACKS {
|
|
||||||
let hashed = simple_hash(track);
|
let hashed = simple_hash(track);
|
||||||
let filename = format!("midis/{}.mid", hashed);
|
let filename = format!("midis/{}.mid", hashed);
|
||||||
let url = format!("https://files.sad.ovh/public/midis/{}", track);
|
|
||||||
|
|
||||||
let file_exists = tokio::fs::try_exists(&filename).await.unwrap_or(false);
|
let file_exists = tokio::fs::try_exists(&filename).await.unwrap_or(false);
|
||||||
if !file_exists {
|
if !file_exists {
|
||||||
match reqwest::get(&url).await {
|
match reqwest::get(&track.clone()).await {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
if resp.status().is_success() {
|
if resp.status().is_success() {
|
||||||
match resp.bytes().await {
|
match resp.bytes().await {
|
||||||
Ok(bytes) => match tokio::fs::write(&filename, &bytes).await {
|
Ok(bytes) => match tokio::fs::write(&filename, &bytes).await {
|
||||||
Ok(_) => {
|
Ok(_) => {}
|
||||||
client
|
|
||||||
.message(format!(
|
|
||||||
"Downloaded midi from files.sad.ovh: {}",
|
|
||||||
track
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
client
|
client
|
||||||
.message(format!("Failed to write file: {}", e))
|
.message(format!("Failed to write file: {}", e))
|
||||||
|
|
@ -137,7 +109,7 @@ impl Command for PlaylistCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut tracks: Vec<&str> = TRACKS.to_vec();
|
let mut tracks = tracks_ref.clone();
|
||||||
tracks.shuffle(&mut rand::rng());
|
tracks.shuffle(&mut rand::rng());
|
||||||
|
|
||||||
if let Some(first) = tracks.first() {
|
if let Some(first) = tracks.first() {
|
||||||
|
|
@ -175,7 +147,7 @@ impl Command for PlaylistCommand {
|
||||||
let first_capture = caps.trim();
|
let first_capture = caps.trim();
|
||||||
|
|
||||||
if first_capture.ends_with('/') {
|
if first_capture.ends_with('/') {
|
||||||
let url = format!("https://files.sad.ovh/public/midis/{}?ls", first_capture);
|
let url = format!("{}/{}?ls", self.conf.commands.copyparty, first_capture);
|
||||||
match reqwest::get(&url).await {
|
match reqwest::get(&url).await {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
if resp.status().is_success() {
|
if resp.status().is_success() {
|
||||||
|
|
@ -209,8 +181,8 @@ impl Command for PlaylistCommand {
|
||||||
let hashed = simple_hash(&file_path);
|
let hashed = simple_hash(&file_path);
|
||||||
let filename = format!("midis/{}.mid", hashed);
|
let filename = format!("midis/{}.mid", hashed);
|
||||||
let url_file = format!(
|
let url_file = format!(
|
||||||
"https://files.sad.ovh/public/midis/{}",
|
"{}/{}",
|
||||||
file_path
|
self.conf.commands.copyparty, file_path
|
||||||
);
|
);
|
||||||
|
|
||||||
let file_exists = tokio::fs::try_exists(&filename)
|
let file_exists = tokio::fs::try_exists(&filename)
|
||||||
|
|
|
||||||
18
src/main.rs
18
src/main.rs
|
|
@ -15,6 +15,8 @@ use crate::client::Client;
|
||||||
use crate::client::ClientEvent;
|
use crate::client::ClientEvent;
|
||||||
use crate::commands::Arguments;
|
use crate::commands::Arguments;
|
||||||
use crate::commands::CommandRegistry;
|
use crate::commands::CommandRegistry;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use cap::Cap;
|
use cap::Cap;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::postgres::PgPoolOptions;
|
use sqlx::postgres::PgPoolOptions;
|
||||||
|
|
@ -46,25 +48,27 @@ macro_rules! register_all {
|
||||||
)+
|
)+
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, Clone)]
|
||||||
struct Configuration {
|
pub struct Configuration {
|
||||||
database: DatabaseConfig,
|
database: DatabaseConfig,
|
||||||
commands: CommandsConfig,
|
commands: CommandsConfig,
|
||||||
client: ClientConfig,
|
client: ClientConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, Clone)]
|
||||||
struct DatabaseConfig {
|
struct DatabaseConfig {
|
||||||
url: String,
|
url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, Clone)]
|
||||||
struct CommandsConfig {
|
struct CommandsConfig {
|
||||||
prefix: String,
|
prefix: String,
|
||||||
name: String,
|
name: String,
|
||||||
|
copyparty: String,
|
||||||
|
playlists: HashMap<String, Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, Clone)]
|
||||||
struct ClientConfig {
|
struct ClientConfig {
|
||||||
token: String,
|
token: String,
|
||||||
ws: String,
|
ws: String,
|
||||||
|
|
@ -98,9 +102,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
registry,
|
registry,
|
||||||
client,
|
client,
|
||||||
[
|
[
|
||||||
PlayCommand::new(midi_state.clone()),
|
PlayCommand::new(midi_state.clone(), conf.clone()),
|
||||||
StopCommand::new(midi_state.clone()),
|
StopCommand::new(midi_state.clone()),
|
||||||
PlaylistCommand::new(midi_state.clone()),
|
PlaylistCommand::new(midi_state.clone(), conf.clone()),
|
||||||
QueueCommand::new(midi_state.clone()),
|
QueueCommand::new(midi_state.clone()),
|
||||||
SkipCommand::new(midi_state),
|
SkipCommand::new(midi_state),
|
||||||
LaunchCommand,
|
LaunchCommand,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue