gatewayd: strip a leading mention of this bot; recognise approval commands
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
use gatewayd::mm::Post;
|
||||
use gatewayd::sessions::{
|
||||
BUSY, Batch, Ignored, M4B_COMMAND, Message, Pushed, Queues, Route, Router, Thread,
|
||||
ApprovalCommand, BUSY, Batch, Ignored, Message, Pushed, Queues, Route, Router, Thread,
|
||||
UNKNOWN_COMMAND, named,
|
||||
};
|
||||
use proto::SessionId;
|
||||
@@ -185,7 +185,7 @@ fn sessions_and_threads() {
|
||||
assert!(reply.resume);
|
||||
let channel = queued(r.route(&post(SHARED, "", "@boxmaker-straylight hi"), "O", &unknown));
|
||||
assert!(channel.joins_thread && !channel.resume);
|
||||
assert_eq!(channel.text, "@boxmaker-straylight hi");
|
||||
assert_eq!(channel.text, "hi", "the leading mention is stripped (M4b)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -195,21 +195,37 @@ fn commands() {
|
||||
channel: DM.to_string(),
|
||||
root: ROOT.to_string(),
|
||||
};
|
||||
let reply = |text: &str| Route::Reply {
|
||||
thread: thread.clone(),
|
||||
text: text.to_string(),
|
||||
};
|
||||
for (message, answer) in [
|
||||
("!approve 42", M4B_COMMAND),
|
||||
("!deny 42 not now", M4B_COMMAND),
|
||||
("!deny", M4B_COMMAND),
|
||||
("!approved", UNKNOWN_COMMAND),
|
||||
("!help", UNKNOWN_COMMAND),
|
||||
("!", UNKNOWN_COMMAND),
|
||||
for (message, command) in [
|
||||
("!approve 42", ApprovalCommand::Approve(42)),
|
||||
(
|
||||
"!deny 42 not now",
|
||||
ApprovalCommand::Deny(42, Some("not now".to_string())),
|
||||
),
|
||||
("!deny", ApprovalCommand::Malformed),
|
||||
(
|
||||
"@boxmaker-straylight !approve 7",
|
||||
ApprovalCommand::Approve(7),
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
r.route(&post(DM, ROOT, message), "D", &unknown),
|
||||
reply(answer),
|
||||
Route::Approval {
|
||||
thread: thread.clone(),
|
||||
command,
|
||||
user: KYLE.to_string(),
|
||||
post: POST.to_string(),
|
||||
at: 5,
|
||||
},
|
||||
"{message}"
|
||||
);
|
||||
}
|
||||
for message in ["!approved", "!help", "!"] {
|
||||
assert_eq!(
|
||||
r.route(&post(DM, ROOT, message), "D", &unknown),
|
||||
Route::Reply {
|
||||
thread: thread.clone(),
|
||||
text: UNKNOWN_COMMAND.to_string(),
|
||||
},
|
||||
"{message}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user