Skip to content

Commit

Permalink
Made old code compatible with new API version
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelemusiani authored and Flecart committed Aug 11, 2023
1 parent 1976949 commit 8ac1773
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
7 changes: 2 additions & 5 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/csunibo/informabot/model"
"github.com/csunibo/informabot/utils"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
tgbotapi "github.com/musianisamuele/telegram-bot-api"
"golang.org/x/exp/slices"
)

Expand All @@ -29,10 +29,7 @@ func run(bot *tgbotapi.BotAPI) {
u := tgbotapi.NewUpdate(0)
u.Timeout = 60

updates, err := bot.GetUpdatesChan(u)
if err != nil {
log.Fatalf("Error getting updates: %s", err)
}
updates := bot.GetUpdatesChan(u)

for update := range updates {
if update.Message == nil {
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ module github.com/csunibo/informabot
go 1.18

require (
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
github.com/mitchellh/mapstructure v1.5.0
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
golang.org/x/text v0.12.0
)

require github.com/technoweenie/multipartstreamer v1.0.1 // indirect
require (
github.com/musianisamuele/telegram-bot-api v0.0.3 // indirect
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaEL
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/musianisamuele/telegram-bot-api v0.0.3 h1:8BTfHOPYTMkn0AX4FhicW1CyzU1NQdCIqlggfuT3P/I=
github.com/musianisamuele/telegram-bot-api v0.0.3/go.mod h1:f8epVo400dyxqaQpXt3la1mnhdQW25R1w3yqYT3GQc4=
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
Expand Down
4 changes: 2 additions & 2 deletions model/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/csunibo/informabot/commands"
"github.com/csunibo/informabot/utils"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
tgbotapi "github.com/musianisamuele/telegram-bot-api"
"golang.org/x/exp/slices"
)

Expand Down Expand Up @@ -43,7 +43,7 @@ func (data LookingForData) HandleBotCommand(bot *tgbotapi.BotAPI, message *tgbot
Groups[chatId] = append(chatArray, senderID)
}
} else {
Groups[chatId] = []int{senderID}
Groups[chatId] = []int64{senderID}
}
SaveGroups()

Expand Down
4 changes: 2 additions & 2 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package model

import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
tgbotapi "github.com/musianisamuele/telegram-bot-api"
)

type DataInterface interface {
Expand Down Expand Up @@ -45,7 +45,7 @@ func GetActionFromType(name string, commandType string) Action {
}

// SECTION GLOBAL JSON STRUCTS
type GroupsStruct = map[int64][]int
type GroupsStruct = map[int64][]int64

type AutoReply struct {
Text string `json:"text"`
Expand Down
11 changes: 8 additions & 3 deletions utils/bot_utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package utils

import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
tgbotapi "github.com/musianisamuele/telegram-bot-api"
)

func makeUnknownMember(chatConfigWithUser tgbotapi.ChatConfigWithUser) tgbotapi.ChatMember {
Expand All @@ -15,15 +15,20 @@ func makeUnknownMember(chatConfigWithUser tgbotapi.ChatConfigWithUser) tgbotapi.
}
}

func GetChatMembers(bot *tgbotapi.BotAPI, chatID int64, memberIds []int) []tgbotapi.ChatMember {
func GetChatMembers(bot *tgbotapi.BotAPI, chatID int64, memberIds []int64) []tgbotapi.ChatMember {
var members []tgbotapi.ChatMember

for _, id := range memberIds {
chatConfigWithUser := tgbotapi.ChatConfigWithUser{
ChatID: chatID,
UserID: id,
}
member, err := bot.GetChatMember(chatConfigWithUser)

getChatMemberConfig := tgbotapi.GetChatMemberConfig{
ChatConfigWithUser: chatConfigWithUser,
}

member, err := bot.GetChatMember(getChatMemberConfig)
if err != nil {
member = makeUnknownMember(chatConfigWithUser)
}
Expand Down
2 changes: 1 addition & 1 deletion utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"strings"

tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
tgbotapi "github.com/musianisamuele/telegram-bot-api"
"golang.org/x/text/unicode/norm"
)

Expand Down

0 comments on commit 8ac1773

Please sign in to comment.