Skip to content

Commit

Permalink
Merge branch 'master' into patch/role-subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 authored Aug 18, 2023
2 parents b133833 + 6d891ab commit 05892a7
Show file tree
Hide file tree
Showing 179 changed files with 3,287 additions and 1,247 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
.env
go.work
go.work.sum
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func main() {
panic(err)
}
// connect to the gateway
if err = client.Open(context.TODO()); err != nil {
if err = client.OpenGateway(context.TODO()); err != nil {
panic(err)
}

Expand Down Expand Up @@ -178,3 +178,7 @@ 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.

## Supported by Jetbrains

<a href="https://www.jetbrains.com/community/opensource" target="_blank" title="Jetbrain Open Source Community Support"><img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="Jetbrain Open Source Community Support" width="400px">
5 changes: 3 additions & 2 deletions _examples/application_commands/gateway/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"os/signal"
"syscall"

"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
)

var (
Expand Down
7 changes: 4 additions & 3 deletions _examples/application_commands/http/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"os/signal"
"syscall"

"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
"github.com/oasisprotocol/curve25519-voi/primitives/ed25519"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/httpserver"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
"github.com/oasisprotocol/curve25519-voi/primitives/ed25519"
)

var (
Expand Down
16 changes: 7 additions & 9 deletions _examples/application_commands/http/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ module github.com/disgoorg/disgo/_examples/application_commands/http

go 1.18

replace github.com/disgoorg/disgo => ../../../

require (
github.com/disgoorg/disgo v0.11.5
github.com/disgoorg/log v1.2.0
github.com/disgoorg/disgo v0.16.8
github.com/disgoorg/log v1.2.1
github.com/disgoorg/snowflake/v2 v2.0.1
github.com/oasisprotocol/curve25519-voi v0.0.0-20220317090546-adb2f9614b17
github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce
)

require (
github.com/disgoorg/json v1.0.0 // indirect
github.com/disgoorg/json v1.1.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b // indirect
golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e // indirect
golang.org/x/exp v0.0.0-20220325121720-054d8573a5d8 // indirect
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect
golang.org/x/sys v0.11.0 // indirect
)
32 changes: 14 additions & 18 deletions _examples/application_commands/http/go.sum
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/disgoorg/json v1.0.0 h1:kDhSM661fgIuNoZF3BO5/odaR5NSq80AWb937DH+Pdo=
github.com/disgoorg/json v1.0.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
github.com/disgoorg/log v1.2.0 h1:sqlXnu/ZKAlIlHV9IO+dbMto7/hCQ474vlIdMWk8QKo=
github.com/disgoorg/log v1.2.0/go.mod h1:3x1KDG6DI1CE2pDwi3qlwT3wlXpeHW/5rVay+1qDqOo=
github.com/disgoorg/disgo v0.16.8 h1:tvUeX+3Iu8U6koDc8RAgcQadRciWJwsI95Y7edHqq2g=
github.com/disgoorg/disgo v0.16.8/go.mod h1:5fsaUpfu6Yv0p+PfmsAeQkV395KQskVu/d1bdq8vsNI=
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=
github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
github.com/disgoorg/log v1.2.1 h1:kZYAWkUBcGy4LbZcgYtgYu49xNVLy+xG5Uq3yz5VVQs=
github.com/disgoorg/log v1.2.1/go.mod h1:hhQWYTFTnIGzAuFPZyXJEi11IBm9wq+/TVZt/FEwX0o=
github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0=
github.com/disgoorg/snowflake/v2 v2.0.1/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/oasisprotocol/curve25519-voi v0.0.0-20220317090546-adb2f9614b17 h1:pxR+aWfo+famermIZvD+SiDQ3qmF7Iy2VPZuEsKTMtA=
github.com/oasisprotocol/curve25519-voi v0.0.0-20220317090546-adb2f9614b17/go.mod h1:WUcXjUd98qaCVFb6j8Xc87MsKeMCXDu9Nk8JRJ9SeC8=
github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce h1:/pEpMk55wH0X+E5zedGEMOdLuWmV8P4+4W3+LZaM6kg=
github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b h1:qYTY2tN72LhgDj2rtWG+LI6TXFl2ygFQQ4YezfVaGQE=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e h1:VvfwVmMH40bpMeizC9/K7ipM5Qjucuu16RWfneFPyhQ=
golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20220325121720-054d8573a5d8 h1:Xt4/LzbTwfocTk9ZLEu4onjeFucl88iW+v4j4PWbQuE=
golang.org/x/exp v0.0.0-20220325121720-054d8573a5d8/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
5 changes: 3 additions & 2 deletions _examples/application_commands/localization/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"os/signal"
"syscall"

"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
)

