midjourney

package
v0.0.0-...-b9c356b Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: AGPL-3.0 Imports: 29 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MJApplicationId                   = "936929561302675456" // Midjourney在Discord的应用Id
	MJVersionId                       = "1166847114203123795"
	MJCommandGenerateImageId          = "938956540159881230"
	MJCommandGenerateImageDescription = "Create images with Midjourney"
)
View Source
const (
	NJApplicationId                   = "1022952195194359889" // Niji在Discord的应用
	NJVersionId                       = "1166842163141816443"
	NJCommandGenerateImageId          = "1023054140580057099"
	NJCommandGenerateImageDescription = "Create images with Niji journey"
)
View Source
const (
	MessageTypeGenerate = 0  // 生图
	MessageTypeCustomId = 19 // CustomId
	MessageTypeModal    = 20 // CustomId
)
View Source
const (
	RequestTypeGenerate = 2 // 生图
	RequestTypeCustomId = 3 // CustomId
	RequestTypeModal    = 5 // Modal
)
View Source
const ApiUrl = "https://discord.com/api/v9/"

ID

View Source
const WsUrl = "wss://gateway.discord.gg/?encoding=json&v=9"

Variables

View Source
var BotClientMap sync.Map
View Source
var WsClientMap sync.Map

Functions

func BotRun

func BotRun(config *entity.ConfigMidjourney) (err error)

func CustomIdImage

func CustomIdImage(ctx context.Context, tx *gdb.TX, params *CustomIdImageParams) (err error)

CustomIdImage 组件处理图片

func CustomIdModalImage

func CustomIdModalImage(params *CustomIdModalImageParams) (err error)

func GenerateImage

func GenerateImage(ctx context.Context, tx *gdb.TX, params *GenerateImageParams) (err error)

GenerateImage 生成图片

func WsRun

func WsRun(config *entity.ConfigMidjourney, callback WsRunConnCallback) (err error)

Types

type BotClient

type BotClient struct {
	Session *discordgo.Session
	Config  *entity.ConfigMidjourney
}

type CustomIdData

type CustomIdData struct {
	ComponentType int64  `json:"component_type"`
	CustomId      string `json:"custom_id"`
}

type CustomIdImageParams

type CustomIdImageParams struct {
	ActionType          int
	ConversationId      int64
	ReferConversationId int64
	Index               int
	CustomId            string
	NewPrompt           string // 用于模态弹窗的新提示
}

type CustomIdModalData

type CustomIdModalData struct {
	Id         string                             `json:"id"`
	CustomId   string                             `json:"custom_id"`
	Components []*CustomIdModalDataComponentsItem `json:"components"`
}

type CustomIdModalDataComponentsItem

type CustomIdModalDataComponentsItem struct {
	Type       int64                                            `json:"type"`
	Components []*CustomIdModalDataComponentsItemComponentsItem `json:"components"`
}

type CustomIdModalDataComponentsItemComponentsItem

type CustomIdModalDataComponentsItemComponentsItem struct {
	Type     int64  `json:"type"`
	CustomId string `json:"custom_id"`
	Value    string `json:"value"`
}

type CustomIdModalImageParams

type CustomIdModalImageParams struct {
	ActionType          int
	ConversationId      int64
	ReferConversationId int64
	Index               int
	OriQueueId          string
	OriCustomId         string
	DataId              string
	NewPrompt           string
}

type DSApplicationCommand

type DSApplicationCommand struct {
	Id                       string             `json:"id"`
	ApplicationId            string             `json:"application_id"`
	Version                  string             `json:"version"`
	DefaultPermission        bool               `json:"default_permission"`
	DefaultMemberPermissions map[string]int     `json:"default_member_permissions"`
	Type                     int64              `json:"type"`
	Nsfw                     bool               `json:"nsfw"`
	Name                     string             `json:"name"`
	Description              string             `json:"description"`
	DmPermission             bool               `json:"dm_permission"`
	Options                  []*DSCommandOption `json:"options"`
}

type DSCommand

type DSCommand struct {
	Version            string                   `json:"version"`
	Id                 string                   `json:"id"`
	Name               string                   `json:"name"`
	Type               int64                    `json:"type"`
	Options            []*DSOption              `json:"options"`
	ApplicationCommand *DSApplicationCommand    `json:"application_command"`
	Attachments        []*ReqCommandAttachments `json:"attachments"`
}

