diff --git a/bin/dbVersion.json b/bin/dbVersion.json index 3f237c9..ec4ccb4 100644 --- a/bin/dbVersion.json +++ b/bin/dbVersion.json @@ -2,7 +2,8 @@ "versions":[ {"file": "main.sql", "version": 1}, {"file": "20180628-1.sql", "version": 2}, - {"file": "20180628-2.sql", "version": 3} + {"file": "20180628-2.sql", "version": 3}, + {"file": "20180702-1.sql", "version": 4} ], "test": [] } \ No newline at end of file diff --git a/libs/line-message/commands/actions/group.js b/libs/line-message/commands/actions/group.js index e71faaf..bd158f6 100644 --- a/libs/line-message/commands/actions/group.js +++ b/libs/line-message/commands/actions/group.js @@ -375,10 +375,15 @@ const delTwitch = async (txt = '', source = {}, db) => { } } +const hello = async () => { + return 'Hello World' +} + module.exports = { addgroup: run.bind(null, addGroup), addpage: run.bind(null, addPage), delpage: run.bind(null, delPage), addtwitch: run.bind(null, addTwitch), - deltwitch: run.bind(null, delTwitch) + deltwitch: run.bind(null, delTwitch), + hello: run.bind(null, hello) } diff --git a/libs/line-message/commands/index.js b/libs/line-message/commands/index.js index 97d1201..9f765a9 100644 --- a/libs/line-message/commands/index.js +++ b/libs/line-message/commands/index.js @@ -15,11 +15,14 @@ const parseCMD = async (text = '', source = {}) => { try { let result = await db.query({ - text: `select "message" from "public"."commands" where "cmd" = $1`, - values: [cmd] + text: `select "message", "group" from "public"."commands" where "cmd" = $1 and ("group" = '' or "group" = $2)`, + values: [cmd, source.groupId] }) if (result.rowCount > 0) { - let content = result.rows[0].message + let obj = result.rows.filter(t => t.group === source.groupId) + if (obj.length === 0) obj = result.rows[0] + else obj = obj[0] + let content = obj.message let m = content.match(/{{(.+?)}}/g) if (m !== null && m.length > 0) { for (let i = 0; i < m.length; i++) { diff --git a/schema/20180702-1.sql b/schema/20180702-1.sql new file mode 100644 index 0000000..4f9a93a --- /dev/null +++ b/schema/20180702-1.sql @@ -0,0 +1,19 @@ +-- auto-generated definition +create table "public"."commands" +( + cmd varchar(200) not null + constraint commands_pkey + primary key, + message varchar(300) default '' :: character varying not null, + ctime timestamp with time zone default CURRENT_TIMESTAMP not null, + mtime timestamp with time zone default CURRENT_TIMESTAMP not null, + "group" varchar(100) default '' :: character varying not null +); + +insert into "public"."commands" ("cmd", "message", "ctime", "mtime", "group") values +('addgroup', '{{addgroup}}', now(), now(), ''), +('addpage', '{{addpage}}', now(), now(), ''), +('delpage', '{{delpage}}', now(), now(), ''), +('addtwitch', '{{addtwitch}}', now(), now(), ''), +('deltwitch', '{{deltwitch}}', now(), now(), ''), +('hello', '{{hello}}', now(), now(), ''); \ No newline at end of file