Skip to content

Commit

Permalink
feat(client::bot): ability to dispatch event through event command
Browse files Browse the repository at this point in the history
  • Loading branch information
rumblefrog committed Oct 5, 2019
1 parent 69f69db commit 64768d4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If applicable, add screenshots to help explain your problem.
**Info (please complete the following information):**
- OS: [e.g. Ubuntu 18.04 LTS]
- Sourcemod Version [e.g. 1.9.6260]
- Relay Version [e.g. 2.0.1]
- Relay Version [e.g. 2.1.0]

**Additional context**
Add any other context about the problem here.
8 changes: 8 additions & 0 deletions server/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ func Initialize() {
r.On("entities", entitiesCommand).Desc("Fetch all entities (of certain type)").Alias("e")
})

router.Group(func(r *exrouter.Route) {
r.Cat("message")

r.Use(Auth)

r.On("event", eventCommand).Desc("Send an event message")
})

router.Group(func(r *exrouter.Route) {
r.Cat("other")

Expand Down
37 changes: 37 additions & 0 deletions server/bot/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package bot

import (
"strings"

"github.com/Necroforger/dgrouter/exrouter"
"github.com/rumblefrog/source-chat-relay/server/protocol"
"github.com/rumblefrog/source-chat-relay/server/relay"
)

func eventCommand(ctx *exrouter.Context) {
if len(ctx.Args) < 2 {
ctx.Reply("Missing arguments")

return
}

channel, err := ctx.Channel(ctx.Msg.ChannelID)

if err != nil {
ctx.Reply("Unable to fetch channel")

return
}

message := &protocol.EventMessage{
BaseMessage: protocol.BaseMessage{
Type: protocol.MessageChat,
SenderID: ctx.Msg.ChannelID,
EntityName: strings.Title(channel.Name),
},
Event: ctx.Args.Get(0),
Data: ctx.Args.Get(1),
}

relay.Instance.Router <- message
}

0 comments on commit 64768d4

Please sign in to comment.