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/bwmarrin/discordgo"
"bitbucket.org/rw_grim/wasdead/presence"
)
type
StatusCmd
struct
{
Target
string
`kong:"arg"`
}
func
(
c
*
StatusCmd
)
Run
(
g
*
Globals
)
error
{
uri
:=
""
if
!
strings
.
HasPrefix
(
c
.
Target
,
"<@"
)
||
!
strings
.
HasSuffix
(
c
.
Target
,
">"
)
{
return
fmt
.
Errorf
(
"mention required"
)
}
// this is gross, but we're going to assume the second mention is the
// target. We have to do this because discord keeps randomly injecting
// a ! after the <@. We could do multiple calls to verify, but eff that
// noise.
p
:=
g
.
client
.
getPresence
(
g
.
msg
.
GuildID
,
g
.
msg
.
Mentions
[
0
].
ID
)
if
p
!=
nil
&&
p
.
Game
!=
nil
&&
p
.
Game
.
Type
==
discordgo
.
GameTypeStreaming
{
uri
=
p
.
Game
.
URL
}
else
{
return
fmt
.
Errorf
(
"%s is not currently streaming"
,
c
.
Target
)
}
presence
,
err
:=
presence
.
GetPresence
(
uri
)
if
err
!=
nil
{
return
err
}
return
g
.
client
.
sendEmbedChannel
(
g
.
msg
.
ChannelID
,
presenceEmbed
(
presence
))
}