cmds func fin v1
This commit is contained in:
parent
d6f1b81796
commit
d7c64b3c65
@ -2,7 +2,8 @@
|
|||||||
"versions":[
|
"versions":[
|
||||||
{"file": "main.sql", "version": 1},
|
{"file": "main.sql", "version": 1},
|
||||||
{"file": "20180628-1.sql", "version": 2},
|
{"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": []
|
"test": []
|
||||||
}
|
}
|
@ -375,10 +375,15 @@ const delTwitch = async (txt = '', source = {}, db) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hello = async () => {
|
||||||
|
return 'Hello World'
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addgroup: run.bind(null, addGroup),
|
addgroup: run.bind(null, addGroup),
|
||||||
addpage: run.bind(null, addPage),
|
addpage: run.bind(null, addPage),
|
||||||
delpage: run.bind(null, delPage),
|
delpage: run.bind(null, delPage),
|
||||||
addtwitch: run.bind(null, addTwitch),
|
addtwitch: run.bind(null, addTwitch),
|
||||||
deltwitch: run.bind(null, delTwitch)
|
deltwitch: run.bind(null, delTwitch),
|
||||||
|
hello: run.bind(null, hello)
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,14 @@ const parseCMD = async (text = '', source = {}) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let result = await db.query({
|
let result = await db.query({
|
||||||
text: `select "message" from "public"."commands" where "cmd" = $1`,
|
text: `select "message", "group" from "public"."commands" where "cmd" = $1 and ("group" = '' or "group" = $2)`,
|
||||||
values: [cmd]
|
values: [cmd, source.groupId]
|
||||||
})
|
})
|
||||||
if (result.rowCount > 0) {
|
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)
|
let m = content.match(/{{(.+?)}}/g)
|
||||||
if (m !== null && m.length > 0) {
|
if (m !== null && m.length > 0) {
|
||||||
for (let i = 0; i < m.length; i++) {
|
for (let i = 0; i < m.length; i++) {
|
||||||
|
19
schema/20180702-1.sql
Normal file
19
schema/20180702-1.sql
Normal file
@ -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(), '');
|
Loading…
Reference in New Issue
Block a user