Fix broken multi alias commands

fixes #25
This commit is contained in:
joeyak 2019-03-14 00:21:41 -04:00
parent 2ef3684c14
commit fc126d599e
2 changed files with 55 additions and 13 deletions

View File

@ -239,35 +239,38 @@ var commands = &CommandControl{
}
func (cc *CommandControl) RunCommand(command string, args []string, sender *Client) string {
// get correct command from combined commands
cmd := common.GetFullChatCommand(command)
// Look for user command
if userCmd, ok := cc.user[command]; ok {
fmt.Printf("[user] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
if userCmd, ok := cc.user[cmd]; ok {
fmt.Printf("[user] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
return userCmd.Function(sender, args)
}
// Look for mod command
if modCmd, ok := cc.mod[command]; ok {
if modCmd, ok := cc.mod[cmd]; ok {
if sender.IsMod || sender.IsAdmin {
fmt.Printf("[mod] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
fmt.Printf("[mod] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
return modCmd.Function(sender, args)
}
fmt.Printf("[mod REJECTED] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
fmt.Printf("[mod REJECTED] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
return "You are not a mod Jebaited"
}
// Look for admin command
if adminCmd, ok := cc.admin[command]; ok {
if adminCmd, ok := cc.admin[cmd]; ok {
if sender.IsAdmin {
fmt.Printf("[admin] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
fmt.Printf("[admin] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
return adminCmd.Function(sender, args)
}
fmt.Printf("[admin REJECTED] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
fmt.Printf("[admin REJECTED] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
return "You are not the admin Jebaited"
}
// Command not found
fmt.Printf("[cmd] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
fmt.Printf("[cmd] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
return "Invalid command."
}

View File

@ -39,6 +39,28 @@ var (
CNModpass ChatCommandNames = []string{"modpass"}
)
var ChatCommands = []ChatCommandNames{
CNMe, CNHelp, CNCount, CNColor, CNWhoAmI, CNAuth, CNUsers,
CNSv, CNPlaying, CNUnmod, CNKick, CNBan, CNUnban,
CNMod, CNReloadPlayer, CNReloadEmotes, CNModpass,
}
func GetFullChatCommand(c string) string {
for _, names := range ChatCommands {
for _, n := range names {
if c == n {
return names.String()
}
}
}
return ""
}
type ClientData struct {
Type ClientDataType
Message string
}
type ChatData struct {
Type DataType
Data DataInterface
@ -71,22 +93,33 @@ type DataInterface interface {
HTML() string
}
func (dc DataMessage) GetType() DataType {
func (c ClientData) GetType() DataType {
return DTClient
}
func (d DataMessage) GetType() DataType {
return DTChat
}
func (de DataError) GetType() DataType {
func (d DataError) GetType() DataType {
return DTError
}
func (dc DataCommand) GetType() DataType {
func (d DataCommand) GetType() DataType {
return DTCommand
}
func (de DataEvent) GetType() DataType {
func (d DataEvent) GetType() DataType {
return DTEvent
}
type ClientDataType int
const (
CdMessage ClientDataType = iota // a normal message from the client meant to be broadcast
CdUsers // get a list of users
)
type DataType int
// Data Types
@ -96,6 +129,7 @@ const (
DTError // something went wrong with the previous request
DTCommand // non-chat function
DTEvent // join/leave/kick/ban events
DTClient // a message coming from the client
)
func ParseDataType(token json.Token) (DataType, error) {
@ -139,6 +173,11 @@ const (
MsgError
)
func (c ClientData) HTML() string {
// Client data is for client to server communication only, so clients should not see this
return `<div style="color: red;"><span>The developer messed up. You should not be seeing this.</span></div>`
}
// TODO: Read this HTML from a template somewhere
func (dc DataMessage) HTML() string {
fmt.Printf("message type: %d\n", dc.Type)