Skip to content

Commit edd34ee

Browse files
committed
Updated music command
1 parent aa95cda commit edd34ee

File tree

4 files changed

+176
-173
lines changed

4 files changed

+176
-173
lines changed

cmd/roboto/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
FROM golang:1.23 AS builder
22

3+
COPY ./go.mod ./go.sum /build/
34
COPY ./cmd /build/cmd/
45
COPY ./internal /build/internal/
5-
COPY ./go.mod ./go.sum /build/
66
WORKDIR /build
77

88
RUN go mod download

cmd/roboto/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"os"
55
"os/signal"
6+
"syscall"
67

78
"github.com/mroctopus/bottie-bot/internal/bot"
89
"github.com/mroctopus/bottie-bot/internal/command"
@@ -36,7 +37,7 @@ func main() {
3637
log.Info().Msg("Starting bot...")
3738

3839
channel := make(chan os.Signal, 1)
39-
signal.Notify(channel, os.Interrupt)
40+
signal.Notify(channel, syscall.SIGTERM, syscall.SIGINT)
4041

4142
err = bot.Start(cmds, r)
4243
if err != nil {
@@ -46,7 +47,9 @@ func main() {
4647
log.Info().Msg("Bot started, press Ctrl+C to exit")
4748
<-channel
4849

50+
log.Info().Msg("Shutting down bot...")
51+
4952
bot.Stop()
5053

51-
log.Info().Msg("Shutdown bot...")
54+
log.Info().Msg("Finished shutting down bot")
5255
}

internal/command/command.go

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/disgoorg/disgo/discord"
77
"github.com/disgoorg/disgo/handler"
88
"github.com/disgoorg/disgo/handler/middleware"
9-
"github.com/disgoorg/json"
109
"github.com/mroctopus/bottie-bot/internal/bot"
1110
)
1211

@@ -36,54 +35,46 @@ func New(bot *bot.RobotoBot) ([]discord.ApplicationCommandCreate, *handler.Mux)
3635

3736
// -- COMMON --
3837

39-
/*
38+
type MessageType int
39+
4040
const (
41-
MessageColorPrimary =
41+
MessageTypeDefault MessageType = iota
42+
MessageTypeError
4243
)
43-
*/
4444

45-
func message(txt string) discord.MessageCreate {
46-
return discord.MessageCreate{
47-
Embeds: []discord.Embed{
48-
{
49-
Description: txt,
50-
Color: 0,
51-
},
52-
},
45+
func message[T *discord.MessageCreate | *discord.MessageUpdate](dst T, txt string, t MessageType, flags discord.MessageFlags) T {
46+
var color int
47+
switch t {
48+
case MessageTypeError:
49+
color = 0
50+
txt = fmt.Sprintf("Error: %s", txt)
51+
case MessageTypeDefault:
52+
fallthrough
53+
default:
54+
color = 0
5355
}
54-
}
5556

56-
func messageUpdate(txt string) discord.MessageUpdate {
57-
return discord.MessageUpdate{
58-
Embeds: &[]discord.Embed{
59-
{
60-
Description: txt,
61-
Color: 0,
62-
},
57+
embeds := []discord.Embed{
58+
{
59+
Description: txt,
60+
Color: color,
6361
},
6462
}
65-
}
6663

67-
func errorMessage(err error) discord.MessageCreate {
68-
return discord.MessageCreate{
69-
Embeds: []discord.Embed{
70-
{
71-
Description: fmt.Sprintf("Error: %s", err.Error()),
72-
Color: 0,
73-
},
74-
},
75-
Flags: discord.MessageFlagEphemeral,
64+
// NOTE:
65+
// For the love of god, please let this proposal go through:
66+
// https://github.com/golang/go/issues/45380
67+
switch v := any(dst).(type) {
68+
case *discord.MessageCreate:
69+
v.Embeds = embeds
70+
v.Flags = flags
71+
case *discord.MessageUpdate:
72+
v.Embeds = &embeds
73+
if flags > 0 {
74+
v.Flags = &flags
75+
}
76+
v.Components = nil
7677
}
77-
}
7878

79-
func errorMessageUpdate(err error) discord.MessageUpdate {
80-
return discord.MessageUpdate{
81-
Embeds: &[]discord.Embed{
82-
{
83-
Description: fmt.Sprintf("Error: %s", err.Error()),
84-
Color: 0,
85-
},
86-
},
87-
Flags: json.Ptr(discord.MessageFlagEphemeral),
88-
}
79+
return dst
8980
}

0 commit comments

Comments
 (0)