Skip to content
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

Patch fixes qol #272

Merged
merged 17 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .devcontainer/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.dockerignore
devcontainer.json
docker-compose.yml
Dockerfile
README.md
3 changes: 3 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM qmcgaw/godevcontainer
#
RUN apk add make
68 changes: 68 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "southclaws-cj",
"dockerComposeFile": [
"docker-compose.yml"
],
"service": "vscode",
"runServices": [
"vscode"
],
"shutdownAction": "stopCompose",
"postCreateCommand": "~/.windows.sh && go mod download && go mod tidy",
"workspaceFolder": "/workspace",
// "overrideCommand": "",
"customizations": {
"vscode": {
"extensions": [
"golang.go",
"eamodio.gitlens", // IDE Git information
"davidanson.vscode-markdownlint",
"ms-azuretools.vscode-docker", // Docker integration and linting
"shardulm94.trailing-spaces", // Show trailing spaces
"Gruntfuggly.todo-tree", // Highlights TODO comments
"bierner.emojisense", // Emoji sense for markdown
"stkb.rewrap", // rewrap comments after n characters on one line
"vscode-icons-team.vscode-icons", // Better file extension icons
"github.vscode-pull-request-github", // Github interaction
"redhat.vscode-yaml", // Kubernetes, Drone syntax highlighting
"bajdzis.vscode-database", // Supports connections to mysql or postgres, over SSL, socked
"IBM.output-colorizer", // Colorize your output/test logs
"github.copilot" // AI code completion
],
"settings": {
"files.eol": "\n",
"editor.formatOnSave": true,
"go.buildTags": "",
"go.toolsEnvVars": {
"CGO_ENABLED": "0"
},
"go.useLanguageServer": true,
"go.testEnvVars": {
"CGO_ENABLED": "1"
},
"go.testFlags": [
"-v",
"-race"
],
"go.testTimeout": "10s",
"go.coverOnSingleTest": true,
"go.coverOnSingleTestFile": true,
"go.coverOnTestPackage": true,
"go.lintTool": "golangci-lint",
"go.lintOnSave": "package",
"[go]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
}
},
"gopls": {
"usePlaceholders": false,
"staticcheck": true
},
"remote.extensionKind": {
"ms-azuretools.vscode-docker": "workspace"
}
}
}
}
}
38 changes: 38 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: "3.7"

services:
vscode:
build: .
volumes:
- ../:/workspace
# Docker socket to access Docker server
- /var/run/docker.sock:/var/run/docker.sock
# SSH directory for Linux, OSX and WSL
# On Linux and OSX, a symlink /mnt/ssh <-> ~/.ssh is
# created in the container. On Windows, files are copied
# from /mnt/ssh to ~/.ssh to fix permissions.
- ~/.ssh:/mnt/ssh
# Shell history persistence
- ~/.zsh_history:/root/.zsh_history
# Git config
- ~/.gitconfig:/root/.gitconfig
environment:
- TZ=Europe/London
depends_on:
- mongo
cap_add:
# For debugging with dlv
- SYS_PTRACE
security_opt:
# For debugging with dlv
- seccomp:unconfined
entrypoint: [ "zsh", "-c", "while sleep 1000; do :; done" ]

mongo:
image: mongo:4.4.0
container_name: 'southclaws-cj-mongo-${MONGO_CONTAINER_ID:-local}'
hostname: mongo
ports:
- "${MONGO_EXPOSED_PORT:-27017}:27017"
volumes:
- ./data/db:/data/db
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ log.txt

# binary
cj

