Skip to content

Commit

Permalink
update disgo version
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Oct 1, 2024
1 parent 303f1da commit facce2c
Show file tree
Hide file tree
Showing 26 changed files with 255 additions and 294 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ ij_smart_tabs = false
ij_visual_guides = none
ij_wrap_on_typing = false

[{*.go, *.go2}]
[{*.yaml,*.yml}]
indent_size = 2

[{*.go,*.go2}]
indent_style = tab
ij_continuation_indent_size = 4
ij_go_add_leading_space_to_comments = false
Expand Down
82 changes: 41 additions & 41 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
name: Docker

on:
push:
branches:
- master
tags:
- v*
pull_request:
push:
branches:
- master
tags:
- v*
pull_request:

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/disgoorg/disgo-butler
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha,prefix=
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/disgoorg/disgo-butler
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha,prefix=
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./cmd/Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
push: true
build-args: VERSION=${{ steps.meta.outputs.version }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./cmd/Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
push: true
build-args: VERSION=${{ steps.meta.outputs.version }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.23

- name: go build
run: go build cmd/main.go
Expand Down
8 changes: 4 additions & 4 deletions cmd/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
FROM golang:1.19-alpine AS build

ARG VERSION=dev
FROM golang:1.23-alpine AS build

WORKDIR /build

Expand All @@ -10,7 +8,9 @@ RUN go mod download

COPY . .

RUN CGO_ENABLED=0 go build -ldflags="-X 'main.version=${VERSION}'-w -s" -o bot cmd/main.go
ARG VERSION=dev

RUN CGO_ENABLED=0 go build -ldflags="-X 'main.version=${VERSION}'-w -s" -o bot main.go

FROM alpine

Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@ Contributions are welcomed but for bigger changes we recommend first reaching ou

## License

Distributed under the [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/disgoorg/disgo/blob/master/LICENSE)
. See LICENSE for more information.



Distributed under the [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE). See `LICENSE`for more information.
9 changes: 7 additions & 2 deletions butler/butler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (b *Butler) SetupBot(r handler.Router) {
httpserver.WithAddress(b.Config.Interactions.Address),
httpserver.WithURL(b.Config.Interactions.URL),
),
bot.WithLogger(b.Logger),
); err != nil {
b.Logger.Errorf("Failed to start bot: %s", err)
}
Expand Down Expand Up @@ -218,7 +217,13 @@ func (b *Butler) UpdateContributorRoles() error {
continue
}

session := newSession(contributor)
session := oauth2.Session{
AccessToken: contributor.AccessToken,
RefreshToken: contributor.RefreshToken,
Scopes: contributor.Scopes,
TokenType: contributor.TokenType,
Expiration: contributor.Expiration,
}
if _, err = b.OAuth2.UpdateApplicationRoleConnection(session, b.Client.ApplicationID(), discord.ApplicationRoleConnectionUpdate{
Metadata: &metadata,
}); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions butler/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"errors"
"os"

"github.com/disgoorg/disgo-butler/db"
"github.com/disgoorg/disgo-butler/mod_mail"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo-butler/db"
"github.com/disgoorg/disgo-butler/mod_mail"
)

func LoadConfig() (*Config, error) {
Expand Down
2 changes: 1 addition & 1 deletion butler/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func GetDocsEmbed(pkg doc.Package, query string, expandSignature bool, expandCom

options = append(options, discord.NewStringSelectMenuOption("delete", "delete").WithEmoji(discord.ComponentEmoji{Name: "❌"}))

return embed, discord.NewStringSelectMenu("docs_action", "action", options...)
return embed, discord.NewStringSelectMenu("/docs_action", "action", options...)
}

func EmbedFromPackage(pkg doc.Package, expandComment bool, expandExamples bool) (discord.Embed, bool, bool) {
Expand Down
54 changes: 0 additions & 54 deletions butler/session.go

This file was deleted.

5 changes: 3 additions & 2 deletions commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"fmt"

"github.com/disgoorg/disgo-butler/butler"
"github.com/disgoorg/disgo-butler/common"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/handler"
"golang.org/x/exp/slices"

"github.com/disgoorg/disgo-butler/butler"
"github.com/disgoorg/disgo-butler/common"
)

var configCommand = discord.SlashCommandCreate{
Expand Down
18 changes: 10 additions & 8 deletions commands/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package commands

import (
"context"
"errors"
"fmt"
"sort"
"strings"
"time"

"github.com/disgoorg/disgo-butler/butler"
"github.com/disgoorg/disgo-butler/common"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/handler"
"github.com/hhhapz/doc"
"github.com/lithammer/fuzzysearch/fuzzy"

"github.com/disgoorg/disgo-butler/butler"
"github.com/disgoorg/disgo-butler/common"
)

var docsCommand = discord.SlashCommandCreate{
Expand Down Expand Up @@ -64,7 +66,7 @@ func HandleDocsAutocomplete(b *butler.Butler) handler.AutocompleteHandler {
if option, ok := e.Data.Option("query"); ok && option.Focused {
return handleQueryAutocomplete(b, e, e.Data.String("module"), e.Data.String("query"))
}
return e.Result(nil)
return e.AutocompleteResult(nil)
}
}

Expand Down Expand Up @@ -99,19 +101,19 @@ func handleModuleAutocomplete(b *butler.Butler, e *handler.AutocompleteEvent, mo
}
})
}
return e.Result(replaceAliases(b, choices))
return e.AutocompleteResult(replaceAliases(b, choices))
}

