|
6 | 6 | "github.com/disgoorg/disgo/discord" |
7 | 7 | "github.com/disgoorg/disgo/handler" |
8 | 8 | "github.com/disgoorg/disgo/handler/middleware" |
9 | | - "github.com/disgoorg/json" |
10 | 9 | "github.com/mroctopus/bottie-bot/internal/bot" |
11 | 10 | ) |
12 | 11 |
|
@@ -36,54 +35,46 @@ func New(bot *bot.RobotoBot) ([]discord.ApplicationCommandCreate, *handler.Mux) |
36 | 35 |
|
37 | 36 | // -- COMMON -- |
38 | 37 |
|
39 | | -/* |
| 38 | +type MessageType int |
| 39 | + |
40 | 40 | const ( |
41 | | - MessageColorPrimary = |
| 41 | + MessageTypeDefault MessageType = iota |
| 42 | + MessageTypeError |
42 | 43 | ) |
43 | | -*/ |
44 | 44 |
|
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 |
53 | 55 | } |
54 | | -} |
55 | 56 |
|
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, |
63 | 61 | }, |
64 | 62 | } |
65 | | -} |
66 | 63 |
|
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 |
76 | 77 | } |
77 | | -} |
78 | 78 |
|
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 |
89 | 80 | } |
0 commit comments