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 14 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.21

- name: Build
run: go build -v ./...
Expand Down
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
5 changes: 2 additions & 3 deletions bot/commands/cmd_gmname.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,10 @@ var tags = []string{
"MISEBAHXD",
}

func init() {
rand.Seed(time.Now().Unix())
}
func init() {}

func generateGmName() (result string) {
rand.New(rand.NewSource(time.Now().Unix()))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we even need this now?

buf := bytes.NewBuffer(nil)

coolword := coolwordsxd[rand.Intn(len(coolwordsxd))]
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
2 changes: 1 addition & 1 deletion bot/commands/cmd_ltf.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (cm *CommandManager) ltf(
"123456789987654321",
})
if err != nil {
cm.replyDirectly(interaction, fmt.Sprintf(errors.Wrap(err, "failed to get messages for user").Error()))
cm.replyDirectly(interaction, fmt.Sprint(errors.Wrap(err, "failed to get messages for user").Error()))
return
}

Expand Down
5 changes: 4 additions & 1 deletion bot/commands/cmd_mpname.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"

"github.com/bwmarrin/discordgo"
"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/Southclaws/cj/types"
)
Expand Down Expand Up @@ -70,7 +72,8 @@ func mpname() string {
second := seconds[rand.Intn(len(seconds))]
mp[0] = []byte(strings.ToUpper(first))[0]
mp[1] = []byte(strings.ToUpper(second))[0]
return fmt.Sprintf("%s: %s %s Multiplayer", string(mp), strings.Title(first), strings.Title(second))
title := cases.Title(language.English)
return fmt.Sprintf("%s: %s %s Multiplayer", string(mp), title.String(first), title.String(second))
}

func (cm *CommandManager) commandMP(
Expand Down
4 changes: 2 additions & 2 deletions bot/commands/cmd_mytop.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func (cm *CommandManager) commandMyTop(
cm.sendThinkingResponse(interaction)
rank, err := cm.Storage.GetUserRank(interaction.Member.User.ID)
if err != nil {
cm.editOriginalResponse(interaction, fmt.Sprintf(errors.Wrap(err, "failed to get user's rank").Error()))
cm.editOriginalResponse(interaction, fmt.Sprint(errors.Wrap(err, "failed to get user's rank").Error()))
return
}
messageCount, err := cm.Storage.GetUserMessageCount(interaction.Member.User.ID)
if err != nil {
cm.editOriginalResponse(interaction, fmt.Sprintf(errors.Wrap(err, "failed to get user's message count").Error()))
cm.editOriginalResponse(interaction, fmt.Sprint(errors.Wrap(err, "failed to get user's message count").Error()))
return
}

Expand Down
8 changes: 4 additions & 4 deletions bot/commands/cmd_rep.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (cm *CommandManager) commandRep(
// Only post emoji that we have access to
func validateEmoji(input string, serverEmoji []*discordgo.Emoji) bool {
isValid := discordemojimap.ContainsEmoji(input)
if isValid == false {
if !isValid {
for _, v := range serverEmoji {
if v.MessageFormat() == input {
return true
Expand Down Expand Up @@ -75,7 +75,7 @@ func FormatUserReactions(reactions *[]storage.ReactionCounter, author *discordgo
break
}
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
Name: fmt.Sprintf("%s", reaction.Reaction),
Name: fmt.Sprintf("%s\u200b", reaction.Reaction),
Value: fmt.Sprintf("%dx", reaction.Counter),
Inline: true,
})
Expand All @@ -86,8 +86,8 @@ func FormatUserReactions(reactions *[]storage.ReactionCounter, author *discordgo
// fields (with 1 and 3 fields the formatting is fine)
if len(*reactions)%3 == 2 {
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
Name: "€", // Note: the content of this seemingly empty string is u0080
Value: "€", // Note: the content of this seemingly empty string is u0080
Name: "\u0080", // Note: the content of this seemingly empty string is u0080
Value: "\u0080", // Note: the content of this seemingly empty string is u0080
Inline: true,
})
}
Expand Down
5 changes: 4 additions & 1 deletion bot/commands/cmd_rpname.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"

"github.com/bwmarrin/discordgo"
"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/Southclaws/cj/types"
)
Expand Down Expand Up @@ -76,7 +78,8 @@ func rpname() string {
second := rpseconds[rand.Intn(len(rpseconds))]
mp[0] = []byte(strings.ToUpper(first))[0]
mp[1] = []byte(strings.ToUpper(second))[0]
return fmt.Sprintf("%s: %s %s Roleplay", string(mp), strings.Title(first), strings.Title(second))
title := cases.Title(language.English)
return fmt.Sprintf("%s: %s %s Roleplay", string(mp), title.String(first), title.String(second))
}

func (cm *CommandManager) commandRP(
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,
})
}