Compare commits
2 commits
695b22c3d5
...
11f22c627d
Author | SHA1 | Date | |
---|---|---|---|
11f22c627d | |||
d6a47dbfd0 |
9 changed files with 239 additions and 65 deletions
|
@ -37,6 +37,7 @@ var DataLengthCommand *Command = &Command{
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 학습데이터량",
|
Usage: "머핀아 학습데이터량",
|
||||||
},
|
},
|
||||||
|
Category: Generals,
|
||||||
}
|
}
|
||||||
var ch chan chStruct = make(chan chStruct)
|
var ch chan chStruct = make(chan chStruct)
|
||||||
|
|
||||||
|
@ -172,10 +173,10 @@ func (c *Command) dataLengthRun(s *discordgo.Session, m any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) dataLengthMessageRun(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func (c *Command) dataLengthMessageRun(ctx *MsgContext) {
|
||||||
c.dataLengthRun(s, m)
|
c.dataLengthRun(ctx.Session, ctx.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) dataLenghChatInputRun(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func (c *Command) dataLenghChatInputRun(ctx *InterContext) {
|
||||||
c.dataLengthRun(s, i)
|
c.dataLengthRun(ctx.Session, ctx.Inter)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,10 @@ import (
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type messageRun func(s *discordgo.Session, m *discordgo.MessageCreate)
|
type messageRun func(ctx *MsgContext)
|
||||||
type chatInputRun func(s *discordgo.Session, m *discordgo.InteractionCreate)
|
type chatInputRun func(s *InterContext)
|
||||||
|
|
||||||
|
type Category string
|
||||||
|
|
||||||
type DetailedDescription struct {
|
type DetailedDescription struct {
|
||||||
Usage string
|
Usage string
|
||||||
|
@ -19,6 +21,7 @@ type Command struct {
|
||||||
Aliases []string
|
Aliases []string
|
||||||
DetailedDescription *DetailedDescription
|
DetailedDescription *DetailedDescription
|
||||||
discommand *DiscommandStruct
|
discommand *DiscommandStruct
|
||||||
|
Category Category
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiscommandStruct struct {
|
type DiscommandStruct struct {
|
||||||
|
@ -28,6 +31,22 @@ type DiscommandStruct struct {
|
||||||
chatInputRuns map[string]chatInputRun
|
chatInputRuns map[string]chatInputRun
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MsgContext struct {
|
||||||
|
Session *discordgo.Session
|
||||||
|
Msg *discordgo.MessageCreate
|
||||||
|
Args []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type InterContext struct {
|
||||||
|
Session *discordgo.Session
|
||||||
|
Inter *discordgo.InteractionCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
Chattings Category = "채팅"
|
||||||
|
Generals Category = "일반"
|
||||||
|
)
|
||||||
|
|
||||||
func new() *DiscommandStruct {
|
func new() *DiscommandStruct {
|
||||||
discommand := DiscommandStruct{
|
discommand := DiscommandStruct{
|
||||||
Commands: map[string]*Command{},
|
Commands: map[string]*Command{},
|
||||||
|
@ -48,6 +67,7 @@ func new() *DiscommandStruct {
|
||||||
go discommand.addMessageRun(LearnedDataListCommand.Name, LearnedDataListCommand.learnedDataListMessageRun)
|
go discommand.addMessageRun(LearnedDataListCommand.Name, LearnedDataListCommand.learnedDataListMessageRun)
|
||||||
go discommand.addMessageRun(InformationCommand.Name, InformationCommand.informationMessageRun)
|
go discommand.addMessageRun(InformationCommand.Name, InformationCommand.informationMessageRun)
|
||||||
|
|
||||||
|
go discommand.addChatInputRun(HelpCommand.Name, HelpCommand.helpChatInputRun)
|
||||||
go discommand.addChatInputRun(DataLengthCommand.Name, DataLengthCommand.dataLenghChatInputRun)
|
go discommand.addChatInputRun(DataLengthCommand.Name, DataLengthCommand.dataLenghChatInputRun)
|
||||||
go discommand.addChatInputRun(LearnCommand.Name, LearnCommand.learnChatInputRun)
|
go discommand.addChatInputRun(LearnCommand.Name, LearnCommand.learnChatInputRun)
|
||||||
go discommand.addChatInputRun(LearnedDataListCommand.Name, LearnedDataListCommand.learnedDataListChatInputRun)
|
go discommand.addChatInputRun(LearnedDataListCommand.Name, LearnedDataListCommand.learnedDataListChatInputRun)
|
||||||
|
@ -55,13 +75,13 @@ func new() *DiscommandStruct {
|
||||||
return &discommand
|
return &discommand
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiscommandStruct) loadCommands(command *Command) {
|
func (d *DiscommandStruct) loadCommands(c *Command) {
|
||||||
d.Commands[command.Name] = command
|
d.Commands[c.Name] = c
|
||||||
d.Aliases[command.Name] = command.Name
|
d.Aliases[c.Name] = c.Name
|
||||||
command.discommand = d
|
c.discommand = d
|
||||||
|
|
||||||
for _, alias := range command.Aliases {
|
for _, alias := range c.Aliases {
|
||||||
d.Aliases[alias] = command.Name
|
d.Aliases[alias] = c.Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,13 +93,13 @@ func (d *DiscommandStruct) addChatInputRun(name string, run chatInputRun) {
|
||||||
d.chatInputRuns[name] = run
|
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, args []string) {
|
||||||
// 더욱 나아진
|
// 더욱 나아진
|
||||||
d.messageRuns[command](s, m)
|
d.messageRuns[command](&MsgContext{s, m, args})
|
||||||
}
|
}
|
||||||
|
|
||||||
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](s, i)
|
d.chatInputRuns[command](&InterContext{s, i})
|
||||||
}
|
}
|
||||||
|
|
||||||
var Discommand *DiscommandStruct = new()
|
var Discommand *DiscommandStruct = new()
|
||||||
|
|
154
commands/help.go
154
commands/help.go
|
@ -1,25 +1,171 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strings"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 씨발 나중에 구조 개선 하면서 갈아 엎어야지
|
||||||
|
var commandNames []string = []string{
|
||||||
|
"도움말",
|
||||||
|
"데이터학습량",
|
||||||
|
"정보",
|
||||||
|
"배워",
|
||||||
|
"리스트",
|
||||||
|
// "삭제",
|
||||||
|
}
|
||||||
|
|
||||||
var HelpCommand *Command = &Command{
|
var HelpCommand *Command = &Command{
|
||||||
ApplicationCommand: &discordgo.ApplicationCommand{
|
ApplicationCommand: &discordgo.ApplicationCommand{
|
||||||
Type: discordgo.ChatApplicationCommand,
|
Type: discordgo.ChatApplicationCommand,
|
||||||
Name: "도움말",
|
Name: "도움말",
|
||||||
Description: "기본적인 사용ㅂ법이에요.",
|
Description: "기본적인 사용ㅂ법이에요.",
|
||||||
|
Options: []*discordgo.ApplicationCommandOption{
|
||||||
|
{
|
||||||
|
Type: discordgo.ApplicationCommandOptionString,
|
||||||
|
Name: "명령어",
|
||||||
|
Description: "해당 명령어에 대ㅎ한 도움말을 볼 수 있어요.",
|
||||||
|
Choices: func() []*discordgo.ApplicationCommandOptionChoice {
|
||||||
|
choices := []*discordgo.ApplicationCommandOptionChoice{}
|
||||||
|
for _, name := range commandNames {
|
||||||
|
choices = append(choices, &discordgo.ApplicationCommandOptionChoice{
|
||||||
|
Name: name,
|
||||||
|
Value: name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return choices
|
||||||
|
}(),
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Aliases: []string{"도움", "명령어", "help"},
|
Aliases: []string{"도움", "명령어", "help"},
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 도움말 [명령어]",
|
Usage: "머핀아 도움말 [명령어]",
|
||||||
Examples: []string{"머핀아 도움말", "머핀아 도움말 배워"},
|
Examples: []string{"머핀아 도움말", "머핀아 도움말 배워"},
|
||||||
},
|
},
|
||||||
|
Category: Generals,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) helpMessageRun(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func getCommandsByCategory(d *DiscommandStruct, category Category) []string {
|
||||||
fmt.Println(c.Name)
|
commands := []string{}
|
||||||
s.ChannelMessageSend(m.ChannelID, "asdf")
|
for _, command := range d.Commands {
|
||||||
|
if command.Category == category {
|
||||||
|
commands = append(commands, "- "+command.Name+": "+command.Description)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commands
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) helpRun(s *discordgo.Session, m any, args *[]string) {
|
||||||
|
var commandName string
|
||||||
|
embed := &discordgo.MessageEmbed{
|
||||||
|
Color: int(utils.EDefault),
|
||||||
|
Footer: &discordgo.MessageEmbedFooter{
|
||||||
|
Text: "버전:" + configs.MUFFIN_VERSION,
|
||||||
|
},
|
||||||
|
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
||||||
|
URL: s.State.User.AvatarURL("512"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m := m.(type) {
|
||||||
|
case *discordgo.MessageCreate:
|
||||||
|
commandName = strings.Join(*args, " ")
|
||||||
|
case *discordgo.InteractionCreate:
|
||||||
|
optsMap := map[string]*discordgo.ApplicationCommandInteractionDataOption{}
|
||||||
|
for _, opt := range m.ApplicationCommandData().Options {
|
||||||
|
optsMap[opt.Name] = opt
|
||||||
|
}
|
||||||
|
if opt, ok := optsMap["명령어"]; ok {
|
||||||
|
commandName = opt.StringValue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if commandName == "" || c.discommand.Commands[commandName] == nil {
|
||||||
|
embed.Title = s.State.User.Username + "의 도움말"
|
||||||
|
embed.Description = utils.CodeBlockWithLanguage(
|
||||||
|
"md",
|
||||||
|
"# 일반\n"+
|
||||||
|
strings.Join(getCommandsByCategory(c.discommand, Generals), "\n")+
|
||||||
|
"\n\n# 채팅\n"+
|
||||||
|
strings.Join(getCommandsByCategory(c.discommand, Chattings), "\n"),
|
||||||
|
)
|
||||||
|
|
||||||
|
switch m := m.(type) {
|
||||||
|
case *discordgo.MessageCreate:
|
||||||
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
|
case *discordgo.InteractionCreate:
|
||||||
|
s.InteractionRespond(m.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Embeds: []*discordgo.MessageEmbed{embed},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
command := c.discommand.Commands[commandName]
|
||||||
|
|
||||||
|
embed.Title = s.State.User.Username + "의 " + command.Name + " 도움말"
|
||||||
|
embed.Fields = []*discordgo.MessageEmbedField{
|
||||||
|
{
|
||||||
|
Name: "설명",
|
||||||
|
Value: utils.InlineCode(command.Description),
|
||||||
|
Inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "사용법",
|
||||||
|
Value: utils.InlineCode(command.DetailedDescription.Usage),
|
||||||
|
Inline: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if command.Aliases != nil {
|
||||||
|
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
||||||
|
Name: "별칭",
|
||||||
|
Value: utils.CodeBlockWithLanguage("md", strings.Join(addPrefix(command.Aliases), "\n")),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
||||||
|
Name: "별칭",
|
||||||
|
Value: "없음",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if command.DetailedDescription.Examples != nil {
|
||||||
|
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
||||||
|
Name: "예시",
|
||||||
|
Value: utils.CodeBlockWithLanguage("md", strings.Join(addPrefix(c.DetailedDescription.Examples), "\n")),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
||||||
|
Name: "예시",
|
||||||
|
Value: "없음",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m := m.(type) {
|
||||||
|
case *discordgo.MessageCreate:
|
||||||
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
|
case *discordgo.InteractionCreate:
|
||||||
|
s.InteractionRespond(m.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Embeds: []*discordgo.MessageEmbed{embed},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) helpMessageRun(ctx *MsgContext) {
|
||||||
|
c.helpRun(ctx.Session, ctx.Msg, &ctx.Args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) helpChatInputRun(ctx *InterContext) {
|
||||||
|
var args *[]string
|
||||||
|
c.helpRun(ctx.Session, ctx.Inter, args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ var InformationCommand *Command = &Command{
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 정보",
|
Usage: "머핀아 정보",
|
||||||
},
|
},
|
||||||
|
Category: Generals,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) informationRun(s *discordgo.Session, m any) {
|
func (c *Command) informationRun(s *discordgo.Session, m any) {
|
||||||
|
@ -65,10 +66,10 @@ func (c *Command) informationRun(s *discordgo.Session, m any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) informationMessageRun(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func (c *Command) informationMessageRun(ctx *MsgContext) {
|
||||||
c.informationRun(s, m)
|
c.informationRun(ctx.Session, ctx.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) informationChatInputRun(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func (c *Command) informationChatInputRun(ctx *InterContext) {
|
||||||
c.informationRun(s, i)
|
c.informationRun(ctx.Session, ctx.Inter)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,8 @@ import (
|
||||||
"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/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
|
||||||
|
|
||||||
"github.com/LoperLee/golang-hangul-toolkit/hangul"
|
"github.com/LoperLee/golang-hangul-toolkit/hangul"
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var LearnCommand *Command = &Command{
|
var LearnCommand *Command = &Command{
|
||||||
|
@ -42,6 +41,7 @@ var LearnCommand *Command = &Command{
|
||||||
"머핀아 배워 미간은_누구야? 이봇의_개발자요",
|
"머핀아 배워 미간은_누구야? 이봇의_개발자요",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Category: Chattings,
|
||||||
}
|
}
|
||||||
|
|
||||||
func addPrefix(arr []string) (newArr []string) {
|
func addPrefix(arr []string) (newArr []string) {
|
||||||
|
@ -51,44 +51,36 @@ func addPrefix(arr []string) (newArr []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) learnRun(s *discordgo.Session, m any) {
|
func (c *Command) learnRun(s *discordgo.Session, m any, args *[]string) {
|
||||||
var userId, command, result string
|
var userId, command, result string
|
||||||
|
|
||||||
igCommands := []string{}
|
igCommands := []string{}
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
userId = m.Author.ID
|
userId = m.Author.ID
|
||||||
matches := utils.ExtractQuotedText.FindAllStringSubmatch(strings.TrimPrefix(m.Content, configs.Config.Bot.Prefix), 2)
|
|
||||||
|
|
||||||
if len(matches) < 2 {
|
if len(*args) < 2 {
|
||||||
content := strings.TrimPrefix(m.Content, configs.Config.Bot.Prefix)
|
s.ChannelMessageSendEmbedReply(m.ChannelID, &discordgo.MessageEmbed{
|
||||||
command = strings.ReplaceAll(strings.Split(content, " ")[1], "_", "")
|
Title: "❌ 오류",
|
||||||
result = strings.ReplaceAll(strings.Split(content, " ")[2], "_", "")
|
Description: "올바르지 않ㅇ은 용법이에요.",
|
||||||
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
if command == "" || result == "" {
|
{
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, &discordgo.MessageEmbed{
|
Name: "사용법",
|
||||||
Title: "❌ 오류",
|
Value: utils.InlineCode(c.DetailedDescription.Usage),
|
||||||
Description: "올바르지 않ㅇ은 용법이에요.",
|
Inline: true,
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
|
||||||
{
|
|
||||||
Name: "사용법",
|
|
||||||
Value: utils.InlineCode(c.DetailedDescription.Usage),
|
|
||||||
Inline: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "예시",
|
|
||||||
Value: strings.Join(addPrefix(c.DetailedDescription.Examples), "\n"),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Color: int(utils.EFail),
|
{
|
||||||
}, m.Reference())
|
Name: "예시",
|
||||||
return
|
Value: strings.Join(addPrefix(c.DetailedDescription.Examples), "\n"),
|
||||||
}
|
},
|
||||||
} else {
|
},
|
||||||
command = matches[0][1]
|
Color: int(utils.EFail),
|
||||||
result = matches[1][1]
|
}, m.Reference())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command = strings.ReplaceAll((*args)[0], "_", " ")
|
||||||
|
result = strings.ReplaceAll((*args)[1], "_", " ")
|
||||||
case *discordgo.InteractionCreate:
|
case *discordgo.InteractionCreate:
|
||||||
s.InteractionRespond(m.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(m.Interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
|
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
|
||||||
|
@ -206,10 +198,11 @@ func (c *Command) learnRun(s *discordgo.Session, m any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) learnMessageRun(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func (c *Command) learnMessageRun(ctx *MsgContext) {
|
||||||
c.learnRun(s, m)
|
c.learnRun(ctx.Session, ctx.Msg, &ctx.Args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) learnChatInputRun(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func (c *Command) learnChatInputRun(ctx *InterContext) {
|
||||||
c.learnRun(s, i)
|
var args *[]string
|
||||||
|
c.learnRun(ctx.Session, ctx.Inter, args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ var LearnedDataListCommand *Command = &Command{
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: "머핀아 리스트",
|
Usage: "머핀아 리스트",
|
||||||
},
|
},
|
||||||
|
Category: Chattings,
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDescriptions(datas *[]databases.Learn) (descriptions []string) {
|
func getDescriptions(datas *[]databases.Learn) (descriptions []string) {
|
||||||
|
@ -114,10 +115,10 @@ func (c *Command) learnedDataListRun(s *discordgo.Session, m any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) learnedDataListMessageRun(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func (c *Command) learnedDataListMessageRun(ctx *MsgContext) {
|
||||||
c.learnedDataListRun(s, m)
|
c.learnedDataListRun(ctx.Session, ctx.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) learnedDataListChatInputRun(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func (c *Command) learnedDataListChatInputRun(ctx *InterContext) {
|
||||||
c.learnedDataListRun(s, i)
|
c.learnedDataListRun(ctx.Session, ctx.Inter)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MUFFIN_VERSION = "0.0.0-gopher_canary.250329c"
|
const MUFFIN_VERSION = "0.0.0-gopher_canary.250330a"
|
||||||
|
|
||||||
var updatedString string = utils.Decimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]
|
var updatedString string = utils.Decimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,17 @@ import (
|
||||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func argParser(content string) (args []string) {
|
||||||
|
for _, arg := range utils.FlexibleStringParser.FindAllStringSubmatch(content, -1) {
|
||||||
|
if arg[1] != "" {
|
||||||
|
args = append(args, arg[1])
|
||||||
|
} else {
|
||||||
|
args = append(args, arg[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// MessageCreate is handlers of messageCreate event
|
// MessageCreate is handlers of messageCreate event
|
||||||
func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
config := configs.Config
|
config := configs.Config
|
||||||
|
@ -25,7 +36,8 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
|
||||||
if strings.HasPrefix(m.Content, config.Bot.Prefix) {
|
if strings.HasPrefix(m.Content, config.Bot.Prefix) {
|
||||||
content := strings.TrimPrefix(m.Content, config.Bot.Prefix)
|
content := strings.TrimPrefix(m.Content, config.Bot.Prefix)
|
||||||
command := commands.Discommand.Aliases[strings.Split(content, " ")[0]]
|
args := argParser(content)
|
||||||
|
command := commands.Discommand.Aliases[args[0]]
|
||||||
|
|
||||||
if m.Author.ID == config.Train.UserID {
|
if m.Author.ID == config.Train.UserID {
|
||||||
if _, err := databases.Texts.InsertOne(context.TODO(), databases.InsertText{
|
if _, err := databases.Texts.InsertOne(context.TODO(), databases.InsertText{
|
||||||
|
@ -104,7 +116,7 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commands.Discommand.MessageRun(command, s, m)
|
commands.Discommand.MessageRun(command, s, m, args[1:])
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
|
|
|
@ -2,5 +2,5 @@ package utils
|
||||||
|
|
||||||
import "regexp"
|
import "regexp"
|
||||||
|
|
||||||
var ExtractQuotedText *regexp.Regexp = regexp.MustCompile("[\"'`](.*?)[\"'`]")
|
var FlexibleStringParser *regexp.Regexp = regexp.MustCompile("[^\\s\"'「」«»]+|\"([^\"]*)\"|'([^']*)'|「([^」]*)」|«([^»]*)»")
|
||||||
var Decimals *regexp.Regexp = regexp.MustCompile(`\d+`)
|
var Decimals *regexp.Regexp = regexp.MustCompile(`\d+`)
|
||||||
|
|
Loading…
Reference in a new issue