-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add get discord message logs api #755
base: develop
Are you sure you want to change the base?
Changes from 3 commits
c4fc704
1576bc1
b6fdccd
ee45f85
ec17de8
dc910f2
0a066f5
3c29625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -776,3 +776,52 @@ | |
|
||
c.JSON(http.StatusOK, view.CreateResponse[any](nil, nil, nil, nil, "events swept successfully")) | ||
} | ||
|
||
// ListChannelMessageLogs godoc | ||
// @Summary Get list of messages in channel and its thread | ||
// @Description Get list of messages in channel and its thread | ||
// @id ListChannelMessageLogs | ||
// @Tags Discord | ||
// @Accept json | ||
// @Produce json | ||
// @Param discord_channel_id path string true "Channel Discord ID" | ||
// @Param startDate query string true "Start Date" | ||
// @Param endDate query string true "End Date" | ||
// @Success 200 {object} ListResearchTopicResponse | ||
// @Failure 400 {object} ErrorResponse | ||
// @Failure 404 {object} ErrorResponse | ||
// @Failure 500 {object} ErrorResponse | ||
// @Router /discords/{discord_channel_id}/message-logs [get] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be updated |
||
func (h *handler) ListChannelMessageLogs(c *gin.Context) { | ||
var input = request.GetChannelMessagesInput{ | ||
DiscordChannelID: c.Param("discord_channel_id"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nnhuyhoang will this allow client call any discord_channel_id, if yes, gonna reject this for now please follow up with me about this approach, need to validate/whitelist some channels only |
||
} | ||
|
||
if err := c.ShouldBindQuery(&input); err != nil { | ||
c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, input, "bind query failed")) | ||
return | ||
} | ||
|
||
if err := input.Validate(); err != nil { | ||
c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, input, "")) | ||
return | ||
} | ||
|
||
startDate := input.GetStartDate() | ||
endDate := input.GetEndDate() | ||
|
||
// maximum 3 month messages | ||
threeMonths := time.Hour * 24 * 90 | ||
if endDate.Sub(*startDate) > threeMonths { | ||
newEndDate := startDate.Add(threeMonths) | ||
endDate = &newEndDate | ||
} | ||
|
||
messages, err := h.controller.Discord.ListDiscordChannelMessageLogs(c, input.DiscordChannelID, startDate, endDate) | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, view.CreateResponse[any](nil, nil, err, nil, "")) | ||
return | ||
} | ||
c.JSON(http.StatusOK, view.CreateResponse(messages, nil, nil, nil, "")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. define view |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. failed linter |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package model | ||
|
||
import "github.com/bwmarrin/discordgo" | ||
import ( | ||
"time" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
type DiscordMessage struct { | ||
AvatarURL string `json:"avatar_url"` | ||
|
@@ -66,3 +70,13 @@ type OriginalDiscordMessage struct { | |
Author *discordgo.User | ||
Roles []string | ||
} | ||
|
||
type DiscordTextMessageLog struct { | ||
ID string `json:"id"` | ||
Content string `json:"content"` | ||
AuthorName string `json:"author_name"` | ||
AuthorID string `json:"author_id"` | ||
ChannelID string `json:"channel_id"` | ||
GuildID string `json:"guild_id"` | ||
Timestamp time.Time `json:"timestamp"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove json tag |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namnhce @nnhuyhoang
this seems like a potential OOM, since on prod we only have 100MB-ish memory, make sure we dont OOM here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will test on dev with the same amount of messages, if cannot handle them , find another way