Skip to content

Commit d3c3bfb

Browse files
authored
Use handler module & remove translations (#11)
* convert to handler module * more refactor work * make stuff work with handler module & remove translations * fix some minor issues * remove crowdin banner * fix nil sprintf pointer string * fix last translations * fix messages
1 parent f34c995 commit d3c3bfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2164
-2538
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[![KittyBot Version](https://img.shields.io/github/v/tag/KittyBot-Org/KittyBotGo?label=release)](https://github.com/KittyBot-Org/KittyBotGo/releases/latest)
55
[![Docker](https://github.com/KittyBot-Org/KittyBotGo/actions/workflows/docker-build.yml/badge.svg)](https://github.com/KittyBot-Org/KittyBotGo/actions/workflows/docker-build.yml)
66
[![Test](https://github.com/KittyBot-Org/KittyBotGo/actions/workflows/go-test.yml/badge.svg)](https://github.com/KittyBot-Org/KittyBotGo/actions/workflows/go-test.yml)
7-
[![Crowdin](https://badges.crowdin.net/kittybot/localized.svg)](https://crowdin.com/project/kittybot)
87
[![KittyBot Support Guild](https://discordapp.com/api/guilds/608506410803658753/embed.png?style=shield)](https://discord.gg/sD3ABd5)
98

109
[![Website Banner](.github/banner.png)](https://kittybot.de)

backend/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"time"
66

77
"github.com/KittyBot-Org/KittyBotGo/db"
8-
"github.com/KittyBot-Org/KittyBotGo/dbot"
8+
"github.com/disgoorg/handler"
99

1010
"github.com/disgoorg/disgo/discord"
1111
"github.com/disgoorg/disgo/rest"
@@ -49,7 +49,7 @@ func (b *Backend) SetupScheduler() error {
4949
return nil
5050
}
5151

52-
func (b *Backend) LoadCommands(commands ...dbot.Command) {
52+
func (b *Backend) LoadCommands(commands ...handler.Command) {
5353
b.Logger.Info("Loading commands...")
5454

5555
for _, command := range commands {

cmd/backend/main.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/KittyBot-Org/KittyBotGo/backend/routes"
1111
"github.com/KittyBot-Org/KittyBotGo/config"
1212
"github.com/KittyBot-Org/KittyBotGo/db"
13-
"github.com/KittyBot-Org/KittyBotGo/dbot/commands"
1413
"github.com/disgoorg/log"
1514
_ "github.com/lib/pq"
1615
)
@@ -57,28 +56,6 @@ func main() {
5756
os.Exit(0)
5857
}
5958

60-
b.LoadCommands(
61-
commands.BassBoost,
62-
commands.ClearQueue,
63-
commands.History,
64-
commands.LikedSongs,
65-
commands.Loop,
66-
commands.Next,
67-
commands.NowPlaying,
68-
commands.Pause,
69-
commands.Play,
70-
commands.Previous,
71-
commands.Queue,
72-
commands.Remove,
73-
commands.Seek,
74-
commands.Shuffle,
75-
commands.Stop,
76-
commands.Tag,
77-
commands.Tags,
78-
commands.Volume,
79-
commands.Report,
80-
commands.Settings,
81-
)
8259
b.SetupRestServices()
8360
if err = b.SetupPrometheusAPI(); err != nil {
8461
b.Logger.Fatal("Failed to setup prometheus api: ", err)

cmd/dbot/main.go

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"github.com/KittyBot-Org/KittyBotGo/dbot"
1313
"github.com/KittyBot-Org/KittyBotGo/dbot/commands"
1414
"github.com/KittyBot-Org/KittyBotGo/dbot/listeners"
15-
"github.com/KittyBot-Org/KittyBotGo/i18n"
1615
"github.com/disgoorg/log"
16+
"github.com/disgoorg/snowflake/v2"
1717
_ "github.com/lib/pq"
1818
)
1919

@@ -46,34 +46,44 @@ func main() {
4646
logger.Info("Exiting after syncing? ", *exitAfterSync)
4747
defer logger.Info("Shutting down discord dbot...")
4848

49-
if err := i18n.Setup(logger); err != nil {
50-
logger.Fatal("Failed to setup i18n: ", err)
51-
}
52-
5349
b := dbot.New(logger, cfg, version)
54-
b.LoadCommands(
55-
commands.BassBoost,
56-
commands.ClearQueue,
57-
commands.History,
58-
commands.LikedSongs,
59-
commands.Loop,
60-
commands.Next,
61-
commands.NowPlaying,
62-
commands.Pause,
63-
commands.Play,
64-
commands.Previous,
65-
commands.Queue,
66-
commands.Remove,
67-
commands.Seek,
68-
commands.Shuffle,
69-
commands.Stop,
70-
commands.Tag,
71-
commands.Tags,
72-
commands.Volume,
73-
commands.Report,
74-
commands.Reports,
75-
commands.ReportUser,
76-
commands.Settings,
50+
b.Handler.AddCommands(
51+
commands.BassBoost(b),
52+
commands.ClearQueue(b),
53+
commands.History(b),
54+
commands.LikedSongs(b),
55+
commands.Loop(b),
56+
commands.Next(b),
57+
commands.NowPlaying(b),
58+
commands.Pause(b),
59+
commands.Play(b),
60+
commands.Previous(b),
61+
commands.Queue(b),
62+
commands.Remove(b),
63+
commands.Seek(b),
64+
commands.Shuffle(b),
65+
commands.Stop(b),
66+
commands.Tag(b),
67+
commands.Tags(b),
68+
commands.Volume(b),
69+
commands.Report(b),
70+
commands.Reports(b),
71+
commands.ReportUser(b),
72+
commands.Settings(b),
73+
)
74+
75+
b.Handler.AddComponents(
76+
commands.ReportAction(b),
77+
commands.ReportConfirm(b),
78+
commands.ReportDelete(b),
79+
commands.PlayerLike(b),
80+
commands.PlayerNext(b),
81+
commands.PlayerPlayPause(b),
82+
commands.PlayerPrevious(b),
83+
)
84+
85+
b.Handler.AddModals(
86+
commands.ReportActionConfirm(b),
7787
)
7888

7989
if err := b.SetupBot(
@@ -87,7 +97,11 @@ func main() {
8797
defer b.Client.Close(context.TODO())
8898

8999
if *shouldSyncCommands {
90-
b.SyncCommands()
100+
var guilds []snowflake.ID
101+
if b.Config.DevMode {
102+
guilds = b.Config.DevGuildIDs
103+
}
104+
b.Handler.SyncCommands(b.Client, guilds...)
91105
}
92106

93107
var err error

dbot/bot.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/disgoorg/disgo/gateway"
1212
"github.com/disgoorg/disgo/webhook"
1313
"github.com/disgoorg/disgolink/disgolink"
14+
"github.com/disgoorg/handler"
1415
"github.com/disgoorg/log"
1516
"github.com/disgoorg/snowflake/v2"
1617
"github.com/disgoorg/utils/paginator"
@@ -19,6 +20,7 @@ import (
1920
func New(logger log.Logger, config Config, version string) *Bot {
2021
return &Bot{
2122
Logger: logger,
23+
Handler: handler.New(logger),
2224
Paginator: paginator.NewManager(),
2325
ReportLogWebhookMap: NewReportLogWebhookMap(),
2426
Config: config,
@@ -29,10 +31,10 @@ func New(logger log.Logger, config Config, version string) *Bot {
2931
type Bot struct {
3032
Logger log.Logger
3133
Client bot.Client
34+
Handler *handler.Handler
3235
Lavalink disgolink.Link
3336
MusicPlayers *MusicPlayerMap
3437
Paginator *paginator.Manager
35-
CommandMap *CommandMap
3638
DB db.DB
3739
ReportLogWebhookMap *ReportLogWebhookMap
3840
Config Config
@@ -49,7 +51,7 @@ func (b *Bot) SetupBot(listeners ...bot.EventListener) (err error) {
4951
return member.User.ID == b.Client.ID()
5052
}),
5153
),
52-
bot.WithEventListeners(append([]bot.EventListener{b.CommandMap, b.Paginator}, listeners...)...),
54+
bot.WithEventListeners(append([]bot.EventListener{b.Handler, b.Paginator}, listeners...)...),
5355
)
5456
return err
5557
}

dbot/command.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

dbot/command_check.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)