mirror of
https://github.com/Fluffy-Bean/Lynxie.git
synced 2025-05-14 08:02:17 +00:00
Compare commits
2 commits
573296e7d0
...
efcba1f555
Author | SHA1 | Date | |
---|---|---|---|
efcba1f555 | |||
e8f6e7cc0a |
2 changed files with 43 additions and 13 deletions
|
@ -132,8 +132,19 @@ func (b *Bot) handler(session *discordgo.Session, message *discordgo.MessageCrea
|
|||
func printHelp(bot *Bot, h *Handler) {
|
||||
var commands []string
|
||||
|
||||
for cmd := range bot.commands {
|
||||
commands = append(commands, cmd)
|
||||
for command := range bot.commands {
|
||||
var found []string
|
||||
for a, c := range bot.aliases {
|
||||
if c == command {
|
||||
found = append(found, a)
|
||||
}
|
||||
}
|
||||
|
||||
if len(found) > 0 {
|
||||
commands = append(commands, fmt.Sprintf("%s (%s)", command, strings.Join(found, ", ")))
|
||||
} else {
|
||||
commands = append(commands, command)
|
||||
}
|
||||
}
|
||||
|
||||
_, _ = h.Session.ChannelMessageSendComplex(h.Message.ChannelID, &discordgo.MessageSend{
|
||||
|
@ -141,6 +152,9 @@ func printHelp(bot *Bot, h *Handler) {
|
|||
Title: "Help",
|
||||
Description: strings.Join(commands, "\n"),
|
||||
Color: color.RGBToDiscord(255, 255, 255),
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "command (aliases...)",
|
||||
},
|
||||
},
|
||||
Reference: h.Reference,
|
||||
})
|
||||
|
|
|
@ -76,7 +76,7 @@ func registerSaveable(bot *handler.Bot) handler.Callback {
|
|||
Image: &discordgo.MessageEmbedImage{
|
||||
URL: "attachment://saveable.gif",
|
||||
},
|
||||
Color: color.RGBToDiscord(1, 1, 1),
|
||||
Color: color.RGBToDiscord(255, 255, 255),
|
||||
},
|
||||
Files: []*discordgo.File{
|
||||
{
|
||||
|
@ -205,7 +205,7 @@ func registerCaption(bot *handler.Bot) handler.Callback {
|
|||
Image: &discordgo.MessageEmbedImage{
|
||||
URL: "attachment://caption.jpeg",
|
||||
},
|
||||
Color: color.RGBToDiscord(1, 1, 1),
|
||||
Color: color.RGBToDiscord(255, 255, 255),
|
||||
},
|
||||
Files: []*discordgo.File{
|
||||
{
|
||||
|
@ -256,7 +256,6 @@ func loadImageFromBytes(buff []byte) (image.Image, error) {
|
|||
}
|
||||
|
||||
func findClosestImage(h *handler.Handler) (string, error) {
|
||||
// Get message attachments
|
||||
if len(h.Message.Attachments) >= 1 {
|
||||
if h.Message.Attachments[0].Size > maxFileSize {
|
||||
return "", fmt.Errorf("file size is too big")
|
||||
|
@ -265,20 +264,37 @@ func findClosestImage(h *handler.Handler) (string, error) {
|
|||
return h.Message.Attachments[0].ProxyURL, nil
|
||||
}
|
||||
|
||||
// If no attachments exist... see if the message is replying to someone
|
||||
if h.Message.ReferencedMessage != nil {
|
||||
if len(h.Message.ReferencedMessage.Attachments) >= 1 {
|
||||
if h.Message.ReferencedMessage.Attachments[0].Size > maxFileSize {
|
||||
message := h.Message.ReferencedMessage
|
||||
|
||||
if len(message.Attachments) >= 1 {
|
||||
if message.Attachments[0].Size > maxFileSize {
|
||||
return "", fmt.Errorf("file size is too big")
|
||||
}
|
||||
|
||||
return h.Message.ReferencedMessage.Attachments[0].ProxyURL, nil
|
||||
return message.Attachments[0].ProxyURL, nil
|
||||
}
|
||||
|
||||
// Maybe replying to an embed...?
|
||||
if len(h.Message.ReferencedMessage.Embeds) >= 1 {
|
||||
//... no file size is provided
|
||||
return h.Message.ReferencedMessage.Embeds[0].Image.ProxyURL, nil
|
||||
if len(message.Embeds) >= 1 && message.Embeds[0].Image != nil {
|
||||
return message.Embeds[0].Image.ProxyURL, nil
|
||||
}
|
||||
}
|
||||
|
||||
history, err := h.Session.ChannelMessages(h.Message.ChannelID, 10, h.Message.ID, "", "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, message := range history {
|
||||
if len(message.Attachments) >= 1 {
|
||||
if message.Attachments[0].Size > maxFileSize {
|
||||
return "", fmt.Errorf("file size is too big")
|
||||
}
|
||||
|
||||
return message.Attachments[0].ProxyURL, nil
|
||||
}
|
||||
|
||||
if len(message.Embeds) >= 1 && message.Embeds[0].Image != nil {
|
||||
return message.Embeds[0].Image.ProxyURL, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue