mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-07-23 13:20:51 +00:00
Compare commits
3 commits
d13aa00a57
...
65d7b8765b
Author | SHA1 | Date | |
---|---|---|---|
|
65d7b8765b | ||
|
74019dc909 | ||
|
abeaef8122 |
|
@ -191,7 +191,7 @@ func (c *Client) Message(channelID discord.ChannelID, messageID discord.MessageI
|
||||||
EndpointChannels+channelID.String()+"/messages/"+messageID.String())
|
EndpointChannels+channelID.String()+"/messages/"+messageID.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendText posts a only-text message to a guild text or DM channel.
|
// SendText posts a text-only message to a guild text or DM channel.
|
||||||
//
|
//
|
||||||
// If operating on a guild channel, this endpoint requires the SEND_MESSAGES
|
// If operating on a guild channel, this endpoint requires the SEND_MESSAGES
|
||||||
// permission to be present on the current user.
|
// permission to be present on the current user.
|
||||||
|
@ -203,6 +203,23 @@ func (c *Client) SendText(channelID discord.ChannelID, content string) (*discord
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendTextReply posts a text-only reply to a message ID in a guild text or DM channel
|
||||||
|
//
|
||||||
|
// If operating on a guild channel, this endpoint requires the SEND_MESSAGES
|
||||||
|
// permission to be present on the current user.
|
||||||
|
//
|
||||||
|
// Fires a Message Create Gateway event.
|
||||||
|
func (c *Client) SendTextReply(
|
||||||
|
channelID discord.ChannelID,
|
||||||
|
content string,
|
||||||
|
referenceID discord.MessageID) (*discord.Message, error) {
|
||||||
|
|
||||||
|
return c.SendMessageComplex(channelID, SendMessageData{
|
||||||
|
Content: content,
|
||||||
|
Reference: &discord.MessageReference{MessageID: referenceID},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// SendEmbed posts an Embed to a guild text or DM channel.
|
// SendEmbed posts an Embed to a guild text or DM channel.
|
||||||
//
|
//
|
||||||
// If operating on a guild channel, this endpoint requires the SEND_MESSAGES
|
// If operating on a guild channel, this endpoint requires the SEND_MESSAGES
|
||||||
|
@ -217,6 +234,23 @@ func (c *Client) SendEmbed(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendEmbedReply posts an Embed reply to a message ID in a guild text or DM channel.
|
||||||
|
//
|
||||||
|
// If operating on a guild channel, this endpoint requires the SEND_MESSAGES
|
||||||
|
// permission to be present on the current user.
|
||||||
|
//
|
||||||
|
// Fires a Message Create Gateway event.
|
||||||
|
func (c *Client) SendEmbedReply(
|
||||||
|
channelID discord.ChannelID,
|
||||||
|
e discord.Embed,
|
||||||
|
referenceID discord.MessageID) (*discord.Message, error) {
|
||||||
|
|
||||||
|
return c.SendMessageComplex(channelID, SendMessageData{
|
||||||
|
Embed: &e,
|
||||||
|
Reference: &discord.MessageReference{MessageID: referenceID},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// SendMessage posts a message to a guild text or DM channel.
|
// SendMessage posts a message to a guild text or DM channel.
|
||||||
//
|
//
|
||||||
// If operating on a guild channel, this endpoint requires the SEND_MESSAGES
|
// If operating on a guild channel, this endpoint requires the SEND_MESSAGES
|
||||||
|
@ -232,6 +266,25 @@ func (c *Client) SendMessage(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendMessageReply posts a reply to a message ID in a guild text or DM channel.
|
||||||
|
//
|
||||||
|
// If operating on a guild channel, this endpoint requires the SEND_MESSAGES
|
||||||
|
// permission to be present on the current user.
|
||||||
|
//
|
||||||
|
// Fires a Message Create Gateway event.
|
||||||
|
func (c *Client) SendMessageReply(
|
||||||
|
channelID discord.ChannelID,
|
||||||
|
content string,
|
||||||
|
embed *discord.Embed,
|
||||||
|
referenceID discord.MessageID) (*discord.Message, error) {
|
||||||
|
|
||||||
|
return c.SendMessageComplex(channelID, SendMessageData{
|
||||||
|
Content: content,
|
||||||
|
Embed: embed,
|
||||||
|
Reference: &discord.MessageReference{MessageID: referenceID},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/channel#edit-message-json-params
|
// https://discord.com/developers/docs/resources/channel#edit-message-json-params
|
||||||
type EditMessageData struct {
|
type EditMessageData struct {
|
||||||
// Content is the new message contents (up to 2000 characters).
|
// Content is the new message contents (up to 2000 characters).
|
||||||
|
|
|
@ -378,12 +378,9 @@ func (ctx *Context) Start() func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ctx.SendMessageComplex(mc.ChannelID, api.SendMessageData{
|
_, err = ctx.SendMessageComplex(mc.ChannelID, api.SendMessageData{
|
||||||
// Escape the error using the message sanitizer:
|
Content: str,
|
||||||
Content: ctx.SanitizeMessage(str),
|
// Don't allow mentions.
|
||||||
AllowedMentions: &api.AllowedMentions{
|
AllowedMentions: &api.AllowedMentions{Parse: emptyMentionTypes},
|
||||||
// Don't allow mentions.
|
|
||||||
Parse: emptyMentionTypes,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/diamondburned/arikawa/v2/api"
|
"github.com/diamondburned/arikawa/v2/api"
|
||||||
"github.com/diamondburned/arikawa/v2/discord"
|
"github.com/diamondburned/arikawa/v2/discord"
|
||||||
"github.com/diamondburned/arikawa/v2/gateway"
|
"github.com/diamondburned/arikawa/v2/gateway"
|
||||||
|
"github.com/diamondburned/arikawa/v2/utils/json/option"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -303,23 +304,36 @@ func (ctx *Context) callMessageCreate(mc *gateway.MessageCreateEvent, value refl
|
||||||
Call:
|
Call:
|
||||||
// call the function and parse the error return value
|
// call the function and parse the error return value
|
||||||
v, err := cmd.call(value, argv...)
|
v, err := cmd.call(value, argv...)
|
||||||
if err != nil {
|
if err != nil || v == nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var data api.SendMessageData
|
||||||
|
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
v = sub.SanitizeMessage(v)
|
data.Content = v
|
||||||
_, err = ctx.SendMessage(mc.ChannelID, v, nil)
|
|
||||||
case *discord.Embed:
|
case *discord.Embed:
|
||||||
_, err = ctx.SendMessage(mc.ChannelID, "", v)
|
data.Embed = v
|
||||||
case *api.SendMessageData:
|
case *api.SendMessageData:
|
||||||
if v.Content != "" {
|
data = *v
|
||||||
v.Content = sub.SanitizeMessage(v.Content)
|
default:
|
||||||
}
|
return nil
|
||||||
_, err = ctx.SendMessageComplex(mc.ChannelID, *v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if data.Reference == nil {
|
||||||
|
data.Reference = &discord.MessageReference{MessageID: mc.ID}
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.AllowedMentions == nil {
|
||||||
|
// Do not mention on reply by default. Only allow author mentions.
|
||||||
|
data.AllowedMentions = &api.AllowedMentions{
|
||||||
|
Users: []discord.UserID{mc.Author.ID},
|
||||||
|
RepliedUser: option.False,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = ctx.SendMessageComplex(mc.ChannelID, data)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,12 +76,14 @@ type Subcommand struct {
|
||||||
// Aliases is alternative way to call this subcommand in Discord.
|
// Aliases is alternative way to call this subcommand in Discord.
|
||||||
Aliases []string
|
Aliases []string
|
||||||
|
|
||||||
// SanitizeMessage is executed on the message content if the method returns
|
// SanitizeMessage is currently no longer used automatically.
|
||||||
// a string content or a SendMessageData.
|
// AllowedMentions is used instead.
|
||||||
|
//
|
||||||
|
// This field is deprecated and will be removed eventually.
|
||||||
SanitizeMessage func(content string) string
|
SanitizeMessage func(content string) string
|
||||||
|
|
||||||
// Commands can actually return either a string, an embed, or a
|
// Commands can return either a string, a *discord.Embed, or an
|
||||||
// SendMessageData, with error as the second argument.
|
// *api.SendMessageData, with error as the second argument.
|
||||||
|
|
||||||
// All registered method contexts:
|
// All registered method contexts:
|
||||||
Events []*MethodContext
|
Events []*MethodContext
|
||||||
|
|
Loading…
Reference in a new issue