|
|
|
@ -37,7 +37,7 @@ enum NameOrId {
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
struct ResponseCommandInput {
|
|
|
|
|
hero: Option<NameOrId>,
|
|
|
|
|
message_id: Option<usize>,
|
|
|
|
|
response_id: Option<usize>,
|
|
|
|
|
processed_text: String,
|
|
|
|
|
}
|
|
|
|
|
impl ResponseCommandInput {
|
|
|
|
@ -45,7 +45,7 @@ impl ResponseCommandInput {
|
|
|
|
|
input: &str,
|
|
|
|
|
) -> core::result::Result<Self, core::num::ParseIntError> {
|
|
|
|
|
let mut hero = None;
|
|
|
|
|
let mut message_id = None;
|
|
|
|
|
let mut response_id = None;
|
|
|
|
|
let mut pieces = Vec::new();
|
|
|
|
|
|
|
|
|
|
let words = input.split_whitespace();
|
|
|
|
@ -65,9 +65,9 @@ impl ResponseCommandInput {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(id) = word.strip_prefix("@message_id:") {
|
|
|
|
|
if let Some(id) = word.strip_prefix("@response_id:") {
|
|
|
|
|
let id: usize = id.parse()?;
|
|
|
|
|
message_id = Some(id);
|
|
|
|
|
response_id = Some(id);
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -80,7 +80,7 @@ impl ResponseCommandInput {
|
|
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
|
hero,
|
|
|
|
|
message_id,
|
|
|
|
|
response_id,
|
|
|
|
|
processed_text,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
@ -121,7 +121,7 @@ fn choose_response(
|
|
|
|
|
r.map_err(Error::from)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
match (&input.message_id, &input.hero) {
|
|
|
|
|
match (&input.response_id, &input.hero) {
|
|
|
|
|
(Some(id), _) => {
|
|
|
|
|
let mut stmt = conn.prepare(
|
|
|
|
|
r"
|
|
|
|
@ -359,12 +359,12 @@ async fn handle_response_autocomplete(
|
|
|
|
|
|
|
|
|
|
let suggestions: Vec<Suggestion> = {
|
|
|
|
|
let map_row = |r: &Row| -> rusqlite::Result<Suggestion> {
|
|
|
|
|
let message_id = responses::Id(r.get(0)?);
|
|
|
|
|
let response_id = responses::Id(r.get(0)?);
|
|
|
|
|
let original_text = responses::OriginalTextOwned(r.get(1)?);
|
|
|
|
|
let hero_name = heroes::NameOwned(r.get(2)?);
|
|
|
|
|
|
|
|
|
|
let name = format!("{}: {}", hero_name.0, original_text.0);
|
|
|
|
|
let value = format!("@message_id:{}", message_id.0);
|
|
|
|
|
let value = format!("@response_id:{}", response_id.0);
|
|
|
|
|
|
|
|
|
|
let name = name[0..min(100, name.len())].to_string();
|
|
|
|
|
let value = value[0..min(100, value.len())].to_string();
|
|
|
|
@ -376,7 +376,7 @@ async fn handle_response_autocomplete(
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let conn = conn.lock().unwrap();
|
|
|
|
|
match (&input.message_id, &input.hero) {
|
|
|
|
|
match (&input.response_id, &input.hero) {
|
|
|
|
|
(Some(id), _) => {
|
|
|
|
|
let mut stmt = conn.prepare(
|
|
|
|
|
r"
|
|
|
|
|