add module-alias , add image message

This commit is contained in:
Jay 2018-07-13 13:30:54 +08:00
parent 4c56ff4300
commit e1ad83566b
16 changed files with 51 additions and 20 deletions

View File

@ -6,7 +6,8 @@
{"file": "20180702-1.sql", "version": 4},
{"file": "20180706-1.sql", "version": 5},
{"file": "20180710-1.sql", "version": 6},
{"file": "20180711-1.sql", "version": 7}
{"file": "20180711-1.sql", "version": 7},
{"file": "20180712-1.sql", "version": 8}
],
"test": []
}

View File

@ -1,6 +1,7 @@
/* eslint-disable no-unused-expressions */
require('module-alias/register')
const pg = require('pg')
const config = require('../config')
const config = require('@config/index')
const path = require('path')
const fs = require('fs')

View File

@ -1,3 +1,4 @@
require('module-alias/register')
const fs = require('fs')
const path = require('path')
try {

11
jsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"@libs/*": ["libs/*"],
"@config/*": ["config/*"],
"@route/*": ["route/*"]
}
}
}

View File

@ -1,5 +1,5 @@
const axios = require('axios')
const config = require('../../config')
const config = require('@config/index')
const qs = require('querystring')
const queryYoutubeName = async (id = '') => {

View File

@ -1,5 +1,5 @@
const axios = require('axios')
const config = require('../../config')
const config = require('@config/index')
const client = axios.create({
baseURL: 'https://api.line.me/v2/bot',
@ -44,6 +44,16 @@ const textObject = (txt = '') => {
}
}
const imageObject = (txt = '') => {
if (typeof txt !== 'string' || txt.trim().length === 0) return null
txt = txt.split(';')
return {
type: 'image',
originalContentUrl: txt[0],
previewImageUrl: txt[1]
}
}
/**
* send reply message
* @param {string} replyToken line message reply token
@ -59,6 +69,7 @@ const replyMessage = async (replyToken, message) => {
if (m !== null && m.length > 1) {
switch (m[1]) {
case 'image':
obj = imageObject(message)
break
case 'text':
obj = textObject(message)

View File

@ -1,5 +1,5 @@
const axios = require('axios')
const config = require('../../config')
const config = require('@config/index')
const client = axios.create({
baseURL: 'https://api.twitch.tv/helix',
headers: {

View File

@ -1,5 +1,5 @@
const pg = require('pg')
const config = require('../config')
const config = require('@config/index')
const pool = new pg.Pool({
user: config.database.user,

View File

@ -1,5 +1,5 @@
const api = require('../../../api-action')
const DB = require('../../../database')
const api = require('@libs/api-action')
const DB = require('@libs/database')
const axios = require('axios')
async function run (fn = null, txt, source) {

View File

@ -1,4 +1,4 @@
const DB = require('../../database')
const DB = require('@libs/database')
const actions = require('./actions')
const parseCMD = async (text = '', source = {}) => {

View File

@ -1,5 +1,5 @@
const commands = require('./commands')
const api = require('../api-action')
const api = require('@libs/api-action')
/**
* parse text message object

View File

@ -1,4 +1,4 @@
const config = require('../../config')
const config = require('@config/index')
const rawBody = require('raw-body')
const crypto = require('crypto')

View File

@ -21,6 +21,7 @@
"koa-body": "^4.0.3",
"koa-logger": "^3.2.0",
"koa-router": "^7.4.0",
"module-alias": "^2.1.0",
"pg": "^7.4.3",
"raw-body": "^2.3.3",
"request": "^2.87.0",
@ -28,5 +29,10 @@
},
"devDependencies": {
"standard": "^11.0.1"
},
"_moduleAliases": {
"@libs": "libs",
"@config": "config",
"@route": "route"
}
}

View File

@ -4,9 +4,9 @@ const r = new Router()
// const koaBody = require('koa-body')
const {
getRaw
} = require('../../libs/middleware')
const api = require('../../libs/api-action')
const DB = require('../../libs/database')
} = require('@libs/middleware')
const api = require('@libs/api-action')
const DB = require('@libs/database')
r.get('/youtube/webhook', async (c, n) => {
let db = await DB.connect()

View File

@ -4,10 +4,10 @@ const r = new Router()
const {
verifyLine,
getRaw
} = require('../../libs/middleware')
} = require('@libs/middleware')
const {
textMessage
} = require('../../libs/line-message')
} = require('@libs/line-message')
r.post('/', getRaw, verifyLine, async (c, n) => {
console.log(JSON.stringify(c.request.body, null, 2))

View File

@ -2,9 +2,9 @@ const Router = require('koa-router')
const r = new Router()
const {
getRaw
} = require('../../libs/middleware')
const DB = require('../../libs/database')
const api = require('../../libs/api-action')
} = require('@libs/middleware')
const DB = require('@libs/database')
const api = require('@libs/api-action')
// const config = require('../../config')
r.get('/webhook', async (c, n) => {