one-api/common/telegram/command_aff.go

36 lines
887 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package telegram
import (
"one-api/common"
"one-api/common/utils"
"strings"
"github.com/PaulSonOfLars/gotgbot/v2"
"github.com/PaulSonOfLars/gotgbot/v2/ext"
)
func commandAffStart(b *gotgbot.Bot, ctx *ext.Context) error {
user := getBindUser(b, ctx)
if user == nil {
return nil
}
if user.AffCode == "" {
user.AffCode = utils.GetRandomString(4)
if err := user.Update(false); err != nil {
ctx.EffectiveMessage.Reply(b, "系统错误,请稍后再试", nil)
return nil
}
}
messae := "您可以通过分享您的邀请码来邀请朋友,每次成功邀请将获得奖励。\n\n您的邀请码是: " + user.AffCode
if common.ServerAddress != "" {
serverAddress := strings.TrimSuffix(common.ServerAddress, "/")
messae += "\n\n页面地址" + serverAddress + "/register?aff=" + user.AffCode
}
ctx.EffectiveMessage.Reply(b, messae, nil)
return nil
}