add youtube
This commit is contained in:
@@ -375,6 +375,74 @@ const delTwitch = async (txt = '', source = {}, db) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add youtube channel notify to group
|
||||
* @param {string} txt command body format => youtube tmpl
|
||||
* @param {object} source
|
||||
* @param {object} db
|
||||
*/
|
||||
const addYoutube = async (txt = '', source = {}, db) => {
|
||||
if (!db) return null
|
||||
if (!('type' in source) || !('groupId' in source) || !('userId' in source)) return null
|
||||
let {groupId, userId} = source
|
||||
let arr = txt.split(' ')
|
||||
if (arr.length < 2) return null
|
||||
let id = arr[0]
|
||||
let tmpl = arr.slice(1).join(' ')
|
||||
let text = `select "id","owner" from "public"."line_group" where "id" = $1`
|
||||
let values = [groupId]
|
||||
let result = await db.query({
|
||||
text,
|
||||
values
|
||||
})
|
||||
if (result.rowCount === 0) {
|
||||
let reply = 'group not register'
|
||||
return { reply }
|
||||
}
|
||||
if (result.rows[0].owner !== userId) {
|
||||
let reply = 'not owner'
|
||||
return { reply }
|
||||
}
|
||||
|
||||
let youtubeName = await api.google.queryYoutubeName(id)
|
||||
if (youtubeName === null) return null
|
||||
|
||||
text = `select "id" from "public"."youtube_channel" where "id" = $1`
|
||||
values = [id]
|
||||
let ytch = await db.query({
|
||||
text,
|
||||
values
|
||||
})
|
||||
|
||||
if (ytch.rowCount === 0) {
|
||||
let text = `insert into "public"."youtube_channel" ("id", "name", "lastvideo", "expire", "ctime", "mtime") values
|
||||
($1, $2, '', -1, now(), now())`
|
||||
let values = [id, youtubeName]
|
||||
await db.query({
|
||||
text, values
|
||||
})
|
||||
text = `insert into "public"."line_youtube_rt" ("line", "youtube", "tmpl") values ($1, $2, $3)`
|
||||
values = [groupId, id, tmpl]
|
||||
await db.query({
|
||||
text, values
|
||||
})
|
||||
} else {
|
||||
let text = `insert into "public"."line_youtube_rt" ("line", "youtube", "tmpl") values ($1, $2, $3)`
|
||||
let values = [groupId, id, tmpl]
|
||||
await db.query({
|
||||
text, values
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
await api.google.subYoutube(id)
|
||||
} catch (err) {}
|
||||
|
||||
return {
|
||||
reply: 'add youtube channel success'
|
||||
}
|
||||
}
|
||||
|
||||
const hello = async () => {
|
||||
return 'Hello World'
|
||||
}
|
||||
@@ -385,5 +453,6 @@ module.exports = {
|
||||
delpage: run.bind(null, delPage),
|
||||
addtwitch: run.bind(null, addTwitch),
|
||||
deltwitch: run.bind(null, delTwitch),
|
||||
addyoutube: run.bind(null, addYoutube),
|
||||
hello: run.bind(null, hello)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user