fix v2
This commit is contained in:
parent
f00e8e1509
commit
d52bd7d692
2 changed files with 37 additions and 21 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
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 := `<a href="` + `tg://user?id=` + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + `">` + currentName + `</a>` + ` currently has ` + `<b>` + strconv.FormatInt(points, 10) + `</b>` + ` gaypoints` + "\n"
|
||||
messagetext = `<a href="` + `tg://user?id=` + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + `">` + currentName + `</a>` + ` currently has ` + `<b>` + strconv.FormatInt(points, 10) + `</b>` + ` gaypoints` + "\n"
|
||||
|
||||
} else {
|
||||
messagetext = "Something went wrong :("
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
currentUser := botIO.GetUserByID(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID, bot)
|
||||
var messagetext string
|
||||
if gotUser {
|
||||
currentName := currentUser.User.FirstName
|
||||
if currentUser.User.UserName != "" {
|
||||
currentName = currentUser.User.UserName
|
||||
}
|
||||
messagetext = `<a href="` + `tg://user?id=` + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + `">` + currentName + `</a>` + ` now has ` + `<b>` + strconv.FormatInt(finalgp, 10) + `</b>` + ` 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))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
message := tgbotapi.MessageConfig{
|
||||
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||
ParseMode: "html",
|
||||
DisableWebPagePreview: false,
|
||||
Text: `<a href="` + `tg://user?id=` + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + `">` + currentName + `</a>` + ` now has ` + `<b>` + strconv.FormatInt(finalgp, 10) + `</b>` + ` 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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue