feat: add devproje/commando
This commit is contained in:
parent
7127a57eb0
commit
8b55a83287
5 changed files with 46 additions and 24 deletions
1
go.mod
1
go.mod
|
@ -12,6 +12,7 @@ require (
|
|||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
github.com/devproje/commando v0.1.0-alpha.1 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
github.com/klauspost/compress v1.18.0 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -6,6 +6,8 @@ github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd
|
|||
github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/devproje/commando v0.1.0-alpha.1 h1:JU6CKIdt1otjUKh+asCJC0yTzwVj+4Yh8KoTdzaKAkU=
|
||||
github.com/devproje/commando v0.1.0-alpha.1/go.mod h1:OhrPX3mZUGSyEX/E7d1o0vaQIYkjG/N5rk6Nqwgyc7k=
|
||||
github.com/go-sql-driver/mysql v1.9.2 h1:4cNKDYQ1I84SXslGddlsrMhc8k4LeDVj6Ad6WRjiHuU=
|
||||
github.com/go-sql-driver/mysql v1.9.2/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
|
|
29
main.go
29
main.go
|
@ -6,7 +6,6 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
|
@ -17,19 +16,33 @@ import (
|
|||
"git.wh64.net/muffin/goMuffin/handler"
|
||||
"git.wh64.net/muffin/goMuffin/scripts"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/devproje/commando"
|
||||
"github.com/devproje/commando/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
command := commando.NewCommando(os.Args[1:])
|
||||
config := configs.Config
|
||||
|
||||
if len(os.Args) > 1 {
|
||||
switch strings.ToLower(os.Args[1]) {
|
||||
case "dbmigrate":
|
||||
scripts.DBMigrate()
|
||||
case "deleteallcommands":
|
||||
scripts.DeleteAllCommands()
|
||||
default:
|
||||
log.Fatalln(fmt.Errorf("[goMuffin] 명령어 인자에는 dbmigrate나 deleteallcommands만 올 수 있어요"))
|
||||
command.Root("db-migrate", "봇의 데이터를 MariaDB에서 MongoDB로 옮깁니다.", scripts.DBMigrate)
|
||||
command.Root("delete-all-commands", "봇의 모든 슬래시 커맨드를 삭제합니다.", scripts.DeleteAllCommands,
|
||||
types.OptionData{
|
||||
Name: "id",
|
||||
Desc: "봇의 디스코드 아이디",
|
||||
Type: types.STRING,
|
||||
},
|
||||
types.OptionData{
|
||||
Name: "isYes",
|
||||
Short: []string{"y"},
|
||||
Type: types.BOOLEAN,
|
||||
},
|
||||
)
|
||||
|
||||
err := command.Execute()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"git.wh64.net/muffin/goMuffin/configs"
|
||||
|
||||
"github.com/devproje/commando"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
|
@ -19,7 +20,7 @@ import (
|
|||
var wg sync.WaitGroup
|
||||
|
||||
// 이 스크립트는 MariaDB -> MongoDB로의 전환을 위해 만들었음.
|
||||
func DBMigrate() {
|
||||
func DBMigrate(n *commando.Node) error {
|
||||
mariaURL := os.Getenv("PREVIOUS_DATABASE_URL")
|
||||
mongoURL := configs.Config.DatabaseURL
|
||||
dbName := configs.Config.DBName
|
||||
|
@ -189,4 +190,5 @@ func DBMigrate() {
|
|||
// 모든 고루틴이 끝날 떄 까지 대기
|
||||
wg.Wait()
|
||||
fmt.Println("데이터 마이그레이션이 끝났어요.")
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package scripts
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -10,40 +9,45 @@ import (
|
|||
|
||||
"git.wh64.net/muffin/goMuffin/configs"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/devproje/commando"
|
||||
"github.com/devproje/commando/option"
|
||||
)
|
||||
|
||||
func DeleteAllCommands() {
|
||||
func DeleteAllCommands(n *commando.Node) error {
|
||||
var answer string
|
||||
id := flag.String("id", "", "디스코드 봇의 토큰")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
fmt.Printf("정말로 모든 명령어를 삭제하시겠어요? [y/N]: ")
|
||||
fmt.Scanf("%s", &answer)
|
||||
if strings.ToLower(answer) != "y" && strings.ToLower(answer) != "yes" {
|
||||
os.Exit(1)
|
||||
id, err := option.ParseString(*n.MustGetOpt("id"), n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if *id == "" {
|
||||
panic(fmt.Errorf("--id 플래그의 값이 필요해요"))
|
||||
yes, _ := option.ParseBool(*n.MustGetOpt("isYes"), n)
|
||||
if !yes {
|
||||
fmt.Printf("정말로 모든 명령어를 삭제하시겠어요? [y/N]: ")
|
||||
fmt.Scanf("%s", &answer)
|
||||
if strings.ToLower(answer) != "y" && strings.ToLower(answer) != "yes" {
|
||||
fmt.Println("모든 명령어 삭제를 취소했어요.")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
c := http.Client{}
|
||||
req, err := http.NewRequest("PUT", discordgo.EndpointApplicationGlobalCommands(*id), nil)
|
||||
req, err := http.NewRequest("PUT", discordgo.EndpointApplicationGlobalCommands(id), nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Add("Authorization", "Bot "+configs.Config.Bot.Token)
|
||||
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
bytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
fmt.Println(string(bytes))
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue