diff --git a/commands.go b/commands.go index 5b795fc..213c4e1 100644 --- a/commands.go +++ b/commands.go @@ -29,6 +29,7 @@ type CommandHandler struct { log maulogger.Logger } +// NewCommandHandler creates a CommandHandler func NewCommandHandler(bridge *Bridge) *CommandHandler { return &CommandHandler{ bridge: bridge, @@ -36,6 +37,7 @@ func NewCommandHandler(bridge *Bridge) *CommandHandler { } } +// CommandEvent stores all data which might be used to handle commands type CommandEvent struct { Bot *appservice.IntentAPI Bridge *Bridge @@ -45,6 +47,7 @@ type CommandEvent struct { Args []string } +// Reply sends a reply to command as notice func (ce *CommandEvent) Reply(msg string) { _, err := ce.Bot.SendNotice(string(ce.RoomID), msg) if err != nil { @@ -52,6 +55,7 @@ func (ce *CommandEvent) Reply(msg string) { } } +// Handle handles messages to the bridge func (handler *CommandHandler) Handle(roomID types.MatrixRoomID, user *User, message string) { args := strings.Split(message, " ") cmd := strings.ToLower(args[0]) @@ -70,9 +74,14 @@ func (handler *CommandHandler) Handle(roomID types.MatrixRoomID, user *User, mes handler.CommandLogout(ce) case "help": handler.CommandHelp(ce) + default: + ce.Reply("Unknown Command") } } +const cmdLoginHelp = `login - Authenticate this Bridge as WhatsApp Web Client` + +// CommandLogin handles login command func (handler *CommandHandler) CommandLogin(ce *CommandEvent) { if ce.User.Session != nil { ce.Reply("You're already logged in.") @@ -83,6 +92,9 @@ func (handler *CommandHandler) CommandLogin(ce *CommandEvent) { ce.User.Login(ce.RoomID) } +const cmdLogoutHelp = `logout - Logout from WhatsApp` + +// CommandLogout handles !logout command func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { if ce.User.Session == nil { ce.Reply("You're not logged in.") @@ -100,6 +112,14 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { ce.Reply("Logged out successfully.") } +const cmdHelpHelp = `help - Prints this help` + +// CommandHelp handles help command func (handler *CommandHandler) CommandHelp(ce *CommandEvent) { - ce.Reply("Help is not yet implemented 3:") + cmdPrefix := handler.bridge.Config.Bridge.CommandPrefix + " " + ce.Reply(strings.Join([]string{ + cmdPrefix + cmdHelpHelp, + cmdPrefix + cmdLoginHelp, + cmdPrefix + cmdLogoutHelp, + }, "\n")) }