Documentation ¶
Index ¶
- Constants
- Variables
- func CountTokens(text string) int
- func FilterSlice(slice []string, filter string) []string
- func GetRandomString(length int) string
- func NewProxyClient(proxyUrl string) (proxyParse *url.URL, client *http.Client, err error)
- func NextID() (string, error)
- func RandomElement[T any](slice []T) (T, error)
- func ReverseSegment(s string, segLen int) []string
- func SliceContains(slice []string, str string) bool
- type BotConfig
- type ChannelReq
- type ChannelResp
- type ChannelStopChan
- type DiscordBot
- func (b *DiscordBot) CancelChannelDeleteTimer(channelId string)
- func (b *DiscordBot) ChannelCreate(guildID, channelName string, channelType int) (string, error)
- func (b *DiscordBot) ChannelCreateComplex(guildID, parentId, channelName string, channelType int) (string, error)
- func (b *DiscordBot) ChannelDel(channelId string) (string, error)
- func (b *DiscordBot) ChannelDelAllForCdp() (bool, error)
- func (b *DiscordBot) ChannelDelOldestForCdp() (bool, error)
- func (b *DiscordBot) Check()
- func (b *DiscordBot) CreateChannelWithRetry(guildID, channelName string, channelType int) (string, error)
- func (b *DiscordBot) GetSendChannelId() (sendChannelId string, err error)
- func (b *DiscordBot) SendMessageSpec(channelid, bottoken, message string) (*discordgo.Message, string, string, error)
- func (b *DiscordBot) SendMsgByAuthorization(userAuth, content, channelId string) (string, error)
- func (b *DiscordBot) SendPlain(message string) (string, error)
- func (b *DiscordBot) SendRaw(message string) (*discordgo.Message, string, string, error)
- func (b *DiscordBot) SetChannelDeleteTimer(channelId string, duration time.Duration)
- func (b *DiscordBot) StartBot(ctx context.Context)
- func (b *DiscordBot) ThreadStart(channelId, threadName string, archiveDuration int) (string, error)
- func (b *DiscordBot) UploadToDiscordAndGetURL(channelID string, base64Data string) (string, error)
- type DiscordUnauthorizedError
- type ModelNotFoundError
- type ReplyResp
- type SnowflakeGenerator
- type ThreadReq
- type ThreadResp
- type WithConfig
- func WithBotAlive(alive string) WithConfig
- func WithBotID(botid string) WithConfig
- func WithBotToken(token string) WithConfig
- func WithChannelAutoDelTime(deltime string) WithConfig
- func WithGuilID(id string) WithConfig
- func WithProxySecret(secret string) WithConfig
- func WithProxyUrl(url string) WithConfig
- func WithRateLimit(limit int) WithConfig
- func WithUserAgent(agent string) WithConfig
- func Withdefaultchannel(botid string) WithConfig
Constants ¶
View Source
const ( RequestIdKey = "X-Request-Id" OutTime = "out-time" )
Variables ¶
View Source
var BotConfigList []BotConfig
View Source
var CozeDailyLimitErrorMessages = []string{
"You have exceeded the daily limit for sending messages to the bot. Please try again later.",
}
View Source
var CozeErrorMessages = []string{
"Something wrong occurs, please retry. If the error persists, please contact the support team.",
"You have exceeded the daily limit for sending messages to the bot. Please try again later.",
"Some error occurred. Please try again or contact the support team in our communities.",
"We've detected unusual traffic from your network, so Coze is temporarily unavailable.",
"There are too many users now. Please try again a bit later.",
"I'm sorry, but I can't assist with that.",
}
View Source
var CreateChannelRiskChan = make(chan string)
View Source
var CreateChannelRiskPreNotifyTime time.Time
View Source
var DefaultOpenaiModelList = []string{
"gpt-3.5-turbo", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-1106", "gpt-3.5-turbo-0125",
"gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613",
"gpt-3.5-turbo-instruct",
"gpt-4", "gpt-4-0314", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-0125-preview",
"gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613",
"gpt-4-turbo-preview", "gpt-4-turbo", "gpt-4-turbo-2024-04-09",
"gpt-4o", "gpt-4o-2024-05-13",
"gpt-4-vision-preview",
"dall-e-3",
}
View Source
var ImgGeneratePrompt = "请根据下面的描述生成对应的图片:\\n"
View Source
var NoAvailableUserAuthChan = make(chan string)
View Source
var NoAvailableUserAuthPreNotifyTime time.Time
View Source
var RateLimitKeyExpirationDuration = 20 * time.Minute
View Source
var RequestOutTimeDuration = 5 * time.Minute
View Source
var (
Tke *tiktoken.Tiktoken
)
View Source
var Version = "v4.5.3" // this hard coding will be replaced automatically when building, no need to manually change
Functions ¶
func CountTokens ¶
func FilterSlice ¶
func GetRandomString ¶
func NewProxyClient ¶
func ReverseSegment ¶
func SliceContains ¶
Types ¶
type BotConfig ¶
type BotConfig struct { ProxySecret string `json:"proxySecret"` BotId string `json:"botId"` Model []string `json:"model"` ChannelId string `json:"channelId"` }
func FilterConfigs ¶
FilterConfigs 根据proxySecret和channelId过滤BotConfig
func FilterUniqueBotChannel ¶
FilterUniqueBotChannel 给定BotConfig切片,筛选出具有不同CozeBotId+ChannelId组合的元素
type ChannelReq ¶
type ChannelResp ¶
type ChannelStopChan ¶
type DiscordBot ¶
type DiscordBot struct {
// contains filtered or unexported fields
}
func NewDiscordBot ¶
func NewDiscordBot(auth string, conf ...WithConfig) *DiscordBot
func (*DiscordBot) CancelChannelDeleteTimer ¶
func (b *DiscordBot) CancelChannelDeleteTimer(channelId string)
CancelChannelDeleteTimer 取消频道的删除定时器
func (*DiscordBot) ChannelCreate ¶
func (b *DiscordBot) ChannelCreate(guildID, channelName string, channelType int) (string, error)
func (*DiscordBot) ChannelCreateComplex ¶
func (b *DiscordBot) ChannelCreateComplex(guildID, parentId, channelName string, channelType int) (string, error)
func (*DiscordBot) ChannelDel ¶
func (b *DiscordBot) ChannelDel(channelId string) (string, error)
func (*DiscordBot) ChannelDelAllForCdp ¶
func (b *DiscordBot) ChannelDelAllForCdp() (bool, error)
func (*DiscordBot) ChannelDelOldestForCdp ¶
func (b *DiscordBot) ChannelDelOldestForCdp() (bool, error)
func (*DiscordBot) Check ¶
func (b *DiscordBot) Check()
func (*DiscordBot) CreateChannelWithRetry ¶
func (b *DiscordBot) CreateChannelWithRetry(guildID, channelName string, channelType int) (string, error)
func (*DiscordBot) GetSendChannelId ¶
func (b *DiscordBot) GetSendChannelId() (sendChannelId string, err error)
func (*DiscordBot) SendMessageSpec ¶
func (*DiscordBot) SendMsgByAuthorization ¶
func (b *DiscordBot) SendMsgByAuthorization(userAuth, content, channelId string) (string, error)
用户端发送消息 注意 此为临时解决方案 后续会优化代码
func (*DiscordBot) SetChannelDeleteTimer ¶
func (b *DiscordBot) SetChannelDeleteTimer(channelId string, duration time.Duration)
SetChannelDeleteTimer 设置或重置频道的删除定时器
func (*DiscordBot) StartBot ¶
func (b *DiscordBot) StartBot(ctx context.Context)
func (*DiscordBot) ThreadStart ¶
func (b *DiscordBot) ThreadStart(channelId, threadName string, archiveDuration int) (string, error)
func (*DiscordBot) UploadToDiscordAndGetURL ¶
func (b *DiscordBot) UploadToDiscordAndGetURL(channelID string, base64Data string) (string, error)
type DiscordUnauthorizedError ¶
type DiscordUnauthorizedError struct {}
自定义错误类型
func (*DiscordUnauthorizedError) Error ¶
func (e *DiscordUnauthorizedError) Error() string
实现 error 接口的 Error 方法
type ModelNotFoundError ¶
func (*ModelNotFoundError) Error ¶
func (e *ModelNotFoundError) Error() string
实现 error 接口的 Error 方法
type SnowflakeGenerator ¶
type SnowflakeGenerator struct {
// contains filtered or unexported fields
}
SnowflakeGenerator 是雪花ID生成器的封装
type ThreadResp ¶
type WithConfig ¶
type WithConfig func(*DiscordBot)
func WithBotAlive ¶
func WithBotAlive(alive string) WithConfig
func WithChannelAutoDelTime ¶
func WithChannelAutoDelTime(deltime string) WithConfig
func WithProxySecret ¶
func WithProxySecret(secret string) WithConfig
func WithProxyUrl ¶
func WithProxyUrl(url string) WithConfig
func WithRateLimit ¶
func WithRateLimit(limit int) WithConfig
func WithUserAgent ¶
func WithUserAgent(agent string) WithConfig
Click to show internal directories.
Click to hide internal directories.