2018-11-15 14:10:27 +00:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
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;
|
|
|
|
extern crate serde_json;
|
2018-08-13 16:45:49 +00:00
|
|
|
extern crate typemap;
|
|
|
|
|
2018-11-14 14:29:58 +00:00
|
|
|
mod player;
|
2018-08-13 16:45:49 +00:00
|
|
|
|
2019-07-12 08:39:03 +00:00
|
|
|
use serenity::{
|
|
|
|
framework::standard::{
|
|
|
|
help_commands,
|
|
|
|
macros::{check, command, group, help},
|
|
|
|
Args, CheckResult, CommandGroup, CommandOptions, CommandResult, DispatchError, HelpOptions,
|
|
|
|
StandardFramework,
|
|
|
|
},
|
|
|
|
model::{
|
|
|
|
channel::{Channel, Message},
|
|
|
|
gateway::Ready,
|
|
|
|
id::UserId,
|
|
|
|
},
|
|
|
|
utils::{content_safe, ContentSafeOptions},
|
|
|
|
};
|
|
|
|
|
|
|
|
// This imports `typemap`'s `Key` as `TypeMapKey`.
|
|
|
|
use serenity::prelude::*;
|
|
|
|
|
2018-08-13 16:45:49 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2018-11-14 14:29:58 +00:00
|
|
|
use player::prelude::*;
|
2019-07-12 12:41:51 +00:00
|
|
|
use std::collections::HashSet;
|
2018-08-13 16:45:49 +00:00
|
|
|
|
2019-09-14 14:34:00 +00:00
|
|
|
use utilities::prelude::*;
|
|
|
|
|
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(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 08:39:03 +00:00
|
|
|
group!({
|
|
|
|
name: "general",
|
|
|
|
options: {},
|
2019-07-12 12:41:51 +00:00
|
|
|
commands: [ip, list, pause, play, remove, skip, stop]
|
2019-07-12 08:39:03 +00:00
|
|
|
});
|
|
|
|
|
2019-09-14 14:34:00 +00:00
|
|
|
fn main() -> VerboseResult<()> {
|
2018-08-13 16:45:49 +00:00
|
|
|
// read config file
|
2019-09-14 14:34:00 +00:00
|
|
|
let config_file = ConfigHandler::read_config("bot.conf")?;
|
2018-08-15 17:32:44 +00:00
|
|
|
|
|
|
|
let mut config = Config::default();
|
|
|
|
|
|
|
|
match config_file.get("Meta") {
|
|
|
|
Some(info) => {
|
|
|
|
match info.get("token") {
|
|
|
|
Some(token_pair) => {
|
2019-09-14 14:34:00 +00:00
|
|
|
token_pair.set_value(&mut config.token)?;
|
2018-08-15 17:32:44 +00:00
|
|
|
}
|
|
|
|
None => {
|
2019-09-14 14:34:00 +00:00
|
|
|
create_error!("couldn't find token inside meta section");
|
2018-08-15 17:32:44 +00:00
|
|
|
}
|
2018-08-13 16:45:49 +00:00
|
|
|
}
|
2018-08-15 17:32:44 +00:00
|
|
|
match info.get("prefix") {
|
|
|
|
Some(prefix_pair) => {
|
2019-09-14 14:34:00 +00:00
|
|
|
prefix_pair.set_value(&mut config.prefix)?;
|
2018-08-15 17:32:44 +00:00
|
|
|
}
|
|
|
|
None => {
|
2019-09-14 14:34:00 +00:00
|
|
|
create_error!("couldn't find prefix inside meta section");
|
2018-08-15 17:32:44 +00:00
|
|
|
}
|
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 => {
|
2019-09-14 14:34:00 +00:00
|
|
|
create_error!("couldn't find Meta section in config file");
|
2018-08-13 16:45:49 +00:00
|
|
|
}
|
|
|
|
};
|
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.
|
|
|
|
{
|
2019-07-12 08:39:03 +00:00
|
|
|
let mut data = client.data.write();
|
2019-09-14 14:34:00 +00:00
|
|
|
data.insert::<Media>(
|
|
|
|
MediaData::new("Penis1", Arc::clone(&client.voice_manager))
|
|
|
|
.expect("failed to create media data handle"),
|
|
|
|
);
|
2018-08-13 16:45:49 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 12:41:51 +00:00
|
|
|
// We will fetch your bot's owners and id
|
|
|
|
let (owners, bot_id) = match client.cache_and_http.http.get_current_application_info() {
|
|
|
|
Ok(info) => {
|
|
|
|
let mut owners = HashSet::new();
|
|
|
|
owners.insert(info.owner.id);
|
|
|
|
|
|
|
|
(owners, info.id)
|
|
|
|
}
|
|
|
|
Err(why) => panic!("Could not access application info: {:?}", why),
|
|
|
|
};
|
|
|
|
|
|
|
|
client.with_framework(
|
|
|
|
// Configures the client, allowing for options to mutate how the
|
|
|
|
// framework functions.
|
|
|
|
//
|
|
|
|
// Refer to the documentation for
|
|
|
|
// `serenity::ext::framework::Configuration` for all available
|
|
|
|
// configurations.
|
|
|
|
StandardFramework::new()
|
|
|
|
.configure(|c| {
|
|
|
|
c.with_whitespace(true)
|
|
|
|
.on_mention(Some(bot_id))
|
|
|
|
.prefix(&config.prefix)
|
|
|
|
.owners(owners)
|
|
|
|
})
|
|
|
|
.group(&GENERAL_GROUP),
|
|
|
|
);
|
2018-08-14 16:42:53 +00:00
|
|
|
|
2019-07-12 08:39:03 +00:00
|
|
|
/*
|
|
|
|
|
2018-08-14 16:42:53 +00:00
|
|
|
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(),
|
2018-11-21 08:58:06 +00:00
|
|
|
"remove".to_string(),
|
2018-11-14 12:03:06 +00:00
|
|
|
"ip".to_string(),
|
2018-08-15 17:32:44 +00:00
|
|
|
],
|
|
|
|
),
|
2019-04-03 09:42: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()))
|
2018-11-21 08:58:06 +00:00
|
|
|
.cmd("ip", IP::new())
|
|
|
|
.cmd("remove", Remove::new(media_data.clone())),
|
2018-08-14 16:42:53 +00:00
|
|
|
);
|
2019-07-12 12:41:51 +00:00
|
|
|
*/
|
2018-08-14 16:42:53 +00:00
|
|
|
|
|
|
|
let _ = client
|
|
|
|
.start()
|
|
|
|
.map_err(|why| println!("Client ended: {:?}", why));
|
2019-09-14 14:34:00 +00:00
|
|
|
|
|
|
|
Ok(())
|
2018-08-13 16:45:49 +00:00
|
|
|
}
|