feat: Add information command
This commit is contained in:
parent
1e1c5ce561
commit
b6baf89147
7 changed files with 134 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
74
commands/information.go
Normal file
74
commands/information.go
Normal file
|
@ -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)
|
||||
}
|
10
configs/time.go
Normal file
10
configs/time.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package configs
|
||||
|
||||
import "time"
|
||||
|
||||
var StartedAt *time.Time
|
||||
|
||||
func TimeStart() {
|
||||
now := time.Now()
|
||||
StartedAt = &now
|
||||
}
|
|
@ -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
|
||||
}()
|
||||
|
|
1
main.go
1
main.go
|
@ -16,6 +16,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
configs.TimeStart()
|
||||
config := configs.Config
|
||||
|
||||
dg, err := discordgo.New("Bot " + config.Bot.Token)
|
||||
|
|
|
@ -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 "<t:" + strconv.FormatInt(time.Unix(), 10) + ">"
|
||||
}
|
||||
|
||||
func TimeWithStyle(time *time.Time, style string) string {
|
||||
return "<t:" + strconv.FormatInt(time.Unix(), 10) + ":" + style + ">"
|
||||
}
|
||||
|
|
|
@ -3,3 +3,4 @@ package utils
|
|||
import "regexp"
|
||||
|
||||
var ExtractQuotedText *regexp.Regexp = regexp.MustCompile("[\"'`](.*?)[\"'`]")
|
||||
var Decimals *regexp.Regexp = regexp.MustCompile(`\d+`)
|
||||
|
|
Loading…
Reference in a new issue