grim/wasdead
Clone
Summary
Browse
Changes
Graph
Fix the help message for the help command
draft
2019-04-08, Gary Kramlich
c06bc2e462ed
Fix the help message for the help command
package
discord
import
(
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
"github.com/iancoleman/orderedmap"
)
type
Command
interface
{
Run
(
args
[]
string
,
c
*
DiscordClient
,
m
*
discordgo
.
MessageCreate
)
(
interface
{},
error
)
Help
()
string
}
var
(
commands
=
orderedmap
.
New
()
)
func
init
()
{
commands
.
Set
(
"help"
,
&
commandHelp
{})
commands
.
Set
(
"set-channel"
,
&
commandSetChannel
{})
commands
.
Set
(
"status"
,
&
commandStatus
{})
commands
.
Set
(
"uptime"
,
&
commandUptime
{})
}
func
(
c
*
DiscordClient
)
processCommand
(
args
[]
string
,
m
*
discordgo
.
MessageCreate
)
(
interface
{},
error
)
{
if
len
(
args
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"no command specified"
)
}
name
:=
strings
.
ToLower
(
args
[
0
])
if
cmd
,
found
:=
commands
.
Get
(
name
);
found
{
return
cmd
.(
Command
).
Run
(
args
[
1
:],
c
,
m
)
}
return
""
,
fmt
.
Errorf
(
"unknown command '%s'"
,
args
[
0
])
}