28 lines
565 B
Go
28 lines
565 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"errors"
|
||
|
|
||
|
"github.com/bwmarrin/discordgo"
|
||
|
"github.com/justinian/dice"
|
||
|
opentracing "github.com/opentracing/opentracing-go"
|
||
|
)
|
||
|
|
||
|
func roll(ctx context.Context, s *discordgo.Session, m *discordgo.Message, parv []string) error {
|
||
|
sp, ctx := opentracing.StartSpanFromContext(ctx, "dice")
|
||
|
defer sp.Finish()
|
||
|
|
||
|
if len(parv) != 2 {
|
||
|
return errors.New("not enough parameters (expected 1)")
|
||
|
}
|
||
|
|
||
|
text, _, err := dice.Roll(parv[1])
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
_, err = s.ChannelMessageSend(m.ChannelID, text.String())
|
||
|
return err
|
||
|
}
|