-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom command variable system (#533)
- Loading branch information
Showing
29 changed files
with
613 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/senchabot-opensource/monorepo/command" | ||
"github.com/senchabot-opensource/monorepo/model" | ||
) | ||
|
||
func (c *commands) AddCommandVariableCommand(context context.Context, m *discordgo.MessageCreate, commandName string, params []string) (*model.CommandResponse, error) { | ||
msgData := &model.MessageData{ | ||
PlatformEntityID: m.GuildID, | ||
UserName: m.Author.Username, | ||
} | ||
|
||
p, err := c.dS.UserChannelPermissions(m.Author.ID, m.ChannelID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if p&discordgo.PermissionManageChannels != discordgo.PermissionManageChannels { | ||
return nil, errors.New("dont have permission") | ||
} | ||
|
||
return command.AddCommandVariableCommand(context, c.service.CreateCommandVariable, c.service.GetCommandVariable, *msgData, commandName, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/senchabot-opensource/monorepo/command" | ||
"github.com/senchabot-opensource/monorepo/model" | ||
) | ||
|
||
func (c *commands) DeleteCommandVariableCommand(context context.Context, m *discordgo.MessageCreate, commandName string, params []string) (*model.CommandResponse, error) { | ||
msgData := &model.MessageData{ | ||
PlatformEntityID: m.GuildID, | ||
UserName: m.Author.Username, | ||
} | ||
|
||
p, err := c.dS.UserChannelPermissions(m.Author.ID, m.ChannelID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if p&discordgo.PermissionManageChannels != discordgo.PermissionManageChannels { | ||
return nil, errors.New("dont have permission") | ||
} | ||
|
||
return command.DeleteCommandVariableCommand(context, c.service.DeleteCommandVariable, c.service.GetCommandVariable, *msgData, commandName, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/senchabot-opensource/monorepo/command" | ||
"github.com/senchabot-opensource/monorepo/model" | ||
) | ||
|
||
func (c *commands) ListCommandVariablesCommand(context context.Context, m *discordgo.MessageCreate, commandName string, params []string) (*model.CommandResponse, error) { | ||
msgData := &model.MessageData{ | ||
PlatformEntityID: m.GuildID, | ||
UserName: m.Author.Username, | ||
} | ||
|
||
p, err := c.dS.UserChannelPermissions(m.Author.ID, m.ChannelID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if p&discordgo.PermissionManageChannels != discordgo.PermissionManageChannels { | ||
return nil, errors.New("dont have permission") | ||
} | ||
|
||
return command.ListCommandVariablesCommand(context, c.service.ListCommandVariables, *msgData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/senchabot-opensource/monorepo/command" | ||
"github.com/senchabot-opensource/monorepo/model" | ||
) | ||
|
||
func (c *commands) UpdateCommandVariableCommand(context context.Context, m *discordgo.MessageCreate, commandName string, params []string) (*model.CommandResponse, error) { | ||
msgData := &model.MessageData{ | ||
PlatformEntityID: m.GuildID, | ||
UserName: m.Author.Username, | ||
} | ||
|
||
p, err := c.dS.UserChannelPermissions(m.Author.ID, m.ChannelID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if p&discordgo.PermissionManageChannels != discordgo.PermissionManageChannels { | ||
return nil, errors.New("dont have permission") | ||
} | ||
|
||
return command.UpdateCommandVariableCommand(context, c.service.UpdateCommandVariable, c.service.GetCommandVariable, *msgData, commandName, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/gempir/go-twitch-irc/v3" | ||
"github.com/senchabot-opensource/monorepo/apps/twitch-bot/internal/command/helpers" | ||
"github.com/senchabot-opensource/monorepo/command" | ||
"github.com/senchabot-opensource/monorepo/config" | ||
"github.com/senchabot-opensource/monorepo/model" | ||
) | ||
|
||
func (c *commands) AddCommandVariableCommand(context context.Context, message twitch.PrivateMessage, commandName string, params []string) (*model.CommandResponse, error) { | ||
if !helpers.CanExecuteCommand(context, c.service, message.Tags["badges"], message.RoomID) { | ||
return nil, errors.New(message.User.DisplayName + config.CannotExecuteCommand) | ||
} | ||
|
||
msgData := &model.MessageData{ | ||
PlatformEntityID: message.RoomID, | ||
UserName: message.User.DisplayName, | ||
} | ||
|
||
return command.AddCommandVariableCommand(context, c.service.CreateCommandVariable, c.service.GetCommandVariable, *msgData, commandName, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/gempir/go-twitch-irc/v3" | ||
"github.com/senchabot-opensource/monorepo/apps/twitch-bot/internal/command/helpers" | ||
"github.com/senchabot-opensource/monorepo/command" | ||
"github.com/senchabot-opensource/monorepo/config" | ||
"github.com/senchabot-opensource/monorepo/model" | ||
) | ||
|
||
func (c *commands) DeleteCommandVariableCommand(context context.Context, message twitch.PrivateMessage, commandName string, params []string) (*model.CommandResponse, error) { | ||
if !helpers.CanExecuteCommand(context, c.service, message.Tags["badges"], message.RoomID) { | ||
return nil, errors.New(message.User.DisplayName + config.CannotExecuteCommand) | ||
} | ||
|
||
msgData := &model.MessageData{ | ||
PlatformEntityID: message.RoomID, | ||
UserName: message.User.DisplayName, | ||
} | ||
|
||
return command.DeleteCommandVariableCommand(context, c.service.DeleteCommandVariable, c.service.GetCommandVariable, *msgData, commandName, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/gempir/go-twitch-irc/v3" | ||
"github.com/senchabot-opensource/monorepo/apps/twitch-bot/internal/command/helpers" | ||
"github.com/senchabot-opensource/monorepo/command" | ||
"github.com/senchabot-opensource/monorepo/config" | ||
"github.com/senchabot-opensource/monorepo/model" | ||
) | ||
|
||
func (c *commands) ListCommandVariablesCommand(context context.Context, message twitch.PrivateMessage, commandName string, params []string) (*model.CommandResponse, error) { | ||
if !helpers.CanExecuteCommand(context, c.service, message.Tags["badges"], message.RoomID) { | ||
return nil, errors.New(message.User.DisplayName + config.CannotExecuteCommand) | ||
} | ||
|
||
msgData := &model.MessageData{ | ||
PlatformEntityID: message.RoomID, | ||
UserName: message.User.DisplayName, | ||
} | ||
|
||
return command.ListCommandVariablesCommand(context, c.service.ListCommandVariables, *msgData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/gempir/go-twitch-irc/v3" | ||
"github.com/senchabot-opensource/monorepo/apps/twitch-bot/internal/command/helpers" | ||
"github.com/senchabot-opensource/monorepo/command" | ||
"github.com/senchabot-opensource/monorepo/config" | ||
"github.com/senchabot-opensource/monorepo/model" | ||
) | ||
|
||
func (c *commands) UpdateCommandVariableCommand(context context.Context, message twitch.PrivateMessage, commandName string, params []string) (*model.CommandResponse, error) { | ||
if !helpers.CanExecuteCommand(context, c.service, message.Tags["badges"], message.RoomID) { | ||
return nil, errors.New(message.User.DisplayName + config.CannotExecuteCommand) | ||
} | ||
|
||
msgData := &model.MessageData{ | ||
PlatformEntityID: message.RoomID, | ||
UserName: message.User.DisplayName, | ||
} | ||
|
||
return command.UpdateCommandVariableCommand(context, c.service.UpdateCommandVariable, c.service.GetCommandVariable, *msgData, commandName, params) | ||
} |
Oops, something went wrong.