feat: enable/disable notifications of internal/barbarian conquers
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
parent
4b64d0f283
commit
02141fb6e8
|
@ -151,6 +151,14 @@ func (u updateGroupsParamsApplier) apply(q *bun.UpdateQuery) *bun.UpdateQuery {
|
|||
}
|
||||
}
|
||||
|
||||
if u.params.Barbarians.Valid {
|
||||
q = q.Set("barbarians = ?", u.params.Barbarians.Bool)
|
||||
}
|
||||
|
||||
if u.params.Internals.Valid {
|
||||
q = q.Set("internals = ?", u.params.Internals.Bool)
|
||||
}
|
||||
|
||||
return q
|
||||
}
|
||||
|
||||
|
|
|
@ -68,12 +68,22 @@ func TestGroup_Update(t *testing.T) {
|
|||
String: group.ChannelLosses + "update",
|
||||
Valid: true,
|
||||
},
|
||||
Barbarians: domain.NullBool{
|
||||
Bool: !group.Barbarians,
|
||||
Valid: true,
|
||||
},
|
||||
Internals: domain.NullBool{
|
||||
Bool: !group.Internals,
|
||||
Valid: true,
|
||||
},
|
||||
}
|
||||
|
||||
updatedGroup, err := repo.Update(context.Background(), group.ID.String(), group.ServerID, params)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, params.ChannelGains.String, updatedGroup.ChannelGains)
|
||||
assert.Equal(t, params.ChannelLosses.String, updatedGroup.ChannelLosses)
|
||||
assert.Equal(t, params.Barbarians.Bool, updatedGroup.Barbarians)
|
||||
assert.Equal(t, params.Internals.Bool, updatedGroup.Internals)
|
||||
})
|
||||
|
||||
t.Run("ERR: nothing to update", func(t *testing.T) {
|
||||
|
|
|
@ -14,6 +14,8 @@ type GroupService interface {
|
|||
Create(ctx context.Context, params domain.CreateGroupParams) (domain.Group, error)
|
||||
SetChannelGains(ctx context.Context, id, serverID, channel string) (domain.Group, error)
|
||||
SetChannelLosses(ctx context.Context, id, serverID, channel string) (domain.Group, error)
|
||||
SetInternals(ctx context.Context, id, serverID string, internals bool) (domain.Group, error)
|
||||
SetBarbarians(ctx context.Context, id, serverID string, barbarians bool) (domain.Group, error)
|
||||
List(ctx context.Context, params domain.ListGroupsParams) ([]domain.Group, error)
|
||||
Delete(ctx context.Context, id, serverID string) error
|
||||
}
|
||||
|
|
|
@ -147,6 +147,44 @@ func (c *groupCommand) create(s *discordgo.Session) error {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "internals",
|
||||
Description: "Enables/disables notifications of internal conquers",
|
||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Name: "group",
|
||||
Description: "Group ID",
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Name: "internals",
|
||||
Description: "Show conquers in the same group",
|
||||
Type: discordgo.ApplicationCommandOptionBoolean,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "barbarians",
|
||||
Description: "Enables/disables notifications of barbarian conquers",
|
||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Name: "group",
|
||||
Description: "Group ID",
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Name: "barbarians",
|
||||
Description: "Show barbarian conquers",
|
||||
Type: discordgo.ApplicationCommandOptionBoolean,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -351,6 +389,12 @@ func (c *groupCommand) handleSet(s *discordgo.Session, i *discordgo.InteractionC
|
|||
case "channel-losses":
|
||||
c.handleSetChannelLosses(s, i)
|
||||
return
|
||||
case "internals":
|
||||
c.handleSetInternals(s, i)
|
||||
return
|
||||
case "barbarians":
|
||||
c.handleSetBarbarians(s, i)
|
||||
return
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
@ -427,6 +471,78 @@ func (c *groupCommand) handleSetChannelLosses(s *discordgo.Session, i *discordgo
|
|||
})
|
||||
}
|
||||
|
||||
func (c *groupCommand) handleSetInternals(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
ctx := context.Background()
|
||||
|
||||
group := ""
|
||||
internals := false
|
||||
for _, opt := range i.ApplicationCommandData().Options[0].Options[0].Options {
|
||||
if opt == nil {
|
||||
continue
|
||||
}
|
||||
switch opt.Name {
|
||||
case "group":
|
||||
group = opt.StringValue()
|
||||
case "internals":
|
||||
internals = opt.BoolValue()
|
||||
}
|
||||
}
|
||||
|
||||
_, err := c.groupSvc.SetInternals(ctx, group, i.GuildID, internals)
|
||||
if err != nil {
|
||||
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: messageFromError(err),
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "group has been successfully updated",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (c *groupCommand) handleSetBarbarians(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
ctx := context.Background()
|
||||
|
||||
group := ""
|
||||
barbarians := false
|
||||
for _, opt := range i.ApplicationCommandData().Options[0].Options[0].Options {
|
||||
if opt == nil {
|
||||
continue
|
||||
}
|
||||
switch opt.Name {
|
||||
case "group":
|
||||
group = opt.StringValue()
|
||||
case "barbarians":
|
||||
barbarians = opt.BoolValue()
|
||||
}
|
||||
}
|
||||
|
||||
_, err := c.groupSvc.SetBarbarians(ctx, group, i.GuildID, barbarians)
|
||||
if err != nil {
|
||||
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: messageFromError(err),
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "group has been successfully updated",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (c *groupCommand) handleUnset(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
switch i.ApplicationCommandData().Options[0].Options[0].Name {
|
||||
case "channel-gains":
|
||||
|
|
|
@ -4,3 +4,8 @@ type NullString struct {
|
|||
String string
|
||||
Valid bool // Valid is true if String is not NULL
|
||||
}
|
||||
|
||||
type NullBool struct {
|
||||
Bool bool
|
||||
Valid bool // Valid is true if Bool is not NULL
|
||||
}
|
||||
|
|
|
@ -94,11 +94,15 @@ func (c CreateGroupParams) Internals() bool {
|
|||
type UpdateGroupParams struct {
|
||||
ChannelGains NullString
|
||||
ChannelLosses NullString
|
||||
Internals NullBool
|
||||
Barbarians NullBool
|
||||
}
|
||||
|
||||
func (u UpdateGroupParams) IsZero() bool {
|
||||
return !u.ChannelGains.Valid &&
|
||||
!u.ChannelLosses.Valid
|
||||
!u.ChannelLosses.Valid &&
|
||||
!u.Internals.Valid &&
|
||||
!u.Barbarians.Valid
|
||||
}
|
||||
|
||||
type ListGroupsParams struct {
|
||||
|
|
|
@ -115,6 +115,14 @@ func TestUpdateGroupParams_IsZero(t *testing.T) {
|
|||
String: "123",
|
||||
Valid: true,
|
||||
},
|
||||
Barbarians: domain.NullBool{
|
||||
Bool: false,
|
||||
Valid: true,
|
||||
},
|
||||
Internals: domain.NullBool{
|
||||
Bool: false,
|
||||
Valid: true,
|
||||
},
|
||||
},
|
||||
output: false,
|
||||
},
|
||||
|
@ -138,6 +146,26 @@ func TestUpdateGroupParams_IsZero(t *testing.T) {
|
|||
},
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
name: "OK: Barbarians",
|
||||
params: domain.UpdateGroupParams{
|
||||
Barbarians: domain.NullBool{
|
||||
Bool: false,
|
||||
Valid: true,
|
||||
},
|
||||
},
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
name: "OK: Internals",
|
||||
params: domain.UpdateGroupParams{
|
||||
Internals: domain.NullBool{
|
||||
Bool: false,
|
||||
Valid: true,
|
||||
},
|
||||
},
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
name: "OK: empty struct",
|
||||
params: domain.UpdateGroupParams{},
|
||||
|
|
|
@ -85,6 +85,32 @@ func (g *Group) SetChannelLosses(ctx context.Context, id, serverID, channel stri
|
|||
return group, nil
|
||||
}
|
||||
|
||||
func (g *Group) SetInternals(ctx context.Context, id, serverID string, internals bool) (domain.Group, error) {
|
||||
group, err := g.repo.Update(ctx, id, serverID, domain.UpdateGroupParams{
|
||||
Internals: domain.NullBool{
|
||||
Bool: internals,
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return domain.Group{}, fmt.Errorf("GroupRepository.Update: %w", err)
|
||||
}
|
||||
return group, nil
|
||||
}
|
||||
|
||||
func (g *Group) SetBarbarians(ctx context.Context, id, serverID string, barbarians bool) (domain.Group, error) {
|
||||
group, err := g.repo.Update(ctx, id, serverID, domain.UpdateGroupParams{
|
||||
Barbarians: domain.NullBool{
|
||||
Bool: barbarians,
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return domain.Group{}, fmt.Errorf("GroupRepository.Update: %w", err)
|
||||
}
|
||||
return group, nil
|
||||
}
|
||||
|
||||
func (g *Group) List(ctx context.Context, params domain.ListGroupsParams) ([]domain.Group, error) {
|
||||
groups, err := g.repo.List(ctx, params)
|
||||
if err != nil {
|
||||
|
|
|
@ -287,7 +287,7 @@ func (m *Monitor) fetchEnnoblements(ctx context.Context, groups []domain.Group)
|
|||
|
||||
since := ennoblementsSince[key]
|
||||
if since.IsZero() {
|
||||
since = time.Now().Add(-1 * time.Hour)
|
||||
since = time.Now().Add(-1 * time.Minute)
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user