Documentation
¶
Index ¶
- type CommandRunFunc
- type Commands
- func (s Commands) GetCommandRunFunc(name string) (run CommandRunFunc)
- func (s Commands) ListCommands() (list []string)
- func (s Commands) ReadMessage(ctx context.Context, w io.Writer, user irc.User, to, msg string) (invalid bool)
- func (s Commands) RegisterCommand(name string, run CommandRunFunc) (overrided bool)
- func (s Commands) UnregisterCommand(name string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandRunFunc ¶
type Commands ¶
type Commands map[string]CommandRunFunc
func (Commands) GetCommandRunFunc ¶ added in v1.0.12
func (s Commands) GetCommandRunFunc(name string) (run CommandRunFunc)
[CommandRunFunction] fetcher.
func (Commands) ListCommands ¶ added in v1.0.12
Registered commands list.
func (Commands) ReadMessage ¶
func (s Commands) ReadMessage(ctx context.Context, w io.Writer, user irc.User, to, msg string) (invalid bool)
Message Reader. Prefix must be manually cutted. Every run function provided by a command will be run with goroutine.
var cmds commands.Commands
for s.Scan() {
ctx := context.Background()
line := b.Text()
// ...
user, cmd, flags, fullmsg := irc.ParseLine(line)
if cmd == "PRIVMSG" {
msg, hasPrefix := strings.CutPrefix(fullmsg, "!") // assuming ! is your bot's prefix
if !hasPrefix {
continue // ignore message that has no bot prefix
}
to := flags[0]
if to == botnick {
to = user.Nick // this is PM
}
invalid := cmds.ReadMessage(ctx, conn, user, to, msg)
if invalid {
irc.Chat(conn, to, fmt.Sprintf("%s: Unknown command", user.Nick))
}
}
}
func (Commands) RegisterCommand ¶
func (s Commands) RegisterCommand(name string, run CommandRunFunc) (overrided bool)
Command registerer. `overrided` may return false if existing command has been registered in a map.
func (Commands) UnregisterCommand ¶ added in v1.0.12
Command unregisterer.
Click to show internal directories.
Click to hide internal directories.