feat: Add dataLength command's defer cur.Close() & Add pointer
This commit is contained in:
parent
b7257e42d6
commit
e9cef78d54
3 changed files with 28 additions and 15 deletions
|
@ -26,14 +26,14 @@ const (
|
||||||
userLearn
|
userLearn
|
||||||
)
|
)
|
||||||
|
|
||||||
var DataLengthCommand Command = Command{
|
var DataLengthCommand *Command = &Command{
|
||||||
ApplicationCommand: &discordgo.ApplicationCommand{
|
ApplicationCommand: &discordgo.ApplicationCommand{
|
||||||
Type: discordgo.ChatApplicationCommand,
|
Type: discordgo.ChatApplicationCommand,
|
||||||
Name: "데이터학습량",
|
Name: "데이터학습량",
|
||||||
Description: "봇이 학습한 데ㅇ이터량을 보여줘요.",
|
Description: "봇이 학습한 데ㅇ이터량을 보여줘요.",
|
||||||
},
|
},
|
||||||
Aliases: []string{"학습데이터량", "데이터량", "학습량"},
|
Aliases: []string{"학습데이터량", "데이터량", "학습량"},
|
||||||
DetailedDescription: DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 학습데이터량",
|
Usage: "머핀아 학습데이터량",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -77,9 +77,11 @@ func (c *Command) dataLengthRun(s *discordgo.Session, m interface{}) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer cur.Close(context.TODO())
|
||||||
|
|
||||||
cur.All(context.TODO(), &datas)
|
cur.All(context.TODO(), &datas)
|
||||||
ch <- chStruct{name: text, length: len(datas)}
|
ch <- chStruct{name: text, length: len(datas)}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -89,6 +91,9 @@ func (c *Command) dataLengthRun(s *discordgo.Session, m interface{}) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer cur.Close(context.TODO())
|
||||||
|
|
||||||
cur.All(context.TODO(), &datas)
|
cur.All(context.TODO(), &datas)
|
||||||
ch <- chStruct{name: muffin, length: len(datas)}
|
ch <- chStruct{name: muffin, length: len(datas)}
|
||||||
}()
|
}()
|
||||||
|
@ -107,6 +112,9 @@ func (c *Command) dataLengthRun(s *discordgo.Session, m interface{}) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer cur.Close(context.TODO())
|
||||||
|
|
||||||
cur.All(context.TODO(), &datas)
|
cur.All(context.TODO(), &datas)
|
||||||
ch <- chStruct{name: nsfw, length: len(datas)}
|
ch <- chStruct{name: nsfw, length: len(datas)}
|
||||||
}()
|
}()
|
||||||
|
@ -118,6 +126,9 @@ func (c *Command) dataLengthRun(s *discordgo.Session, m interface{}) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer cur.Close(context.TODO())
|
||||||
|
|
||||||
cur.All(context.TODO(), &datas)
|
cur.All(context.TODO(), &datas)
|
||||||
ch <- chStruct{name: learn, length: len(datas)}
|
ch <- chStruct{name: learn, length: len(datas)}
|
||||||
}()
|
}()
|
||||||
|
@ -130,6 +141,8 @@ func (c *Command) dataLengthRun(s *discordgo.Session, m interface{}) {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer cur.Close(context.TODO())
|
||||||
|
|
||||||
cur.All(context.TODO(), &datas)
|
cur.All(context.TODO(), &datas)
|
||||||
ch <- chStruct{name: userLearn, length: len(datas)}
|
ch <- chStruct{name: userLearn, length: len(datas)}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -15,22 +15,22 @@ type DetailedDescription struct {
|
||||||
type Command struct {
|
type Command struct {
|
||||||
*discordgo.ApplicationCommand
|
*discordgo.ApplicationCommand
|
||||||
Aliases []string
|
Aliases []string
|
||||||
DetailedDescription DetailedDescription
|
DetailedDescription *DetailedDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiscommandStruct struct {
|
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]messageRun
|
||||||
chatInputRuns map[string]interface{}
|
chatInputRuns map[string]chatInputRun
|
||||||
}
|
}
|
||||||
|
|
||||||
func new() *DiscommandStruct {
|
func new() *DiscommandStruct {
|
||||||
discommand := DiscommandStruct{
|
discommand := DiscommandStruct{
|
||||||
Commands: map[string]Command{},
|
Commands: map[string]*Command{},
|
||||||
Aliases: map[string]string{},
|
Aliases: map[string]string{},
|
||||||
messageRuns: map[string]interface{}{},
|
messageRuns: map[string]messageRun{},
|
||||||
chatInputRuns: map[string]interface{}{},
|
chatInputRuns: map[string]chatInputRun{},
|
||||||
}
|
}
|
||||||
|
|
||||||
go discommand.loadCommands(HelpCommand)
|
go discommand.loadCommands(HelpCommand)
|
||||||
|
@ -43,7 +43,7 @@ func new() *DiscommandStruct {
|
||||||
return &discommand
|
return &discommand
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiscommandStruct) loadCommands(command Command) {
|
func (d *DiscommandStruct) loadCommands(command *Command) {
|
||||||
d.Commands[command.Name] = command
|
d.Commands[command.Name] = command
|
||||||
d.Aliases[command.Name] = command.Name
|
d.Aliases[command.Name] = command.Name
|
||||||
|
|
||||||
|
@ -62,11 +62,11 @@ func (d *DiscommandStruct) addChatInputRun(name string, run chatInputRun) {
|
||||||
|
|
||||||
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](s, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiscommandStruct) ChatInputRun(command string, s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func (d *DiscommandStruct) ChatInputRun(command string, s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
d.chatInputRuns[command].(chatInputRun)(s, i)
|
d.chatInputRuns[command](s, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
var Discommand *DiscommandStruct = new()
|
var Discommand *DiscommandStruct = new()
|
||||||
|
|
|
@ -6,14 +6,14 @@ import (
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var HelpCommand Command = Command{
|
var HelpCommand *Command = &Command{
|
||||||
ApplicationCommand: &discordgo.ApplicationCommand{
|
ApplicationCommand: &discordgo.ApplicationCommand{
|
||||||
Type: discordgo.ChatApplicationCommand,
|
Type: discordgo.ChatApplicationCommand,
|
||||||
Name: "도움말",
|
Name: "도움말",
|
||||||
Description: "기본적인 사용ㅂ법이에요.",
|
Description: "기본적인 사용ㅂ법이에요.",
|
||||||
},
|
},
|
||||||
Aliases: []string{"도움", "명령어", "help"},
|
Aliases: []string{"도움", "명령어", "help"},
|
||||||
DetailedDescription: DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 도움말 [명령어]",
|
Usage: "머핀아 도움말 [명령어]",
|
||||||
Examples: []string{"머핀아 도움말", "머핀아 도움말 배워"},
|
Examples: []string{"머핀아 도움말", "머핀아 도움말 배워"},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue