Compare commits

...

29 Commits

Author SHA1 Message Date
Jay
c07a1a8c9f add new route
All checks were successful
continuous-integration/drone/push Build is passing
2021-06-21 22:18:13 +08:00
Jay
08e0607a88 fix nil pointer
All checks were successful
continuous-integration/drone/push Build is passing
2021-02-22 11:03:17 +08:00
Jay
01c9402eac fix missing dep
All checks were successful
continuous-integration/drone/push Build is passing
2021-02-22 10:59:31 +08:00
Jay
4758bdb437 add logger
Some checks failed
continuous-integration/drone/push Build is failing
2021-02-22 10:52:03 +08:00
Jay Chen
27274019da add log 2019-06-25 20:56:52 +08:00
d6f4d8d0b1 add new sql 2019-06-25 17:02:50 +08:00
8c432b9b68 add pre group one bot setting 2019-06-25 17:02:03 +08:00
Jay
c605b2d9e9 disable send data to es 2019-06-16 13:13:20 +00:00
f8e79ef9fa modify update user info time 2019-05-29 09:55:19 +08:00
d2dcbdff71 update line user name 2019-05-29 09:50:50 +08:00
93149fd39b remove not dep module 2019-05-28 11:25:45 +08:00
9ffbdfceca add es log 2019-05-28 11:17:22 +08:00
Jay
a7cb7cf8cf fix query 2019-05-22 23:25:25 +08:00
Jay
25892f83ae fix 2019-05-22 22:48:46 +08:00
Jay
c221b0528b update 2019-05-22 22:44:43 +08:00
Jay
83c262d502 add log 2019-05-22 22:44:05 +08:00
Jay
165c10d319 add log 2019-05-22 22:42:42 +08:00
Jay
7b160cc11f add submodule 2019-05-22 22:38:52 +08:00
Jay
50e9738f61 fix ci config 2019-05-22 22:37:48 +08:00
Jay
00e996311c add trigger 2019-05-22 22:37:22 +08:00
Jay
22c3746cb0 modify 2019-05-22 22:36:10 +08:00
Jay
1bbae8e57d edit 2019-05-22 22:33:34 +08:00
Jay
20a80e5c0f edit ci 2019-05-22 22:31:34 +08:00
Jay
a758da6a6f update schema 2019-05-22 22:26:12 +08:00
Jay
426bb0fea8 add instagram api and schema 2019-05-22 22:25:09 +08:00
Jay
d7d5ace2c0 更新 'README.md' 2019-05-03 13:34:49 +00:00
Jay
43cbb6e603 add log 2019-04-03 22:52:24 +08:00
Jay
c986453dca fix docker build error 2019-04-01 09:20:25 +00:00
Jay
4077e19f34 fix sql 2019-04-01 07:33:06 +00:00
31 changed files with 556 additions and 145 deletions

View File

@ -1,9 +1,24 @@
pipeline:
docker:
kind: pipeline
name: build
clone:
depth: 50
steps:
- name: submodules
image: plugins/git
commands:
- git submodule update --recursive --remote --init
- ls schema
- ls
- name: docker
image: plugins/docker
registry: docker.mtfos.xyz
repo: docker.mtfos.xyz/mtfos/go-bot
dockerfile: Dockerfile
tags: [latest, "${DRONE_COMMIT}"]
when:
branch: master
settings:
registry: docker.mtfos.xyz
repo: docker.mtfos.xyz/mtfos/go-bot
dockerfile: Dockerfile
tags: [latest, "${DRONE_COMMIT}"]
trigger:
branch:
- master

View File

@ -1,14 +1,13 @@
FROM golang:1.12.1-alpine as builder
WORKDIR /go/src/git.trj.tw/golang/mtfosbot
RUN apk add --no-cache make git \
&& go get -u github.com/otakukaze/go-bindata/...
WORKDIR /data
RUN apk add --no-cache make git
COPY . .
RUN make
FROM alpine:latest
RUN apk add --no-cache ca-certificates
WORKDIR /data
COPY --from=builder /go/src/git.trj.tw/golang/mtfosbot/mtfosbot /usr/bin
COPY --from=builder /data/mtfosbot /usr/bin
COPY config.default.yml config.yml
EXPOSE 10230
CMD ["/usr/bin/mtfosbot", "-f", "/data/config.yml", "-dbtool"]

View File

@ -2,6 +2,7 @@
.PHONY: clean build
build:
GO111MODULE=off go get -u github.com/go-bindata/go-bindata/...
go-bindata -pkg schema -ignore .git -o module/schema/static.go schema/
GOOS=linux go build -o mtfosbot -ldflags "-s -w" .

View File

