diff --git a/botIO/getinfo.go b/botIO/getinfo.go
index a24c81a..b34cd11 100644
--- a/botIO/getinfo.go
+++ b/botIO/getinfo.go
@@ -2,15 +2,11 @@ package botIO
import tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
-func GetUserByID(chatid int64, userid int64, bot *tgbotapi.BotAPI) (member tgbotapi.ChatMember) {
+func GetUserByID(userToGet tgbotapi.ChatConfigWithUser, bot *tgbotapi.BotAPI) (error bool, member tgbotapi.ChatMember) {
- hi := tgbotapi.ChatConfigWithUser{
- ChatID: chatid,
- UserID: userid,
- }
- member, err := bot.GetChatMember(tgbotapi.GetChatMemberConfig{ChatConfigWithUser: hi})
+ member, err := bot.GetChatMember(tgbotapi.GetChatMemberConfig{ChatConfigWithUser: userToGet})
if err != nil {
- return
+ return true, member
}
- return member
+ return false, member
}
diff --git a/commands/gaypoints/gaypoints.go b/commands/gaypoints/gaypoints.go
index 500c0a1..721a97f 100644
--- a/commands/gaypoints/gaypoints.go
+++ b/commands/gaypoints/gaypoints.go
@@ -20,12 +20,18 @@ func GetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
log.Println("[gaypoints] Looking for gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
points := sqlGetGP(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID)
- currentUser := botIO.GetUserByID(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID, bot)
- currentName := currentUser.User.FirstName
- if currentUser.User.UserName != "" {
- currentName = currentUser.User.UserName
+ gotUser, currentUser := botIO.GetUserByID(tgbotapi.ChatConfigWithUser{ChatID: update.Message.Chat.ID, UserID: update.Message.ReplyToMessage.From.ID}, bot)
+ var messagetext string
+ if !gotUser {
+ currentName := currentUser.User.FirstName
+ if currentUser.User.UserName != "" {
+ currentName = currentUser.User.UserName
+ }
+ messagetext = `` + currentName + `` + ` currently has ` + `` + strconv.FormatInt(points, 10) + `` + ` gaypoints` + "\n"
+
+ } else {
+ messagetext = "Something went wrong :("
}
- messagetext := `` + currentName + `` + ` currently has ` + `` + strconv.FormatInt(points, 10) + `` + ` gaypoints` + "\n"
message := tgbotapi.MessageConfig{
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
@@ -43,7 +49,10 @@ func GetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
var messagetext string
for _, gaypointInfo := range gps {
- currentUser := botIO.GetUserByID(update.Message.Chat.ID, gaypointInfo.userID, bot)
+ gotUser, currentUser := botIO.GetUserByID(tgbotapi.ChatConfigWithUser{ChatID: update.Message.Chat.ID, UserID: gaypointInfo.userID}, bot)
+ if !gotUser {
+ continue
+ }
currentName := currentUser.User.FirstName
if currentUser.User.UserName != "" {
currentName = currentUser.User.UserName
@@ -157,21 +166,32 @@ func SetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
}
}
- log.Println("[gaypoints] Changing gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10) + " from " + strconv.FormatInt(currentPoints, 10) + " to " + strconv.FormatInt(finalgp, 10))
+ gotUser, currentUser := botIO.GetUserByID(tgbotapi.ChatConfigWithUser{ChatID: update.Message.Chat.ID, UserID: update.Message.ReplyToMessage.From.ID}, bot)
- sqlSetGP(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID, finalgp)
+ var messagetext string
+ if gotUser {
+ currentName := currentUser.User.FirstName
+ if currentUser.User.UserName != "" {
+ currentName = currentUser.User.UserName
+ }
+ messagetext = `` + currentName + `` + ` now has ` + `` + strconv.FormatInt(finalgp, 10) + `` + ` gaypoints` + "\n"
+ } else {
+ messagetext = "Something went wrong :("
+ log.Println("[gaypoints] Failed to change gaypoints " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10) + " from " + strconv.FormatInt(currentPoints, 10) + " to " + strconv.FormatInt(finalgp, 10))
- currentUser := botIO.GetUserByID(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID, bot)
- currentName := currentUser.User.FirstName
- if currentUser.User.UserName != "" {
- currentName = currentUser.User.UserName
+ return
}
+
message := tgbotapi.MessageConfig{
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
ParseMode: "html",
DisableWebPagePreview: false,
- Text: `` + currentName + `` + ` now has ` + `` + strconv.FormatInt(finalgp, 10) + `` + ` gaypoints` + "\n",
+ Text: messagetext,
}
+
+ log.Println("[gaypoints] Changing gaypoints " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10) + " from " + strconv.FormatInt(currentPoints, 10) + " to " + strconv.FormatInt(finalgp, 10))
+
+ sqlSetGP(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID, finalgp)
botIO.SendMessage(message, bot)
return
}