chore: refresh gramsrv public release

This commit is contained in:
A 2026-06-30 14:37:43 +08:00
parent 75cebe8dbf
commit 70b6820474
1274 changed files with 378751 additions and 59919 deletions

View file

@ -0,0 +1,440 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: bot.sql
package sqlcgen
import (
"context"
)
const allowBotSendMessage = `-- name: AllowBotSendMessage :one
WITH inserted AS (
INSERT INTO bot_user_permissions (bot_user_id, user_id, from_request)
VALUES ($1, $2, $3)
ON CONFLICT (bot_user_id, user_id) DO NOTHING
RETURNING 1
),
updated AS (
UPDATE bot_user_permissions
SET from_request = bot_user_permissions.from_request OR $3,
updated_at = now()
WHERE bot_user_id = $1 AND user_id = $2
AND NOT EXISTS (SELECT 1 FROM inserted)
AND $3
AND NOT from_request
RETURNING 1
)
SELECT EXISTS (SELECT 1 FROM inserted) AS created
`
type AllowBotSendMessageParams struct {
BotUserID int64
UserID int64
FromRequest bool
}
func (q *Queries) AllowBotSendMessage(ctx context.Context, arg AllowBotSendMessageParams) (bool, error) {
row := q.db.QueryRow(ctx, allowBotSendMessage, arg.BotUserID, arg.UserID, arg.FromRequest)
var created bool
err := row.Scan(&created)
return created, err
}
const bumpBotInfoVersion = `-- name: BumpBotInfoVersion :one
UPDATE users
SET bot_info_version = bot_info_version + 1, updated_at = now()
WHERE id = $1 AND is_bot
RETURNING bot_info_version
`
func (q *Queries) BumpBotInfoVersion(ctx context.Context, id int64) (int32, error) {
row := q.db.QueryRow(ctx, bumpBotInfoVersion, id)
var bot_info_version int32
err := row.Scan(&bot_info_version)
return bot_info_version, err
}
const canBotSendMessage = `-- name: CanBotSendMessage :one
SELECT EXISTS (
SELECT 1
FROM bot_user_permissions
WHERE bot_user_id = $1 AND user_id = $2
)
`
type CanBotSendMessageParams struct {
BotUserID int64
UserID int64
}
func (q *Queries) CanBotSendMessage(ctx context.Context, arg CanBotSendMessageParams) (bool, error) {
row := q.db.QueryRow(ctx, canBotSendMessage, arg.BotUserID, arg.UserID)
var exists bool
err := row.Scan(&exists)
return exists, err
}
const countBotsByOwner = `-- name: CountBotsByOwner :one
SELECT COUNT(*) FROM bots WHERE owner_user_id = $1 AND bot_user_id <> owner_user_id
`
func (q *Queries) CountBotsByOwner(ctx context.Context, ownerUserID int64) (int64, error) {
row := q.db.QueryRow(ctx, countBotsByOwner, ownerUserID)
var count int64
err := row.Scan(&count)
return count, err
}
const deleteBotChatState = `-- name: DeleteBotChatState :exec
DELETE FROM bot_chat_states WHERE bot_user_id = $1 AND user_id = $2
`
type DeleteBotChatStateParams struct {
BotUserID int64
UserID int64
}
func (q *Queries) DeleteBotChatState(ctx context.Context, arg DeleteBotChatStateParams) error {
_, err := q.db.Exec(ctx, deleteBotChatState, arg.BotUserID, arg.UserID)
return err
}
const getBot = `-- name: GetBot :one
SELECT bot_user_id, owner_user_id, token_secret, description, commands, bot_chat_history, bot_nochats, inline_placeholder, created_at, updated_at, menu_button_type, menu_button_text, menu_button_url, bot_inline_geo FROM bots WHERE bot_user_id = $1
`
func (q *Queries) GetBot(ctx context.Context, botUserID int64) (Bot, error) {
row := q.db.QueryRow(ctx, getBot, botUserID)
var i Bot
err := row.Scan(
&i.BotUserID,
&i.OwnerUserID,
&i.TokenSecret,
&i.Description,
&i.Commands,
&i.BotChatHistory,
&i.BotNochats,
&i.InlinePlaceholder,
&i.CreatedAt,
&i.UpdatedAt,
&i.MenuButtonType,
&i.MenuButtonText,
&i.MenuButtonUrl,
&i.BotInlineGeo,
)
return i, err
}
const getBotChatState = `-- name: GetBotChatState :one
SELECT bot_user_id, user_id, state, updated_at FROM bot_chat_states WHERE bot_user_id = $1 AND user_id = $2
`
type GetBotChatStateParams struct {
BotUserID int64
UserID int64
}
func (q *Queries) GetBotChatState(ctx context.Context, arg GetBotChatStateParams) (BotChatState, error) {
row := q.db.QueryRow(ctx, getBotChatState, arg.BotUserID, arg.UserID)
var i BotChatState
err := row.Scan(
&i.BotUserID,
&i.UserID,
&i.State,
&i.UpdatedAt,
)
return i, err
}
const insertBot = `-- name: InsertBot :exec
INSERT INTO bots (bot_user_id, owner_user_id, token_secret)
VALUES ($1, $2, $3)
`
type InsertBotParams struct {
BotUserID int64
OwnerUserID int64
TokenSecret string
}
func (q *Queries) InsertBot(ctx context.Context, arg InsertBotParams) error {
_, err := q.db.Exec(ctx, insertBot, arg.BotUserID, arg.OwnerUserID, arg.TokenSecret)
return err
}
const insertBotUser = `-- name: InsertBotUser :one
INSERT INTO users (access_hash, phone, first_name, last_name, username, country_code, is_bot, bot_info_version)
VALUES ($1, '', $2, '', $3, '', TRUE, 1)
RETURNING id, access_hash, phone, first_name, last_name, username, country_code, created_at, updated_at, verified, support, about, last_seen_at, default_history_ttl_period, is_bot, bot_info_version, premium_expires_at, emoji_status_document_id, emoji_status_until, color_set, color, color_background_emoji_id, profile_color_set, profile_color, profile_color_background_emoji_id, birthday_day, birthday_month, birthday_year, personal_channel_id
`
type InsertBotUserParams struct {
AccessHash int64
FirstName string
Username string
}
func (q *Queries) InsertBotUser(ctx context.Context, arg InsertBotUserParams) (User, error) {
row := q.db.QueryRow(ctx, insertBotUser, arg.AccessHash, arg.FirstName, arg.Username)
var i User
err := row.Scan(
&i.ID,
&i.AccessHash,
&i.Phone,
&i.FirstName,
&i.LastName,
&i.Username,
&i.CountryCode,
&i.CreatedAt,
&i.UpdatedAt,
&i.Verified,
&i.Support,
&i.About,
&i.LastSeenAt,
&i.DefaultHistoryTtlPeriod,
&i.IsBot,
&i.BotInfoVersion,
&i.PremiumExpiresAt,
&i.EmojiStatusDocumentID,
&i.EmojiStatusUntil,
&i.ColorSet,
&i.Color,
&i.ColorBackgroundEmojiID,
&i.ProfileColorSet,
&i.ProfileColor,
&i.ProfileColorBackgroundEmojiID,
&i.BirthdayDay,
&i.BirthdayMonth,
&i.BirthdayYear,
&i.PersonalChannelID,
)
return i, err
}
const listBotsByOwner = `-- name: ListBotsByOwner :many
SELECT bot_user_id, owner_user_id, token_secret, description, commands, bot_chat_history, bot_nochats, inline_placeholder, created_at, updated_at, menu_button_type, menu_button_text, menu_button_url, bot_inline_geo FROM bots WHERE owner_user_id = $1 AND bot_user_id <> owner_user_id ORDER BY bot_user_id
`
// 排除 self-owner 种子行(内置 BotFather 自有),与 memory 实现一致:/mybots 与
// 创建上限只统计用户经 /newbot 创建的 bot。
func (q *Queries) ListBotsByOwner(ctx context.Context, ownerUserID int64) ([]Bot, error) {
rows, err := q.db.Query(ctx, listBotsByOwner, ownerUserID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Bot
for rows.Next() {
var i Bot
if err := rows.Scan(
&i.BotUserID,
&i.OwnerUserID,
&i.TokenSecret,
&i.Description,
&i.Commands,
&i.BotChatHistory,
&i.BotNochats,
&i.InlinePlaceholder,
&i.CreatedAt,
&i.UpdatedAt,
&i.MenuButtonType,
&i.MenuButtonText,
&i.MenuButtonUrl,
&i.BotInlineGeo,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const setBotChatHistoryRow = `-- name: SetBotChatHistoryRow :execrows
UPDATE bots SET bot_chat_history = $2, updated_at = now() WHERE bot_user_id = $1
`
type SetBotChatHistoryRowParams struct {
BotUserID int64
BotChatHistory bool
}
func (q *Queries) SetBotChatHistoryRow(ctx context.Context, arg SetBotChatHistoryRowParams) (int64, error) {
result, err := q.db.Exec(ctx, setBotChatHistoryRow, arg.BotUserID, arg.BotChatHistory)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const setBotInlineGeoRow = `-- name: SetBotInlineGeoRow :execrows
UPDATE bots SET bot_inline_geo = $2, updated_at = now() WHERE bot_user_id = $1
`
type SetBotInlineGeoRowParams struct {
BotUserID int64
BotInlineGeo bool
}
func (q *Queries) SetBotInlineGeoRow(ctx context.Context, arg SetBotInlineGeoRowParams) (int64, error) {
result, err := q.db.Exec(ctx, setBotInlineGeoRow, arg.BotUserID, arg.BotInlineGeo)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const setBotInlinePlaceholderRow = `-- name: SetBotInlinePlaceholderRow :execrows
UPDATE bots SET inline_placeholder = $2, updated_at = now() WHERE bot_user_id = $1
`
type SetBotInlinePlaceholderRowParams struct {
BotUserID int64
InlinePlaceholder string
}
func (q *Queries) SetBotInlinePlaceholderRow(ctx context.Context, arg SetBotInlinePlaceholderRowParams) (int64, error) {
result, err := q.db.Exec(ctx, setBotInlinePlaceholderRow, arg.BotUserID, arg.InlinePlaceholder)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const setBotNochatsRow = `-- name: SetBotNochatsRow :execrows
UPDATE bots SET bot_nochats = $2, updated_at = now() WHERE bot_user_id = $1
`
type SetBotNochatsRowParams struct {
BotUserID int64
BotNochats bool
}
func (q *Queries) SetBotNochatsRow(ctx context.Context, arg SetBotNochatsRowParams) (int64, error) {
result, err := q.db.Exec(ctx, setBotNochatsRow, arg.BotUserID, arg.BotNochats)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const updateBotCommandsRow = `-- name: UpdateBotCommandsRow :execrows
UPDATE bots SET commands = $2, updated_at = now() WHERE bot_user_id = $1
`
type UpdateBotCommandsRowParams struct {
BotUserID int64
Commands []byte
}
func (q *Queries) UpdateBotCommandsRow(ctx context.Context, arg UpdateBotCommandsRowParams) (int64, error) {
result, err := q.db.Exec(ctx, updateBotCommandsRow, arg.BotUserID, arg.Commands)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const updateBotDescriptionRow = `-- name: UpdateBotDescriptionRow :execrows
UPDATE bots SET description = $2, updated_at = now() WHERE bot_user_id = $1
`
type UpdateBotDescriptionRowParams struct {
BotUserID int64
Description string
}
func (q *Queries) UpdateBotDescriptionRow(ctx context.Context, arg UpdateBotDescriptionRowParams) (int64, error) {
result, err := q.db.Exec(ctx, updateBotDescriptionRow, arg.BotUserID, arg.Description)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const updateBotMenuButtonRow = `-- name: UpdateBotMenuButtonRow :execrows
UPDATE bots
SET menu_button_type = $2, menu_button_text = $3, menu_button_url = $4, updated_at = now()
WHERE bot_user_id = $1
`
type UpdateBotMenuButtonRowParams struct {
BotUserID int64
MenuButtonType int16
MenuButtonText string
MenuButtonUrl string
}
func (q *Queries) UpdateBotMenuButtonRow(ctx context.Context, arg UpdateBotMenuButtonRowParams) (int64, error) {
result, err := q.db.Exec(ctx, updateBotMenuButtonRow,
arg.BotUserID,
arg.MenuButtonType,
arg.MenuButtonText,
arg.MenuButtonUrl,
)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const updateBotProfileFields = `-- name: UpdateBotProfileFields :one
UPDATE users
SET first_name = COALESCE($2, first_name),
about = COALESCE($3, about),
updated_at = now()
WHERE id = $1 AND is_bot
RETURNING bot_info_version
`
type UpdateBotProfileFieldsParams struct {
ID int64
FirstName *string
About *string
}
// 部分更新 bot 的 users 行setBotInfo 的 name/aboutNULL 参数表示不动该字段。
func (q *Queries) UpdateBotProfileFields(ctx context.Context, arg UpdateBotProfileFieldsParams) (int32, error) {
row := q.db.QueryRow(ctx, updateBotProfileFields, arg.ID, arg.FirstName, arg.About)
var bot_info_version int32
err := row.Scan(&bot_info_version)
return bot_info_version, err
}
const updateBotTokenSecret = `-- name: UpdateBotTokenSecret :execrows
UPDATE bots SET token_secret = $2, updated_at = now() WHERE bot_user_id = $1
`
type UpdateBotTokenSecretParams struct {
BotUserID int64
TokenSecret string
}
func (q *Queries) UpdateBotTokenSecret(ctx context.Context, arg UpdateBotTokenSecretParams) (int64, error) {
result, err := q.db.Exec(ctx, updateBotTokenSecret, arg.BotUserID, arg.TokenSecret)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const upsertBotChatState = `-- name: UpsertBotChatState :exec
INSERT INTO bot_chat_states (bot_user_id, user_id, state, updated_at)
VALUES ($1, $2, $3, now())
ON CONFLICT (bot_user_id, user_id) DO UPDATE SET state = EXCLUDED.state, updated_at = now()
`
type UpsertBotChatStateParams struct {
BotUserID int64
UserID int64
State []byte
}
func (q *Queries) UpsertBotChatState(ctx context.Context, arg UpsertBotChatStateParams) error {
_, err := q.db.Exec(ctx, upsertBotChatState, arg.BotUserID, arg.UserID, arg.State)
return err
}