mirror of
https://github.com/tiennm99/store-scraper-bot.git
synced 2026-08-31 06:28:43 +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.
44 lines
828 B
Go
44 lines
828 B
Go
package model
|
|
|
|
// AdminID is the singleton document _id used by Java AdminRepository.
|
|
const AdminID = "admin"
|
|
|
|
type Admin struct {
|
|
AbstractModel `bson:",inline"`
|
|
Groups []int64 `bson:"groups" json:"groups"`
|
|
}
|
|
|
|
func NewAdmin() *Admin {
|
|
return &Admin{
|
|
AbstractModel: AbstractModel{ID: AdminID, Class: "Admin"},
|
|
Groups: []int64{},
|
|
}
|
|
}
|
|
|
|
func (a *Admin) AddGroup(groupID int64) bool {
|
|
if a.HasGroup(groupID) {
|
|
return false
|
|
}
|
|
a.Groups = append(a.Groups, groupID)
|
|
return true
|
|
}
|
|
|
|
func (a *Admin) RemoveGroup(groupID int64) bool {
|
|
for i, g := range a.Groups {
|
|
if g == groupID {
|
|
a.Groups = append(a.Groups[:i], a.Groups[i+1:]...)
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (a *Admin) HasGroup(groupID int64) bool {
|
|
for _, g := range a.Groups {
|
|
if g == groupID {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|