Skip to content

Commit

Permalink
Update to deps + go
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRalex committed Sep 18, 2023
1 parent 86e0426 commit 1cef149
Show file tree
Hide file tree
Showing 23 changed files with 435 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###
# Builder to compile our golang code
###
FROM golang:1.19-alpine AS builder
FROM golang:1.21-alpine AS builder

ARG tags="modules.all,databases.all"

Expand Down
51 changes: 25 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
module github.com/lordralex/absol

go 1.19
go 1.21

require (
github.com/bwmarrin/discordgo v0.24.0
github.com/iverly/go-mcping v1.0.0
github.com/spf13/cast v1.3.1
github.com/spf13/viper v1.7.1
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5
gorm.io/driver/mysql v1.0.3
gorm.io/gorm v1.20.9
github.com/bwmarrin/discordgo v0.27.1
github.com/iverly/go-mcping v1.0.1
github.com/spf13/cast v1.5.1
github.com/spf13/viper v1.16.0
golang.org/x/oauth2 v0.12.0
gorm.io/driver/mysql v1.5.1
gorm.io/gorm v1.25.4
)

require (
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.1 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmoiron/jsonq v0.0.0-20150511023944-e874b168d07e // indirect
github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/mapstructure v1.4.0 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/spf13/afero v1.5.1 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 // indirect
golang.org/x/text v0.3.4 // indirect
google.golang.org/appengine v1.6.7 // indirect; indirdeect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
304 changes: 304 additions & 0 deletions go.sum

Large diffs are not rendered by default.

34 changes: 20 additions & 14 deletions modules/hjt/hjt.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,19 @@ func runCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {

content, err := readFromUrl(pasteLink)
if err != nil {
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{
Content: "Invalid URL",
msg := "Invalid URL"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: &msg,
})
return
}

db, err := database.Get()
if err != nil {
logger.Err().Printf("Failed to connect to database\n%s", err)
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{
Content: "Failed to connect to database",
msg := "Failed to connect to database"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: &msg,
})
return
}
Expand All @@ -102,8 +104,9 @@ func runCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {

if err != nil {
logger.Err().Printf("Failed to pull data from database\n%s", err)
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{
Content: "Failed to connect to database",
msg := "Failed to connect to database"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: &msg,
})
return
}
Expand All @@ -112,8 +115,9 @@ func runCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {
for _, v := range values {
matches, err := regexp.Match(v.MatchCriteria, content)
if err != nil {
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{
Content: v.Name + " is an invalid regex statement: " + err.Error(),
msg := v.Name + " is an invalid regex statement: " + err.Error()
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: &msg,
})
return
}
Expand All @@ -123,8 +127,9 @@ func runCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {
}

if len(results) == 0 {
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{
Content: "Report for " + pasteLink + "\nNo matches found",
msg := "Report for " + pasteLink + "\nNo matches found"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: &msg,
})
return
}
Expand All @@ -133,8 +138,9 @@ func runCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {
err = db.Find(&data, results).Order("severity desc").Error
if err != nil {
logger.Err().Printf("Failed to pull data from database\n%s", err)
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{
Content: "Failed to connect to database",
msg := "Failed to connect to database"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: &msg,
})
return
}
Expand All @@ -146,8 +152,8 @@ func runCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {
}
message += v.SeverityEmoji + " [" + v.Category + "] " + v.Name + ": " + v.Description
}
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{
Content: message,
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: &message,
})
}

Expand Down
14 changes: 8 additions & 6 deletions modules/mcping/mcping.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ func runCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {
if len(connectionSlice) == 2 {
port, err = strconv.Atoi(connectionSlice[1])
if err != nil {
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{
Content: "That's not a valid port.",
msg := "That's not a valid port."
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: &msg,
})
return
}
Expand All @@ -101,8 +102,9 @@ func runCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {
response, err := pinger.PingWithTimeout(connectionSlice[0], uint16(port), 5*time.Second)
if err != nil {
// if it takes more than five seconds to ping, then the server is probably down
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{
Content: "Connecting to the server failed.",
msg := "Connecting to the server failed."
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: &msg,
})
return
}
Expand Down Expand Up @@ -155,8 +157,8 @@ func runCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {
files = nil
}

_, err = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{
Embeds: []*discordgo.MessageEmbed{embed},
_, err = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Embeds: &[]*discordgo.MessageEmbed{embed},
Files: files,
})
if err != nil {
Expand Down
21 changes: 14 additions & 7 deletions modules/messagereport/messagereport.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (*Module) Load(ds *discordgo.Session) {
_ = s.ChannelMessageDelete(i.Message.ChannelID, i.Message.ID)
}
} else {
_, _ = s.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Unknown action"})
msg := "Unknown action"
_, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
}
}
}
Expand Down Expand Up @@ -166,13 +167,15 @@ func submitReport(s *discordgo.Session, i *discordgo.InteractionCreate) {
messageId := i.ApplicationCommandData().TargetID
message, err := s.ChannelMessage(i.ChannelID, messageId)
if err != nil {
_, _ = s.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Submitting report failed"})
msg := "Submitting report failed"
_, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
return
}

channel, err := getChannelForReport(s, i.GuildID, messageId)
if err != nil {
_, _ = s.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Submitting report failed"})
msg := "Submitting report failed"
_, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
return
}

Expand All @@ -188,7 +191,8 @@ func submitReport(s *discordgo.Session, i *discordgo.InteractionCreate) {

if err != nil {
logger.Err().Printf("Error submitting report for %s: %s\n", message.ID, err.Error())
_, _ = s.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Submitting report failed"})
msg := "Submitting report failed"
_, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
return
}
} else {
Expand Down Expand Up @@ -254,7 +258,8 @@ func submitReport(s *discordgo.Session, i *discordgo.InteractionCreate) {

if err != nil {
logger.Err().Printf("Error submitting report for %s: %s\n", message.ID, err.Error())
_, _ = s.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Submitting report failed"})
msg := "Submitting report failed"
_, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
return
}
} else {
Expand All @@ -266,12 +271,14 @@ func submitReport(s *discordgo.Session, i *discordgo.InteractionCreate) {
})
if err != nil {
logger.Err().Printf("Error submitting report for %s: %s\n", message.ID, err.Error())
_, _ = s.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Submitting report failed"})
msg := "Submitting report failed"
_, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
return
}
}

_, _ = s.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Report submitted"})
msg := "Report submitted"
_, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
}