# devcontainer
.devcontainer/data
2 changes: 1 addition & 1 deletion bot/commands/all_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (cm *CommandManager) LoadCommands() {
break
}
}
if commandExists == false {
if !commandExists {
zap.L().Info("Deleting non-existent slash command from Discord:", zap.Any("cmd", existingCommand))
cm.Discord.S.ApplicationCommandDelete(cm.Discord.S.State.User.ID, "", existingCommand.ID)
}
Expand Down
2 changes: 1 addition & 1 deletion bot/commands/cmd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (cm *CommandManager) commandConfig(
}

newConfigValue, hasNewConfig := args["config"]
if hasNewConfig == false {
if !hasNewConfig {
var b []byte
b, err = json.Marshal(cmd.Settings)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions bot/commands/cmd_debugreload.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func (cm *CommandManager) commandDebugReload(

cm.Discord.S.ApplicationCommandBulkOverwrite(cm.Discord.S.State.User.ID, "", discordCommands)

cm.Discord.S.InteractionResponseEdit(cm.Discord.S.State.User.ID, interaction.Interaction, &discordgo.WebhookEdit{
Content: "Reload commands succeeded. This can take an hour to take effect.",
content := "Reload commands succeeded. This can take an hour to take effect."
cm.Discord.S.InteractionResponseEdit(interaction.Interaction, &discordgo.WebhookEdit{
Content: &content,
})

return
Expand Down
10 changes: 5 additions & 5 deletions bot/commands/cmd_konesyntees.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ func (cm *CommandManager) commandKonesyntees(

cm.Discord.S.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
Data: &discordgo.InteractionResponseData{
Content: "Processing your konesyntees",
},
})

response, err := gonesyntees.Request(text, gonesyntees.Voice(voice), speed)

if err != nil {
cm.Discord.S.FollowupMessageCreate(cm.Discord.S.State.User.ID, interaction.Interaction, false, &discordgo.WebhookParams{
cm.Discord.S.FollowupMessageCreate(interaction.Interaction, false, &discordgo.WebhookParams{
Content: fmt.Sprintf("Error in sending request: %s", err.Error()),
})
return
}

audio, err := http.Get(response.MP3Url)
if err != nil {
cm.Discord.S.FollowupMessageCreate(cm.Discord.S.State.User.ID, interaction.Interaction, false, &discordgo.WebhookParams{
cm.Discord.S.FollowupMessageCreate(interaction.Interaction, false, &discordgo.WebhookParams{
Content: fmt.Sprintf("Error in getting response URL: %s", err.Error()),
})
return
}

cm.Discord.S.InteractionResponseDelete(cm.Discord.S.State.User.ID, interaction.Interaction)
cm.Discord.S.InteractionResponseDelete(interaction.Interaction)
cm.Discord.ChannelFileSend(interaction.ChannelID, "konesyntees.mp3", audio.Body)
return
}
Expand All @@ -72,7 +72,7 @@ func parseVoiceParams(text string) (string, int, int, error) {
voice := 0

for i := 0; i < len(params); i++ {
if strings.HasPrefix(params[i], "--") == false {
if !strings.HasPrefix(params[i], "--") {
break
}

Expand Down
28 changes: 15 additions & 13 deletions bot/commands/command_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ func (cm *CommandManager) OnMessage(message discordgo.Message) (err error) {
}

func (cm *CommandManager) TryFindAndFireCommand(interaction *discordgo.InteractionCreate) {
zap.L().Info("User attempting command", zap.Any("user", interaction.Member.User.ID), zap.Any("command", interaction.Data.Name))
zap.L().Info("User attempting command", zap.Any("user", interaction.Member.User.ID), zap.Any("command", interaction.ApplicationCommandData().Name))
for _, command := range cm.Commands {
if strings.TrimLeft(command.Name, "/") == interaction.Data.Name {
if strings.TrimLeft(command.Name, "/") == interaction.ApplicationCommandData().Name {
if hasPermissions(command.Settings.Roles, interaction.Member.Roles) {
args := make(map[string]*discordgo.ApplicationCommandInteractionDataOption)
for _, option := range interaction.Data.Options {
for _, option := range interaction.ApplicationCommandData().Options {
args[option.Name] = option
}
command.Function(interaction, args, command.Settings)
} else {
cm.Discord.S.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
Data: &discordgo.InteractionResponseData{
Content: "You're not authorized for this!",
},
})
time.Sleep(time.Second * 5)
cm.Discord.S.InteractionResponseDelete(cm.Discord.S.State.User.ID, interaction.Interaction)
cm.Discord.S.InteractionResponseDelete(interaction.Interaction)
}
break
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func pcd(since time.Duration, cooldown time.Duration) (result string) {
func (cm *CommandManager) replyDirectly(interaction *discordgo.InteractionCreate, response string) {
cm.Discord.S.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
Data: &discordgo.InteractionResponseData{
Content: response,
},
})
Expand All @@ -146,7 +146,7 @@ func (cm *CommandManager) replyDirectly(interaction *discordgo.InteractionCreate
func (cm *CommandManager) replyDirectlyEmbed(interaction *discordgo.InteractionCreate, response string, embed *discordgo.MessageEmbed) {
cm.Discord.S.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
Data: &discordgo.InteractionResponseData{
Content: response,
Embeds: []*discordgo.MessageEmbed{embed},
},
Expand All @@ -157,21 +157,23 @@ func (cm *CommandManager) replyDirectlyEmbed(interaction *discordgo.InteractionC
func (cm *CommandManager) sendThinkingResponse(interaction *discordgo.InteractionCreate) {
cm.Discord.S.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{
Data: &discordgo.InteractionResponseData{
Content: "",
},
})
}

func (cm *CommandManager) editOriginalResponse(interaction *discordgo.InteractionCreate, response string) {
cm.Discord.S.InteractionResponseEdit(cm.Discord.S.State.User.ID, interaction.Interaction, &discordgo.WebhookEdit{
Content: response,
cm.Discord.S.InteractionResponseEdit(interaction.Interaction, &discordgo.WebhookEdit{
Content: &response,
})
}

func (cm *CommandManager) editOriginalResponseWithEmbed(interaction *discordgo.InteractionCreate, embed *discordgo.MessageEmbed) {
cm.Discord.S.InteractionResponseEdit(cm.Discord.S.State.User.ID, interaction.Interaction, &discordgo.WebhookEdit{
Content: "",
Embeds: []*discordgo.MessageEmbed{embed},
content := ""
embeds := []*discordgo.MessageEmbed{embed}
cm.Discord.S.InteractionResponseEdit(interaction.Interaction, &discordgo.WebhookEdit{
Content: &content,
Embeds: &embeds,
})
}
7 changes: 3 additions & 4 deletions discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package discord

import (
"math/rand"
"time"

"github.com/bwmarrin/discordgo"
"github.com/robfig/cron"
Expand Down Expand Up @@ -59,11 +60,11 @@ func (s *Session) GetCurrentChannelMessageFrequency(channelID string) (freq floa
return 0.0, nil
}

start, err := messages[0].Timestamp.Parse()
start, err := time.Parse(time.RFC3339, messages[0].Timestamp.Format(time.RFC3339))
if err != nil {
return
}
end, err := messages[len(messages)-1].Timestamp.Parse()
end, err := time.Parse(time.RFC3339, messages[len(messages)-1].Timestamp.Format(time.RFC3339))
if err != nil {
return
}
Expand Down Expand Up @@ -96,8 +97,6 @@ func (s *Session) cacheUsernames() {
}
s.UserIndex[name] = *u
}

return
}

func must(err error) {
Expand Down
22 changes: 12 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ replace gopkg.in/russross/blackfriday.v2 => github.com/russross/blackfriday/v2 v

require (
github.com/Bios-Marcel/discordemojimap v1.0.1
github.com/bwmarrin/discordgo v0.23.3-0.20210515023446-8dc42757bea5
github.com/bwmarrin/discordgo v0.27.1
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
github.com/google/go-github/v28 v28.1.1
github.com/google/go-querystring v1.1.0 // indirect
github.com/joho/godotenv v1.4.0
github.com/joho/godotenv v1.5.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/kr/pretty v0.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kristoisberg/gonesyntees v0.0.0-20190527174556-0595a02f9399
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/robfig/cron v1.2.0
github.com/stretchr/testify v1.7.1
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.17.0
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/net v0.0.0-20210510120150-4163338589ed // indirect
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
github.com/stretchr/testify v1.9.0
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/xmlpath.v2 v2.0.0-20150820204837-860cbeca3ebc
gopkg.in/yaml.v2 v2.2.8 // indirect
)