From 647d9c548b188e113cd8eec4af4211a00566b5da Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Sat, 22 Dec 2018 18:03:53 +0400 Subject: [PATCH] Move from dep to go mod (experiment) --- Gopkg.lock | 41 ------------------- Gopkg.toml | 34 --------------- context/context.go | 2 +- context/exported.go | 2 +- example/fw_zookeeper_helper.yaml | 4 +- go.mod | 7 ++++ go.sum | 8 ++++ golangci.yaml | 4 -- local/config/announce.go | 9 ++++ {internal => local}/config/struct.go | 3 +- {internal => local}/config/tdlib.go | 0 {internal => local}/telegram/exported.go | 0 {internal => local}/telegram/telegram.go | 37 +++++++++++++---- main.go | 2 +- vendor/github.com/Arman92/go-tdlib/methods.go | 0 vendor/github.com/Arman92/go-tdlib/types.go | 0 vendor/modules.txt | 8 ++++ 17 files changed, 70 insertions(+), 91 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml create mode 100644 go.mod create mode 100644 go.sum delete mode 100644 golangci.yaml create mode 100644 local/config/announce.go rename {internal => local}/config/struct.go (75%) rename {internal => local}/config/tdlib.go (100%) rename {internal => local}/telegram/exported.go (100%) rename {internal => local}/telegram/telegram.go (77%) mode change 100755 => 100644 vendor/github.com/Arman92/go-tdlib/methods.go mode change 100755 => 100644 vendor/github.com/Arman92/go-tdlib/types.go create mode 100644 vendor/modules.txt diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 98479aa..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,41 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - branch = "master" - digest = "1:cdfaade39c21052a144a32f944ce80030cbdce760d0c63c60ca8b9f59928a6f4" - name = "github.com/Arman92/go-tdlib" - packages = ["."] - pruneopts = "UT" - revision = "9577ff528640031a5c3a5f7386c896255f69c723" - -[[projects]] - digest = "1:6112a5eaec2ec65df289ccbb7a730aaf03e3c5cce6c906d367ccf9b7ac567604" - name = "github.com/rs/zerolog" - packages = [ - ".", - "internal/cbor", - "internal/json", - ] - pruneopts = "UT" - revision = "8747b7b3a51b5d08ee7ac50eaf4869edaf9f714a" - version = "v1.11.0" - -[[projects]] - digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96" - name = "gopkg.in/yaml.v2" - packages = ["."] - pruneopts = "UT" - revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" - version = "v2.2.2" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/Arman92/go-tdlib", - "github.com/rs/zerolog", - "gopkg.in/yaml.v2", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index f8e072b..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,34 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - -[[constraint]] - branch = "master" - name = "github.com/Arman92/go-tdlib" - -[prune] - go-tests = true - unused-packages = true diff --git a/context/context.go b/context/context.go index ae94627..ecd4f58 100644 --- a/context/context.go +++ b/context/context.go @@ -8,7 +8,7 @@ import ( "github.com/rs/zerolog" "gopkg.in/yaml.v2" "io/ioutil" - "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/internal/config" + "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/local/config" "os" "path/filepath" "runtime" diff --git a/context/exported.go b/context/exported.go index 0deac0e..83bf07a 100644 --- a/context/exported.go +++ b/context/exported.go @@ -5,7 +5,7 @@ package context import ( "github.com/rs/zerolog" - "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/internal/config" + "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/local/config" ) // VERSION is the current bot's version diff --git a/example/fw_zookeeper_helper.yaml b/example/fw_zookeeper_helper.yaml index a54ded9..daae390 100644 --- a/example/fw_zookeeper_helper.yaml +++ b/example/fw_zookeeper_helper.yaml @@ -3,4 +3,6 @@ tdlib: api_hash: "your-hash" database_directory: "/tmp/tdlib-db/" files_directory: "/tmp/tdlib-files/" - errors_file: "/tmp/tdlib.txt" \ No newline at end of file + errors_file: "/tmp/tdlib.txt" +announce: + channel_id: -1001234567890 \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..15f7f59 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module lab.wtfteam.pro/fat0troll/fw_zookeeper_helper + +require ( + github.com/Arman92/go-tdlib v0.0.0-20181103144727-9577ff528640 + github.com/rs/zerolog v1.11.0 + gopkg.in/yaml.v2 v2.2.2 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5a55057 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/Arman92/go-tdlib v0.0.0-20181103144727-9577ff528640 h1:Esv4AF+AVSwjJJFGVLVBncKgq4z7nikN6TK4X7mj2Vg= +github.com/Arman92/go-tdlib v0.0.0-20181103144727-9577ff528640/go.mod h1:ZzkRfuaFj8etIYMj/ECtXtgfz72RE6U+dos27b3XIwk= +github.com/rs/zerolog v1.11.0 h1:DRuq/S+4k52uJzBQciUcofXx45GrMC6yrEbb/CoK6+M= +github.com/rs/zerolog v1.11.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= +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/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/golangci.yaml b/golangci.yaml deleted file mode 100644 index b729915..0000000 --- a/golangci.yaml +++ /dev/null @@ -1,4 +0,0 @@ -run: - deadline: 5m -linters: - enable-all: true diff --git a/local/config/announce.go b/local/config/announce.go new file mode 100644 index 0000000..3f451c1 --- /dev/null +++ b/local/config/announce.go @@ -0,0 +1,9 @@ +// Fantasy World Zookeeper Helper Bot +// Copyright (c) 2018 Vladimir "fat0troll" Hodakov + +package config + +// Announce is a struch which handles announces configuration +type Announce struct { + ChannelID int64 `yaml:"channel_id"` +} diff --git a/internal/config/struct.go b/local/config/struct.go similarity index 75% rename from internal/config/struct.go rename to local/config/struct.go index ad20bc1..5ad5205 100644 --- a/internal/config/struct.go +++ b/local/config/struct.go @@ -6,5 +6,6 @@ package config // Struct is a main configuration structure that holds all other // structs within. type Struct struct { - TDLib TDLib `yaml:"tdlib"` + TDLib TDLib `yaml:"tdlib"` + Announce Announce `yaml:"announce"` } diff --git a/internal/config/tdlib.go b/local/config/tdlib.go similarity index 100% rename from internal/config/tdlib.go rename to local/config/tdlib.go diff --git a/internal/telegram/exported.go b/local/telegram/exported.go similarity index 100% rename from internal/telegram/exported.go rename to local/telegram/exported.go diff --git a/internal/telegram/telegram.go b/local/telegram/telegram.go similarity index 77% rename from internal/telegram/telegram.go rename to local/telegram/telegram.go index 4396efd..5bf97b0 100644 --- a/internal/telegram/telegram.go +++ b/local/telegram/telegram.go @@ -88,6 +88,7 @@ func Connect() { // Check if message text contains needed battle data msgText := updateMsg.Message.Content.(*tdlib.MessageText) if strings.HasPrefix(msgText.Text.Text, "Я встретил") { + log.Debug().Msgf("%s", msgText.Text.Text) battleType := "" battleTag := "" if strings.Contains(msgText.Text.Text, "Огров") { @@ -99,16 +100,38 @@ func Connect() { if strings.Contains(msgText.Text.Text, "Кабанов") { battleType = "Кабаны!" } - keyboard := updateMsg.Message.ReplyMarkup.(*tdlib.ReplyMarkupInlineKeyboard) - if len(keyboard.Rows) > 0 { - if len(keyboard.Rows[0]) > 0 { - button := keyboard.Rows[0][0] - buttonQuery := button.Type.(*tdlib.InlineKeyboardButtonTypeCallback) - battleTag = string(buttonQuery.Data) + switch updateMsg.Message.ReplyMarkup.(type) { + case *tdlib.ReplyMarkupInlineKeyboard: + keyboard := updateMsg.Message.ReplyMarkup.(*tdlib.ReplyMarkupInlineKeyboard) + if len(keyboard.Rows) > 0 { + if len(keyboard.Rows[0]) > 0 { + button := keyboard.Rows[0][0] + switch button.Type.(type) { + case *tdlib.InlineKeyboardButtonTypeSwitchInline: + buttonQuery := button.Type.(*tdlib.InlineKeyboardButtonTypeSwitchInline) + battleTag = string(buttonQuery.Query) + default: + log.Error().Msg("Invalid button type") + } + } } + default: + log.Error().Msg("Invalid keyboard type") } log.Debug().Msgf("Battle type: %s", battleType) - log.Debug().Msgf("Battle type: %s", battleTag) + log.Debug().Msgf("Battle tag: %s", battleTag) + + reply := tdlib.InputMessageText{ + DisableWebPagePreview: true, + Text: &tdlib.FormattedText{ + Text: "Вызываю на помощь!", + }, + } + + _, err := client.SendMessage(updateMsg.Message.ChatID, 0, false, false, nil, &reply) + if err != nil { + log.Error().Err(err) + } } } diff --git a/main.go b/main.go index 7cef82f..9c22b44 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ package main import ( "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/context" - "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/internal/telegram" + "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/local/telegram" "os" "os/signal" "runtime" diff --git a/vendor/github.com/Arman92/go-tdlib/methods.go b/vendor/github.com/Arman92/go-tdlib/methods.go old mode 100755 new mode 100644 diff --git a/vendor/github.com/Arman92/go-tdlib/types.go b/vendor/github.com/Arman92/go-tdlib/types.go old mode 100755 new mode 100644 diff --git a/vendor/modules.txt b/vendor/modules.txt new file mode 100644 index 0000000..8afaad5 --- /dev/null +++ b/vendor/modules.txt @@ -0,0 +1,8 @@ +# github.com/Arman92/go-tdlib v0.0.0-20181103144727-9577ff528640 +github.com/Arman92/go-tdlib +# github.com/rs/zerolog v1.11.0 +github.com/rs/zerolog +github.com/rs/zerolog/internal/cbor +github.com/rs/zerolog/internal/json +# gopkg.in/yaml.v2 v2.2.2 +gopkg.in/yaml.v2