Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7cNTs5R6Hk4V2lcmLz2NsG2VnInyNo=
github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/disgoorg/disgo v0.18.15 h1:T24I/NdUUody4FDvb8YkhSxHtsgRKD8Ui5Vi5PXnIrQ=
github.com/disgoorg/disgo v0.18.15/go.mod h1:dXYVH059d6aK7mI+Nh/3svSRWedNd09P7C2VX3RqbJY=
github.com/disgoorg/disgo v0.18.16 h1:Yk6pA9TaGbuM4hWfWafH0jAfmkWvZBFY7rh49DgljGE=
github.com/disgoorg/disgo v0.18.16/go.mod h1:dXYVH059d6aK7mI+Nh/3svSRWedNd09P7C2VX3RqbJY=
github.com/disgoorg/json v1.2.0 h1:6e/j4BCfSHIvucG1cd7tJPAOp1RgnnMFSqkvZUtEd1Y=
Expand Down Expand Up @@ -73,8 +71,6 @@ github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.20.0 h1:zrxIyR3RQIOsarIrgL8+sAvALXul9jeEPa06Y0Ph6vY=
github.com/spf13/viper v1.20.0/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
github.com/sqids/sqids-go v0.4.1 h1:eQKYzmAZbLlRwHeHYPF35QhgxwZHLnlmVj9AkIj/rrw=
Expand Down Expand Up @@ -105,12 +101,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
gorm.io/gorm v1.26.0 h1:9lqQVPG5aNNS6AyHdRiwScAVnXHg/L/Srzx55G5fOgs=
gorm.io/gorm v1.26.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
gorm.io/gorm v1.26.1 h1:ghB2gUI9FkS46luZtn6DLZ0f6ooBJ5IbVej2ENFDjRw=
gorm.io/gorm v1.26.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
modernc.org/cc/v4 v4.21.0 h1:D/gLKtcztomvWbsbvBKo3leKQv+86f+DdqEZBBXhnag=
Expand Down
2 changes: 1 addition & 1 deletion interactions/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Register(r *handler.Mux) []discord.ApplicationCommandCreate {
"/admin", func(r handler.Router) {
r.Component("/show-all-button", AdminShowAllButtonHandler)
r.Command("/info", AdminInfoHandler)
r.Command("/mod-channel", AdminModChannelHandler)
r.Command("/channels", AdminChannelsHandler)
r.Command("/infractions", AdminInfractionsHandler)
r.Command("/gatekeep", AdminGatekeepHandler)
r.Command("/gatekeep-message", AdminGatekeepMessageHandler)
Expand Down
57 changes: 43 additions & 14 deletions interactions/admin/mod_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,78 @@ import (
)

var modChannelSubcommand = discord.ApplicationCommandOptionSubCommand{
Name: "mod-channel",
Description: "View or set the moderator channel",
Name: "channels",
Description: "View or set the moderator channels",
Options: []discord.ApplicationCommandOption{
discord.ApplicationCommandOptionChannel{
Name: "channel",
Name: "mod-channel",
Description: "The channel to set as the moderator channel",
Required: false,
ChannelTypes: []discord.ChannelType{discord.ChannelTypeGuildText},
},
discord.ApplicationCommandOptionChannel{
Name: "log-channel",
Description: "the channel in which various information will be logged",
Required: false,
ChannelTypes: []discord.ChannelType{discord.ChannelTypeGuildText},
},
discord.ApplicationCommandOptionString{
Name: "reset",
Description: "Reset the moderator channel setting",
Required: false,
Choices: []discord.ApplicationCommandOptionChoiceString{
{Name: "Reset", Value: "reset"},
{Name: "Moderator channel", Value: "mod-channel"},
{Name: "Log channel", Value: "log-channel"},
{Name: "All", Value: "all"},
},
},
},
}

func AdminModChannelHandler(e *handler.CommandEvent) error {
func AdminChannelsHandler(e *handler.CommandEvent) error {
data := e.SlashCommandInteractionData()
guild, isGuild := e.Guild()
if !isGuild {
return interactions.ErrEventNoGuildID
}

channel, hasChannel := data.OptChannel("channel")
modChannel, hasModChannel := data.OptChannel("mod-channel")
logChannel, hasLogChannel := data.OptChannel("log-channel")
resetOption, hasReset := data.OptString("reset")
settings, err := model.GetGuildSettings(guild.ID)
if err != nil {
return err
}

if !hasChannel && !hasReset {
if !hasModChannel && !hasReset && !hasLogChannel {
return e.CreateMessage(interactions.EphemeralMessageContent(modChannelInfo(settings)).Build())
}

message := ""

if hasReset && resetOption == "reset" {
settings.ModeratorChannel = 0
message = "Moderator channel has been reset."
} else if hasChannel {
settings.ModeratorChannel = channel.ID
message = fmt.Sprintf("Moderator channel set to <#%d>", channel.ID)
if hasReset && resetOption == "mod-channel" {
switch resetOption {
case "mod-channel":
settings.ModeratorChannel = 0
message += "Moderator channel has been reset.\n"
case "log-channel":
settings.LogChannel = 0
message += "Log channel has been reset.\n"
case "all":
settings.ModeratorChannel = 0
settings.LogChannel = 0
message += "All channel settings have been reset.\n"
}

}

if hasModChannel {
settings.ModeratorChannel = modChannel.ID
message += fmt.Sprintf("Moderator channel set to <#%d>\n", modChannel.ID)
}
if hasLogChannel {
settings.LogChannel = logChannel.ID
message += fmt.Sprintf("Log channel set to <#%d>\n", logChannel.ID)
}

err = model.SetGuildSettings(settings)
Expand All @@ -73,9 +99,12 @@ func AdminModChannelHandler(e *handler.CommandEvent) error {

func modChannelInfo(settings *model.GuildSettings) string {
modChannelInfo := "> This is the channel in which notifications and other information for moderators and administrators are sent."
logChannelInfo := "> This is the channel in which various less-important (and potentially frequent) info will be sent."
return fmt.Sprintf(
"**Moderator channel:** %s\n%s",
"## Channels\n**Moderator channel:** %s\n%s\n\n**Log channel:** %s\n%s",
utils.MentionChannelOrDefault(&settings.ModeratorChannel, "not set"),
modChannelInfo,
utils.MentionChannelOrDefault(&settings.LogChannel, "not set"),
logChannelInfo,
)
}
64 changes: 64 additions & 0 deletions listeners/voice_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package listeners

import (
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"

"github.com/NLLCommunity/heimdallr/model"
"github.com/NLLCommunity/heimdallr/utils"
)

func OnUserVoiceJoin(e *events.GuildVoiceJoin) {
settings, err := model.GetGuildSettings(e.VoiceState.GuildID)
if err != nil || settings.LogChannel == 0 {
return
}

e.Client().Rest().CreateMessage(

Check failure on line 17 in listeners/voice_state.go

View workflow job for this annotation

GitHub Actions / GolangCi-Lint

Error return value of `(github.com/disgoorg/disgo/rest.Channels).CreateMessage` is not checked (errcheck)
settings.LogChannel,
discord.NewMessageCreateBuilder().
SetAllowedMentions(&discord.AllowedMentions{}).
SetContentf(
"Voice channel joined: %s joined %s",
e.Member.Mention(),
utils.MentionChannelOrDefault(e.VoiceState.ChannelID, "unknown"),
).Build(),
)
}

func OnUserVoiceLeave(e *events.GuildVoiceLeave) {
settings, err := model.GetGuildSettings(e.OldVoiceState.GuildID)
if err != nil || settings.LogChannel == 0 {
return
}

e.Client().Rest().CreateMessage(

Check failure on line 35 in listeners/voice_state.go

View workflow job for this annotation

GitHub Actions / GolangCi-Lint

Error return value of `(github.com/disgoorg/disgo/rest.Channels).CreateMessage` is not checked (errcheck)
settings.LogChannel,
discord.NewMessageCreateBuilder().
SetAllowedMentions(&discord.AllowedMentions{}).
SetContentf(
"Voice channel left: %s left %s",
e.Member.Mention(),
utils.MentionChannelOrDefault(e.OldVoiceState.ChannelID, "unknown"),
).Build(),
)
}

func OnUserVoiceMove(e *events.GuildVoiceMove) {
settings, err := model.GetGuildSettings(e.OldVoiceState.GuildID)
if err != nil || settings.LogChannel == 0 {
return
}

e.Client().Rest().CreateMessage(

Check failure on line 53 in listeners/voice_state.go

View workflow job for this annotation

GitHub Actions / GolangCi-Lint

Error return value of `(github.com/disgoorg/disgo/rest.Channels).CreateMessage` is not checked (errcheck)
settings.LogChannel,
discord.NewMessageCreateBuilder().
SetAllowedMentions(&discord.AllowedMentions{}).
SetContentf(
"Voice channel changed: %s changed from %s to %s",
e.Member.Mention(),
utils.MentionChannelOrDefault(e.OldVoiceState.ChannelID, "unknown"),
utils.MentionChannelOrDefault(e.VoiceState.ChannelID, "unknown"),
).Build(),
)
}
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func main() {
bot.WithEventListenerFunc(listeners.OnMemberBan),
bot.WithEventListenerFunc(listeners.OnAuditLog),
bot.WithEventListenerFunc(listeners.OnAntispamMessageCreate),
bot.WithEventListenerFunc(listeners.OnUserVoiceJoin),
bot.WithEventListenerFunc(listeners.OnUserVoiceLeave),
bot.WithEventListenerFunc(listeners.OnUserVoiceMove),
bot.WithGatewayConfigOpts(gateway.WithIntents(intents)),
bot.WithCacheConfigOpts(
cache.WithCaches(cache.FlagsAll),
Expand Down
3 changes: 3 additions & 0 deletions model/guild_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type GuildSettings struct {
// information for moderators and administrators are sent.
ModeratorChannel snowflake.ID

// LogChannel is where various, less important information and data is logged.
LogChannel snowflake.ID

// InfractionHalfLifeDays is the half-life time of infractions in days.
InfractionHalfLifeDays float64
NotifyOnWarnedUserJoin bool
Expand Down
Loading