mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-03-21 09:29:21 +00:00
Fixed bug where ParseContent interface methods won't return a proper error
This commit is contained in:
parent
c7d33f5dcc
commit
7e73f00eb9
|
@ -22,6 +22,13 @@ func (bot *Bot) Help(m *gateway.MessageCreateEvent) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (bot *Bot) Add(m *gateway.MessageCreateEvent, a, b int) error {
|
||||
content := fmt.Sprintf("%d + %d = %d", a, b, a+b)
|
||||
|
||||
_, err := bot.Ctx.SendMessage(m.ChannelID, content, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (bot *Bot) Ping(m *gateway.MessageCreateEvent) error {
|
||||
_, err := bot.Ctx.SendMessage(m.ChannelID, "Pong!", nil)
|
||||
return err
|
||||
|
|
|
@ -70,7 +70,7 @@ func (c *Client) Channel(
|
|||
var channel *discord.Channel
|
||||
|
||||
return channel,
|
||||
c.RequestJSON(&channel, "POST", EndpointChannels+channelID.String())
|
||||
c.RequestJSON(&channel, "GET", EndpointChannels+channelID.String())
|
||||
}
|
||||
|
||||
type ModifyChannelData struct {
|
||||
|
|
|
@ -176,7 +176,9 @@ func (ctx *Context) Start() func() {
|
|||
if err := ctx.callCmd(v); err != nil {
|
||||
if str := ctx.FormatError(err); str != "" {
|
||||
// Log the main error first
|
||||
ctx.ErrorLogger(errors.Wrap(err, str))
|
||||
if !ctx.ReplyError {
|
||||
ctx.ErrorLogger(errors.Wrap(err, "Command error"))
|
||||
}
|
||||
|
||||
mc, ok := v.(*gateway.MessageCreateEvent)
|
||||
if !ok {
|
||||
|
|
|
@ -79,7 +79,7 @@ func (ctx *Context) callCmd(ev interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
if len(args) == 0 {
|
||||
return nil // ???
|
||||
}
|
||||
|
||||
|
@ -135,6 +135,16 @@ func (ctx *Context) callCmd(ev interface{}) error {
|
|||
|
||||
// Check manual parser
|
||||
if cmd.parseType != nil {
|
||||
if len(args[start:]) == 0 {
|
||||
return &ErrInvalidUsage{
|
||||
Args: args,
|
||||
Prefix: ctx.Prefix,
|
||||
Index: len(args) - start,
|
||||
Err: "Not enough arguments given",
|
||||
ctx: cmd,
|
||||
}
|
||||
}
|
||||
|
||||
// Create a zero value instance of this
|
||||
v := reflect.New(cmd.parseType)
|
||||
|
||||
|
@ -165,7 +175,7 @@ func (ctx *Context) callCmd(ev interface{}) error {
|
|||
return &ErrInvalidUsage{
|
||||
Args: args,
|
||||
Prefix: ctx.Prefix,
|
||||
Index: len(cmd.arguments) - start,
|
||||
Index: len(args) - 1,
|
||||
Err: "Not enough arguments given",
|
||||
ctx: cmd,
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ type ErrInvalidUsage struct {
|
|||
|
||||
func (err *ErrInvalidUsage) Error() string {
|
||||
if err.Index == 0 {
|
||||
return "Invalid usage"
|
||||
return "Invalid usage, error: " + err.Err
|
||||
}
|
||||
|
||||
if len(err.Args) == 0 {
|
||||
|
|
|
@ -4,7 +4,15 @@ import "fmt"
|
|||
|
||||
type Color uint32
|
||||
|
||||
const DefaultColor Color = 0x303030
|
||||
var DefaultEmbedColor Color = 0x303030
|
||||
|
||||
func (c Color) Uint32() uint32 {
|
||||
return uint32(c)
|
||||
}
|
||||
|
||||
func (c Color) Int() int {
|
||||
return int(c)
|
||||
}
|
||||
|
||||
type Embed struct {
|
||||
Title string `json:"title,omitempty"`
|
||||
|
@ -28,7 +36,7 @@ type Embed struct {
|
|||
func NewEmbed() *Embed {
|
||||
return &Embed{
|
||||
Type: NormalEmbed,
|
||||
Color: DefaultColor,
|
||||
Color: DefaultEmbedColor,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +63,7 @@ func (e *Embed) Validate() error {
|
|||
}
|
||||
|
||||
if e.Color == 0 {
|
||||
e.Color = DefaultColor
|
||||
e.Color = DefaultEmbedColor
|
||||
}
|
||||
|
||||
if len(e.Title) > 256 {
|
||||
|
|
|
@ -8,14 +8,12 @@ import (
|
|||
|
||||
const DiscordEpoch = 1420070400000 * int64(time.Millisecond)
|
||||
|
||||
type Snowflake int64
|
||||
type Snowflake uint64
|
||||
|
||||
func NewSnowflake(t time.Time) Snowflake {
|
||||
return Snowflake(TimeToDiscordEpoch(t) << 22)
|
||||
}
|
||||
|
||||
const Me = Snowflake(-1)
|
||||
|
||||
func (s *Snowflake) UnmarshalJSON(v []byte) error {
|
||||
id := strings.Trim(string(v), `"`)
|
||||
if id == "null" {
|
||||
|
|
|
@ -137,6 +137,9 @@ func (c *Conn) readAll(ctx context.Context) ([]byte, error) {
|
|||
}
|
||||
|
||||
func (c *Conn) Send(ctx context.Context, b []byte) error {
|
||||
c.mut.Lock()
|
||||
defer c.mut.Unlock()
|
||||
|
||||
// TODO: zlib stream
|
||||
return c.Conn.Write(ctx, websocket.MessageText, b)
|
||||
}
|
||||
|
|
|
@ -297,14 +297,7 @@ func (s *State) Member(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.Store.MemberSet(guildID, m); err != nil {
|
||||
return m, err
|
||||
}
|
||||
|
||||
return m, s.Gateway.RequestGuildMembers(gateway.RequestGuildMembersData{
|
||||
GuildID: []discord.Snowflake{guildID},
|
||||
Presences: true,
|
||||
})
|
||||
return m, s.Store.MemberSet(guildID, m)
|
||||
}
|
||||
|
||||
func (s *State) Members(guildID discord.Snowflake) ([]discord.Member, error) {
|
||||
|
|
Loading…
Reference in a new issue