mirror of
https://github.com/tiennm99/store-scraper-bot.git
synced 2026-08-31 16:26:46 +00:00
- Switch Telegram parse mode to HTML to match Java client. - Rename command identifiers to Java's: delgroup/delapple/delgoogle/ checkappscore/rawappleapp/rawgoogleapp. - Move admin singleton to "common" collection at _id="admin". - Store group _id as string-of-int64 to match Java AbstractModel schema. - Add `class` discriminator field on persisted models. - Expand AppleAppResponse (42 fields) and GoogleAppResponse (63 fields, with nested Category/Feature) to match Java records. - Add AppleAppRequest (track id or bundle id) / GoogleAppRequest types. - Implement Raw* commands as Telegram document attachments instead of truncated text. - Group-authorization gate (admin.HasGroup(chatId)) on non-admin commands. - Cache TTL via millis timestamp; round score to 1 decimal; weekend silent send in scheduler. - Match Java table renderer: " │ " separators, "─┼─" rows every 5 lines. - Prefer MONGODB_CONNECTION_STRING env (Java parity); auto-extract DB name from URI with fallback to "store-scraper-bot". Note: This is an AI-assisted port (not human-verified). Behavior parity with the Java implementation has not been tested end-to-end; treat as a starting point.
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package command
|
|
|
|
import (
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
"github.com/miti99/store-scraper-bot-go/internal/config"
|
|
"github.com/miti99/store-scraper-bot-go/internal/repository"
|
|
)
|
|
|
|
// Sender is what bot.Bot exposes to commands. HTML parse mode (Java parity).
|
|
type Sender interface {
|
|
SendMessage(chatID int64, html string) error
|
|
SendMessageSilent(chatID int64, html string) error
|
|
SendDocument(chatID int64, filename, body string) error
|
|
}
|
|
|
|
// Command is the unit registered on the bot dispatcher.
|
|
type Command interface {
|
|
Execute(msg *tgbotapi.Message, sender Sender)
|
|
}
|
|
|
|
// authorizeGroup verifies the chat is in the admin's authorized group list.
|
|
// Mirrors Java's per-command "Group is not allowed to use bot" gate.
|
|
func authorizeGroup(chatID int64, adminRepo *repository.AdminRepository, sender Sender) bool {
|
|
ok, err := adminRepo.HasGroup(chatID)
|
|
if err != nil || !ok {
|
|
_ = sender.SendMessage(chatID, "Group is not allowed to use bot")
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
// requireAdminUser checks the user is in Environment.ADMIN_IDS.
|
|
func requireAdminUser(userID, chatID int64, cfg *config.Config, sender Sender) bool {
|
|
if !cfg.IsAdmin(userID) {
|
|
_ = sender.SendMessage(chatID, "You are not authorized to use this command")
|
|
return false
|
|
}
|
|
return true
|
|
}
|