Compare commits
No commits in common. "b7257e42d676d00bc6220cf8731558bc012f4a87" and "965a976d44f19c3eac32733289aa5bb209c5b38f" have entirely different histories.
b7257e42d6
...
965a976d44
7 changed files with 17 additions and 265 deletions
|
@ -1,205 +0,0 @@
|
||||||
package commands
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"log"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
|
||||||
"github.com/bwmarrin/discordgo"
|
|
||||||
"go.mongodb.org/mongo-driver/v2/bson"
|
|
||||||
)
|
|
||||||
|
|
||||||
type chStruct struct {
|
|
||||||
name lenType
|
|
||||||
length int
|
|
||||||
}
|
|
||||||
|
|
||||||
type lenType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
text lenType = iota
|
|
||||||
muffin
|
|
||||||
nsfw
|
|
||||||
learn
|
|
||||||
userLearn
|
|
||||||
)
|
|
||||||
|
|
||||||
var DataLengthCommand Command = Command{
|
|
||||||
ApplicationCommand: &discordgo.ApplicationCommand{
|
|
||||||
Type: discordgo.ChatApplicationCommand,
|
|
||||||
Name: "데이터학습량",
|
|
||||||
Description: "봇이 학습한 데ㅇ이터량을 보여줘요.",
|
|
||||||
},
|
|
||||||
Aliases: []string{"학습데이터량", "데이터량", "학습량"},
|
|
||||||
DetailedDescription: DetailedDescription{
|
|
||||||
Usage: "머핀아 학습데이터량",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Command) dataLengthRun(s *discordgo.Session, m interface{}) {
|
|
||||||
var i *discordgo.Interaction
|
|
||||||
var referance *discordgo.MessageReference
|
|
||||||
var username, userId, channelId string
|
|
||||||
var textLength,
|
|
||||||
muffinLength,
|
|
||||||
nsfwLength,
|
|
||||||
learnLength,
|
|
||||||
userLearnLength int
|
|
||||||
|
|
||||||
ch := make(chan chStruct)
|
|
||||||
|
|
||||||
switch m := m.(type) {
|
|
||||||
case *discordgo.MessageCreate:
|
|
||||||
username = m.Author.Username
|
|
||||||
userId = m.Author.ID
|
|
||||||
channelId = m.ChannelID
|
|
||||||
referance = m.Reference()
|
|
||||||
case *discordgo.InteractionCreate:
|
|
||||||
username = m.Member.User.Username
|
|
||||||
userId = m.Member.User.ID
|
|
||||||
channelId = m.ChannelID
|
|
||||||
i = m.Interaction
|
|
||||||
s.InteractionRespond(i,
|
|
||||||
&discordgo.InteractionResponse{
|
|
||||||
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Flags: discordgo.MessageFlagsEphemeral,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
var datas []databases.Text
|
|
||||||
|
|
||||||
cur, err := databases.Texts.Find(context.TODO(), bson.D{{}})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
cur.All(context.TODO(), &datas)
|
|
||||||
ch <- chStruct{name: text, length: len(datas)}
|
|
||||||
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
var datas []databases.Text
|
|
||||||
|
|
||||||
cur, err := databases.Texts.Find(context.TODO(), bson.D{{Key: "persona", Value: "muffin"}})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
cur.All(context.TODO(), &datas)
|
|
||||||
ch <- chStruct{name: muffin, length: len(datas)}
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
var datas []databases.Text
|
|
||||||
|
|
||||||
cur, err := databases.Texts.Find(context.TODO(), bson.D{
|
|
||||||
{
|
|
||||||
Key: "persona",
|
|
||||||
Value: bson.M{
|
|
||||||
"$regex": "^user",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
cur.All(context.TODO(), &datas)
|
|
||||||
ch <- chStruct{name: nsfw, length: len(datas)}
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
var datas []databases.Learn
|
|
||||||
|
|
||||||
cur, err := databases.Learns.Find(context.TODO(), bson.D{{}})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
cur.All(context.TODO(), &datas)
|
|
||||||
ch <- chStruct{name: learn, length: len(datas)}
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
var datas []databases.Learn
|
|
||||||
|
|
||||||
cur, err := databases.Learns.Find(context.TODO(), bson.D{{Key: "user_id", Value: userId}})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cur.All(context.TODO(), &datas)
|
|
||||||
ch <- chStruct{name: userLearn, length: len(datas)}
|
|
||||||
}()
|
|
||||||
|
|
||||||
for i := 0; i < 5; i++ {
|
|
||||||
resp := <-ch
|
|
||||||
switch lenType(resp.name) {
|
|
||||||
case text:
|
|
||||||
textLength = resp.length
|
|
||||||
case muffin:
|
|
||||||
muffinLength = resp.length
|
|
||||||
case nsfw:
|
|
||||||
nsfwLength = resp.length
|
|
||||||
case learn:
|
|
||||||
learnLength = resp.length
|
|
||||||
case userLearn:
|
|
||||||
userLearnLength = resp.length
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sum := textLength + learnLength
|
|
||||||
|
|
||||||
// 나중에 djs처럼 Embed 만들어 주는 함수 만들어야겠다
|
|
||||||
// 지금은 임시방편
|
|
||||||
embed := &discordgo.MessageEmbed{
|
|
||||||
Title: "저장된 데이터량",
|
|
||||||
Description: "총합: " + utils.InlineCode(strconv.Itoa(sum)) + "개",
|
|
||||||
Color: int(utils.EDefault),
|
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
|
||||||
{
|
|
||||||
Name: "총 채팅 데이터량",
|
|
||||||
Value: utils.InlineCode(strconv.Itoa(textLength)) + "개",
|
|
||||||
Inline: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "총 지식 데이터량",
|
|
||||||
Value: utils.InlineCode(strconv.Itoa(learnLength)) + "개",
|
|
||||||
Inline: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "머핀 데이터량",
|
|
||||||
Value: utils.InlineCode(strconv.Itoa(muffinLength)) + "개",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "nsfw 데이터량",
|
|
||||||
Value: utils.InlineCode(strconv.Itoa(nsfwLength)) + "개",
|
|
||||||
Inline: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: username + "님이 가르쳐준 데이터량",
|
|
||||||
Value: utils.InlineCode(strconv.Itoa(userLearnLength)) + "개",
|
|
||||||
Inline: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
switch m.(type) {
|
|
||||||
case *discordgo.MessageCreate:
|
|
||||||
s.ChannelMessageSendEmbedReply(channelId, embed, referance)
|
|
||||||
case *discordgo.InteractionCreate:
|
|
||||||
s.InteractionResponseEdit(i, &discordgo.WebhookEdit{
|
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Command) dataLengthMessageRun(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
||||||
c.dataLengthRun(s, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Command) dataLenghChatInputRun(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
||||||
c.dataLengthRun(s, i)
|
|
||||||
}
|
|
|
@ -4,8 +4,7 @@ import (
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type messageRun func(s *discordgo.Session, m *discordgo.MessageCreate)
|
// type messageRun func(s *discordgo.Session, m *discordgo.MessageCreate)
|
||||||
type chatInputRun func(s *discordgo.Session, m *discordgo.InteractionCreate)
|
|
||||||
|
|
||||||
type DetailedDescription struct {
|
type DetailedDescription struct {
|
||||||
Usage string
|
Usage string
|
||||||
|
@ -13,8 +12,9 @@ type DetailedDescription struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Command struct {
|
type Command struct {
|
||||||
*discordgo.ApplicationCommand
|
Name string
|
||||||
Aliases []string
|
Aliases []string
|
||||||
|
Description string
|
||||||
DetailedDescription DetailedDescription
|
DetailedDescription DetailedDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ type DiscommandStruct struct {
|
||||||
Commands map[string]Command
|
Commands map[string]Command
|
||||||
Aliases map[string]string
|
Aliases map[string]string
|
||||||
messageRuns map[string]interface{}
|
messageRuns map[string]interface{}
|
||||||
chatInputRuns map[string]interface{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func new() *DiscommandStruct {
|
func new() *DiscommandStruct {
|
||||||
|
@ -30,16 +29,11 @@ func new() *DiscommandStruct {
|
||||||
Commands: map[string]Command{},
|
Commands: map[string]Command{},
|
||||||
Aliases: map[string]string{},
|
Aliases: map[string]string{},
|
||||||
messageRuns: map[string]interface{}{},
|
messageRuns: map[string]interface{}{},
|
||||||
chatInputRuns: map[string]interface{}{},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
go discommand.loadCommands(HelpCommand)
|
discommand.loadCommands(HelpCommand)
|
||||||
go discommand.loadCommands(DataLengthCommand)
|
|
||||||
|
|
||||||
go discommand.addMessageRun(HelpCommand.Name, HelpCommand.helpMessageRun)
|
discommand.addMessageRun(HelpCommand.Name, HelpCommand.helpMessageRun)
|
||||||
go discommand.addMessageRun(DataLengthCommand.Name, DataLengthCommand.dataLengthMessageRun)
|
|
||||||
|
|
||||||
go discommand.addChatInputRun(DataLengthCommand.Name, DataLengthCommand.dataLenghChatInputRun)
|
|
||||||
return &discommand
|
return &discommand
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,21 +46,13 @@ func (d *DiscommandStruct) loadCommands(command Command) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiscommandStruct) addMessageRun(name string, run messageRun) {
|
func (d *DiscommandStruct) addMessageRun(name string, run func(s *discordgo.Session, m *discordgo.MessageCreate)) {
|
||||||
d.messageRuns[name] = run
|
d.messageRuns[name] = run
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiscommandStruct) addChatInputRun(name string, run chatInputRun) {
|
|
||||||
d.chatInputRuns[name] = run
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DiscommandStruct) MessageRun(command string, s *discordgo.Session, m *discordgo.MessageCreate) {
|
func (d *DiscommandStruct) MessageRun(command string, s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
// 더욱 나아진
|
// 더욱 나아진
|
||||||
d.messageRuns[command].(messageRun)(s, m)
|
d.messageRuns[command].(func(s *discordgo.Session, m *discordgo.MessageCreate))(s, m)
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DiscommandStruct) ChatInputRun(command string, s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
||||||
d.chatInputRuns[command].(chatInputRun)(s, i)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var Discommand *DiscommandStruct = new()
|
var Discommand *DiscommandStruct = new()
|
||||||
|
|
|
@ -7,12 +7,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var HelpCommand Command = Command{
|
var HelpCommand Command = Command{
|
||||||
ApplicationCommand: &discordgo.ApplicationCommand{
|
|
||||||
Type: discordgo.ChatApplicationCommand,
|
|
||||||
Name: "도움말",
|
Name: "도움말",
|
||||||
Description: "기본적인 사용ㅂ법이에요.",
|
|
||||||
},
|
|
||||||
Aliases: []string{"도움", "명령어", "help"},
|
Aliases: []string{"도움", "명령어", "help"},
|
||||||
|
Description: "기본적인 사용ㅂ법이에요.",
|
||||||
DetailedDescription: DetailedDescription{
|
DetailedDescription: DetailedDescription{
|
||||||
Usage: "머핀아 도움말 [명령어]",
|
Usage: "머핀아 도움말 [명령어]",
|
||||||
Examples: []string{"머핀아 도움말", "머핀아 도움말 배워"},
|
Examples: []string{"머핀아 도움말", "머핀아 도움말 배워"},
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var MUFFIN_VERSION = "0.0.0-gopher_canary.250326a"
|
var MUFFIN_VERSION = "0.0.0-gopher_canary.250325a"
|
||||||
|
|
||||||
type botConfig struct {
|
type botConfig struct {
|
||||||
Token string
|
Token string
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.wh64.net/muffin/goMuffin/commands"
|
|
||||||
"github.com/bwmarrin/discordgo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func InteractionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
||||||
commands.Discommand.ChatInputRun(i.ApplicationCommandData().Name, s, i)
|
|
||||||
return
|
|
||||||
}
|
|
6
main.go
6
main.go
|
@ -8,7 +8,6 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"git.wh64.net/muffin/goMuffin/commands"
|
|
||||||
"git.wh64.net/muffin/goMuffin/configs"
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
"git.wh64.net/muffin/goMuffin/handler"
|
"git.wh64.net/muffin/goMuffin/handler"
|
||||||
|
@ -25,14 +24,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
dg.AddHandler(handler.MessageCreate)
|
dg.AddHandler(handler.MessageCreate)
|
||||||
dg.AddHandler(handler.InteractionCreate)
|
|
||||||
|
|
||||||
dg.Open()
|
dg.Open()
|
||||||
|
|
||||||
for _, command := range commands.Discommand.Commands {
|
|
||||||
dg.ApplicationCommandCreate(dg.State.User.ID, "", command.ApplicationCommand)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := databases.Client.Disconnect(context.TODO()); err != nil {
|
if err := databases.Client.Disconnect(context.TODO()); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package utils
|
|
||||||
|
|
||||||
type EmbedColorType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
EDefault EmbedColorType = 0xaddb87
|
|
||||||
EFail EmbedColorType = 0xff0000
|
|
||||||
ESuccess EmbedColorType = 0x00ff00
|
|
||||||
)
|
|
Loading…
Reference in a new issue