@ -1,2 +1,3 @@
### MTFoS Bot
[![Build Status](https://ci.trj.tw/api/badges/golang/mtfosbot/status.svg)](https://ci.trj.tw/golang/mtfosbot)

View File

@ -25,5 +25,7 @@ redis:
host: 'localhost'
port: 6379
elasticsearch:
username: ''
password: ''
host: 'http://localhost:9200'
index: 'mtfosbot'

36
go.mod
View File

@ -1,36 +1,32 @@
module git.trj.tw/golang/mtfosbot
go 1.16
require (
github.com/DeanThompson/ginpprof v0.0.0-20170218162546-8c0e31bfeaa8
github.com/DeanThompson/ginpprof v0.0.0-20190408063150-3be636683586
github.com/PuerkitoBio/goquery v1.5.0
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/gin-contrib/cors v0.0.0-20190301062745-f9e10995c85a
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 // indirect
github.com/gin-gonic/contrib v0.0.0-20190302003538-54ff787f7c73
github.com/gin-gonic/gin v1.3.0
github.com/gin-contrib/cors v1.3.0
github.com/gin-gonic/contrib v0.0.0-20190526021735-7fb7810ed2a0
github.com/gin-gonic/gin v1.4.0
github.com/go-irc/irc v2.1.0+incompatible
github.com/go-sql-driver/mysql v1.4.1 // indirect
github.com/golang/protobuf v1.3.1 // indirect
github.com/google/go-cmp v0.2.0 // indirect
github.com/google/go-cmp v0.3.0 // indirect
github.com/gorilla/sessions v1.1.3 // indirect
github.com/jmoiron/sqlx v1.2.0
github.com/json-iterator/go v1.1.6
github.com/kr/pretty v0.1.0 // indirect
github.com/lib/pq v1.0.0
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe // indirect
github.com/mattn/go-isatty v0.0.7 // indirect
github.com/lib/pq v1.1.1
github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/olivere/elastic v6.2.16+incompatible
github.com/olivere/elastic v6.2.18+incompatible
github.com/pkg/errors v0.8.1 // indirect
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967
github.com/stretchr/testify v1.3.0 // indirect
github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780 // indirect
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c
golang.org/x/net v0.0.0-20190328230028-74de082e2cca // indirect
golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65 // indirect
google.golang.org/appengine v1.5.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
github.com/robfig/cron v1.1.0
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 // indirect
golang.org/x/sys v0.0.0-20190528012530-adf421d2caf4 // indirect
google.golang.org/appengine v1.6.0 // indirect
gopkg.in/yaml.v2 v2.2.2
)

81
go.sum
View File

@ -1,5 +1,5 @@
github.com/DeanThompson/ginpprof v0.0.0-20170218162546-8c0e31bfeaa8 h1:ciyrUaonhkfoqjGNUKzRVvpkugE+afQ7HKU2umHvANo=
github.com/DeanThompson/ginpprof v0.0.0-20170218162546-8c0e31bfeaa8/go.mod h1:kMi/fSDAgvjo9TYfYwYeQ2vkyj+VTR/tB6u/Tjh39t0=
github.com/DeanThompson/ginpprof v0.0.0-20190408063150-3be636683586 h1:vDSj8WQZoe+dhK9JVwkSEBwtmcJw5rJ7l1L0Yik8Ku0=
github.com/DeanThompson/ginpprof v0.0.0-20190408063150-3be636683586/go.mod h1:kMi/fSDAgvjo9TYfYwYeQ2vkyj+VTR/tB6u/Tjh39t0=
github.com/PuerkitoBio/goquery v1.5.0 h1:uGvmFXOA73IKluu/F84Xd1tt/z07GYm8X49XKHP7EJk=
github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg=
github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o=
@ -11,30 +11,26 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/gin-contrib/cors v0.0.0-20190301062745-f9e10995c85a h1:zBycVvXa03SIX+jdMv8wGu9TMDMWdN8EhaR1FoeKHNo=
github.com/gin-contrib/cors v0.0.0-20190301062745-f9e10995c85a/go.mod h1:pL2kNE+DgDU+eQ+dary5bX0Z6LPP8nR6Mqs1iejILw4=
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 h1:AzN37oI0cOS+cougNAV9szl6CVoj2RYwzS3DpUQNtlY=
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
github.com/gin-contrib/cors v1.3.0 h1:PolezCc89peu+NgkIWt9OB01Kbzt6IP0J/JvkG6xxlg=
github.com/gin-contrib/cors v1.3.0/go.mod h1:artPvLlhkF7oG06nK8v3U8TNz6IeX+w1uzCSEId5/Vc=
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g=
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
github.com/gin-gonic/contrib v0.0.0-20190302003538-54ff787f7c73 h1:dC6mPFx+I6Kkj/NJhI/ZVGVapv0u9tIEo6vp4ogXEjQ=
github.com/gin-gonic/contrib v0.0.0-20190302003538-54ff787f7c73/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg=
github.com/gin-gonic/gin v1.3.0 h1:kCmZyPklC0gVdL728E6Aj20uYBJV93nj/TkwBTKhFbs=
github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y=
github.com/gin-gonic/contrib v0.0.0-20190526021735-7fb7810ed2a0 h1:R0oj52DmXWiPxZEedx/Uxxbvs6yB0l8hLgrubGpKsq4=
github.com/gin-gonic/contrib v0.0.0-20190526021735-7fb7810ed2a0/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg=
github.com/gin-gonic/gin v1.4.0 h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ=
github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
github.com/go-irc/irc v2.1.0+incompatible h1:pg7pMVq5OYQbqTxceByD/EN8VIsba7DtKn49rsCnG8Y=
github.com/go-irc/irc v2.1.0+incompatible/go.mod h1:jJILTRy8s/qOvusiKifAEfhQMVwft1ZwQaVJnnzmyX4=
github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
@ -44,8 +40,6 @@ github.com/gorilla/sessions v1.1.3 h1:uXoZdcdA5XdXF3QzuSlheVRUvjl+1rKY7zBXL68L9R
github.com/gorilla/sessions v1.1.3/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w=
github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@ -53,15 +47,14 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe h1:W/GaMY0y69G4cFlmsC6B9sbuo2fP8OFP1ABjt4kPz+w=
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 h1:wL11wNW7dhKIcRCHSm4sHKPWz0tt4mwBsVodG7+Xyqg=
github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/4=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
@ -71,44 +64,38 @@ github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/olivere/elastic v6.2.16+incompatible h1:+mQIHbkADkOgq9tFqnbyg7uNFVV6swGU07EoK1u0nEQ=
github.com/olivere/elastic v6.2.16+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8=
github.com/olivere/elastic v6.2.18+incompatible h1:sd4eZY7YExzuvTz4tpBAvWY6go/SZLMj5GKl9vZgtwM=
github.com/olivere/elastic v6.2.18+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 h1:x7xEyJDP7Hv3LVgvWhzioQqbC/KtuUhTigKlH/8ehhE=
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/robfig/cron v1.1.0 h1:jk4/Hud3TTdcrJgUOBgsqrZBarcxl6ADIjSC2iniwLY=
github.com/robfig/cron v1.1.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/ugorji/go v1.1.2 h1:JON3E2/GPW2iDNGoSAusl1KDf5TRQ8k8q7Tp097pZGs=
github.com/ugorji/go v1.1.2/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780 h1:vG/gY/PxA3v3l04qxe3tDjXyu3bozii8ulSlIPOYKhI=
github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780/go.mod h1:iT03XoTwV7xq/+UGwKO3UbC1nNNlopQiY61beSdrtOA=
github.com/ugorji/go v1.1.4 h1:j4s+tAvLfL3bZyefP2SEWmhBzmuIlH/eqNuPdFPgngw=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190328230028-74de082e2cca h1:hyA6yiAgbUwuWqtscNvWAI7U1CtlaD1KilQ6iudt1aI=
golang.org/x/net v0.0.0-20190328230028-74de082e2cca/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65 h1:hOY+O8MxdkPV10pNf7/XEHaySCiPKxixMKUshfHsGn0=
golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190528012530-adf421d2caf4 h1:gd52YanAQJ4UkvuNi/7z63JEyc6ejHh9QwdzbTiEtAY=
golang.org/x/sys v0.0.0-20190528012530-adf421d2caf4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
google.golang.org/appengine v1.6.0 h1:Tfd7cKwKbFRsI8RMAD3oqqw7JPFRrvFlOsfbgVkjOOw=
google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -78,6 +78,11 @@ func main() {
log.Fatal(errors.New("log image root not exists"))
}
// err = es.NewClient()
// if err != nil {
// log.Println("es create client error :: ", err)
// }
server.Run(strings.Join([]string{":", strconv.Itoa(config.GetConf().Port)}, ""))
}

View File

@ -40,7 +40,7 @@ func GetAccount(account string) (acc *Account, err error) {
// CreateAccount -
func CreateAccount(account, password string) (acc *Account, err error) {
acc = &Account{}
err = x.Get(acc, `insert into "public"."account" ("account", "password", "ctime", "mtime") values ($1, $2, now(), now())`, account, password)
err = x.Get(acc, `insert into "public"."account" ("account", "password", "ctime", "mtime") values ($1, $2, now(), now()) returning *`, account, password)
if err == sql.ErrNoRows {
return nil, nil
}

74
model/instagram.go Normal file
View File

@ -0,0 +1,74 @@
package model
import (
"database/sql"
"time"
)
type IGGroup struct {
*LineGroup
Tmpl string `db:"tmpl"`
}
//Instagram -
type Instagram struct {
ID string `db:"id" cc:"id"`
LastPost string `db:"lastpost" cc:"lastpost"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
Groups []*IGGroup `db:"-"`
}
// GetAllInstagram -
func GetAllInstagram() (igs []*Instagram, err error) {
err = x.Select(&igs, `select * from "public"."instagram"`)
if err != nil {
return nil, err
}
return
}
// GetInstagram -
func GetInstagram(id string) (ig *Instagram, err error) {
ig = &Instagram{}
err = x.Get(ig, `select * from "public"."instagram" where "id" = $1`, id)
if err == sql.ErrNoRows {
return nil, nil
}
return
}
// AddIG -
func (p *Instagram) AddIG() (err error) {
stmt, err := x.PrepareNamed(`insert into "public"."instagram" ("id", "lastpost") values (:id, :lastpost) returning *`)
if err != nil {
return err
}
err = stmt.Get(p, p)
return
}
// UpdatePost -
func (p *Instagram) UpdatePost(postID string) (err error) {
query := `update "public"."instagram" set "lastpost" = $1, "mtime" = now() where "id" = $2`
_, err = x.Exec(query, postID, p.ID)
if err != nil {
return
}
p.LastPost = postID
return
}
// GetGroups -
func (p *Instagram) GetGroups() (err error) {
query := `select g.*, rt.tmpl as tmpl from "public"."instagram" p
left join "public"."line_ig_rt" rt
on rt."ig" = p.id
left join "public"."line_group" g
on g.id = rt."line"
where
p.id = $1
and rt.ig is not null`
err = x.Select(&p.Groups, query, p.ID)
return
}

37
model/line_bot.go Normal file
View File

@ -0,0 +1,37 @@
package model
import (
"database/sql"
"errors"
"time"
)
// LineBot -
type LineBot struct {
ID string `db:"id" cc:"id"`
Name string `db:"name" cc:"name"`
AccessToken string `db:"access_token" cc:"access_token"`
Secret string `db:"secret" cc:"secret"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"mtime"`
}
// GetBotInfo -
func GetBotInfo(id string) (bot *LineBot, err error) {
if len(id) == 0 {
return nil, errors.New("id is emptu")
}
query := `select
"id", "name", "access_token", "secret", "ctime", "mtime"
from public."line_bot"
where
"id" = $1`
bot = &LineBot{}
err = x.Get(bot, query, id)
if err == sql.ErrNoRows {
return nil, nil
}
return
}

View File

@ -2,17 +2,19 @@ package model
import (
"database/sql"
"errors"
"time"
)
// LineGroup - struct
type LineGroup struct {
ID string `db:"id" cc:"id"`
Name string `db:"name" cc:"name"`
Notify bool `db:"notify" cc:"notify"`
Owner string `db:"owner" cc:"owner"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
ID string `db:"id" cc:"id"`
Name string `db:"name" cc:"name"`
Notify bool `db:"notify" cc:"notify"`
Owner string `db:"owner" cc:"owner"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
BotID sql.NullString `db:"bot_id" cc:"bot_id"`
}
// CheckGroup -
@ -75,3 +77,18 @@ func (p *LineGroup) DeleteGroup() (err error) {
_, err = x.Exec(`delete from "public"."line_group" where "id" = $1`, p.ID)
return
}
// GetBot - get group binding bot
func (p *LineGroup) GetBot() (bot *LineBot, err error) {
id, err := p.BotID.Value()
if err != nil {
return nil, err
}
var botid string
var ok bool
if botid, ok = id.(string); !ok {
return nil, errors.New("botid get fail")
}
bot, err = GetBotInfo(botid)
return
}

View File

@ -28,3 +28,9 @@ func (p *LineUser) Add() (err error) {
_, err = x.NamedExec(`insert into "public"."line_user" ("id", "name") values (:id, :name)`, p)
return
}
// UpdateName -
func (p *LineUser) UpdateName() (err error) {
_, err = x.NamedExec(`update "public"."line_user" set "name" = :name, "mtime" = now() where "id" = :id`, p)
return
}

View File

@ -19,6 +19,12 @@ type LineYoutubeRT struct {
Tmpl string `db:"tmpl" cc:"tmpl"`
}
type LineIGRT struct {
Line string `db:"line" cc:"line"`
IG string `db:"ig" cc:"ig"`
Tmpl string `db:"tmpl" cc:"tmpl"`
}
// AddRT - add facebook line rt
func (p *LineFacebookRT) AddRT() (err error) {
_, err = x.NamedExec(`insert into "public"."line_fb_rt" ("line", "facebook", "tmpl") values (:line, :facebook, :tmpl)`, p)
@ -64,3 +70,15 @@ func (p *LineYoutubeRT) DelRT() (err error) {
_, err = x.NamedExec(`delete from "public"."line_youtube_rt" where "line" = :line and "youtube" = :youtube`, p)
return
}
// AddRT -
func (p *LineIGRT) AddRT() (err error) {
_, err = x.NamedExec(`insert into "public"."line_ig_rt" ("line", "ig", "tmpl") values (:line, :ig, :tmpl)`, p)
return
}
// DelRT -
func (p *LineIGRT) DelRT() (err error) {
_, err = x.NamedExec(`delete from "public"."line_ig_rt" where "line" = :line and "ig" = :ig`, p)
return
}

View File

@ -13,7 +13,6 @@ import (
"strings"
"git.trj.tw/golang/mtfosbot/module/apis"
"git.trj.tw/golang/mtfosbot/module/config"
)
// TextMessage - line text message object
@ -66,11 +65,10 @@ func getURL(p string) (string, bool) {
return str, true
}
func getHeaders() map[string]string {
func getHeaders(token string) map[string]string {
m := make(map[string]string)
conf := config.GetConf()
m["Content-Type"] = "application/json"
m["Authorization"] = fmt.Sprintf("Bearer %s", conf.Line.Access)
m["Authorization"] = fmt.Sprintf("Bearer %s", token)
return m
}
@ -104,7 +102,7 @@ func checkMessageObject(m interface{}) interface{} {
}
// PushMessage -
func PushMessage(target string, message ...interface{}) {
func PushMessage(accessToken, target string, message ...interface{}) {
log.Println("push target :::: ", target)
if len(target) == 0 || len(message) == 0 {
return
@ -145,7 +143,7 @@ func PushMessage(target string, message ...interface{}) {
reqObj := apis.RequestObj{
Method: "POST",
URL: apiURL,
Headers: getHeaders(),
Headers: getHeaders(accessToken),
Body: byteReader,
}
@ -163,7 +161,7 @@ func PushMessage(target string, message ...interface{}) {
}
// ReplyMessage -
func ReplyMessage(replyToken string, message ...interface{}) {
func ReplyMessage(accessToken, replyToken string, message ...interface{}) {
if len(replyToken) == 0 || len(message) == 0 {
return
}
@ -201,7 +199,7 @@ func ReplyMessage(replyToken string, message ...interface{}) {
reqObj := apis.RequestObj{
Method: "POST",
URL: apiURL,
Headers: getHeaders(),
Headers: getHeaders(accessToken),
Body: byteReader,
}
@ -217,9 +215,9 @@ func ReplyMessage(replyToken string, message ...interface{}) {
}
// GetUserInfo -
func GetUserInfo(u, g string) (user *LineUserInfo, err error) {
func GetUserInfo(accessToken, u, g string) (user *LineUserInfo, err error) {
urlPath := fmt.Sprintf("/v2/bot/group/%s/member/%s", g, u)
header := getHeaders()
header := getHeaders(accessToken)
apiURL, ok := getURL(urlPath)
if !ok {
return nil, errors.New("url parser fail")
@ -263,9 +261,9 @@ func GetUserInfo(u, g string) (user *LineUserInfo, err error) {
}
// GetContentHead -
func GetContentHead(id string) (mime string, err error) {
func GetContentHead(accessToken, id string) (mime string, err error) {
urlPath := fmt.Sprintf("/v2/bot/message/%s/content", id)
header := getHeaders()
header := getHeaders(accessToken)
u, ok := getURL(urlPath)
if !ok {
return "", errors.New("get url fail")
@ -294,9 +292,9 @@ func GetContentHead(id string) (mime string, err error) {
}
// DownloadContent -
func DownloadContent(id string, w io.Writer) (err error) {
func DownloadContent(accessToken, id string, w io.Writer) (err error) {
urlPath := fmt.Sprintf("/v2/bot/message/%s/content", id)
header := getHeaders()
header := getHeaders(accessToken)
u, ok := getURL(urlPath)
if !ok {
return errors.New("get url fail")

View File

@ -2,6 +2,7 @@ package background
import (
"fmt"
"log"
"net/http"
"regexp"
"sort"
@ -138,6 +139,11 @@ func getPageHTML(page *model.FacebookPage) {
for _, v := range page.Groups {
if v.Notify {
bot, err := v.GetBot()
if err != nil || bot == nil {
log.Println("get group binding bot fail :: ", err)
continue
}
tmpl := v.Tmpl
if len(tmpl) > 0 {
tmpl = strings.Replace(tmpl, "{link}", lastData.Link, -1)
@ -148,7 +154,7 @@ func getPageHTML(page *model.FacebookPage) {
msg := line.TextMessage{
Text: tmpl,
}
line.PushMessage(v.ID, msg)
line.PushMessage(bot.AccessToken, v.ID, msg)
}
}
}

View File

@ -7,7 +7,7 @@ import (
"net/http"
"strings"
"git.trj.tw/golang/mtfosbot/module/twitch-irc"
twitchirc "git.trj.tw/golang/mtfosbot/module/twitch-irc"
"git.trj.tw/golang/mtfosbot/model"
)
@ -50,7 +50,7 @@ func getOpayData(ch *model.TwitchChannel) {
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0")
req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/80.0")
resp, err := http.DefaultClient.Do(req)
if err != nil {

View File

@ -2,6 +2,7 @@ package background
import (
"fmt"
"log"
"strings"
"time"
@ -61,6 +62,11 @@ func checkStream(ch *model.TwitchChannel, info *twitch.StreamInfo) {
link := fmt.Sprintf("https://twitch.tv/%s", ch.Name)
for _, v := range ch.Groups {
if v.Notify {
bot, err := v.GetBot()
if err != nil || bot == nil {
log.Println("get group binding bot fail :: ", err)
continue
}
tmpl := v.Tmpl
if len(tmpl) > 0 {
tmpl = strings.Replace(tmpl, "{txt}", info.Title, -1)
@ -71,7 +77,7 @@ func checkStream(ch *model.TwitchChannel, info *twitch.StreamInfo) {
msg := line.TextMessage{
Text: tmpl,
}
line.PushMessage(v.ID, msg)
line.PushMessage(bot.AccessToken, v.ID, msg)
}
}
}

View File

@ -43,9 +43,11 @@ type Config struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
} `yaml:"redis"`
Elasticsearch struct{
Host string `yaml:"host"`
Index string `yaml:"index"`
Elasticsearch struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
Host string `yaml:"host"`
Index string `yaml:"index"`
} `yaml:"elasticsearch"`
}

View File

@ -14,7 +14,11 @@ var client *elastic.Client
// NewClient -
func NewClient() (err error) {
conf := config.GetConf()
client, err = elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(conf.Elasticsearch.Host))
client, err = elastic.NewClient(
elastic.SetSniff(false),
elastic.SetURL(conf.Elasticsearch.Host),
elastic.SetBasicAuth(conf.Elasticsearch.Username, conf.Elasticsearch.Password),
)
fmt.Println("host ", conf.Elasticsearch.Host)
if err != nil {
fmt.Println(err)
@ -24,11 +28,11 @@ func NewClient() (err error) {
}
// PutLog -
func PutLog(t string, body map[string]interface{}) (err error) {
func PutLog(logType string, body map[string]interface{}) (err error) {
if client == nil {
return
}
if len(t) == 0 || body == nil {
if len(logType) == 0 || body == nil {
return
}
conf := config.GetConf()
@ -37,6 +41,6 @@ func PutLog(t string, body map[string]interface{}) (err error) {
body["date"] = time.Now().UTC()
nt := time.Now()
idx := fmt.Sprintf("%v-%v-%v-%v", conf.Elasticsearch.Index, nt.Year(), int(nt.Month()), nt.Day())
_, err = client.Index().Index(idx).Type(t).BodyJson(body).Do(ctx)
_, err = client.Index().Index(idx).Type(logType).BodyJson(body).Do(ctx)
return
}

View File

@ -2,16 +2,20 @@ package linemsg
import (
"fmt"
"log"
lineobj "git.trj.tw/golang/mtfosbot/module/line-message/line-object"
)
// MessageEvent -
func MessageEvent(e *lineobj.EventObject) {
func MessageEvent(botid string, e *lineobj.EventObject) {
log.Println("proc message evt :: ", botid, *e)
if len(botid) == 0 {
return
}
switch e.Type {
case "message":
messageType(e)
messageType(botid, e)
break
default:
fmt.Println("line webhook type not match")

View File

@ -2,17 +2,22 @@ package linemsg
import (
"fmt"
"log"
"net/url"
"os"
"path"
"time"
"git.trj.tw/golang/mtfosbot/model"
"git.trj.tw/golang/mtfosbot/module/apis/line"
"git.trj.tw/golang/mtfosbot/module/config"
"git.trj.tw/golang/mtfosbot/module/es"
lineobj "git.trj.tw/golang/mtfosbot/module/line-message/line-object"
msgcmd "git.trj.tw/golang/mtfosbot/module/message-command"
)
func messageType(e *lineobj.EventObject) {
func messageType(botid string, e *lineobj.EventObject) {
log.Println("proc msg type text :: ", botid)
msg := e.Message
mtype, ok := msg["type"]
if !ok {
@ -22,17 +27,17 @@ func messageType(e *lineobj.EventObject) {
if t, ok := mtype.(string); ok {
switch t {
case "text":
textMsg(e)
textMsg(botid, e)
break
case "image":
imageMsg(e)
imageMsg(botid, e)
break
}
}
return
}
func textMsg(e *lineobj.EventObject) {
func textMsg(botid string, e *lineobj.EventObject) {
msg := e.Message
mtxt, ok := msg["text"]
if !ok {
@ -42,14 +47,14 @@ func textMsg(e *lineobj.EventObject) {
// group action
if e.Source.Type == "group" {
if txt, ok := mtxt.(string); ok {
msgcmd.ParseLineMsg(txt, e.ReplyToken, e.Source)
saveTextMsgToLog(txt, e.Source)
msgcmd.ParseLineMsg(botid, txt, e.ReplyToken, e.Source)
saveTextMsgToLog(botid, txt, e.Source)
}
}
return
}
func imageMsg(e *lineobj.EventObject) {
func imageMsg(botid string, e *lineobj.EventObject) {
msg := e.Message
imgID, ok := msg["id"]
if !ok {
@ -58,18 +63,19 @@ func imageMsg(e *lineobj.EventObject) {
// group action
if e.Source.Type == "group" {
if id, ok := imgID.(string); ok {
saveImageMsgToLog(id, e.Source)
saveImageMsgToLog(botid, id, e.Source)
}
}
}
func getSourceUser(uid, gid string) (u *model.LineUser, err error) {
func getSourceUser(accessToken, uid, gid string) (u *model.LineUser, err error) {
userData, err := model.GetLineUserByID(uid)
if err != nil {
return
}
if userData == nil {
tmpu, err := line.GetUserInfo(uid, gid)
tmpu, err := line.GetUserInfo(accessToken, uid, gid)
if err != nil || tmpu == nil {
return nil, err
}
@ -80,27 +86,50 @@ func getSourceUser(uid, gid string) (u *model.LineUser, err error) {
if err != nil {
return nil, err
}
} else {
if userData.Mtime.Unix() < (time.Now().Unix() - 86400) {
tmpu, err := line.GetUserInfo(accessToken, uid, gid)
if err != nil || tmpu == nil {
return nil, err
}
userData.Name = tmpu.DisplayName
err = userData.UpdateName()
if err != nil {
return nil, err
}
}
}
return userData, nil
}
func saveTextMsgToLog(txt string, s *lineobj.SourceObject) {
u, err := getSourceUser(s.UserID, s.GroupID)
func saveTextMsgToLog(botid, txt string, s *lineobj.SourceObject) {
bot, err := model.GetBotInfo(botid)
if err != nil || bot == nil {
fmt.Println("get bot info fail :: ", err)
return
}
u, err := getSourceUser(bot.AccessToken, s.UserID, s.GroupID)
if err != nil || u == nil {
return
}
// go saveLineMessageLogToES(s.GroupID, s.UserID, txt, "text")
model.AddLineMessageLog(s.GroupID, s.UserID, txt, "text")
}
func saveImageMsgToLog(id string, s *lineobj.SourceObject) {
u, err := getSourceUser(s.UserID, s.GroupID)
func saveImageMsgToLog(botid, id string, s *lineobj.SourceObject) {
bot, err := model.GetBotInfo(botid)
if err != nil || bot == nil {
fmt.Println("get bot info fail :: ", err)
return
}
u, err := getSourceUser(bot.AccessToken, s.UserID, s.GroupID)
if err != nil || u == nil {
return
}
mime, err := line.GetContentHead(id)
mime, err := line.GetContentHead(bot.AccessToken, id)
if err != nil || len(mime) == 0 {
return
}
@ -132,10 +161,46 @@ func saveImageMsgToLog(id string, s *lineobj.SourceObject) {
}
defer w.Close()
err = line.DownloadContent(id, w)
err = line.DownloadContent(bot.AccessToken, id, w)
if err != nil {
return
}
furl, err := url.Parse(conf.URL)
if err == nil {
furl, err = furl.Parse(fmt.Sprintf("/image/line_log_image/%s", fname))
if err == nil {
fname = furl.String()
}
}
// go saveLineMessageLogToES(s.GroupID, s.UserID, fname, "image")
model.AddLineMessageLog(s.GroupID, s.UserID, fname, "image")
}
func saveLineMessageLogToES(gid, uid, content, msgType string) {
lineGroup, err := model.GetLineGroup(gid)
if err != nil {
log.Println("get line group error :: ", err)
return
}
lineUser, err := model.GetLineUserByID(uid)
if err != nil {
log.Println("get line user error :: ", err)
return
}
logMsg := make(map[string]interface{})
logMsg["message"] = content
logMsg["type"] = msgType
logMsg["group"] = lineGroup.ID
logMsg["group_name"] = lineGroup.Name
logMsg["user"] = lineUser.ID
logMsg["user_name"] = lineUser.Name
err = es.PutLog("log", logMsg)
if err != nil {
log.Println("put log fail :: ", err)
}
}

View File

@ -1,6 +1,7 @@
package msgcmd
import (
"fmt"
"regexp"
"strings"
@ -22,10 +23,15 @@ func parseCMD(in string) (c [][]string) {
}
// ParseLineMsg -
func ParseLineMsg(txt, replyToken string, source *lineobj.SourceObject) {
func ParseLineMsg(botid, txt, replyToken string, source *lineobj.SourceObject) {
if source.Type != "group" {
return
}
bot, err := model.GetBotInfo(botid)
if err != nil || bot == nil {
fmt.Println("get bot err or no bot :: ", err)
return
}
strs := strings.Split(strings.Trim(txt, " "), " ")
// skip empty string
@ -57,7 +63,7 @@ func ParseLineMsg(txt, replyToken string, source *lineobj.SourceObject) {
m := parseResult(v)
msgs = append(msgs, m)
}
line.ReplyMessage(replyToken, msgs...)
line.ReplyMessage(bot.AccessToken, replyToken, msgs...)
} else {
// key cmd
@ -72,7 +78,8 @@ func ParseLineMsg(txt, replyToken string, source *lineobj.SourceObject) {
m := parseResult(v)
msgs = append(msgs, m)
}
line.ReplyMessage(replyToken, msgs...)
line.ReplyMessage(bot.AccessToken, replyToken, msgs...)
}
}

View File

@ -27,7 +27,20 @@ func PushLineMessage(c *context.Context) {
textObj := line.TextMessage{}
textObj.Text = bodyData.Message
line.PushMessage(bodyData.Group, textObj)
group, err := model.GetLineGroup(bodyData.Group)
if err != nil {
c.ServerError(nil)
log.Println("get group :: ", err)
return
}
bot, err := group.GetBot()
if err != nil || bot == nil {
log.Println("get group binding bot fail :: ", err)
c.ServerError(nil)
return
}
line.PushMessage(bot.AccessToken, bodyData.Group, textObj)
c.Success(nil)
}

View File

@ -1,12 +1,13 @@
package api
import (
"fmt"
"time"
"git.trj.tw/golang/mtfosbot/model"
"git.trj.tw/golang/mtfosbot/module/apis/twitch"
"git.trj.tw/golang/mtfosbot/module/context"
"git.trj.tw/golang/mtfosbot/module/twitch-irc"
twitchirc "git.trj.tw/golang/mtfosbot/module/twitch-irc"
"git.trj.tw/golang/mtfosbot/module/utils"
"github.com/gin-gonic/contrib/sessions"
)
@ -99,7 +100,12 @@ func hasChannel(id string, c *context.Context) *model.TwitchChannel {
return nil
}
fmt.Println("channels :: ", chs)
for _, v := range chs {
if v == nil {
continue
}
if v.ID == id {
return v
}

View File

@ -79,6 +79,7 @@ func GetNotifyWebhook(c *context.Context) {
c.DataFormat(nil)
return
}
fmt.Println("Hook string ::: ", string(byteBody))
id, ok := c.GetQuery("id")
if !ok {
@ -128,6 +129,11 @@ func GetNotifyWebhook(c *context.Context) {
for _, v := range yt.Groups {
log.Println("group data :::: ", v, v.Notify, v.Name, v.ID)
bot, err := v.GetBot()
if err != nil || bot == nil {
log.Println("get group binding bot fail :: ", err)
continue
}
if v.Notify == true {
str := v.Tmpl
log.Println("template :::: ", str)
@ -143,7 +149,7 @@ func GetNotifyWebhook(c *context.Context) {
}
log.Println("msg ::::: ", msg)
lineapi.PushMessage(v.ID, msg)
lineapi.PushMessage(bot.AccessToken, v.ID, msg)
}
}

View File

@ -6,10 +6,11 @@ import (
"encoding/base64"
"encoding/json"
"io/ioutil"
"log"
"git.trj.tw/golang/mtfosbot/module/config"
"git.trj.tw/golang/mtfosbot/model"
"git.trj.tw/golang/mtfosbot/module/context"
"git.trj.tw/golang/mtfosbot/module/line-message"
linemsg "git.trj.tw/golang/mtfosbot/module/line-message"
lineobj "git.trj.tw/golang/mtfosbot/module/line-message/line-object"
)
@ -42,10 +43,21 @@ func VerifyLine(c *context.Context) {
return
}
conf := config.GetConf()
botid, ok := c.GetQuery("id")
if !ok || len(botid) == 0 {
c.CustomRes(403, map[string]string{
"message": "no bot data",
})
}
hash := hmac.New(sha256.New, []byte(conf.Line.Secret))
_, err := hash.Write(raw)
bot, err := model.GetBotInfo(botid)
if err != nil {
c.ServerError(nil)
return
}
hash := hmac.New(sha256.New, []byte(bot.Secret))
_, err = hash.Write(raw)
if err != nil {
c.ServerError(nil)
return
@ -70,6 +82,12 @@ func GetLineMessage(c *context.Context) {
if raw, ok = rawbody.([]byte); !ok {
c.DataFormat("body type error")
}
botid, ok := c.GetQuery("id")
if !ok || len(botid) == 0 {
c.CustomRes(403, map[string]string{
"message": "no bot data",
})
}
events := struct {
Events []*lineobj.EventObject `json:"events"`
@ -83,7 +101,8 @@ func GetLineMessage(c *context.Context) {
if len(events.Events) > 0 {
for _, v := range events.Events {
go linemsg.MessageEvent(v)
log.Println("get line message :: ", v)
go linemsg.MessageEvent(botid, v)
}
}

View File

@ -2,6 +2,7 @@ package private
import (
"fmt"
"log"
"strings"
"git.trj.tw/golang/mtfosbot/model"
@ -46,6 +47,24 @@ func GetFacebookPageIDs(c *context.Context) {
})
}
//GetInstagramIDs -
func GetInstagramIDs(c *context.Context) {
igs, err := model.GetAllInstagram()
if err != nil {
c.ServerError(nil)
return
}
ids := make([]string, 0, len(igs))
for _, v := range igs {
ids = append(ids, v.ID)
}
c.Success(map[string]interface{}{
"list": ids,
})
}
// UpdateFacebookPagePost -
func UpdateFacebookPagePost(c *context.Context) {
var err error
@ -89,6 +108,11 @@ func UpdateFacebookPagePost(c *context.Context) {
for _, g := range page.Groups {
if g.Notify {
bot, err := g.GetBot()
if err != nil || bot == nil {
log.Println("get group binding bot fail ::: ", err)
continue
}
tmpl := g.Tmpl
if len(tmpl) > 0 {
tmpl = strings.Replace(tmpl, "{link}", v.Link, -1)
@ -99,7 +123,73 @@ func UpdateFacebookPagePost(c *context.Context) {
msg := line.TextMessage{
Text: tmpl,
}
line.PushMessage(g.ID, msg)
line.PushMessage(bot.AccessToken, g.ID, msg)
}
}
}
c.Success(nil)
}
// UpdateInstagramPost -
func UpdateInstagramPost(c *context.Context) {
var err error
type pageStruct struct {
ID string `json:"id"`
PostID string `json:"post_id"`
Link string `json:"link"`
Text string `json:"text"`
}
bodyArg := struct {
IGs []pageStruct `json:"igs"`
}{}
err = c.BindData(&bodyArg)
if err != nil {
c.DataFormat(nil)
return
}
for _, v := range bodyArg.IGs {
if len(v.ID) == 0 || len(v.PostID) == 0 || len(v.Link) == 0 {
continue
}
ig, err := model.GetInstagram(v.ID)
if err != nil {
continue
}
if ig.LastPost == v.PostID {
continue
}
err = ig.UpdatePost(v.PostID)
if err != nil {
continue
}
err = ig.GetGroups()
if err != nil {
fmt.Println("get group err :: ", err)
continue
}
for _, g := range ig.Groups {
if g.Notify {
bot, err := g.GetBot()
if err != nil || bot == nil {
log.Println("get group binding bot fail :: ", err)
continue
}
tmpl := g.Tmpl
if len(tmpl) > 0 {
tmpl = strings.Replace(tmpl, "{link}", v.Link, -1)
tmpl = strings.Replace(tmpl, "{txt}", v.Text, -1)
} else {
tmpl = fmt.Sprintf("%s\n%s", v.Text, v.Link)
}
msg := line.TextMessage{Text: tmpl}
line.PushMessage(bot.AccessToken, g.ID, msg)
}
}
}

View File

@ -91,6 +91,8 @@ func SetRoutes(r *gin.Engine) {
{
privateAPIGroup.GET("/pages", context.PatchCtx(private.GetFacebookPageIDs))
privateAPIGroup.POST("/pageposts", context.PatchCtx(private.UpdateFacebookPagePost))
privateAPIGroup.GET("/ig", context.PatchCtx(private.GetInstagramIDs))
privateAPIGroup.POST("/igposts", context.PatchCtx(private.UpdateInstagramPost))
}
apiTwitchGroup := apiGroup.Group("/twitch", context.PatchCtx(api.CheckSession))
@ -122,6 +124,7 @@ func SetRoutes(r *gin.Engine) {
{
twitchApis.GET("/login", context.PatchCtx(twitch.OAuthLogin))
twitchApis.GET("/oauth", context.PatchCtx(twitch.OAuthProc))
twitchApis.POST("/send", context.PatchCtx(twitch.SendToChannel))
}
// set pprof router

View File

@ -8,6 +8,7 @@ import (
twitchapi "git.trj.tw/golang/mtfosbot/module/apis/twitch"
"git.trj.tw/golang/mtfosbot/module/config"
"git.trj.tw/golang/mtfosbot/module/context"
twitchirc "git.trj.tw/golang/mtfosbot/module/twitch-irc"
"github.com/gin-gonic/contrib/sessions"
)
@ -92,3 +93,26 @@ func OAuthProc(c *context.Context) {
session.Save()
c.Redirect(301, goURL)
}
func SendToChannel(c *context.Context) {
key := c.GetHeader("x-private-key")
if key == "" || key != "mtfos" {
c.Forbidden(nil)
return
}
ch, ok := c.GetQuery("channel")
if !ok || ch == "" {
c.DataFormat(nil)
return
}
msg, ok := c.GetQuery("message")
if !ok || msg == "" {
c.DataFormat(nil)
return
}
twitchirc.SendMessage(ch, msg)
c.Success(nil)
}

2
schema

@ -1 +1 @@
Subproject commit bda09929578505cd4712856bee125b9838643d78
Subproject commit 7928d0598bd06bf11305b543d3f1b4c20e3975dc