Add /config trial VPN generation for users (1 day default)
Users get Remnawave subscription via /config or inline button; TRIAL_USER_DAYS and panel lookup by Telegram ID. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -46,6 +46,30 @@ func (d *DB) SaveVPNUser(ctx context.Context, u VPNUser) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DB) GetVPNByTelegramID(ctx context.Context, telegramID int64) (*VPNUser, error) {
|
||||
row := d.pool.QueryRow(ctx, `
|
||||
SELECT id, telegram_id, remnawave_uuid::text, remnawave_username,
|
||||
external_squad_uuid::text, internal_squad_uuids::text[], expire_at
|
||||
FROM vpn_users
|
||||
WHERE telegram_id = $1
|
||||
ORDER BY expire_at DESC NULLS LAST
|
||||
LIMIT 1`, telegramID)
|
||||
|
||||
var u VPNUser
|
||||
var ext *string
|
||||
var internal []string
|
||||
err := row.Scan(&u.ID, &u.TelegramID, &u.RemnawaveUUID, &u.RemnawaveUsername, &ext, &internal, &u.ExpireAt)
|
||||
if err == pgx.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u.ExternalSquadUUID = ext
|
||||
u.InternalSquadUUIDs = internal
|
||||
return &u, nil
|
||||
}
|
||||
|
||||
func (d *DB) GetVPNByUsername(ctx context.Context, username string) (*VPNUser, error) {
|
||||
row := d.pool.QueryRow(ctx, `
|
||||
SELECT id, telegram_id, remnawave_uuid::text, remnawave_username,
|
||||
|
||||
Reference in New Issue
Block a user