Make prefix static; add shout command

This commit is contained in:
Sakuhl 2018-01-22 14:56:37 +01:00
parent 37c670ea3b
commit 57bfb7d997
6 changed files with 124 additions and 48 deletions

34
Cargo.lock generated
View File

@ -17,7 +17,7 @@ dependencies = [
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -605,7 +605,7 @@ dependencies = [
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -690,7 +690,7 @@ dependencies = [
[[package]]
name = "reqwest"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytes 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -698,7 +698,7 @@ dependencies = [
"hyper 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libflate 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 2.0.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)",
"native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
@ -727,7 +727,7 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -916,7 +916,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1080,11 +1080,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.3"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1094,12 +1094,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -1117,7 +1117,7 @@ version = "0.1.0"
source = "git+https://gitlab.com/Sakuhl/wynncraft#8b3427867d7867f7333e15f5375c5555524062b9"
dependencies = [
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1130,7 +1130,7 @@ dependencies = [
"diesel 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1219,7 +1219,7 @@ dependencies = [
"checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1"
"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
"checksum relay 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f301bafeb60867c85170031bdb2fcf24c8041f33aee09e7b116a58d4e9f781c5"
"checksum reqwest 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3161ca63fd11ce36c7718af239e6492a25a3dbfcec54240f959b9d816cf42413"
"checksum reqwest 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8080379de728e9bf2be6bd5b52348978a5525e7d4a25f106ce73953fe7e810d9"
"checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e"
"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
"checksum schannel 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "acece75e0f987c48863a6c792ec8b7d6c4177d4a027f8ccc72f849794f437016"
@ -1266,9 +1266,9 @@ dependencies = [
"checksum vec_shift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc05c2b00a487511056141401ac10b15c0fb7422154dda53d1c610c228c3e08e"
"checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b09fb3b6f248ea4cd42c9a65113a847d612e17505d6ebd1f7357ad68a8bf8693"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
"checksum winapi-i686-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ec6667f60c23eca65c561e63a13d81b44234c2e38a6b6c959025ee907ec614cc"
"checksum winapi-x86_64-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98f12c52b2630cd05d2c3ffd8e008f7f48252c042b4871c72aed9dc733b96668"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
"checksum wynncraft 0.1.0 (git+https://gitlab.com/Sakuhl/wynncraft)" = "<none>"

View File

@ -10,7 +10,7 @@ reqwest = "0.8.1"
serde = "1.0.24"
serde_derive = "1.0.24"
serde_json = "1.0.8"
serenity = "0.4.5"
serenity = { version = "0.4.5", features = [] }
[dependencies.diesel]
features = ["postgres"]

View File

@ -12,8 +12,8 @@ use failure::Error;
use ::ResponseError;
pub fn wc_guild(msg: &Message) -> Result<(), Error> {
let guild_name = &msg.content[9..];
pub fn wc_guild(command: &str, msg: &Message) -> Result<(), Error> {
let guild_name = &command[6..];
let guild;
if guild_name.len() <= 3 {
@ -111,8 +111,8 @@ fn guild_by_prefix(prefix: &str) -> Result<Option<String>, Error> {
Ok(None)
}
pub fn wc_topguilds(msg: &Message) -> Result<(), Error> {
let limit: usize = msg.content[13..].parse().unwrap();
pub fn wc_topguilds(command: &str, msg: &Message) -> Result<(), Error> {
let limit: usize = command[10..].parse().unwrap();
wc_topguilds_limit(msg, limit)
}

View File

@ -35,8 +35,8 @@ pub fn wc_status(msg: &Message) -> Result<(), Error> {
Ok(())
}
pub fn wc_territory(msg: &Message) -> Result<(), Error> {
let territory = &msg.content[13..];
pub fn wc_territory(command: &str, msg: &Message) -> Result<(), Error> {
let territory = &command[10..];
let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=territoryList")?.text().unwrap();
@ -81,8 +81,8 @@ Servers: {}", env!("CARGO_PKG_VERSION"), guilds))?;
Ok(())
}
pub fn wc_crop(msg: &Message) -> Result<(), Error> {
let url = &msg.content[8..];
pub fn wc_crop(command: &str, msg: &Message) -> Result<(), Error> {
let url = &command[5..];
let new_url = reqwest::get(&format!("https://wynncraft-autocrop.herokuapp.com/crop?url={}", url))?.text().unwrap();
if new_url.starts_with("https://i.imgur.com") {
msg.channel_id.say(&new_url)?;
@ -105,5 +105,72 @@ pub fn wc_crop_discord_upload(msg: &Message) -> Result<(), Error> {
}
}
Ok(())
}
pub fn wc_shout(command: &str, msg: &Message) -> Result<(), Error> {
let shout = &command[6..];
for guild_id in serenity::http::get_current_user().unwrap().guilds().unwrap() {
println!("Showing {:?}", guild_id.name);
let mut wynnbots = vec![];
let mut botchannels = vec![];
let mut bots = vec![];
let mut general = vec![];
let mut others = vec![];
for (channel_id, channel) in Guild::get(&guild_id).unwrap().channels().unwrap() {
if channel.kind != ChannelType::Text {
continue;
}
if channel.name.contains("wynnbot") {
//println!("{:?}: {:?}", channel_id, channel);
wynnbots.push(channel);
continue;
}
if channel.name.contains("bot-channel") || channel.name.contains("bot_channel") {
//println!("{:?}: {:?}", channel_id, channel);
botchannels.push(channel);
continue;
}
if channel.name.contains("bot") {
//println!("{:?}: {:?}", channel_id, channel);
bots.push(channel);
continue;
}
if channel.name == "general" {
//println!("{:?}: {:?}", channel_id, channel);
general.push(channel);
continue;
}
others.push(channel);
}
/*
println!("{:?}\n{:?}\n{:?}\n{:?}\n{:?}",
wynnbots.into_iter().map(|x| x.name).collect::<Vec<_>>(),
botchannels.into_iter().map(|x| x.name).collect::<Vec<_>>(),
bots.into_iter().map(|x| x.name).collect::<Vec<_>>(),
general.into_iter().map(|x| x.name).collect::<Vec<_>>(),
others.into_iter().map(|x| x.name).collect::<Vec<_>>()
);
*/
wynnbots.extend(botchannels);
wynnbots.extend(bots);
wynnbots.extend(general);
wynnbots.extend(others);
for channel in &wynnbots {
println!("posting in {:?}", channel.name);
/*
if guild_id.name != "WynnBot" {
println!("jk im not");
break;
}
*/
//println!("doing it");
if let Ok(_) = channel.say(shout) {
println!("success!");
break;
}
}
}
msg.channel_id.say("Success!")?;
Ok(())
}

View File

@ -4,8 +4,8 @@ use serenity::model::*;
use failure::Error;
pub fn wc_player(msg: &Message) -> Result<(), Error> {
let player = &msg.content[10..];
pub fn wc_player(command: &str, msg: &Message) -> Result<(), Error> {
let player = &command[7..];
let player = wynncraft::player(player)?;

View File

@ -27,7 +27,9 @@ mod schema;
mod commands;
use commands::*;
// change these for production
const ENABLE_FEEDS: bool = true;
const PREFIX: &'static str = "wc!";
#[derive(Debug, Fail)]
pub enum ResponseError {
@ -79,37 +81,44 @@ impl EventHandler for Handler {
impl Handler {
fn process_message(&self, msg: &Message) -> Result<(), Error> {
if !msg.content.starts_with("wc!") {
if !msg.content.starts_with(PREFIX) {
return Ok(());
}
if msg.content.starts_with("wc!guild ") {
wc_guild(msg)?;
} else if msg.content == "wc!topguilds" {
let command = &msg.content[PREFIX.len()..];
if command.starts_with("guild ") {
wc_guild(command, msg)?;
} else if command == "topguilds" {
wc_topguilds_limit(msg, 10)?;
} else if msg.content.starts_with("wc!topguilds ") {
wc_topguilds(msg)?;
} else if msg.content.starts_with("wc!territory ") {
wc_territory(msg)?;
} else if msg.content == "wc!status" {
} else if command.starts_with("topguilds ") {
wc_topguilds(command, msg)?;
} else if command.starts_with("territory ") {
wc_territory(command, msg)?;
} else if command == "status" {
wc_status(msg)?;
} else if msg.content.starts_with("wc!player ") {
wc_player(msg)?;
} else if msg.content == "wc!livefeed" {
} else if command.starts_with("player ") {
wc_player(command, msg)?;
} else if command == "livefeed" {
wc_livefeed(msg)?;
} else if msg.content == "wc!unlivefeed" {
} else if command == "unlivefeed" {
wc_unlivefeed(msg)?;
} else if msg.content == "wc!info" || msg.content == "wc!help" || msg.content == "wc!" {
} else if command == "info" || command == "help" || command == "" {
wc_info(msg)?;
} else if msg.content.starts_with("wc!crop ") {
wc_crop(msg)?;
} else if msg.content == "wc!crop" {
} else if command.starts_with("crop ") {
wc_crop(command, msg)?;
} else if command == "crop" {
wc_crop_discord_upload(msg)?;
} else if msg.content == "wc!warfeed" {
} else if command == "warfeed" {
wc_warfeed(msg)?;
} else if msg.content == "wc!unwarfeed" {
} else if command == "unwarfeed" {
wc_unwarfeed(msg)?;
} else if command.starts_with("shout") {
if msg.author.name == "Wurst" && msg.author.discriminator == 1783 {
wc_shout(command, msg)?;
} else {
"<@210743594061922306>".parse::<User>().unwrap().dm(|f| f.content(format!("{} tried to shout {:?}", msg.author, &command[6..]))).unwrap();
}
} else {
bail!(ResponseError::UnknownCommand { name: msg.content[3..].to_owned() });
bail!(ResponseError::UnknownCommand { name: command.to_owned() });
}
return Ok(());
}