2018-08-14 16:42:53 +00:00
|
|
|
extern crate serenity;
|
2018-08-13 16:45:49 +00:00
|
|
|
|
2018-08-14 16:42:53 +00:00
|
|
|
extern crate parking_lot;
|
2018-11-14 15:43:53 +00:00
|
|
|
extern crate rand;
|
2018-08-14 16:42:53 +00:00
|
|
|
extern crate serde_json;
|
2018-08-13 16:45:49 +00:00
|
|
|
extern crate typemap;
|
|
|
|
|
2018-08-14 17:08:13 +00:00
|
|
|
mod confighandler;
|
|
|
|
mod macros;
|
2018-11-14 14:29:58 +00:00
|
|
|
mod player;
|
2018-08-13 16:45:49 +00:00
|
|
|
|
2018-11-14 14:29:58 +00:00
|
|
|
use serenity::client::Client;
|
2018-08-13 16:45:49 +00:00
|
|
|
use serenity::framework::StandardFramework;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2018-08-14 17:08:13 +00:00
|
|
|
use confighandler::*;
|
2018-11-14 14:29:58 +00:00
|
|
|
use player::prelude::*;
|
2018-08-13 16:45:49 +00:00
|
|
|
|
2018-08-15 17:32:44 +00:00
|
|
|
struct Config {
|
|
|
|
token: String,
|
|
|
|
prefix: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Config {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
token: String::new(),
|
|
|
|
prefix: String::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 16:45:49 +00:00
|
|
|
fn main() {
|
|
|
|
// read config file
|
2018-08-15 17:32:44 +00:00
|
|
|
let config_file = check_result_return!(read_config("bot.conf"));
|
|
|
|
|
|
|
|
let mut config = Config::default();
|
|
|
|
|
|
|
|
match config_file.get("Meta") {
|
|
|
|
Some(info) => {
|
|
|
|
match info.get("token") {
|
|
|
|
Some(token_pair) => {
|
|
|
|
display_error!(token_pair.set_value(&mut config.token));
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
println!("couldn't find token inside meta section");
|
|
|
|
return;
|
|
|
|
}
|
2018-08-13 16:45:49 +00:00
|
|
|
}
|
2018-08-15 17:32:44 +00:00
|
|
|
match info.get("prefix") {
|
|
|
|
Some(prefix_pair) => {
|
|
|
|
display_error!(prefix_pair.set_value(&mut config.prefix));
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
println!("couldn't find prefix inside meta section");
|
|
|
|
return;
|
|
|
|
}
|
2018-08-13 16:45:49 +00:00
|
|
|
}
|
2018-08-15 17:32:44 +00:00
|
|
|
}
|
2018-08-13 16:45:49 +00:00
|
|
|
None => {
|
|
|
|
println!("couldn't find Meta section in config file");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2018-08-14 16:42:53 +00:00
|
|
|
|
2018-08-15 17:32:44 +00:00
|
|
|
let mut client = Client::new(&config.token, Handler).expect("Err creating client");
|
2018-08-13 16:45:49 +00:00
|
|
|
|
|
|
|
// Obtain a lock to the data owned by the client, and insert the client's
|
|
|
|
// voice manager into it. This allows the voice manager to be accessible by
|
|
|
|
// event handlers and framework commands.
|
|
|
|
{
|
|
|
|
let mut data = client.data.lock();
|
|
|
|
data.insert::<VoiceManager>(Arc::clone(&client.voice_manager));
|
|
|
|
}
|
|
|
|
|
2018-08-14 16:42:53 +00:00
|
|
|
let media_data = Arc::new(MediaData::default());
|
|
|
|
|
|
|
|
client.with_framework(
|
|
|
|
StandardFramework::new()
|
2018-08-15 17:32:44 +00:00
|
|
|
.configure(|c| c.prefix(&config.prefix).on_mention(true))
|
2018-08-14 16:42:53 +00:00
|
|
|
.cmd("play", Play::new(media_data.clone()))
|
|
|
|
.cmd("pause", Pause::new(media_data.clone()))
|
2018-08-15 17:32:44 +00:00
|
|
|
.cmd(
|
|
|
|
"help",
|
|
|
|
Help::new(
|
|
|
|
&config.prefix,
|
|
|
|
vec![
|
|
|
|
"play".to_string(),
|
|
|
|
"pause".to_string(),
|
|
|
|
"stop".to_string(),
|
|
|
|
"help".to_string(),
|
|
|
|
"list".to_string(),
|
2018-11-14 12:03:06 +00:00
|
|
|
"skip".to_string(),
|
|
|
|
"ip".to_string(),
|
2018-08-15 17:32:44 +00:00
|
|
|
],
|
|
|
|
),
|
2018-11-14 12:03:06 +00:00
|
|
|
).cmd("stop", Stop::new(media_data.clone()))
|
2018-09-16 08:25:57 +00:00
|
|
|
.cmd("list", List::new(media_data.clone()))
|
2018-11-14 12:03:06 +00:00
|
|
|
.cmd("skip", Skip::new(media_data.clone()))
|
|
|
|
.cmd("ip", IP::new()),
|
2018-08-14 16:42:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
let _ = client
|
|
|
|
.start()
|
|
|
|
.map_err(|why| println!("Client ended: {:?}", why));
|
2018-08-13 16:45:49 +00:00
|
|
|
}
|