package gaypoints import ( tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" "log" "strconv" "strings" "watn3y/bloaterbotv3/botIO" "watn3y/bloaterbotv3/commonlogic" "watn3y/bloaterbotv3/config" ) func GetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) { if !commonlogic.ContainsInt64(config.BotConfig.GayPoints.EnabledChats, update.Message.Chat.ID) { return } if update.Message.ReplyToMessage != nil { 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) 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 :(" } message := tgbotapi.MessageConfig{ BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, ParseMode: "html", DisableWebPagePreview: false, Text: messagetext, } botIO.SendMessage(message, bot) return } log.Println("[gaypoints] Looking for gaypoints for chat " + strconv.FormatInt(update.Message.Chat.ID, 10)) gps := sqlGetAllGP(update.Message.Chat.ID) var messagetext string for _, gaypointInfo := range gps { 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 } text := `` + currentName + `` + ` currently has ` + `` + strconv.FormatInt(gaypointInfo.gaypoints, 10) + `` + ` gaypoints` + "\n" messagetext = messagetext + text } message := tgbotapi.MessageConfig{ BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, ParseMode: "html", DisableWebPagePreview: false, Text: messagetext, } botIO.SendMessage(message, bot) return } func SetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) { if !commonlogic.ContainsInt64(config.BotConfig.GayPoints.EnabledChats, update.Message.Chat.ID) { return } if !commonlogic.ContainsInt64(config.BotConfig.GayPoints.ModifyUsers, update.Message.From.ID) { sticker := tgbotapi.StickerConfig{BaseFile: tgbotapi.BaseFile{ BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, File: tgbotapi.FilePath("bloater.webp"), }} botIO.SendSticker(sticker, bot) return } cmd := strings.ToLower(update.Message.Command()) commandArgs := strings.Fields(update.Message.CommandArguments()) var arg string if len(commandArgs) >= 1 { arg = strings.ToLower(commandArgs[0]) } else { arg = "" } log.Println("[gaypoints] Trying to modify gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10)) if update.Message.ReplyToMessage == nil { message := tgbotapi.MessageConfig{ BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, ParseMode: "html", DisableWebPagePreview: false, Text: "Please reply to a message to set gaypoints", } log.Println("[gaypoints] Failed to set gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10)) botIO.SendMessage(message, bot) return } if arg == "" { message := tgbotapi.MessageConfig{ BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, ParseMode: "html", DisableWebPagePreview: false, Text: "Please specify a valid gaypoint value", } log.Println("[gaypoints] Failed to set gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10)) botIO.SendMessage(message, bot) return } newPoints, err := strconv.ParseInt(arg, 10, 64) if err != nil || newPoints <= 0 { message := tgbotapi.MessageConfig{ BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, ParseMode: "html", DisableWebPagePreview: false, Text: "Please specify a valid gaypoint value", } log.Println("[gaypoints] Failed to set gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10)) botIO.SendMessage(message, bot) return } var finalgp int64 var currentPoints int64 if cmd == "addgp" { currentPoints = sqlGetGP(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID) if currentPoints <= -1 { finalgp = newPoints } else { finalgp = currentPoints + newPoints } } if cmd == "subtractgp" { currentPoints = sqlGetGP(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID) if currentPoints <= 0 { message := tgbotapi.MessageConfig{ BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, ParseMode: "html", DisableWebPagePreview: false, Text: "Please specify a valid gaypoint value", } log.Println("[gaypoints] Failed to subtrackt gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10)) botIO.SendMessage(message, bot) return } else { finalgp = currentPoints - newPoints } } 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 + `` + ` 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)) return } message := tgbotapi.MessageConfig{ BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID}, ParseMode: "html", DisableWebPagePreview: false, 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 }