Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

organize discordgo Handlers and other jobs/workers into new package #21

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ type Env struct {
ChannelFeedback string
}

type Context struct {
type State struct {
Env *Env
Session *discordgo.Session
}

type Context struct {
*State
Message *discordgo.Message
}

Expand All @@ -31,6 +35,13 @@ type Command struct {
ModeratorOnly bool
}

type Cmdi interface {
Exec(*Context, []string)
Usage() string
Help() string
ModeratorOnly() bool
}

var Commands = map[string]Command{
"modping": {
Exec: modping,
Expand Down
12 changes: 12 additions & 0 deletions job/job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package job

import (
"trup/command"

"github.com/bwmarrin/discordgo"
)

func messageCreate(env *command.Env) func(s *discordgo.Session, m *discordgo.MessageCreate) {
return func(s *discordgo.Session, m *discordgo.MessageCreate) {
}
}
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if strings.HasPrefix(m.Content, prefix) {
args := strings.Fields(m.Content[len(prefix):])
context := command.Context{
Env: &env,
Session: s,
State: &command.State{
Env: &env,
Session: s,
},
Message: m.Message,
}

Expand Down