discord

package
v0.0.0-...-43b9d63 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

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 CountTokens(text string) int

func FilterSlice

func FilterSlice(slice []string, filter string) []string

func GetRandomString

func GetRandomString(length int) string

func NewProxyClient

func NewProxyClient(proxyUrl string) (proxyParse *url.URL, client *http.Client, err error)

func NextID

func NextID() (string, error)

NextID 生成一个新的雪花ID

func RandomElement

func RandomElement[T any](slice []T) (T, error)

RandomElement 返回给定切片中的随机元素

func ReverseSegment

func ReverseSegment(s string, segLen int) []string

func SliceContains

func SliceContains(slice []string, str string) bool

Types

type BotConfig

type BotConfig struct {
	ProxySecret string   `json:"proxySecret"`
	BotId       string   `json:"botId"`
	Model       []string `json:"model"`
	ChannelId   string   `json:"channelId"`
}

func FilterConfigs

func FilterConfigs(configs []BotConfig, secret, gptModel string, channelId *string) []BotConfig

FilterConfigs 根据proxySecret和channelId过滤BotConfig

func FilterUniqueBotChannel

func FilterUniqueBotChannel(configs []BotConfig) []BotConfig

FilterUniqueBotChannel 给定BotConfig切片,筛选出具有不同CozeBotId+ChannelId组合的元素

type ChannelReq

type ChannelReq struct {
	ParentId string `json:"parentId" swaggertype:"string" description:"父频道Id,为空时默认为创建父频道"`
	Type     int    `json:"type" swaggertype:"number" description:"类型:[0:文本频道,4:频道分类](其它枚举请查阅discord-api文档)"`
	Name     string `json:"name" swaggertype:"string" description:"频道名称"`
}

type ChannelResp

type ChannelResp struct {
	Id   string `json:"id" swaggertype:"string" description:"频道ID"`
	Name string `json:"name" swaggertype:"string" description:"频道名称"`
}

type ChannelStopChan

type ChannelStopChan struct {
	Id    string `json:"id" `
	IsNew bool   `json:"IsNew"`
}

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 (b *DiscordBot) SendMessageSpec(channelid, bottoken, message string) (*discordgo.Message, string, string, error)

func (*DiscordBot) SendMsgByAuthorization

func (b *DiscordBot) SendMsgByAuthorization(userAuth, content, channelId string) (string, error)

用户端发送消息 注意 此为临时解决方案 后续会优化代码

func (*DiscordBot) SendPlain

func (b *DiscordBot) SendPlain(message string) (string, error)

func (*DiscordBot) SendRaw

func (b *DiscordBot) SendRaw(message string) (*discordgo.Message, 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 {
	Message string
	ErrCode int
}

自定义错误类型

func (*DiscordUnauthorizedError) Error

func (e *DiscordUnauthorizedError) Error() string

实现 error 接口的 Error 方法

type ModelNotFoundError

type ModelNotFoundError struct {
	Message string
	ErrCode int
}

func (*ModelNotFoundError) Error

func (e *ModelNotFoundError) Error() string

实现 error 接口的 Error 方法

type ReplyResp

type ReplyResp struct {
	Content   string   `json:"content" swaggertype:"string" description:"回复内容"`
	EmbedUrls []string `json:"embedUrls" swaggertype:"array,string" description:"嵌入网址"`
}

type SnowflakeGenerator

type SnowflakeGenerator struct {
	// contains filtered or unexported fields
}

SnowflakeGenerator 是雪花ID生成器的封装

type ThreadReq

type ThreadReq struct {
	ChannelId       string `json:"channelId" swaggertype:"string" description:"频道Id"`
	Name            string `json:"name" swaggertype:"string" description:"线程名称"`
	ArchiveDuration int    `json:"archiveDuration" swaggertype:"number" description:"线程存档时间[分钟]"`
}

type ThreadResp

type ThreadResp struct {
	Id   string `json:"id" swaggertype:"string" description:"线程ID"`
	Name string `json:"name" swaggertype:"string" description:"线程名称"`
}

type WithConfig

type WithConfig func(*DiscordBot)

func WithBotAlive

func WithBotAlive(alive string) WithConfig

func WithBotID

func WithBotID(botid string) WithConfig

要对话的botid

func WithBotToken

func WithBotToken(token string) WithConfig

要对话的bot token

func WithChannelAutoDelTime

func WithChannelAutoDelTime(deltime string) WithConfig

func WithGuilID

func WithGuilID(id string) WithConfig

服务器id

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

func Withdefaultchannel

func Withdefaultchannel(botid string) WithConfig

用于保活的的bot id

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL