diff --git a/commands/discommand.go b/commands/discommand.go index 38d1714..351eaad 100644 --- a/commands/discommand.go +++ b/commands/discommand.go @@ -40,15 +40,18 @@ func new() *DiscommandStruct { go discommand.loadCommands(DataLengthCommand) go discommand.loadCommands(LearnCommand) go discommand.loadCommands(LearnedDataListCommand) + go discommand.loadCommands(InformationCommand) go discommand.addMessageRun(HelpCommand.Name, HelpCommand.helpMessageRun) go discommand.addMessageRun(DataLengthCommand.Name, DataLengthCommand.dataLengthMessageRun) go discommand.addMessageRun(LearnCommand.Name, LearnCommand.learnMessageRun) go discommand.addMessageRun(LearnedDataListCommand.Name, LearnedDataListCommand.learnedDataListMessageRun) + go discommand.addMessageRun(InformationCommand.Name, InformationCommand.informationMessageRun) go discommand.addChatInputRun(DataLengthCommand.Name, DataLengthCommand.dataLenghChatInputRun) go discommand.addChatInputRun(LearnCommand.Name, LearnCommand.learnChatInputRun) go discommand.addChatInputRun(LearnedDataListCommand.Name, LearnedDataListCommand.learnedDataListChatInputRun) + go discommand.addChatInputRun(InformationCommand.Name, DataLengthCommand.informationChatInputRun) return &discommand } diff --git a/commands/information.go b/commands/information.go new file mode 100644 index 0000000..4829354 --- /dev/null +++ b/commands/information.go @@ -0,0 +1,74 @@ +package commands + +import ( + "runtime" + + "git.wh64.net/muffin/goMuffin/configs" + "git.wh64.net/muffin/goMuffin/utils" + "github.com/bwmarrin/discordgo" +) + +var InformationCommand *Command = &Command{ + ApplicationCommand: &discordgo.ApplicationCommand{ + Name: "정보", + Description: "머핀봇의 정보를 알ㄹ려줘요.", + }, + DetailedDescription: &DetailedDescription{ + Usage: "머핀아 정보", + }, +} + +func (c *Command) informationRun(s *discordgo.Session, m any) { + owner, _ := s.User(configs.Config.Bot.OwnerId) + embed := &discordgo.MessageEmbed{ + Title: s.State.User.Username + "의 정보", + Fields: []*discordgo.MessageEmbedField{ + { + Name: "운영 체제", + Value: runtime.GOOS + " " + runtime.GOARCH, + }, + { + Name: "제작자", + Value: owner.Username, + }, + { + Name: "버전", + Value: utils.InlineCode(configs.MUFFIN_VERSION), + }, + { + Name: "최근에 업데이트된 날짜", + Value: utils.TimeWithStyle(configs.UpdatedAt, utils.RelativeTime), + Inline: true, + }, + { + Name: "업타임", + Value: utils.TimeWithStyle(configs.StartedAt, utils.RelativeTime), + Inline: true, + }, + }, + Color: int(utils.EDefault), + Thumbnail: &discordgo.MessageEmbedThumbnail{ + URL: s.State.User.AvatarURL("512"), + }, + } + + 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) informationMessageRun(s *discordgo.Session, m *discordgo.MessageCreate) { + c.informationRun(s, m) +} + +func (c *Command) informationChatInputRun(s *discordgo.Session, i *discordgo.InteractionCreate) { + c.informationRun(s, i) +} diff --git a/configs/time.go b/configs/time.go new file mode 100644 index 0000000..852bef5 --- /dev/null +++ b/configs/time.go @@ -0,0 +1,10 @@ +package configs + +import "time" + +var StartedAt *time.Time + +func TimeStart() { + now := time.Now() + StartedAt = &now +} diff --git a/configs/version.go b/configs/version.go index a3a86d5..77e773e 100644 --- a/configs/version.go +++ b/configs/version.go @@ -1,3 +1,21 @@ package configs -var MUFFIN_VERSION = "0.0.0-gopher_canary.250329a" +import ( + "strconv" + "time" + + "git.wh64.net/muffin/goMuffin/utils" +) + +const MUFFIN_VERSION = "0.0.0-gopher_canary.250329b" + +var updatedString string = utils.Decimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0] + +var UpdatedAt *time.Time = func() *time.Time { + year, _ := strconv.Atoi("20" + updatedString[0:2]) + monthInt, _ := strconv.Atoi(updatedString[2:4]) + month := time.Month(monthInt) + day, _ := strconv.Atoi(updatedString[4:6]) + time := time.Date(year, month, day, 0, 0, 0, 0, &time.Location{}) + return &time +}() diff --git a/main.go b/main.go index 2b027b9..3f68600 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( ) func main() { + configs.TimeStart() config := configs.Config dg, err := discordgo.New("Bot " + config.Bot.Token) diff --git a/utils/codeFormatter.go b/utils/codeFormatter.go index 063a6a0..cc4a8f2 100644 --- a/utils/codeFormatter.go +++ b/utils/codeFormatter.go @@ -1,5 +1,23 @@ package utils +import ( + "strconv" + "time" +) + +const ( + ShortTime = "t" + LongTime = "T" + + ShortDate = "d" + LongDate = "D" + + ShortDateTime = "f" + LongDateTime = "F" + + RelativeTime = "R" +) + func InlineCode(str string) string { return "`" + str + "`" } @@ -11,3 +29,11 @@ func CodeBlockWithLanguage(language string, content string) string { func CodeBlock(content string) string { return "```\n" + content + "\n" + "```" } + +func Time(time *time.Time) string { + return "" +} + +func TimeWithStyle(time *time.Time, style string) string { + return "" +} diff --git a/utils/regexp.go b/utils/regexp.go index 3a2a85b..726e22e 100644 --- a/utils/regexp.go +++ b/utils/regexp.go @@ -3,3 +3,4 @@ package utils import "regexp" var ExtractQuotedText *regexp.Regexp = regexp.MustCompile("[\"'`](.*?)[\"'`]") +var Decimals *regexp.Regexp = regexp.MustCompile(`\d+`)