type DSCommandOption

type DSCommandOption struct {
	Type        int64  `json:"type"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Required    bool   `json:"required"`
}

type DSOption

type DSOption struct {
	Type  int64       `json:"type"`
	Name  string      `json:"name"`
	Value interface{} `json:"value"`
}

type GenerateImageParams

type GenerateImageParams struct {
	ConversationId  int64  `json:"conversation_id"`
	ApplicationType int    `json:"application_type"`
	Prompt          string `json:"prompt"`
}

type MidjourneyClient

type MidjourneyClient struct {
}

MidjourneyClient Midjourney客户端

func Instance

func Instance() *MidjourneyClient

Instance 单例

func (*MidjourneyClient) GetConfig

func (c *MidjourneyClient) GetConfig() (configData *entity.ConfigMidjourney, err error)

GetConfig 获取配置

type QueueClient

type QueueClient struct {
	Event chan *QueueEvent
	// contains filtered or unexported fields
}

QueueClient Queue客户端

func QueueInstance

func QueueInstance() *QueueClient

QueueInstance 单例

func (*QueueClient) InsertTask

func (q *QueueClient) InsertTask(queueData *entity.QueueMidjourney, callback func(signal int)) (err error)

func (*QueueClient) Run

func (q *QueueClient) Run()

type QueueEvent

type QueueEvent struct {
	EventType string
	Config    *entity.ConfigMidjourney
	QueueData *entity.QueueMidjourney
	Message   *QueueEventMessage
}

type QueueEventMessage

type QueueEventMessage = WsReceiveMessageDCommon

type QueueTask

type QueueTask struct {
	Data            *entity.QueueMidjourney  // 队列数据,与数据库一致
	StatusChannel   chan int                 // 状态通道,用来监听任务执行进度情况
	Config          *entity.ConfigMidjourney // 任务对应的配置信息 防止重复查询所以单提出来
	CallbackChannel chan int                 // 回调通道,用来监听任务完成执行回调方法的通道
}

type ReqCommandAttachments

type ReqCommandAttachments struct {
	Id             string `json:"id"`
	Filename       string `json:"filename"`
	UploadFilename string `json:"uploaded_filename"`
}

type ReqCustomIdDiscord

type ReqCustomIdDiscord struct {
	Type          int64         `json:"type"`
	GuildId       string        `json:"guild_id"`
	ChannelId     string        `json:"channel_id"`
	MessageFlags  int64         `json:"message_flags"`
	MessageId     string        `json:"message_id"`
	ApplicationId string        `json:"application_id"`
	SessionId     string        `json:"session_id"`
	Data          *CustomIdData `json:"data"`
	Nonce         string        `json:"nonce"`
}

type ReqCustomIdModalDiscord

type ReqCustomIdModalDiscord struct {
	Type          int64              `json:"type"`
	ApplicationId string             `json:"application_id"`
	ChannelId     string             `json:"channel_id"`
	GuildId       string             `json:"guild_id"`
	Data          *CustomIdModalData `json:"data"`
	SessionId     string             `json:"session_id"`
	Nonce         string             `json:"nonce"`
}

type ReqTriggerDiscord

type ReqTriggerDiscord struct {
	Type          int64      `json:"type"`
	GuildId       string     `json:"guild_id"`
	ChannelId     string     `json:"channel_id"`
	ApplicationId string     `json:"application_id"`
	SessionId     string     `json:"session_id"`
	Data          *DSCommand `json:"data"`
	Nonce         string     `json:"nonce"`
}

type VerifyHuman

type VerifyHuman struct {
	Config *entity.ConfigMidjourney
}

func NewVerifyHuman

func NewVerifyHuman(config *entity.ConfigMidjourney) (v *VerifyHuman, err error)

func (*VerifyHuman) Verify

func (v *VerifyHuman) Verify(imageUrl string, categories []string) (re string, err error)

type WsClient

type WsClient struct {
	Client    *ghttp.WebSocketClient
	Conn      *websocket.Conn
	Config    *entity.ConfigMidjourney
	UserId    int64
	SessionId string
	// contains filtered or unexported fields
}

type WsMessage

type WsMessage struct {
	Op int         `json:"op"`
	D  interface{} `json:"d"`
}

type WsMessageAuth

type WsMessageAuth struct {
	Token        string                   `json:"token"`
	Capabilities int                      `json:"capabilities"`
	Properties   *WsMessageAuthProperties `json:"properties"`
	Compress     bool                     `json:"compress"`
}

type WsMessageAuthProperties

type WsMessageAuthProperties struct {
	Os      string `json:"os"`
	Browser string `json:"browser"`
	Device  string `json:"device"`
}

type WsReceiveMessage

type WsReceiveMessage struct {
	T  string      `json:"t"`
	S  int         `json:"s"`
	Op int         `json:"op"`
	D  interface{} `json:"d"`
}

type WsReceiveMessageDAttachmentsItem

type WsReceiveMessageDAttachmentsItem struct {
	Id          string `json:"id"`
	Filename    string `json:"filename"`
	ContentType string `json:"content_type"`
	Width       int    `json:"width"`
	Height      int    `json:"height"`
	Url         string `json:"url"`
	ProxyUrl    string `json:"proxy_url"`
	Size        int    `json:"size"`
}

type WsReceiveMessageDAuthor

type WsReceiveMessageDAuthor struct {
	Id       string `json:"id"`
	Username string `json:"username"`
}

type WsReceiveMessageDCommon

type WsReceiveMessageDCommon struct {
	Id                string                              `json:"id"`
	ChannelId         string                              `json:"channel_id"`
	GuildId           string                              `json:"guild_id"`
	Type              int                                 `json:"type"`
	Author            *WsReceiveMessageDAuthor            `json:"author"`
	Nonce             string                              `json:"nonce"`
	Content           string                              `json:"content"`
	Flags             int                                 `json:"flags"`
	Components        []*WsReceiveMessageDComponentsItem  `json:"components"`
	Attachments       []*discordgo.MessageAttachment      `json:"attachments"`
	Embeds            []*WsReceiveMessageDEmbedsItem      `json:"embeds"`
	Interaction       *WsReceiveMessageDInteraction       `json:"interaction"`
	ReferencedMessage *WsReceiveMessageDReferencedMessage `json:"referenced_message"`
	MessageReference  *discordgo.MessageReference         `json:"message_reference"`
}

type WsReceiveMessageDComponentsItem

type WsReceiveMessageDComponentsItem struct {
	Type       int                                              `json:"type"`
	Components []*WsReceiveMessageDComponentsItemComponentsItem `json:"components"`
}

type WsReceiveMessageDComponentsItemComponentsItem

type WsReceiveMessageDComponentsItemComponentsItem struct {
	Type     int                                                 `json:"type"`
	Style    int                                                 `json:"style"`
	Label    string                                              `json:"label"`
	Emoji    *WsReceiveMessageDComponentsItemComponentsItemEmoji `json:"emoji"`
	CustomId string                                              `json:"custom_id"`
}

type WsReceiveMessageDComponentsItemComponentsItemEmoji

type WsReceiveMessageDComponentsItemComponentsItemEmoji struct {
	Name string `json:"name"`
}

type WsReceiveMessageDEmbedsItem

type WsReceiveMessageDEmbedsItem struct {
	Color       int                               `json:"color"`
	Description string                            `json:"description"`
	Title       string                            `json:"title"`
	Image       *WsReceiveMessageDEmbedsItemImage `json:"image"`
}

type WsReceiveMessageDEmbedsItemImage

type WsReceiveMessageDEmbedsItemImage struct {
	Url string `json:"url"`
}

type WsReceiveMessageDInteraction

type WsReceiveMessageDInteraction struct {
	Id   string                      `json:"id"`
	Name string                      `json:"name"`
	Type int                         `json:"type"`
	User *WsReceiveMessageDReadyUser `json:"user"`
}

type WsReceiveMessageDReady

type WsReceiveMessageDReady struct {
	User      *WsReceiveMessageDReadyUser `json:"user"`
	SessionId string                      `json:"session_id"`
}

type WsReceiveMessageDReadyUser

type WsReceiveMessageDReadyUser struct {
	Id string `json:"id"`
}

type WsReceiveMessageDReferencedMessage

type WsReceiveMessageDReferencedMessage struct {
	Id         string                             `json:"id"`
	ChannelId  string                             `json:"channel_id"`
	Content    string                             `json:"content"`
	Timestamp  string                             `json:"timestamp"`
	Components []*WsReceiveMessageDComponentsItem `json:"components"`
}

type WsRunConnCallback

type WsRunConnCallback func()

Jump to

Keyboard shortcuts

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