func handleQueryAutocomplete(b *butler.Butler, e *handler.AutocompleteEvent, module string, query string) error {
ex, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
pkg, err := b.DocClient.Search(ex, module)
if err == doc.InvalidStatusError(404) {
return e.Result([]discord.AutocompleteChoice{
if errors.Is(err, doc.InvalidStatusError(404)) {
return e.AutocompleteResult([]discord.AutocompleteChoice{
discord.AutocompleteChoiceString{Name: "module not found", Value: ""},
})
} else if err != nil {
return e.Result(nil)
return e.AutocompleteResult(nil)
}
choices := make([]discord.AutocompleteChoiceString, 0, 25)
if query == "" {
Expand All @@ -136,7 +138,7 @@ func handleQueryAutocomplete(b *butler.Butler, e *handler.AutocompleteEvent, mod
}
choices = append(choices, discord.AutocompleteChoiceString{Name: rank.Target, Value: rank.Target})
}
return e.Result(replaceAliases(b, choices))
return e.AutocompleteResult(replaceAliases(b, choices))
}

func replaceAliases(b *butler.Butler, choices []discord.AutocompleteChoiceString) []discord.AutocompleteChoice {
Expand Down
13 changes: 7 additions & 6 deletions commands/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"regexp"
"strings"

"github.com/disgoorg/disgo-butler/butler"
"github.com/disgoorg/disgo-butler/common"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/handler"
"github.com/disgoorg/json"
"github.com/disgoorg/snowflake/v2"
gopiston "github.com/milindmadhukar/go-piston"

"github.com/disgoorg/disgo-butler/butler"
"github.com/disgoorg/disgo-butler/common"
)

var discordCodeblockRegex = regexp.MustCompile(`(?s)\x60\x60\x60(?P<language>\w+)\n(?P<code>.+)\x60\x60\x60`)
Expand All @@ -24,11 +25,11 @@ var evalCommand = discord.MessageCommandCreate{
func HandleEval(b *butler.Butler) handler.CommandHandler {
return func(e *handler.CommandEvent) error {
message := e.MessageCommandInteractionData().TargetMessage()
return Eval(b, e.Client(), e.BaseInteraction, e.Respond, message.Content, message.ID, false)
return Eval(b, e.Client(), e.ApplicationCommandInteraction, e.Respond, message.Content, message.ID, false)
}
}

func Eval(b *butler.Butler, client bot.Client, i discord.BaseInteraction, r events.InteractionResponderFunc, content string, messageID snowflake.ID, update bool) error {
func Eval(b *butler.Butler, client bot.Client, i discord.Interaction, r events.InteractionResponderFunc, content string, messageID snowflake.ID, update bool) error {
runtimes, err := b.PistonClient.GetRuntimes()
if err != nil {
return common.RespondErr(r, err)
Expand Down Expand Up @@ -112,10 +113,10 @@ runtimeLoop:
Embeds: &[]discord.Embed{output},
Components: &[]discord.ContainerComponent{
discord.ActionRowComponent{
discord.NewPrimaryButton("", "eval/rerun/"+messageID.String()).WithEmoji(discord.ComponentEmoji{
discord.NewPrimaryButton("", "/eval/rerun/"+messageID.String()).WithEmoji(discord.ComponentEmoji{
Name: "🔁",
}),
discord.NewDangerButton("", "eval/delete").WithEmoji(discord.ComponentEmoji{
discord.NewDangerButton("", "/eval/delete").WithEmoji(discord.ComponentEmoji{
Name: "🗑️",
}),
},
Expand Down
5 changes: 3 additions & 2 deletions commands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package commands

import (
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo-butler/butler"
"github.com/disgoorg/disgo-butler/common"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/handler"

"github.com/disgoorg/disgo-butler/butler"
"github.com/disgoorg/disgo-butler/common"
)

var infoCommand = discord.SlashCommandCreate{
Expand Down
3 changes: 2 additions & 1 deletion commands/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package commands
import (
"time"

"github.com/disgoorg/disgo-butler/common"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/handler"
"github.com/disgoorg/disgo/rest"

"github.com/disgoorg/disgo-butler/common"
)

var pingCommand = discord.SlashCommandCreate{
Expand Down
Loading

0 comments on commit facce2c

Please sign in to comment.