Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ utility.hasHooks = (message) => {
for(let i=0; i<utility.hooks.length; i++) {
let hook = utility.hooks[i];

if (typeof hook.keyword === "undefined" || hook.keyword == message.text) {
const keywordMatch = typeof hook.keyword === "undefined" || hook.keyword == message.text;
const prefixMatch = typeof hook.prefix === "undefined" || (typeof message.text === "string" && message.text.startsWith(hook.prefix));
if (keywordMatch && prefixMatch) {
if (!utility.users[message.user]) continue;

if (hook.user) {
Expand Down
5 changes: 5 additions & 0 deletions test/settings_sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ hooks:
user: hideack
cron: "58 23 * * *"
hook: cron test
-
user: hideack
channel: times_hideack
prefix: "!deploy"
hook: echo DEPLOY
logging:
file: ./logs
sqlite: ./logs/slack.db
Expand Down
12 changes: 11 additions & 1 deletion test/util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe("設定ファイル読み込みのテスト", () => {
});

it("複数のhook定義が入っていること(但しhookの定義がないものは除外される)", () => {
assert.equal(util.hooks.length, 4, "4件分の定義が存在すること");
assert.equal(util.hooks.length, 5, "5件分の定義が存在すること");
});

it("1件目の定義に必要な設定が読み取られていること", () => {
Expand Down Expand Up @@ -144,6 +144,16 @@ describe("設定ファイル読み込みのテスト", () => {
let message = {type: 'message', channel: 'XXEGEXXS0', user: 'XX3NKUBXX', text: 'slack', ts: '1563587208.0006',source_team: 'XXYGLB4ZZ', team: 'ZZ3GLB4XX' };
assert.deepEqual(util.hasHooks(message), ["echo HOGE"], "userが一致したためhookさせるコマンドが1つ返る");
});

it("prefixが一致したらhookさせるコマンドが返ること", () => {
let message = {type: 'message', channel: 'XXEGEXXS0', user: 'XX3NKUBXX', text: '!deploy production', ts: '1563587208.0006', source_team: 'XXYGLB4ZZ', team: 'ZZ3GLB4XX' };
assert.include(util.hasHooks(message), "echo DEPLOY", "prefixが一致したためhookさせるコマンドが返る");
});

it("prefixが一致しない場合はhookが反応しないこと", () => {
let message = {type: 'message', channel: 'XXEGEXXS0', user: 'XX3NKUBXX', text: 'hello world', ts: '1563587208.0006', source_team: 'XXYGLB4ZZ', team: 'ZZ3GLB4XX' };
assert.notInclude(util.hasHooks(message), "echo DEPLOY", "prefixが一致しないためhookが反応しない");
});
});
});

Expand Down
Loading