Update Packages, Add Status Command, and Bugfixes (!8)
Co-authored-by: Layla Manley <layla@layla.gg> Reviewed-on: #8
This commit is contained in:
@ -29,7 +29,7 @@ func NewFeedbackWebhookComponent(webhookURL string, config FeedbackWebhookConfig
|
||||
m := &feedbackWebhookModule{
|
||||
webhookURL: webhookURL,
|
||||
payloadType: "default",
|
||||
successMessage: "Feedback recieved!",
|
||||
successMessage: "Feedback received!",
|
||||
failureMessage: "Failed to send feedback!",
|
||||
}
|
||||
|
||||
|
@ -14,17 +14,17 @@ type roleSelectionModule struct {
|
||||
session *discord.Discord
|
||||
db persistence.Database
|
||||
|
||||
cfg core.RoleSelectionConfig
|
||||
exlusive bool
|
||||
cfg core.RoleSelectionConfig
|
||||
exclusive bool
|
||||
}
|
||||
|
||||
// NewRoleSelectionComponent creates a new component
|
||||
func NewRoleSelectionComponent(discord *discord.Discord, db persistence.Database, cfg core.RoleSelectionConfig) common.Module {
|
||||
return &roleSelectionModule{
|
||||
session: discord,
|
||||
cfg: cfg,
|
||||
db: db,
|
||||
exlusive: true,
|
||||
session: discord,
|
||||
cfg: cfg,
|
||||
db: db,
|
||||
exclusive: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,27 +49,30 @@ func (c *roleSelectionModule) Initialize(birdbot common.ModuleManager) error {
|
||||
btn := c.session.NewButton(fmt.Sprint(c.cfg.Title, role.Name), role.Name)
|
||||
btn.OnClick(func(user common.User) {
|
||||
|
||||
// Remove other roles if exclusive
|
||||
if c.exlusive {
|
||||
for _, r := range roles {
|
||||
if r.ID == role.ID {
|
||||
continue
|
||||
}
|
||||
// Assign the roles asynchronously to avoid Discord's response timeout
|
||||
go func() {
|
||||
// Remove other roles if exclusive
|
||||
if c.exclusive {
|
||||
for _, r := range roles {
|
||||
if r.ID == role.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
if c.session.HasRole(user, r) {
|
||||
c.session.UnassignRole(user, r)
|
||||
if c.session.HasRole(user, r) {
|
||||
c.session.UnassignRole(user, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle role
|
||||
if c.session.HasRole(user, role) {
|
||||
if err := c.session.UnassignRole(user, role); err != nil {
|
||||
log.Printf("Failed to unassign role: %s", err)
|
||||
// Toggle role
|
||||
if c.session.HasRole(user, role) {
|
||||
if err := c.session.UnassignRole(user, role); err != nil {
|
||||
log.Printf("Failed to unassign role: %s", err)
|
||||
}
|
||||
} else if err := c.session.AssignRole(user, role); err != nil {
|
||||
log.Printf("Failed to assign role: %s", err)
|
||||
}
|
||||
} else if err := c.session.AssignRole(user, role); err != nil {
|
||||
log.Printf("Failed to assign role: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
})
|
||||
|
||||
|
31
modules/status.go
Normal file
31
modules/status.go
Normal file
@ -0,0 +1,31 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/yeslayla/birdbot-common/common"
|
||||
)
|
||||
|
||||
type statusModule struct {
|
||||
portalURL string
|
||||
}
|
||||
|
||||
// NewStatusComponent creates a new component
|
||||
func NewStatusComponent(portalURL string) common.Module {
|
||||
m := &statusModule{
|
||||
portalURL: portalURL,
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (c *statusModule) Initialize(birdbot common.ModuleManager) error {
|
||||
birdbot.RegisterCommand("status", common.ChatCommandConfiguration{
|
||||
Description: "Gets the current status of the bot",
|
||||
EphemeralResponse: false,
|
||||
}, func(user common.User, args map[string]any) string {
|
||||
|
||||
return fmt.Sprintf("The bot is currently OK.\nSee Status Portal for more information: %s", c.portalURL)
|
||||
})
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user