From 98c7e15e3049607bb0fbea6dfedaf53b432bd47f Mon Sep 17 00:00:00 2001 From: Evan Date: Wed, 7 Dec 2022 15:47:46 +0900 Subject: [PATCH] add slack --- bootstrap/{bootstrap.go => wechat.go} | 15 ++++++++++----- config/config.go | 5 +++++ go.mod | 1 + go.sum | 6 ++++++ main.go | 2 +- {handler => wechat}/handler.go | 2 +- .../wechat_handler.go | 2 +- 7 files changed, 25 insertions(+), 8 deletions(-) rename bootstrap/{bootstrap.go => wechat.go} (74%) rename {handler => wechat}/handler.go (97%) rename handler/group_msg_handler.go => wechat/wechat_handler.go (98%) diff --git a/bootstrap/bootstrap.go b/bootstrap/wechat.go similarity index 74% rename from bootstrap/bootstrap.go rename to bootstrap/wechat.go index bbd3a5f..83e14ae 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/wechat.go @@ -3,12 +3,12 @@ package bootstrap import ( "github.com/eatmoreapple/openwechat" log "github.com/sirupsen/logrus" - "github.com/wechatgpt/wechatbot/handler" + "github.com/wechatgpt/wechatbot/wechat" ) -func Run() { +func StartWebChat() { bot := openwechat.DefaultBot(openwechat.Desktop) - bot.MessageHandler = handler.Handler + bot.MessageHandler = wechat.Handler bot.UUIDCallback = openwechat.PrintlnQrcodeUrl reloadStorage := openwechat.NewJsonFileHotReloadStorage("token.json") @@ -28,9 +28,14 @@ func Run() { } friends, err := self.Friends() - log.Println(friends, err) + + for i, friend := range friends { + log.Println(i, friend) + } groups, err := self.Groups() - log.Println(groups, err) + for i, group := range groups { + log.Println(i, group) + } err = bot.Block() if err != nil { diff --git a/config/config.go b/config/config.go index 273d246..bf6303f 100644 --- a/config/config.go +++ b/config/config.go @@ -8,6 +8,7 @@ var config *Config type Config struct { ChatGpt ChatGptConfig `json:"chatgpt"` + Slack SlackConfig `json:"slack"` } type ChatGptConfig struct { @@ -15,6 +16,10 @@ type ChatGptConfig struct { Token string `json:"token,omitempty" json:"token,omitempty"` } +type SlackConfig struct { + Token string `json:"token"` +} + func LoadConfig() error { viper.SetConfigName("config") viper.SetConfigType("yaml") diff --git a/go.mod b/go.mod index 1532bab..cb9ce87 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,6 @@ go 1.16 require ( github.com/eatmoreapple/openwechat v1.2.1 github.com/sirupsen/logrus v1.6.0 + github.com/slack-go/slack v0.11.4 github.com/spf13/viper v1.14.0 ) diff --git a/go.sum b/go.sum index 0789268..e078c36 100644 --- a/go.sum +++ b/go.sum @@ -257,6 +257,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho= +github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= @@ -347,6 +349,8 @@ github.com/googleapis/gax-go/v2 v2.5.1/go.mod h1:h6B0KMMFNtI2ddbGJn3T3ZbwkeT6yqE github.com/googleapis/gax-go/v2 v2.6.0/go.mod h1:1mjbznJAPHFpesgE5ucqfYEscaz5kMdcIDwU/6+DDoY= github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/consul/api v1.15.3/go.mod h1:/g/qgcoBcEXALCNZgRRisyTW0nY86++L0KbeAMXYCeY= @@ -488,6 +492,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/slack-go/slack v0.11.4 h1:ojSa7KlPm3PqY2AomX4VTxEsK5eci5JaxCjlzGV5zoM= +github.com/slack-go/slack v0.11.4/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.9.2 h1:j49Hj62F0n+DaZ1dDCvhABaPNSGNkt32oRFxI33IEMw= github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y= diff --git a/main.go b/main.go index 0dd1a83..7c22ad4 100644 --- a/main.go +++ b/main.go @@ -10,5 +10,5 @@ func main() { if err != nil { panic(err) } - bootstrap.Run() + bootstrap.StartWebChat() } diff --git a/handler/handler.go b/wechat/handler.go similarity index 97% rename from handler/handler.go rename to wechat/handler.go index 54eb40e..7b4d3fe 100644 --- a/handler/handler.go +++ b/wechat/handler.go @@ -1,4 +1,4 @@ -package handler +package wechat import ( "github.com/eatmoreapple/openwechat" diff --git a/handler/group_msg_handler.go b/wechat/wechat_handler.go similarity index 98% rename from handler/group_msg_handler.go rename to wechat/wechat_handler.go index db0fde5..63d50b4 100644 --- a/handler/group_msg_handler.go +++ b/wechat/wechat_handler.go @@ -1,4 +1,4 @@ -package handler +package wechat import ( "errors"