func (*Module) Name() string {
Expand Down
4 changes: 2 additions & 2 deletions modules/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/lordralex/absol/api/logger"
)

var availableModules = make(map[string]api.Module, 0)
var loadedModules = make(map[string]api.Module, 0)
var availableModules = make(map[string]api.Module)
var loadedModules = make(map[string]api.Module)

func Load(ds *discordgo.Session, modules []string) {
if len(modules) == 1 && modules[0] == "all" {
Expand Down
1 change: 0 additions & 1 deletion modules/module_alert.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build modules.alert || modules.all
// +build modules.alert modules.all

package modules

Expand Down
1 change: 0 additions & 1 deletion modules/module_cleaner.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build modules.cleaner || modules.all
// +build modules.cleaner modules.all

package modules

Expand Down
1 change: 0 additions & 1 deletion modules/module_factoids.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build modules.factoids || modules.all
// +build modules.factoids modules.all

package modules

Expand Down
1 change: 0 additions & 1 deletion modules/module_hjt.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build modules.hjt || modules.all
// +build modules.hjt modules.all

package modules

Expand Down
1 change: 0 additions & 1 deletion modules/module_log.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build modules.log || modules.all
// +build modules.log modules.all

package modules

Expand Down
1 change: 0 additions & 1 deletion modules/module_mcping.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build modules.mcping || modules.all
// +build modules.mcping modules.all

package modules

Expand Down
1 change: 0 additions & 1 deletion modules/module_messagereport.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build modules.messagereport || modules.all
// +build modules.messagereport modules.all

package modules

Expand Down
1 change: 0 additions & 1 deletion modules/module_pastes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build modules.pastes || modules.all
// +build modules.pastes modules.all

package modules

Expand Down
1 change: 0 additions & 1 deletion modules/module_polls.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build modules.polls || modules.all
// +build modules.polls modules.all

package modules

Expand Down
1 change: 0 additions & 1 deletion modules/module_twitch.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build modules.twitch || modules.all
// +build modules.twitch modules.all

package modules

Expand Down
4 changes: 2 additions & 2 deletions modules/pastes/pastes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func HandleMessage(ds *discordgo.Session, mc *discordgo.MessageCreate) {
if !used {
return
}
rows := []discordgo.MessageComponent{}
row := []discordgo.MessageComponent{}
var rows []discordgo.MessageComponent
var row []discordgo.MessageComponent
for _, element := range mc.Attachments {
if isAcceptedFile(element) {
btn := discordgo.Button{
Expand Down
20 changes: 13 additions & 7 deletions modules/polls/closepoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,29 @@ var closePollOperation = &discordgo.ApplicationCommand{
func runCloseCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {
_ = ds.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{Flags: uint64(discordgo.MessageFlagsEphemeral)},
Data: &discordgo.InteractionResponseData{Flags: discordgo.MessageFlagsEphemeral},
})

messageId := i.ApplicationCommandData().Options[0].StringValue()

originalMessage, err := ds.ChannelMessage(i.ChannelID, messageId)
if err != nil {
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Unable to get poll"})
msg := "Unable to get poll"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
return
}

if originalMessage.Author.ID != ds.State.User.ID {
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "This does not appear to be a poll"})
msg := "This does not appear to be a poll"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
return
}

db, err := database.Get()
if err != nil {
logger.Err().Println(err.Error())
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Unable to get poll"})
msg := "Unable to get poll"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
return
}

Expand All @@ -55,17 +58,20 @@ func runCloseCommand(ds *discordgo.Session, i *discordgo.InteractionCreate) {
if errors.Is(err, gorm.ErrRecordNotFound) {
logger.Err().Println(err.Error())
}
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Unable to get poll"})
msg := "Unable to get poll"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
return
}
if poll.Closed {
_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Poll is already closed"})
msg := "Poll is already closed"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
return
}

closePoll(ds, poll, originalMessage, db)

_, _ = ds.InteractionResponseEdit(appId, i.Interaction, &discordgo.WebhookEdit{Content: "Poll closed"})
msg := "Poll closed"
_, _ = ds.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
}

func closePoll(ds *discordgo.Session, poll *Poll, message *discordgo.Message, db *gorm.DB) {
Expand Down
Loading

0 comments on commit 1cef149

Please sign in to comment.