Security/quality

This commit is contained in:
HugeFrog24
2026-03-05 01:51:59 +01:00
parent 6e2d2fce2f
commit e1a9261699
30 changed files with 2823 additions and 295 deletions
Executable → Regular
+16 -12
View File
@@ -29,16 +29,19 @@ type ConfigModel struct {
type Message struct {
gorm.Model
BotID uint
ChatID int64
UserID int64
Username string
UserRole string
Text string
StickerFileID string `json:"sticker_file_id,omitempty"` // New field to store Sticker File ID
StickerPNGFile string `json:"sticker_png_file,omitempty"` // Optionally store PNG file ID if needed
Timestamp time.Time
BotID uint `gorm:"index"`
ChatID int64 `gorm:"index"`
UserID int64 `gorm:"index"`
Username string `gorm:"index"`
UserRole string // Store the role as a string
Text string `gorm:"type:text"`
Timestamp time.Time `gorm:"index"`
IsUser bool
StickerFileID string
StickerPNGFile string
StickerEmoji string // Store the emoji associated with the sticker
DeletedAt gorm.DeletedAt `gorm:"index"` // Add soft delete field
AnsweredOn *time.Time `gorm:"index"` // Tracks when a user message was answered (NULL for assistant messages and unanswered user messages)
}
type ChatMemory struct {
@@ -54,15 +57,16 @@ type Role struct {
type User struct {
gorm.Model
BotID uint `gorm:"index"` // Foreign key to BotModel
TelegramID int64 `gorm:"uniqueIndex;not null"` // Unique per user
BotID uint `gorm:"uniqueIndex:idx_user_bot;index"` // Foreign key to BotModel
TelegramID int64 `gorm:"uniqueIndex:idx_user_bot;not null"` // Unique per (telegram_id, bot_id) pair
Username string
RoleID uint
Role Role `gorm:"foreignKey:RoleID"`
IsOwner bool `gorm:"default:false"` // Indicates if the user is the owner
}
// Compound unique index to ensure only one owner per bot
// idx_user_bot is a composite unique index on (bot_id, telegram_id),
// allowing the same Telegram user to be registered independently on each bot.
func (User) TableName() string {
return "users"
}