modify key command
This commit is contained in:
parent
8b75f41d55
commit
5755b465cb
@ -75,7 +75,7 @@ const parseCMD = async (text = '', source = {}) => {
|
||||
for (let i of obj) {
|
||||
txt += (txt.length > 0 ? '|' : '') + i.key
|
||||
}
|
||||
regex = new RegExp(`(${txt})`)
|
||||
regex = new RegExp(`^(${txt})$`)
|
||||
console.log(regex)
|
||||
let m = text.match(regex)
|
||||
console.log('match :::: ', m)
|
||||
|
@ -9,7 +9,11 @@ const api = require('@libs/api-action')
|
||||
const textMessage = async (evt) => {
|
||||
let {replyToken, source, message, type} = evt
|
||||
if (type === 'leave' && 'groupId' in source && 'type' in source && source.type === 'group') {
|
||||
await leaveGroup(source.groupId)
|
||||
try {
|
||||
await leaveGroup(source.groupId)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (!source || !('type' in source) || source.type !== 'group') return
|
||||
@ -28,7 +32,69 @@ const textMessage = async (evt) => {
|
||||
}
|
||||
|
||||
const leaveGroup = async (group = '') => {
|
||||
|
||||
if (typeof group !== 'string' || group.trim().length === 0) return
|
||||
let db = await DB.connect()
|
||||
let gData = await db.query({
|
||||
text: `select * from "public"."line_group" where "id" = $1`,
|
||||
values: [group]
|
||||
})
|
||||
if (gData.rowCount === 0) {
|
||||
db.release()
|
||||
return
|
||||
}
|
||||
try {
|
||||
await db.query({
|
||||
text: `delete from "public"."commands" where "group" = $1`,
|
||||
values: [group]
|
||||
})
|
||||
await db.query({
|
||||
text: `delete from "public"."key_commands" where "group" = $1`,
|
||||
values: [group]
|
||||
})
|
||||
await db.query({
|
||||
text: `delete from "public"."line_fb_rt" where "line" = $1`,
|
||||
values: [group]
|
||||
})
|
||||
await db.query({
|
||||
text: `delete from "public"."line_twitch_rt" where "line" = $1`,
|
||||
values: [group]
|
||||
})
|
||||
await db.query({
|
||||
text: `delete from "public"."line_youtube_rt" where "line" = $1`,
|
||||
values: [group]
|
||||
})
|
||||
await db.query({
|
||||
text: `delete from "public"."twitch_channel" where "id" in (
|
||||
select ch."id" from "public"."twitch_channel" ch
|
||||
left join "line_twitch_rt" rt
|
||||
on rt."twitch" = ch."id"
|
||||
where rt."twitch" is null
|
||||
)`
|
||||
})
|
||||
await db.query({
|
||||
text: `delete from "public"."facebook_page" where "id" in (
|
||||
select ch."id" from "public"."facebook_page" ch
|
||||
left join "line_fb_rt" rt
|
||||
on rt."twitch" = ch."id"
|
||||
where rt."twitch" is null
|
||||
)`
|
||||
})
|
||||
await db.query({
|
||||
text: `delete from "public"."youtube_channel" where "id" in (
|
||||
select ch."id" from "public"."youtube_channel" ch
|
||||
left join "line_youtube_rt" rt
|
||||
on rt."twitch" = ch."id"
|
||||
where rt."twitch" is null
|
||||
)`
|
||||
})
|
||||
await db.query({
|
||||
text: `delete from "public"."line_group" where "id" = $1`,
|
||||
values: [group]
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
db.release()
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Loading…
Reference in New Issue
Block a user