grim/wasdead
Clone
Summary
Browse
Changes
Graph
Clean up some logging
draft
2020-09-26, Gary Kramlich
bedb77e608b8
Clean up some logging
package
discord
import
(
"fmt"
"strings"
"github.com/alecthomas/kong"
"github.com/bwmarrin/discordgo"
log
"github.com/sirupsen/logrus"
)
type
Globals
struct
{
client
*
DiscordClient
msg
*
discordgo
.
MessageCreate
ctx
*
kong
.
Context
}
type
Commands
struct
{
Globals
Help
HelpCmd
`kong:"cmd,help='displays this help message'"`
Order66
Order66Cmd
`kong:"cmd,hidden"`
SetChannel
SetChannelCmd
`kong:"cmd,help='set the current channel as the channel to announce new streams'"`
ShowConfig
ShowConfigCmd
`kong:"cmd,help='show the configuration for the current guild.'"`
Status
StatusCmd
`kong:"cmd,help='get the streaming status of someone'"`
Twitch
TwitchCmd
`kong:"cmd,help='check if someone is streaming on twitch'"`
Uptime
UptimeCmd
`kong:"cmd,help='display how long the bot has been running for'"`
Youtube
YoutubeCmd
`kong:"cmd,help='check if someone is streaming on youtube'"`
}
type
Order66Cmd
struct
{}
func
(
c
*
Order66Cmd
)
Run
(
g
*
Globals
)
error
{
g
.
client
.
sendChannel
(
g
.
msg
.
ChannelID
,
"yes my lord"
)
return
nil
}
func
(
c
*
DiscordClient
)
processCommand
(
args
[]
string
,
m
*
discordgo
.
MessageCreate
)
error
{
cmd
:=
Commands
{
Globals
:
Globals
{
client
:
c
,
msg
:
m
,
},
}
buf
:=
&
strings
.
Builder
{}
parser
,
err
:=
kong
.
New
(
&
cmd
,
kong
.
Description
(
"This bot auto announces when people start streaming"
),
kong
.
Exit
(
func
(
int
)
{}),
kong
.
ConfigureHelp
(
kong
.
HelpOptions
{
Compact
:
true
,
}),
kong
.
Name
(
"@wasdead"
),
kong
.
NoDefaultHelp
(),
kong
.
Writers
(
buf
,
buf
),
)
if
err
!=
nil
{
log
.
Errorf
(
"Failed to create kong parser: %v"
,
err
)
c
.
sendChannel
(
m
.
ChannelID
,
fmt
.
Sprintf
(
"error: %v"
,
err
))
return
err
}
ctx
,
err
:=
parser
.
Parse
(
args
)
if
err
!=
nil
{
log
.
Errorf
(
"Failed to parse command line: %v"
,
err
)
c
.
sendChannel
(
m
.
ChannelID
,
fmt
.
Sprintf
(
"error: %v"
,
err
))
return
err
}
cmd
.
Globals
.
ctx
=
ctx
err
=
ctx
.
Run
(
&
cmd
.
Globals
)
if
err
!=
nil
{
log
.
Errorf
(
"error running command: %v"
,
err
)
return
err
}
if
buf
.
Len
()
>
0
{
c
.
sendChannel
(
m
.
ChannelID
,
fmt
.
Sprintf
(
"```%s```"
,
buf
.
String
()))
}
return
nil
}