Skip to content

Commit

Permalink
Merge pull request #21 from TwinhelixConsulting/main
Browse files Browse the repository at this point in the history
Fix imports (embed package no longer separate package)
  • Loading branch information
szerookii authored Feb 17, 2024
2 parents e69a2f8 + 918c142 commit 4db50c7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 5 deletions.
11 changes: 10 additions & 1 deletion goscord/discord/channel.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package discord

import (
"github.com/Goscord/goscord/goscord/discord/embed"
"github.com/bytedance/sonic"
"time"
)
Expand Down Expand Up @@ -173,6 +172,16 @@ type AllowedMentions struct {
RepliedUsers bool `json:"replied_users"`
}

type MessageReaction struct {
UserId string `json:"user_id"`
ChannelId string `json:"channel_id"`
MessageId string `json:"message_id"`
GuildId string `json:"guild_id"`
Member *GuildMember `json:"member"`
Emoji *Emoji `json:"emoji"`
MessageAuthorId string `json:"message_author_id"`
}

type Message struct {
Id string `json:"id"`
ChannelId string `json:"channel_id"`
Expand Down
1 change: 0 additions & 1 deletion goscord/discord/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package discord

import (
"encoding/json"
"github.com/Goscord/goscord/goscord/discord/embed"
"github.com/bytedance/sonic"
)

Expand Down
22 changes: 22 additions & 0 deletions goscord/gateway/event/message_reaction_add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package event

import (
"github.com/Goscord/goscord/goscord/discord"
"github.com/Goscord/goscord/goscord/rest"
"github.com/bytedance/sonic"
)

type MessageReactionAdd struct {
Data *discord.MessageReaction `json:"d"`
}

func NewMessageReactionAdd(rest *rest.Client, data []byte) (*MessageReactionAdd, error) {
pk := new(MessageReactionAdd)

err := sonic.Unmarshal(data, pk)

if err != nil {
return nil, err
}
return pk, nil
}
16 changes: 16 additions & 0 deletions goscord/gateway/reaction_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gateway

import (
"github.com/Goscord/goscord/goscord/gateway/event"
)

type MessageReactionHandler struct{}

func (_ *MessageReactionHandler) Handle(s *Session, data []byte) {
ev, err := event.NewMessageReactionAdd(s.rest, data)

if err != nil {
return
}
s.Publish(event.EventMessageReactionAdd, ev.Data)
}
2 changes: 2 additions & 0 deletions goscord/gateway/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func (s *Session) registerHandlers() {
event.EventInteractionCreate: &InteractionCreateHandler{},
event.EventVoiceStateUpdate: &VoiceStateUpdateHandler{},
event.EventVoiceServerUpdate: &VoiceServerUpdateHandler{},

event.EventMessageReactionAdd: &MessageReactionHandler{},
}
}

Expand Down
19 changes: 17 additions & 2 deletions goscord/rest/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"errors"
"fmt"
"github.com/Goscord/goscord/goscord/discord"
"github.com/Goscord/goscord/goscord/discord/embed"
"github.com/Goscord/goscord/goscord/discord/builder"
"github.com/bytedance/sonic"
"io"
"mime/multipart"
"os"
)

type ChannelHandler struct {
Expand Down Expand Up @@ -38,6 +37,22 @@ func (ch *ChannelHandler) GetChannel(channelId string) (*discord.Channel, error)
return channel, nil
}

// GetMessages gets messages from a channel
func (ch *ChannelHandler) GetMessages(channelId string, limit int) ([]*discord.Message, error) {
data, err := ch.rest.Request(fmt.Sprintf(EndpointGetChannelMessages, channelId), "GET", nil, "application/json")
if err != nil {
return nil, err
}

var messages []*discord.Message
err = sonic.Unmarshal(data, &messages)
if err != nil {
return nil, err
}

return messages, nil
}

// GetMessage gets a message from a channel
func (ch *ChannelHandler) GetMessage(channelId, messageId string) (*discord.Message, error) {
res, err := ch.rest.Request(fmt.Sprintf(EndpointGetChannelMessage, channelId, messageId), "GET", nil, "application/json")
Expand Down
1 change: 0 additions & 1 deletion goscord/rest/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"github.com/Goscord/goscord/goscord/discord"
"github.com/Goscord/goscord/goscord/discord/embed"
"github.com/bytedance/sonic"
)

Expand Down

0 comments on commit 4db50c7

Please sign in to comment.