Skip to content

Commit

Permalink
Update because of lib
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRalex committed Oct 30, 2023
1 parent bd16fe8 commit 9f73989
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions modules/messagereport/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/lordralex/absol/api/logger"
"strings"
"time"
)

type InteractionAction struct {
Function func(action *InteractionAction, session *discordgo.Session, interaction *discordgo.Interaction, id *CustomId)
Function func(session *discordgo.Session, interaction *discordgo.Interaction, id *CustomId)
ButtonText string
RequiresConfirmation bool
Action string
Expand Down Expand Up @@ -93,7 +94,7 @@ func getRawAction(name string) *InteractionAction {
return nil
}

func deleteMessage(action *InteractionAction, s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
func deleteMessage(s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
err := s.ChannelMessageDelete(id.ChannelId, id.MessageId)
if err != nil {
_, _ = s.ChannelMessageSend(i.Message.ChannelID, "Failed to delete message, it may already be deleted")
Expand All @@ -103,7 +104,7 @@ func deleteMessage(action *InteractionAction, s *discordgo.Session, i *discordgo
}
}

func sendConfirmation(action *InteractionAction, s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
func sendConfirmation(s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
id.BaseMessageId = i.Message.ID

confirm := id.Clone()
Expand Down Expand Up @@ -134,13 +135,26 @@ func sendConfirmation(action *InteractionAction, s *discordgo.Session, i *discor
_, _ = s.ChannelMessageSendComplex(i.ChannelID, m)
}

func muteUser(action *InteractionAction, s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
func muteUser(s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
till := time.Now().Add(time.Hour * 24)
err := s.GuildMemberTimeout(i.GuildID, id.UserId, &till)
if err != nil {
_, _ = s.ChannelMessageSend(i.Message.ChannelID, "Failed to time out user: "+err.Error())
return
}
_, _ = s.ChannelMessageSend(i.Message.ChannelID, "User timed out for 24 hours")
}

func banUser(action *InteractionAction, s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
func banUser(s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
err := s.GuildBanCreate(i.GuildID, id.UserId, 0)
if err != nil {
_, _ = s.ChannelMessageSend(i.Message.ChannelID, "Failed to ban user: "+err.Error())
return
}
_, _ = s.ChannelMessageSend(i.Message.ChannelID, "User banned")
}

func cancelConfirmation(action *InteractionAction, s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
func cancelConfirmation(s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
err := s.ChannelMessageDelete(i.Message.ChannelID, i.Message.ID)
if err != nil {
logger.Err().Println(err.Error())
Expand All @@ -153,6 +167,6 @@ func cancelConfirmation(action *InteractionAction, s *discordgo.Session, i *disc
}
}

func closeReport(action *InteractionAction, s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
func closeReport(s *discordgo.Session, i *discordgo.Interaction, id *CustomId) {
_, _ = s.ChannelDelete(i.ChannelID)
}
2 changes: 1 addition & 1 deletion modules/messagereport/messagereport.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (*Module) Load(ds *discordgo.Session) {
})

if action != nil {
action.Function(action, s, i.Interaction, customId)
action.Function(s, i.Interaction, customId)

//delete the confirmation request
if action.RequiresConfirmation {
Expand Down

0 comments on commit 9f73989

Please sign in to comment.