Compare commits

..

No commits in common. "4d46177a66ca905820d467d2d455faba4b5a6f0a" and "a35ba84efc6cd969d024936d7fbd49801aed956e" have entirely different histories.

5 changed files with 21 additions and 38 deletions

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"strconv" "strconv"
"sync"
"git.wh64.net/muffin/goMuffin/configs" "git.wh64.net/muffin/goMuffin/configs"
"git.wh64.net/muffin/goMuffin/databases" "git.wh64.net/muffin/goMuffin/databases"
@ -29,8 +28,7 @@ const (
userLearn userLearn
) )
var dataLengthCh chan chStruct = make(chan chStruct) var ch chan chStruct = make(chan chStruct)
var dataLengthWg sync.WaitGroup
var DataLengthCommand *Command = &Command{ var DataLengthCommand *Command = &Command{
ApplicationCommand: &discordgo.ApplicationCommand{ ApplicationCommand: &discordgo.ApplicationCommand{
@ -52,7 +50,6 @@ var DataLengthCommand *Command = &Command{
} }
func getLength(data dataType, coll *mongo.Collection, filter bson.D) { func getLength(data dataType, coll *mongo.Collection, filter bson.D) {
defer dataLengthWg.Done()
var err error var err error
var cur *mongo.Cursor var cur *mongo.Cursor
var datas []bson.M var datas []bson.M
@ -65,7 +62,7 @@ func getLength(data dataType, coll *mongo.Collection, filter bson.D) {
defer cur.Close(context.TODO()) defer cur.Close(context.TODO())
cur.All(context.TODO(), &datas) cur.All(context.TODO(), &datas)
dataLengthCh <- chStruct{name: data, length: len(datas)} ch <- chStruct{name: data, length: len(datas)}
} }
func dataLengthRun(s *discordgo.Session, m any) { func dataLengthRun(s *discordgo.Session, m any) {
@ -88,7 +85,6 @@ func dataLengthRun(s *discordgo.Session, m any) {
channelId = m.ChannelID channelId = m.ChannelID
} }
dataLengthWg.Add(5)
go getLength(text, databases.Texts, bson.D{{}}) go getLength(text, databases.Texts, bson.D{{}})
go getLength(muffin, databases.Texts, bson.D{{Key: "persona", Value: "muffin"}}) go getLength(muffin, databases.Texts, bson.D{{Key: "persona", Value: "muffin"}})
go getLength(nsfw, databases.Texts, bson.D{ go getLength(nsfw, databases.Texts, bson.D{
@ -102,12 +98,8 @@ func dataLengthRun(s *discordgo.Session, m any) {
go getLength(learn, databases.Learns, bson.D{{}}) go getLength(learn, databases.Learns, bson.D{{}})
go getLength(userLearn, databases.Learns, bson.D{{Key: "user_id", Value: userId}}) go getLength(userLearn, databases.Learns, bson.D{{Key: "user_id", Value: userId}})
go func() { for range 5 {
dataLengthWg.Wait() resp := <-ch
close(dataLengthCh)
}()
for resp := range dataLengthCh {
switch dataType(resp.name) { switch dataType(resp.name) {
case text: case text:
textLength = resp.length textLength = resp.length
@ -121,6 +113,7 @@ func dataLengthRun(s *discordgo.Session, m any) {
userLearnLength = resp.length userLearnLength = resp.length
} }
} }
close(ch)
sum := textLength + learnLength sum := textLength + learnLength

View file

@ -63,8 +63,8 @@ const (
Generals Category = "일반" Generals Category = "일반"
) )
var commandMutex sync.Mutex var commandMutex *sync.Mutex = &sync.Mutex{}
var componentMutex sync.Mutex var componentMutex *sync.Mutex = &sync.Mutex{}
func new() *DiscommandStruct { func new() *DiscommandStruct {
discommand := DiscommandStruct{ discommand := DiscommandStruct{
@ -76,7 +76,6 @@ func new() *DiscommandStruct {
} }
func (d *DiscommandStruct) LoadCommand(c *Command) { func (d *DiscommandStruct) LoadCommand(c *Command) {
defer commandMutex.Unlock()
commandMutex.Lock() commandMutex.Lock()
d.Commands[c.Name] = c d.Commands[c.Name] = c
d.Aliases[c.Name] = c.Name d.Aliases[c.Name] = c.Name
@ -84,12 +83,13 @@ func (d *DiscommandStruct) LoadCommand(c *Command) {
for _, alias := range c.Aliases { for _, alias := range c.Aliases {
d.Aliases[alias] = c.Name d.Aliases[alias] = c.Name
} }
commandMutex.Unlock()
} }
func (d *DiscommandStruct) LoadComponent(c *Component) { func (d *DiscommandStruct) LoadComponent(c *Component) {
defer componentMutex.Unlock()
componentMutex.Lock() componentMutex.Lock()
d.Components = append(d.Components, c) d.Components = append(d.Components, c)
componentMutex.Unlock()
} }
func (d *DiscommandStruct) MessageRun(name string, s *discordgo.Session, m *discordgo.MessageCreate, args []string) { func (d *DiscommandStruct) MessageRun(name string, s *discordgo.Session, m *discordgo.MessageCreate, args []string) {

View file

@ -19,7 +19,16 @@ var HelpCommand *Command = &Command{
Type: discordgo.ApplicationCommandOptionString, Type: discordgo.ApplicationCommandOptionString,
Name: "명령어", Name: "명령어",
Description: "해당 명령어에 대ㅎ한 도움말을 볼 수 있어요.", Description: "해당 명령어에 대ㅎ한 도움말을 볼 수 있어요.",
Choices: []*discordgo.ApplicationCommandOptionChoice{}, Choices: func() []*discordgo.ApplicationCommandOptionChoice {
choices := []*discordgo.ApplicationCommandOptionChoice{}
for _, command := range Discommand.Commands {
choices = append(choices, &discordgo.ApplicationCommandOptionChoice{
Name: command.Name,
Value: command.Name,
})
}
return choices
}(),
}, },
}, },
}, },
@ -64,7 +73,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
case *discordgo.MessageCreate: case *discordgo.MessageCreate:
commandName = Discommand.Aliases[strings.Join(*args, " ")] commandName = Discommand.Aliases[strings.Join(*args, " ")]
case *utils.InteractionCreate: case *utils.InteractionCreate:
if opt, ok := m.Options["명령어"]; ok { if opt, ok := m.Options["도움말"]; ok {
commandName = opt.StringValue() commandName = opt.StringValue()
} else { } else {
commandName = "" commandName = ""

View file

@ -7,7 +7,7 @@ import (
"git.wh64.net/muffin/goMuffin/utils" "git.wh64.net/muffin/goMuffin/utils"
) )
const MUFFIN_VERSION = "5.0.0-gopher_preview.250405b" const MUFFIN_VERSION = "5.0.0-gopher_preview.250405a"
var updatedString string = utils.Decimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0] var updatedString string = utils.Decimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]

19
main.go
View file

@ -6,7 +6,6 @@ import (
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"time"
"git.wh64.net/muffin/goMuffin/commands" "git.wh64.net/muffin/goMuffin/commands"
"git.wh64.net/muffin/goMuffin/components" "git.wh64.net/muffin/goMuffin/components"
@ -39,25 +38,7 @@ func main() {
dg.Open() dg.Open()
go func() {
for {
dg.UpdateCustomStatus("ㅅ살려주세요..!")
time.Sleep(time.Minute * 10)
}
}()
for _, cmd := range commands.Discommand.Commands { for _, cmd := range commands.Discommand.Commands {
if cmd.Name == "도움말" {
// 극한의 성능 똥망 코드 탄생!
// 무려 똑같은 걸 반복해서 돌리는!
for _, a := range commands.Discommand.Commands {
cmd.Options[0].Choices = append(cmd.Options[0].Choices, &discordgo.ApplicationCommandOptionChoice{
Name: a.Name,
Value: a.Name,
})
}
}
go dg.ApplicationCommandCreate(dg.State.User.ID, "", cmd.ApplicationCommand) go dg.ApplicationCommandCreate(dg.State.User.ID, "", cmd.ApplicationCommand)
} }