mirror of
https://github.com/osmarks/autobotrobot
synced 2025-01-05 05:10:26 +00:00
stuff
This commit is contained in:
parent
90a5fce01e
commit
a2718a2442
34
src/main.rs
34
src/main.rs
@ -8,7 +8,6 @@ extern crate regex;
|
|||||||
use serenity::client::{Client, EventHandler};
|
use serenity::client::{Client, EventHandler};
|
||||||
use serenity::framework::standard::{StandardFramework, help_commands};
|
use serenity::framework::standard::{StandardFramework, help_commands};
|
||||||
use serenity::model::{channel::Message, id::ChannelId};
|
use serenity::model::{channel::Message, id::ChannelId};
|
||||||
use serenity::utils::Colour;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
@ -83,11 +82,24 @@ command!(eval_polish(_context, message, args) {
|
|||||||
|
|
||||||
command!(exec(_context, message) {
|
command!(exec(_context, message) {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref RE: Regex = Regex::new("^.*exec.*```(.*)\n(.*)```").unwrap();
|
static ref RE: Regex = Regex::new("(?s)^.*exec.*```([a-zA-Z0-9_\\-+]+)\n(.+)\n```").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{:?}", &message.content);
|
let captures = match RE.captures(&message.content) {
|
||||||
println!("{:?}", RE.captures(&message.content));
|
Some(x) => x,
|
||||||
|
// Presumably just returning the Result from send_error should work, but it doesn't.
|
||||||
|
None => {
|
||||||
|
send_error(&message.channel_id, r#"Invalid format; expected a codeblock with a language set."#)?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let code = &captures[2];
|
||||||
|
let lang = &captures[1];
|
||||||
|
|
||||||
|
match lang {
|
||||||
|
_ => send_error(&message.channel_id, &format!("Unknown language `{}`.", lang))?
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// BELOW THIS LINE BE DRAGONS
|
// BELOW THIS LINE BE DRAGONS
|
||||||
@ -161,12 +173,14 @@ command!(search(_context, message, args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ddg::Type::Exclusive => send_search_result(channel, SearchResult {
|
ddg::Type::Exclusive => {
|
||||||
title: query,
|
send_search_result(channel, SearchResult {
|
||||||
text: String::from("[see link]"),
|
title: query,
|
||||||
image: None,
|
text: result.redirect.clone(),
|
||||||
url: Some(result.abstract_url)
|
image: None,
|
||||||
})?,
|
url: Some(result.redirect)
|
||||||
|
})?
|
||||||
|
},
|
||||||
ddg::Type::Nothing => send_error(channel, "No results.")?,
|
ddg::Type::Nothing => send_error(channel, "No results.")?,
|
||||||
other => send_error(channel, &format!("{:?} - unrecognized result type", other))?
|
other => send_error(channel, &format!("{:?} - unrecognized result type", other))?
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user