Compare commits

..

No commits in common. "master" and "refactor_model" have entirely different histories.

31 changed files with 145 additions and 556 deletions

View File

@ -1,24 +1,9 @@
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
pipeline:
docker:
image: plugins/docker
settings:
registry: docker.mtfos.xyz
repo: docker.mtfos.xyz/mtfos/go-bot
dockerfile: Dockerfile
tags: [latest, "${DRONE_COMMIT}"]
trigger:
branch:
- master
when:
branch: master

View File

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

View File

@ -2,7 +2,6 @@
.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,3 +1,2 @@
### MTFoS Bot
[![Build Status](https://ci.trj.tw/api/badges/golang/mtfosbot/status.svg)](https://ci.trj.tw/golang/mtfosbot)

View File

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

36
go.mod
View File

@ -1,32 +1,36 @@
module git.trj.tw/golang/mtfosbot
go 1.16
require (
github.com/DeanThompson/ginpprof v0.0.0-20190408063150-3be636683586
github.com/DeanThompson/ginpprof v0.0.0-20170218162546-8c0e31bfeaa8
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 v1.3.0
github.com/gin-gonic/contrib v0.0.0-20190526021735-7fb7810ed2a0
github.com/gin-gonic/gin v1.4.0
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/go-irc/irc v2.1.0+incompatible
github.com/go-sql-driver/mysql v1.4.1 // indirect
github.com/google/go-cmp v0.3.0 // indirect
github.com/golang/protobuf v1.3.1 // indirect
github.com/google/go-cmp v0.2.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/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/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/mattn/go-sqlite3 v1.10.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/olivere/elastic v6.2.18+incompatible
github.com/olivere/elastic v6.2.16+incompatible
github.com/pkg/errors v0.8.1 // 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
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
gopkg.in/yaml.v2 v2.2.2
)

81
go.sum
View File

@ -1,5 +1,5 @@
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/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/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,26 +11,30 @@ 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 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/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/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-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/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/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.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
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/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=
@ -40,6 +44,8 @@ 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=
@ -47,14 +53,15 @@ 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/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/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/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
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 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/4=
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=
@ -64,38 +71,44 @@ 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.18+incompatible h1:sd4eZY7YExzuvTz4tpBAvWY6go/SZLMj5GKl9vZgtwM=
github.com/olivere/elastic v6.2.18+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8=
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/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 v1.1.0 h1:jk4/Hud3TTdcrJgUOBgsqrZBarcxl6ADIjSC2iniwLY=
github.com/robfig/cron v1.1.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
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/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.4 h1:j4s+tAvLfL3bZyefP2SEWmhBzmuIlH/eqNuPdFPgngw=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
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=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/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/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/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-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/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/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-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/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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
google.golang.org/appengine v1.6.0 h1:Tfd7cKwKbFRsI8RMAD3oqqw7JPFRrvFlOsfbgVkjOOw=
google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
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=
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,11 +78,6 @@ 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()) returning *`, account, password)
err = x.Get(acc, `insert into "public"."account" ("account", "password", "ctime", "mtime") values ($1, $2, now(), now())`, account, password)
if err == sql.ErrNoRows {
return nil, nil
}

View File

@ -1,74 +0,0 @@
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
}

View File

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

View File

@ -2,7 +2,6 @@ package background
import (
"fmt"
"log"
"net/http"
"regexp"
"sort"
@ -139,11 +138,6 @@ 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)
@ -154,7 +148,7 @@ func getPageHTML(page *model.FacebookPage) {
msg := line.TextMessage{
Text: tmpl,
}
line.PushMessage(bot.AccessToken, v.ID, msg)
line.PushMessage(v.ID, msg)
}
}
}

View File

@ -7,7 +7,7 @@ import (
"net/http"
"strings"
twitchirc "git.trj.tw/golang/mtfosbot/module/twitch-irc"
"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/80.0")
req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0")
resp, err := http.DefaultClient.Do(req)
if err != nil {

View File

@ -2,7 +2,6 @@ package background
import (
"fmt"
"log"
"strings"
"time"
@ -62,11 +61,6 @@ 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)
@ -77,7 +71,7 @@ func checkStream(ch *model.TwitchChannel, info *twitch.StreamInfo) {
msg := line.TextMessage{
Text: tmpl,
}
line.PushMessage(bot.AccessToken, v.ID, msg)
line.PushMessage(v.ID, msg)
}
}
}

View File

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

View File

@ -14,11 +14,7 @@ var client *elastic.Client
// NewClient -
func NewClient() (err error) {
conf := config.GetConf()
client, err = elastic.NewClient(
elastic.SetSniff(false),
elastic.SetURL(conf.Elasticsearch.Host),
elastic.SetBasicAuth(conf.Elasticsearch.Username, conf.Elasticsearch.Password),
)
client, err = elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(conf.Elasticsearch.Host))
fmt.Println("host ", conf.Elasticsearch.Host)
if err != nil {
fmt.Println(err)
@ -28,11 +24,11 @@ func NewClient() (err error) {
}
// PutLog -
func PutLog(logType string, body map[string]interface{}) (err error) {
func PutLog(t string, body map[string]interface{}) (err error) {
if client == nil {
return
}
if len(logType) == 0 || body == nil {
if len(t) == 0 || body == nil {
return
}
conf := config.GetConf()
@ -41,6 +37,6 @@ func PutLog(logType 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(logType).BodyJson(body).Do(ctx)
_, err = client.Index().Index(idx).Type(t).BodyJson(body).Do(ctx)
return
}

View File

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

View File

@ -2,22 +2,17 @@ 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(botid string, e *lineobj.EventObject) {
log.Println("proc msg type text :: ", botid)
func messageType(e *lineobj.EventObject) {
msg := e.Message
mtype, ok := msg["type"]
if !ok {
@ -27,17 +22,17 @@ func messageType(botid string, e *lineobj.EventObject) {
if t, ok := mtype.(string); ok {
switch t {
case "text":
textMsg(botid, e)
textMsg(e)
break
case "image":
imageMsg(botid, e)
imageMsg(e)
break
}
}
return
}
func textMsg(botid string, e *lineobj.EventObject) {
func textMsg(e *lineobj.EventObject) {
msg := e.Message
mtxt, ok := msg["text"]
if !ok {
@ -47,14 +42,14 @@ func textMsg(botid string, e *lineobj.EventObject) {
// group action
if e.Source.Type == "group" {
if txt, ok := mtxt.(string); ok {
msgcmd.ParseLineMsg(botid, txt, e.ReplyToken, e.Source)
saveTextMsgToLog(botid, txt, e.Source)
msgcmd.ParseLineMsg(txt, e.ReplyToken, e.Source)
saveTextMsgToLog(txt, e.Source)
}
}
return
}
func imageMsg(botid string, e *lineobj.EventObject) {
func imageMsg(e *lineobj.EventObject) {
msg := e.Message
imgID, ok := msg["id"]
if !ok {
@ -63,19 +58,18 @@ func imageMsg(botid string, e *lineobj.EventObject) {
// group action
if e.Source.Type == "group" {
if id, ok := imgID.(string); ok {
saveImageMsgToLog(botid, id, e.Source)
saveImageMsgToLog(id, e.Source)
}
}
}
func getSourceUser(accessToken, uid, gid string) (u *model.LineUser, err error) {
func getSourceUser(uid, gid string) (u *model.LineUser, err error) {
userData, err := model.GetLineUserByID(uid)
if err != nil {
return
}
if userData == nil {
tmpu, err := line.GetUserInfo(accessToken, uid, gid)
tmpu, err := line.GetUserInfo(uid, gid)
if err != nil || tmpu == nil {
return nil, err
}
@ -86,50 +80,27 @@ func getSourceUser(accessToken, 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(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)
func saveTextMsgToLog(txt string, s *lineobj.SourceObject) {
u, err := getSourceUser(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(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)
func saveImageMsgToLog(id string, s *lineobj.SourceObject) {
u, err := getSourceUser(s.UserID, s.GroupID)
if err != nil || u == nil {
return
}
mime, err := line.GetContentHead(bot.AccessToken, id)
mime, err := line.GetContentHead(id)
if err != nil || len(mime) == 0 {
return
}
@ -161,46 +132,10 @@ func saveImageMsgToLog(botid, id string, s *lineobj.SourceObject) {
}
defer w.Close()
err = line.DownloadContent(bot.AccessToken, id, w)
err = line.DownloadContent(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,7 +1,6 @@
package msgcmd
import (
"fmt"
"regexp"
"strings"
@ -23,15 +22,10 @@ func parseCMD(in string) (c [][]string) {
}
// ParseLineMsg -
func ParseLineMsg(botid, txt, replyToken string, source *lineobj.SourceObject) {
func ParseLineMsg(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
@ -63,7 +57,7 @@ func ParseLineMsg(botid, txt, replyToken string, source *lineobj.SourceObject) {
m := parseResult(v)
msgs = append(msgs, m)
}
line.ReplyMessage(bot.AccessToken, replyToken, msgs...)
line.ReplyMessage(replyToken, msgs...)
} else {
// key cmd
@ -78,8 +72,7 @@ func ParseLineMsg(botid, txt, replyToken string, source *lineobj.SourceObject) {
m := parseResult(v)
msgs = append(msgs, m)
}
line.ReplyMessage(bot.AccessToken, replyToken, msgs...)
line.ReplyMessage(replyToken, msgs...)
}
}

View File

@ -27,20 +27,7 @@ func PushLineMessage(c *context.Context) {
textObj := line.TextMessage{}
textObj.Text = bodyData.Message
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)
line.PushMessage(bodyData.Group, textObj)
c.Success(nil)
}

View File

@ -1,13 +1,12 @@
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"
twitchirc "git.trj.tw/golang/mtfosbot/module/twitch-irc"
"git.trj.tw/golang/mtfosbot/module/twitch-irc"
"git.trj.tw/golang/mtfosbot/module/utils"
"github.com/gin-gonic/contrib/sessions"
)
@ -100,12 +99,7 @@ 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,7 +79,6 @@ func GetNotifyWebhook(c *context.Context) {
c.DataFormat(nil)
return
}
fmt.Println("Hook string ::: ", string(byteBody))
id, ok := c.GetQuery("id")
if !ok {
@ -129,11 +128,6 @@ 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)
@ -149,7 +143,7 @@ func GetNotifyWebhook(c *context.Context) {
}
log.Println("msg ::::: ", msg)
lineapi.PushMessage(bot.AccessToken, v.ID, msg)
lineapi.PushMessage(v.ID, msg)
}
}

View File

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

View File

@ -2,7 +2,6 @@ package private
import (
"fmt"
"log"
"strings"
"git.trj.tw/golang/mtfosbot/model"
@ -47,24 +46,6 @@ 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
@ -108,11 +89,6 @@ 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)
@ -123,73 +99,7 @@ func UpdateFacebookPagePost(c *context.Context) {
msg := line.TextMessage{
Text: tmpl,
}
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)
line.PushMessage(g.ID, msg)
}
}
}

View File

@ -91,8 +91,6 @@ 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))
@ -124,7 +122,6 @@ 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,7 +8,6 @@ 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"
)
@ -93,26 +92,3 @@ 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 7928d0598bd06bf11305b543d3f1b4c20e3975dc
Subproject commit bda09929578505cd4712856bee125b9838643d78