Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable custom command groups (Suggestion #2224) #1681

Merged
merged 14 commits into from
Jun 27, 2024
Merged
2 changes: 1 addition & 1 deletion customcommands/assets/customcommands-editcmd.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h2>Custom commands</h2>
class="nav-item {{if $dot.CurrentCommandGroup}}{{if eq $dot.CurrentCommandGroup.ID .ID}}active{{end}}{{end}}">
<a data-partial-load="true"
class="nav-link show {{if $dot.CurrentCommandGroup}}{{if eq $dot.CurrentCommandGroup.ID .ID}}active{{end}}{{end}}"
href="/manage/{{$dot.ActiveGuild.ID}}/customcommands/groups/{{.ID}}">{{.Name}}</a>
href="/manage/{{$dot.ActiveGuild.ID}}/customcommands/groups/{{.ID}}">{{.Name}}{{if .Disabled}} <code>Disabled</code>{{end}}</a>
</li>
{{end}}
<li class="nav-item">
Expand Down
6 changes: 5 additions & 1 deletion customcommands/assets/customcommands.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h2>Custom commands</h2>
class="nav-item {{if $dot.CurrentCommandGroup}}{{if eq $dot.CurrentCommandGroup.ID .ID}}active{{end}}{{end}}">
<a data-partial-load="true"
class="nav-link show {{if $dot.CurrentCommandGroup}}{{if eq $dot.CurrentCommandGroup.ID .ID}}active{{end}}{{end}}"
href="/manage/{{$dot.ActiveGuild.ID}}/customcommands/groups/{{.ID}}">{{.Name}}</a>
href="/manage/{{$dot.ActiveGuild.ID}}/customcommands/groups/{{.ID}}">{{.Name}}{{if .Disabled}} <code>Disabled</code>{{end}}</a>
</li>
{{end}}
<li class="nav-item">
Expand Down Expand Up @@ -106,6 +106,10 @@ <h2>Custom commands</h2>
{{textChannelOptionsMulti .ActiveGuild.Channels .CurrentCommandGroup.IgnoreChannels }}
</select>
</div>
<div class="form-group">
<label>Group disabled</label><br>
{{checkbox "disabled" "disabled" "Enables or Disables the group" .CurrentCommandGroup.Disabled}}
</div>
<div class="form-group">
<button type="submit"
title="Group #{{.CurrentCommandGroup.ID}} - {{.CurrentCommandGroup.Name}} &#013;Deleted group's commands become ungrouped."
Expand Down
18 changes: 13 additions & 5 deletions customcommands/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,14 @@ func StringCommands(ccs []*models.CustomCommand, gMap map[int64]string) string {

func handleDelayedRunCC(evt *schEventsModels.ScheduledEvent, data interface{}) (retry bool, err error) {
dataCast := data.(*DelayedRunCCData)
cmd, err := models.CustomCommands(qm.Where("guild_id = ? AND local_id = ?", evt.GuildID, dataCast.CmdID)).OneG(context.Background())
cmd, err := models.CustomCommands(qm.Where("guild_id = ? AND local_id = ?", evt.GuildID, dataCast.CmdID), qm.Load("Group")).OneG(context.Background())
if err != nil {
return false, errors.WrapIf(err, "find_command")
}

if cmd.R.Group != nil && cmd.R.Group.Disabled {
return false, errors.New("custom command group is disabled")
}

if cmd.Disabled {
return false, errors.New("custom command is disabled")
Expand Down Expand Up @@ -465,11 +469,15 @@ func handleDelayedRunCC(evt *schEventsModels.ScheduledEvent, data interface{}) (
}

func handleNextRunScheduledEVent(evt *schEventsModels.ScheduledEvent, data interface{}) (retry bool, err error) {
cmd, err := models.CustomCommands(qm.Where("guild_id = ? AND local_id = ?", evt.GuildID, (data.(*NextRunScheduledEvent)).CmdID)).OneG(context.Background())
cmd, err := models.CustomCommands(qm.Where("guild_id = ? AND local_id = ?", evt.GuildID, (data.(*NextRunScheduledEvent)).CmdID), qm.Load("Group")).OneG(context.Background())
if err != nil {
return false, errors.WrapIf(err, "find_command")
}

if cmd.R.Group != nil && cmd.R.Group.Disabled {
return false, errors.New("custom command group is disabled")
}

if cmd.Disabled {
return false, errors.New("custom command is disabled")
}
Expand Down Expand Up @@ -841,7 +849,7 @@ func findMessageTriggerCustomCommands(ctx context.Context, cs *dstate.ChannelSta

var matched []*TriggeredCC
for _, cmd := range cmds {
if cmd.Disabled || !CmdRunsInChannel(cmd, common.ChannelOrThreadParentID(cs)) || !CmdRunsForUser(cmd, ms) {
if cmd.Disabled || !CmdRunsInChannel(cmd, common.ChannelOrThreadParentID(cs)) || !CmdRunsForUser(cmd, ms) || cmd.R.Group != nil && cmd.R.Group.Disabled {
continue
}

Expand Down Expand Up @@ -877,7 +885,7 @@ func findReactionTriggerCustomCommands(ctx context.Context, cs *dstate.ChannelSt

var matched []*TriggeredCC
for _, cmd := range cmds {
if cmd.Disabled || !CmdRunsInChannel(cmd, common.ChannelOrThreadParentID(cs)) {
if cmd.Disabled || !CmdRunsInChannel(cmd, common.ChannelOrThreadParentID(cs)) || cmd.R.Group != nil && cmd.R.Group.Disabled {
continue
}

Expand Down Expand Up @@ -935,7 +943,7 @@ func findComponentOrModalTriggerCustomCommands(ctx context.Context, cs *dstate.C

var matched []*TriggeredCC
for _, cmd := range cmds {
if cmd.Disabled || !CmdRunsInChannel(cmd, common.ChannelOrThreadParentID(cs)) {
if cmd.Disabled || !CmdRunsInChannel(cmd, common.ChannelOrThreadParentID(cs)) || cmd.R.Group != nil && cmd.R.Group.Disabled {
continue
}

Expand Down
20 changes: 18 additions & 2 deletions customcommands/models/custom_command_groups.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 72 additions & 21 deletions customcommands/models/custom_commands.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions customcommands/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ CREATE INDEX IF NOT EXISTS templates_user_database_expires_idx ON templates_user
ALTER TABLE custom_commands ADD COLUMN IF NOT EXISTS name TEXT;
`, `
ALTER TABLE custom_commands ADD COLUMN IF NOT EXISTS public BOOLEAN NOT NULL DEFAULT false;
`, `
ALTER TABLE custom_command_groups ADD COLUMN IF NOT EXISTS disabled BOOLEAN NOT NULL DEFAULT false;
`}
Loading