Documentation
¶
Index ¶
- type MySQL
- type Repository
- func (r *Repository) ActivateBot(ctx context.Context, token string) error
- func (r *Repository) BanUser(ctx context.Context, botID, userChatID, bannedBy int64) error
- func (r *Repository) CreateAutoReply(ctx context.Context, botID int64, ...) error
- func (r *Repository) CreateBot(ctx context.Context, token string, ownerChatID int64, username string) (*models.Bot, error)
- func (r *Repository) CreateForcedChannel(ctx context.Context, botID, channelID int64, ...) error
- func (r *Repository) CreateScheduledMessage(ctx context.Context, msg *models.ScheduledMessage) (int64, error)
- func (r *Repository) DeactivateBot(ctx context.Context, token string) error
- func (r *Repository) DeleteAutoReply(ctx context.Context, botID, replyID int64) error
- func (r *Repository) DeleteBot(ctx context.Context, token string) error
- func (r *Repository) DeleteForcedChannel(ctx context.Context, botID, channelID int64) error
- func (r *Repository) DeleteScheduledMessage(ctx context.Context, msgID, botID int64) error
- func (r *Repository) GetActiveBots(ctx context.Context) ([]models.Bot, error)
- func (r *Repository) GetActiveUserCount(ctx context.Context, botID int64, since time.Time) (int64, error)
- func (r *Repository) GetAllBots(ctx context.Context) ([]models.Bot, error)
- func (r *Repository) GetAllUserChatIDs(ctx context.Context, botID int64) ([]int64, error)
- func (r *Repository) GetAutoReplies(ctx context.Context, botID int64, triggerType string) ([]models.AutoReply, error)
- func (r *Repository) GetAutoReplyByID(ctx context.Context, replyID int64) (*models.AutoReply, error)
- func (r *Repository) GetAutoReplyByTrigger(ctx context.Context, botID int64, trigger, triggerType string) (*models.AutoReply, error)
- func (r *Repository) GetAutoReplyCount(ctx context.Context, botID int64, triggerType string) (int64, error)
- func (r *Repository) GetBannedUserCount(ctx context.Context, botID int64) (int64, error)
- func (r *Repository) GetBannedUsers(ctx context.Context, botID int64, limit, offset int) ([]models.BannedUser, error)
- func (r *Repository) GetBotByToken(ctx context.Context, token string) (*models.Bot, error)
- func (r *Repository) GetBotFirstActivity(ctx context.Context, botID int64) (time.Time, error)
- func (r *Repository) GetBotsByOwner(ctx context.Context, ownerChatID int64) ([]models.Bot, error)
- func (r *Repository) GetDeletedBotByToken(ctx context.Context, token string) (*models.Bot, error)
- func (r *Repository) GetDeletedBotsCount(ctx context.Context) (int64, error)
- func (r *Repository) GetFirstMessageDate(ctx context.Context, botID int64, userChatID int64) (time.Time, error)
- func (r *Repository) GetForcedChannel(ctx context.Context, botID, channelID int64) (*models.ForcedChannel, error)
- func (r *Repository) GetForcedChannelCount(ctx context.Context, botID int64) (int64, error)
- func (r *Repository) GetForcedChannels(ctx context.Context, botID int64) ([]models.ForcedChannel, error)
- func (r *Repository) GetGlobalActiveUserCount(ctx context.Context, since time.Time) (int64, error)
- func (r *Repository) GetGlobalAutoReplyCount(ctx context.Context) (int64, error)
- func (r *Repository) GetGlobalBannedUserCount(ctx context.Context) (int64, error)
- func (r *Repository) GetGlobalForcedChannelCount(ctx context.Context) (int64, error)
- func (r *Repository) GetGlobalMessageCountSince(ctx context.Context, since time.Time) (int64, error)
- func (r *Repository) GetGlobalNewUserCount(ctx context.Context, since time.Time) (int64, error)
- func (r *Repository) GetGlobalTotalMessageCount(ctx context.Context) (int64, error)
- func (r *Repository) GetGlobalUniqueUserCount(ctx context.Context) (int64, error)
- func (r *Repository) GetMessageCountSince(ctx context.Context, botID int64, since time.Time) (int64, error)
- func (r *Repository) GetNewUserCount(ctx context.Context, botID int64, since time.Time) (int64, error)
- func (r *Repository) GetPendingScheduledMessages(ctx context.Context, beforeTime time.Time, limit int) ([]models.ScheduledMessage, error)
- func (r *Repository) GetScheduledMessage(ctx context.Context, msgID int64) (*models.ScheduledMessage, error)
- func (r *Repository) GetScheduledMessagesByBot(ctx context.Context, botID int64, limit, offset int) ([]models.ScheduledMessage, error)
- func (r *Repository) GetScheduledMessagesCount(ctx context.Context, botID int64) (int64, error)
- func (r *Repository) GetTotalMessageCount(ctx context.Context, botID int64) (int64, error)
- func (r *Repository) GetUniqueOwnerCount(ctx context.Context) (int64, error)
- func (r *Repository) GetUniqueUserCount(ctx context.Context, botID int64) (int64, error)
- func (r *Repository) GetUserChatID(ctx context.Context, adminMsgID int, botID int64) (int64, error)
- func (r *Repository) HasUserInteracted(ctx context.Context, botID int64, userChatID int64) (bool, error)
- func (r *Repository) IsUserBanned(ctx context.Context, botID, userChatID int64) (bool, error)
- func (r *Repository) PauseScheduledMessage(ctx context.Context, msgID, botID int64) error
- func (r *Repository) RestoreBot(ctx context.Context, token string, ownerChatID int64, username string) error
- func (r *Repository) ResumeScheduledMessage(ctx context.Context, msgID, botID int64) error
- func (r *Repository) SaveMessageLog(ctx context.Context, adminMsgID int, userChatID int64, botID int64) error
- func (r *Repository) UnbanUser(ctx context.Context, botID, userChatID int64) error
- func (r *Repository) UpdateBotForwardAutoReplies(ctx context.Context, botID int64, forward bool) error
- func (r *Repository) UpdateBotShowSentConfirmation(ctx context.Context, botID int64, show bool) error
- func (r *Repository) UpdateBotStartMessage(ctx context.Context, botID int64, message string) error
- func (r *Repository) UpdateBotUsername(ctx context.Context, botID int64, username string) error
- func (r *Repository) UpdateForcedSubEnabled(ctx context.Context, botID int64, enabled bool) error
- func (r *Repository) UpdateForcedSubMessage(ctx context.Context, botID int64, message string) error
- func (r *Repository) UpdateScheduledMessageAfterSend(ctx context.Context, msgID int64, lastSent time.Time, nextRun *time.Time) error
- func (r *Repository) UpdateScheduledMessageStatus(ctx context.Context, msgID int64, status, failureReason string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MySQL ¶
type MySQL struct {
// contains filtered or unexported fields
}
MySQL wraps the sqlx.DB connection
func NewMySQLFromDB ¶
NewMySQLFromDB creates a MySQL wrapper from an existing sqlx.DB This is useful for testing with mock databases
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository handles all database operations Methods are organized across multiple files by domain: - bot.go: Bot CRUD operations - schedule.go: Scheduled messages operations - auto_reply.go: Auto-reply and custom commands - user.go: Message logs, user analytics, and bans - forced_sub.go: Forced channel subscription operations
func NewRepository ¶
func NewRepository(mysql *MySQL, encryptionKey string) *Repository
NewRepository creates a new repository instance
func (*Repository) ActivateBot ¶
func (r *Repository) ActivateBot(ctx context.Context, token string) error
ActivateBot sets is_active to true for a bot
func (*Repository) BanUser ¶
func (r *Repository) BanUser(ctx context.Context, botID, userChatID, bannedBy int64) error
BanUser adds a user to the banned list for a bot
func (*Repository) CreateAutoReply ¶
func (r *Repository) CreateAutoReply(ctx context.Context, botID int64, trigger, response, messageType, fileID, caption, triggerType, matchType string) error
CreateAutoReply creates a new auto-reply or custom command with optional media support
func (*Repository) CreateBot ¶
func (r *Repository) CreateBot(ctx context.Context, token string, ownerChatID int64, username string) (*models.Bot, error)
CreateBot inserts a new bot into the database
func (*Repository) CreateForcedChannel ¶
func (r *Repository) CreateForcedChannel(ctx context.Context, botID, channelID int64, username, title, inviteLink string) error
CreateForcedChannel adds a new forced subscription channel
func (*Repository) CreateScheduledMessage ¶
func (r *Repository) CreateScheduledMessage(ctx context.Context, msg *models.ScheduledMessage) (int64, error)
CreateScheduledMessage inserts a new scheduled message
func (*Repository) DeactivateBot ¶
func (r *Repository) DeactivateBot(ctx context.Context, token string) error
DeactivateBot sets is_active to false for a bot
func (*Repository) DeleteAutoReply ¶
func (r *Repository) DeleteAutoReply(ctx context.Context, botID, replyID int64) error
DeleteAutoReply removes an auto-reply by ID
func (*Repository) DeleteBot ¶
func (r *Repository) DeleteBot(ctx context.Context, token string) error
DeleteBot performs a soft delete by setting deleted_at timestamp
func (*Repository) DeleteForcedChannel ¶
func (r *Repository) DeleteForcedChannel(ctx context.Context, botID, channelID int64) error
DeleteForcedChannel removes a channel from forced subscription list
func (*Repository) DeleteScheduledMessage ¶
func (r *Repository) DeleteScheduledMessage(ctx context.Context, msgID, botID int64) error
DeleteScheduledMessage cancels a scheduled message
func (*Repository) GetActiveBots ¶
GetActiveBots retrieves all active bots (excludes soft-deleted)
func (*Repository) GetActiveUserCount ¶
func (r *Repository) GetActiveUserCount(ctx context.Context, botID int64, since time.Time) (int64, error)
GetActiveUserCount returns the number of unique users active since a given time
func (*Repository) GetAllBots ¶
GetAllBots retrieves all non-deleted bots (both active and inactive)
func (*Repository) GetAllUserChatIDs ¶
GetAllUserChatIDs returns all unique user chat IDs for a bot
func (*Repository) GetAutoReplies ¶
func (r *Repository) GetAutoReplies(ctx context.Context, botID int64, triggerType string) ([]models.AutoReply, error)
GetAutoReplies retrieves all auto-replies or commands for a bot
func (*Repository) GetAutoReplyByID ¶
func (r *Repository) GetAutoReplyByID(ctx context.Context, replyID int64) (*models.AutoReply, error)
GetAutoReplyByID retrieves an auto-reply by its ID
func (*Repository) GetAutoReplyByTrigger ¶
func (r *Repository) GetAutoReplyByTrigger(ctx context.Context, botID int64, trigger, triggerType string) (*models.AutoReply, error)
GetAutoReplyByTrigger finds an auto-reply by its trigger word
func (*Repository) GetAutoReplyCount ¶
func (r *Repository) GetAutoReplyCount(ctx context.Context, botID int64, triggerType string) (int64, error)
GetAutoReplyCount returns the count of auto-replies for a bot by type
func (*Repository) GetBannedUserCount ¶
GetBannedUserCount returns the count of banned users for a bot
func (*Repository) GetBannedUsers ¶
func (r *Repository) GetBannedUsers(ctx context.Context, botID int64, limit, offset int) ([]models.BannedUser, error)
GetBannedUsers retrieves all banned users for a bot with pagination
func (*Repository) GetBotByToken ¶
GetBotByToken retrieves a bot by its token (excludes soft-deleted bots)
func (*Repository) GetBotFirstActivity ¶
GetBotCreatedAt returns the creation date of a bot (first message received)
func (*Repository) GetBotsByOwner ¶
GetBotsByOwner retrieves all bots owned by a specific user (excludes soft-deleted)
func (*Repository) GetDeletedBotByToken ¶
GetDeletedBotByToken retrieves a soft-deleted bot by its token (for restore)
func (*Repository) GetDeletedBotsCount ¶
func (r *Repository) GetDeletedBotsCount(ctx context.Context) (int64, error)
GetDeletedBotsCount returns the count of soft-deleted bots
func (*Repository) GetFirstMessageDate ¶
func (r *Repository) GetFirstMessageDate(ctx context.Context, botID int64, userChatID int64) (time.Time, error)
GetFirstMessageDate retrieves the timestamp of the first message from a user
func (*Repository) GetForcedChannel ¶
func (r *Repository) GetForcedChannel(ctx context.Context, botID, channelID int64) (*models.ForcedChannel, error)
GetForcedChannel retrieves a single forced channel by bot and channel ID
func (*Repository) GetForcedChannelCount ¶
GetForcedChannelCount returns count of active forced channels for a bot
func (*Repository) GetForcedChannels ¶
func (r *Repository) GetForcedChannels(ctx context.Context, botID int64) ([]models.ForcedChannel, error)
GetForcedChannels retrieves all active forced channels for a bot
func (*Repository) GetGlobalActiveUserCount ¶
GetGlobalActiveUserCount returns the total active users across all bots since a given time
func (*Repository) GetGlobalAutoReplyCount ¶
func (r *Repository) GetGlobalAutoReplyCount(ctx context.Context) (int64, error)
GetGlobalAutoReplyCount returns total auto-replies across all bots
func (*Repository) GetGlobalBannedUserCount ¶
func (r *Repository) GetGlobalBannedUserCount(ctx context.Context) (int64, error)
GetGlobalBannedUserCount returns total banned users across all bots
func (*Repository) GetGlobalForcedChannelCount ¶
func (r *Repository) GetGlobalForcedChannelCount(ctx context.Context) (int64, error)
GetGlobalForcedChannelCount returns total forced channels across all bots
func (*Repository) GetGlobalMessageCountSince ¶
func (r *Repository) GetGlobalMessageCountSince(ctx context.Context, since time.Time) (int64, error)
GetGlobalMessageCountSince returns total messages across all bots since a given time
func (*Repository) GetGlobalNewUserCount ¶
GetGlobalNewUserCount returns new users across all bots since a given time
func (*Repository) GetGlobalTotalMessageCount ¶
func (r *Repository) GetGlobalTotalMessageCount(ctx context.Context) (int64, error)
GetGlobalTotalMessageCount returns the total messages across all bots
func (*Repository) GetGlobalUniqueUserCount ¶
func (r *Repository) GetGlobalUniqueUserCount(ctx context.Context) (int64, error)
GetGlobalUniqueUserCount returns the total unique users across all bots
func (*Repository) GetMessageCountSince ¶
func (r *Repository) GetMessageCountSince(ctx context.Context, botID int64, since time.Time) (int64, error)
GetMessageCountSince returns the number of messages since a given time
func (*Repository) GetNewUserCount ¶
func (r *Repository) GetNewUserCount(ctx context.Context, botID int64, since time.Time) (int64, error)
GetNewUserCount returns the number of new users (first message) since a given time Uses LEFT JOIN for better performance compared to correlated subquery
func (*Repository) GetPendingScheduledMessages ¶
func (r *Repository) GetPendingScheduledMessages(ctx context.Context, beforeTime time.Time, limit int) ([]models.ScheduledMessage, error)
GetPendingScheduledMessages retrieves messages ready to be sent
func (*Repository) GetScheduledMessage ¶
func (r *Repository) GetScheduledMessage(ctx context.Context, msgID int64) (*models.ScheduledMessage, error)
GetScheduledMessage retrieves a single scheduled message by ID
func (*Repository) GetScheduledMessagesByBot ¶
func (r *Repository) GetScheduledMessagesByBot(ctx context.Context, botID int64, limit, offset int) ([]models.ScheduledMessage, error)
GetScheduledMessagesByBot retrieves all scheduled messages for a bot
func (*Repository) GetScheduledMessagesCount ¶
GetScheduledMessagesCount returns count of scheduled messages for a bot
func (*Repository) GetTotalMessageCount ¶
GetTotalMessageCount returns the total number of messages for a bot
func (*Repository) GetUniqueOwnerCount ¶
func (r *Repository) GetUniqueOwnerCount(ctx context.Context) (int64, error)
GetUniqueOwnerCount returns the number of unique bot owners
func (*Repository) GetUniqueUserCount ¶
GetUniqueUserCount returns the number of unique users tracked for a bot
func (*Repository) GetUserChatID ¶
GetUserChatID retrieves the user chat ID for a given admin message
func (*Repository) HasUserInteracted ¶
func (r *Repository) HasUserInteracted(ctx context.Context, botID int64, userChatID int64) (bool, error)
HasUserInteracted checks if a user has ever messaged a bot
func (*Repository) IsUserBanned ¶
IsUserBanned checks if a user is banned for a specific bot
func (*Repository) PauseScheduledMessage ¶
func (r *Repository) PauseScheduledMessage(ctx context.Context, msgID, botID int64) error
PauseScheduledMessage pauses a scheduled message
func (*Repository) RestoreBot ¶
func (r *Repository) RestoreBot(ctx context.Context, token string, ownerChatID int64, username string) error
RestoreBot restores a soft-deleted bot
func (*Repository) ResumeScheduledMessage ¶
func (r *Repository) ResumeScheduledMessage(ctx context.Context, msgID, botID int64) error
ResumeScheduledMessage resumes a paused message
func (*Repository) SaveMessageLog ¶
func (r *Repository) SaveMessageLog(ctx context.Context, adminMsgID int, userChatID int64, botID int64) error
SaveMessageLog stores the message link in database
func (*Repository) UnbanUser ¶
func (r *Repository) UnbanUser(ctx context.Context, botID, userChatID int64) error
UnbanUser removes a user from the banned list
func (*Repository) UpdateBotForwardAutoReplies ¶
func (r *Repository) UpdateBotForwardAutoReplies(ctx context.Context, botID int64, forward bool) error
UpdateBotForwardAutoReplies updates the forward_auto_replies setting for a bot
func (*Repository) UpdateBotShowSentConfirmation ¶
func (r *Repository) UpdateBotShowSentConfirmation(ctx context.Context, botID int64, show bool) error
UpdateBotShowSentConfirmation updates the show_sent_confirmation setting for a bot
func (*Repository) UpdateBotStartMessage ¶
UpdateBotStartMessage updates the welcome message for a bot
func (*Repository) UpdateBotUsername ¶
UpdateBotUsername updates the username for a bot
func (*Repository) UpdateForcedSubEnabled ¶
UpdateForcedSubEnabled toggles the forced subscription feature for a bot
func (*Repository) UpdateForcedSubMessage ¶
UpdateForcedSubMessage updates the custom message for non-subscribers
func (*Repository) UpdateScheduledMessageAfterSend ¶
func (r *Repository) UpdateScheduledMessageAfterSend(ctx context.Context, msgID int64, lastSent time.Time, nextRun *time.Time) error
UpdateScheduledMessageAfterSend updates message after sending
func (*Repository) UpdateScheduledMessageStatus ¶
func (r *Repository) UpdateScheduledMessageStatus(ctx context.Context, msgID int64, status, failureReason string) error
UpdateScheduledMessageStatus updates the status of a message