Skip to content

Commit

Permalink
Updated the API to work with latest discordgo.
Browse files Browse the repository at this point in the history
Discord API was updated to stop using username & password for auth
and bruxism broke due to the change. Fixed the API and upgraded
dependencies.
  • Loading branch information
Akshay committed Jun 3, 2022
1 parent a6739bc commit e6c41e6
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 43 deletions.
14 changes: 9 additions & 5 deletions discord.go
Expand Up @@ -192,7 +192,7 @@ func (m *DiscordMessage) ParseCommand(prefix string) (string, []string, bool) {

// Discord is a Service provider for Discord.
type Discord struct {
args []interface{}
token string
messageChan chan Message

// The first session, used to send messages (and maintain backwards compatibility).
Expand All @@ -203,9 +203,13 @@ type Discord struct {
}

// NewDiscord creates a new discord service.
func NewDiscord(args ...interface{}) *Discord {
// If the token is for a bot, it must be prefixed with "Bot "
// e.g. "Bot ..."
// Or if it is an OAuth2 token, it must be prefixed with "Bearer "
// e.g. "Bearer ..."
func NewDiscord(token string) *Discord {
return &Discord{
args: args,
token: token,
messageChan: make(chan Message, 200),
}
}
Expand Down Expand Up @@ -294,7 +298,7 @@ func (d *Discord) Name() string {

// Open opens the service and returns a channel which all messages will be sent on.
func (d *Discord) Open() (<-chan Message, error) {
gateway, err := discordgo.New(d.args...)
gateway, err := discordgo.New(d.token)
if err != nil {
return nil, err
}
Expand All @@ -310,7 +314,7 @@ func (d *Discord) Open() (<-chan Message, error) {
wg := sync.WaitGroup{}
for i := 0; i < s.Shards; i++ {
log.Printf("%s opening shard %d\n", d.Name(), i+1)
session, err := discordgo.New(d.args...)
session, err := discordgo.New(d.token)
if err != nil {
return nil, err
}
Expand Down
20 changes: 9 additions & 11 deletions go.mod
@@ -1,27 +1,25 @@
module github.com/iopred/bruxism

require (
cloud.google.com/go/compute v1.1.0 // indirect
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect
github.com/atotto/clipboard v0.1.4
github.com/bwmarrin/discordgo v0.23.2
github.com/bwmarrin/discordgo v0.25.0
github.com/dustin/go-humanize v1.0.0
github.com/fluffle/goirc v1.1.1
github.com/fluffle/goirc v1.2.0
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/iopred/comicgen v0.0.0-20201007025231-1d7f3d63a039
github.com/lithammer/fuzzysearch v1.1.3
github.com/nlopes/slack v0.6.0
golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect
golang.org/x/net v0.0.0-20220531201128-c960675eff93 // indirect
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401
gonum.org/v1/netlib v0.0.0-20210927171344-7274ea1d1842 // indirect
gonum.org/v1/plot v0.10.0
google.golang.org/api v0.66.0
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/api v0.81.0
google.golang.org/genproto v0.0.0-20220531173845-685668d2de03 // indirect
google.golang.org/grpc v1.47.0 // indirect
)

go 1.14

0 comments on commit e6c41e6

Please sign in to comment.