var (
Expand Down
7 changes: 4 additions & 3 deletions _examples/auto_moderation/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"syscall"
"time"

"github.com/disgoorg/json"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/json"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion _examples/components/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/events"

"github.com/disgoorg/log"

"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/log"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions _examples/custom_cache/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"syscall"
"time"

"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions _examples/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (
"syscall"
"time"

"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/disgo/voice"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion _examples/guild_scheduled_events/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"syscall"
"time"

"github.com/disgoorg/log"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/log"
)

var (
Expand Down
143 changes: 143 additions & 0 deletions _examples/handler/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package main

import (
"context"
"os"
"os/signal"
"syscall"

"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/handler"
"github.com/disgoorg/disgo/handler/middleware"
)

var (
token = os.Getenv("disgo_token")
guildID = snowflake.GetEnv("disgo_guild_id")

commands = []discord.ApplicationCommandCreate{
discord.SlashCommandCreate{
Name: "ping",
Description: "Replies with pong",
},
discord.SlashCommandCreate{
Name: "test",
Description: "Replies with test",
Options: []discord.ApplicationCommandOption{
discord.ApplicationCommandOptionSubCommandGroup{
Name: "idk",
Description: "Group command",
Options: []discord.ApplicationCommandOptionSubCommand{
{
Name: "sub",
Description: "Sub command",
},
},
},
discord.ApplicationCommandOptionSubCommandGroup{
Name: "idk2",
Description: "Group2 command",
Options: []discord.ApplicationCommandOptionSubCommand{
{
Name: "sub",
Description: "Sub command",
},
},
},
discord.ApplicationCommandOptionSubCommand{
Name: "sub2",
Description: "Sub2 command",
},
},
},
discord.SlashCommandCreate{
Name: "ping2",
Description: "Replies with pong2",
},
}
)

func main() {
log.SetLevel(log.LevelInfo)
log.Info("starting example...")
log.Infof("disgo version: %s", disgo.Version)

r := handler.New()
r.Use(middleware.Logger)
r.Group(func(r handler.Router) {
r.Use(middleware.Print("group1"))
r.Route("/test", func(r handler.Router) {
r.Command("/sub2", handleContent("/test/sub2"))
r.Route("/{group}", func(r handler.Router) {
r.Command("/sub", handleVariableContent)
})
})
})
r.Group(func(r handler.Router) {
r.Use(middleware.Print("group2"))
r.Command("/ping", handlePing)
r.Command("/ping2", handleContent("pong2"))
r.Component("button1/{data}", handleComponent)
})
r.NotFound(handleNotFound)

client, err := disgo.New(token,
bot.WithDefaultGateway(),
bot.WithEventListeners(r),
)
if err != nil {
log.Fatal("error while building bot: ", err)
}

if err = handler.SyncCommands(client, commands, []snowflake.ID{guildID}); err != nil {
log.Fatal("error while syncing commands: ", err)
}

defer client.Close(context.TODO())

if err = client.OpenGateway(context.TODO()); err != nil {
log.Fatal("error while connecting to gateway: ", err)
}

log.Info("example is now running. Press CTRL-C to exit.")
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s
}

func handleContent(content string) handler.CommandHandler {
return func(event *handler.CommandEvent) error {
return event.CreateMessage(discord.MessageCreate{Content: content})
}
}

func handleVariableContent(event *handler.CommandEvent) error {
group := event.Variables["group"]
return event.CreateMessage(discord.MessageCreate{Content: "group: " + group})
}

func handlePing(event *handler.CommandEvent) error {
return event.CreateMessage(discord.MessageCreate{
Content: "pong",
Components: []discord.ContainerComponent{
discord.ActionRowComponent{
discord.NewPrimaryButton("button1", "button1/testData"),
},
},
})
}

func handleComponent(event *handler.ComponentEvent) error {
data := event.Variables["data"]
return event.CreateMessage(discord.MessageCreate{Content: "component: " + data})
}

func handleNotFound(event *events.InteractionCreate) error {
return event.Respond(discord.InteractionResponseTypeCreateMessage, discord.MessageCreate{Content: "not found"})
}
5 changes: 3 additions & 2 deletions _examples/listening_events/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"os/signal"
"syscall"

"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion _examples/message_collector/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"

"github.com/disgoorg/log"

"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/log"
)

var (
Expand Down
Loading

0 comments on commit 05892a7

Please sign in to comment.