From 63f245aa44cf396ed324c2aedfc5064b32940b3e Mon Sep 17 00:00:00 2001 From: cByst Date: Fri, 13 Nov 2020 15:22:49 -0500 Subject: [PATCH 1/5] Fixed typo in log message --- amongushandlers/amongushandlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amongushandlers/amongushandlers.go b/amongushandlers/amongushandlers.go index 24bacaf..e8385a4 100644 --- a/amongushandlers/amongushandlers.go +++ b/amongushandlers/amongushandlers.go @@ -82,7 +82,7 @@ func messageReactionAddHandle(s *discordgo.Session, m *discordgo.MessageReaction } else { err = s.MessageReactionRemove(m.MessageReaction.ChannelID, m.MessageReaction.MessageID, m.MessageReaction.Emoji.Name, m.MessageReaction.UserID) if err != nil { - log.Error(errors.WithMessage(err, fmt.Sprintf("Error removing unsupported reactio in message reaction add handler for %s reaction event", m.MessageReaction.Emoji.Name))) + log.Error(errors.WithMessage(err, fmt.Sprintf("Error removing unsupported reaction in message reaction add handler for %s reaction event", m.MessageReaction.Emoji.Name))) } } } From ebb230654a74d75d05c90699bee31f7a63b09d20 Mon Sep 17 00:00:00 2001 From: cByst Date: Fri, 20 Nov 2020 22:44:04 -0500 Subject: [PATCH 2/5] Fixed unsupported reaction removal to work with custom guild emojis and added additional logging --- amongushandlers/amongushandlers.go | 18 +++++++++++++++++- main.go | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/amongushandlers/amongushandlers.go b/amongushandlers/amongushandlers.go index e8385a4..27ed7fd 100644 --- a/amongushandlers/amongushandlers.go +++ b/amongushandlers/amongushandlers.go @@ -2,6 +2,7 @@ package amongushandlers import ( "fmt" + "net/url" "strings" "github.com/bwmarrin/discordgo" @@ -15,6 +16,16 @@ func AttachHandlers(discordSession *discordgo.Session) { discordSession.AddHandler(commandHandler) discordSession.AddHandler(messageReactionAddHandle) discordSession.AddHandler(messageReactionRemoveHandle) + discordSession.AddHandler(serverBotAddHandler) + discordSession.AddHandler(serverBotRemoveHandler) +} + +func serverBotAddHandler(s *discordgo.Session, g *discordgo.GuildCreate) { + log.Infof("Discord Server %s added the AmongUsEvents bot", g.Name) +} + +func serverBotRemoveHandler(s *discordgo.Session, g *discordgo.GuildDelete) { + log.Infof("Discord Server %s removed AmongUsEvents bot", g.Name) } func messageReactionRemoveHandle(s *discordgo.Session, m *discordgo.MessageReactionRemove) { @@ -80,7 +91,11 @@ func messageReactionAddHandle(s *discordgo.Session, m *discordgo.MessageReaction log.Error(errors.WithMessage(err, "Error resyncing event state in reaction add handler for change time reaction event")) } } else { - err = s.MessageReactionRemove(m.MessageReaction.ChannelID, m.MessageReaction.MessageID, m.MessageReaction.Emoji.Name, m.MessageReaction.UserID) + reactionID := m.MessageReaction.Emoji.Name + if m.MessageReaction.Emoji.ID != "" { + reactionID = url.QueryEscape(fmt.Sprintf("<:%s:%s", m.MessageReaction.Emoji.Name, m.MessageReaction.Emoji.ID)) + } + err = s.MessageReactionRemove(m.MessageReaction.ChannelID, m.MessageReaction.MessageID, reactionID, m.MessageReaction.UserID) if err != nil { log.Error(errors.WithMessage(err, fmt.Sprintf("Error removing unsupported reaction in message reaction add handler for %s reaction event", m.MessageReaction.Emoji.Name))) } @@ -108,6 +123,7 @@ func commandHandler(s *discordgo.Session, m *discordgo.MessageCreate) { if strings.HasPrefix(m.Content, "!CreateAmongEvent ") { title := strings.Trim(strings.TrimPrefix(m.Content, "!CreateAmongEvent "), "\"") + log.Infof("Creating new among event with title: %s for user: %s", title, m.Author.Username) err = amongusevents.CreateEvent(s, title, m.ChannelID) if err != nil { log.Error(errors.WithMessage(err, "Error creating event in create event command handler")) diff --git a/main.go b/main.go index 37c4299..eeaa4b2 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ func main() { if *logDebug { log.SetLevel(log.DebugLevel) } else { - log.SetLevel(log.WarnLevel) + log.SetLevel(log.InfoLevel) } // Check for required token From f39b60c519d116757078886395baf45f562b663e Mon Sep 17 00:00:00 2001 From: cByst Date: Fri, 20 Nov 2020 23:23:49 -0500 Subject: [PATCH 3/5] Renamed bot to AmongUsEvents --- .github/workflows/aws.yml | 6 +++--- .github/workflows/task-definition.json | 8 ++++---- Dockerfile | 6 +++--- README.md | 10 ++++------ amongusevents/amongusevents.go | 4 ++-- amongushandlers/amongushandlers.go | 2 +- go.mod | 2 +- go.sum | 2 ++ main.go | 4 ++-- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/aws.yml b/.github/workflows/aws.yml index c1553bc..895bd5d 100644 --- a/.github/workflows/aws.yml +++ b/.github/workflows/aws.yml @@ -53,7 +53,7 @@ jobs: id: build-image env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: amongushelper + ECR_REPOSITORY: amongusevents IMAGE_TAG: latest run: | # Build a docker container and @@ -78,13 +78,13 @@ jobs: uses: aws-actions/amazon-ecs-render-task-definition@v1 with: task-definition: ./.github/workflows/task-definition.json - container-name: AmongUsHelper + container-name: AmongUsEvents image: ${{ steps.build-image.outputs.image }} - name: Deploy Amazon ECS task definition uses: aws-actions/amazon-ecs-deploy-task-definition@v1 with: task-definition: ${{ steps.task-def.outputs.task-definition }} - service: AmongUsHelperService + service: AmongUsEventsService cluster: AmongUsBot wait-for-service-stability: true diff --git a/.github/workflows/task-definition.json b/.github/workflows/task-definition.json index 7fe445a..e08f468 100644 --- a/.github/workflows/task-definition.json +++ b/.github/workflows/task-definition.json @@ -9,7 +9,7 @@ "logDriver": "awslogs", "secretOptions": null, "options": { - "awslogs-group": "/ecs/AmongUsHelperTask", + "awslogs-group": "/ecs/AmongUsEventsTask", "awslogs-region": "us-east-1", "awslogs-stream-prefix": "ecs" } @@ -51,7 +51,7 @@ "dockerLabels": null, "systemControls": null, "privileged": null, - "name": "AmongUsHelper" + "name": "AmongUsEvents" } ], "placementConstraints": [], @@ -61,8 +61,8 @@ "EC2", "FARGATE" ], - "taskDefinitionArn": "arn:aws:ecs:us-east-1:{REPLACE.AccountId}:task-definition/AmongUsHelperTask:4", - "family": "AmongUsHelperTask", + "taskDefinitionArn": "arn:aws:ecs:us-east-1:{REPLACE.AccountId}:task-definition/AmongUsEventsTask:1", + "family": "AmongUsEventsTask", "requiresAttributes": [ { "targetId": null, diff --git a/Dockerfile b/Dockerfile index ee61a28..118e301 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ FROM golang:alpine as builder -WORKDIR /amongushelper +WORKDIR /amongusevents COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /amongushelper/main +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /amongusevents/main FROM scratch -COPY --chown=65534:0 --from=builder /amongushelper/main / +COPY --chown=65534:0 --from=builder /amongusevents/main / COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt diff --git a/README.md b/README.md index 84b09ba..edc577a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Among Us Helper - Discord Bot +# Among Us Events - Discord Bot A discord bot for organizing and planning among us games. This bot was born out of the pain of trying to organize weekly discord games with a group of friends. The bot allows the organizer to create an event in a given discord channel. Users of this discord server can rsvp to the event with 3 options (accept,decline,change time request).



@@ -7,15 +7,13 @@ A discord bot for organizing and planning among us games. This bot was born out Visit and authorize the bot to your discord server:
- https://discord.com/oauth2/authorize?client_id=758468803583279114&scope=bot&permissions=8 + https://discord.com/oauth2/authorize?client_id=779556729343049729&scope=bot&permissions=485440 -Once the bot is authorized and added to your discord server you will need to create a discord role called ``amongusbot`` the privileges of this role do not matter so you can make them as you see fit. - -This role will need to be added to any user you would like to command the bot.
+Once the bot is authorized and added to your discord server you will need to add the server role ``AmongUs - Events`` to any user who wishes to command the bot.
## Usage -The bot responds to one main command by any user with the ``amongusbot`` role. This command creates a new event in the channel the users runs it in: +The bot responds to one main command by any user with the ``AmongUs - Events`` role. This command creates a new event in the channel the users runs it in: !CreateAmongEvent TITLE OF EVENT HERE diff --git a/amongusevents/amongusevents.go b/amongusevents/amongusevents.go index 7ef867f..f015cc7 100644 --- a/amongusevents/amongusevents.go +++ b/amongusevents/amongusevents.go @@ -22,7 +22,7 @@ func CreateEvent(session *discordgo.Session, title string, channelID string) err Title: title, Color: 15105570, Author: &discordgo.MessageEmbedAuthor{ - Name: "Among Us Helper Bot", + Name: "Among Us Events Bot", IconURL: "https://i.imgur.com/Mf4Rj0T.png", }, Description: "\u200B\n", @@ -136,7 +136,7 @@ func (s *amongUsEventState) updateEmbedMessageFromState(session *discordgo.Sessi Title: s.eventTitle, Color: 15105570, Author: &discordgo.MessageEmbedAuthor{ - Name: "Among Us Helper Bot", + Name: "Among Us Events Bot", IconURL: "https://i.imgur.com/Mf4Rj0T.png", }, Description: "\u200B\n", diff --git a/amongushandlers/amongushandlers.go b/amongushandlers/amongushandlers.go index 27ed7fd..54c2312 100644 --- a/amongushandlers/amongushandlers.go +++ b/amongushandlers/amongushandlers.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/bwmarrin/discordgo" - "github.com/cbyst/AmongUsHelper/amongusevents" + "github.com/cbyst/AmongUsEvents/amongusevents" "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) diff --git a/go.mod b/go.mod index 2bc12ce..5b04f0b 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/cbyst/AmongUsHelper +module github.com/cbyst/AmongUsEvents go 1.15 diff --git a/go.sum b/go.sum index 8fd75ed..1589eda 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/bwmarrin/discordgo v0.22.0 h1:uBxY1HmlVCsW1IuaPjpCGT6A2DBwRn0nvOguQIxDdFM= github.com/bwmarrin/discordgo v0.22.0/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M= +github.com/cbyst/AmongUsHelper v0.0.2 h1:nWblRJIC8f+F6g9fPJDtZgPLccC9cZm7QTt4KTeSpXo= +github.com/cbyst/AmongUsHelper v0.0.2/go.mod h1:BIz5A4VqB4MVO1z+mnhrjppQ606iSWLvf/wNJLl9n6Y= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= diff --git a/main.go b/main.go index eeaa4b2..8869131 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( "syscall" "github.com/bwmarrin/discordgo" - "github.com/cbyst/AmongUsHelper/amongushandlers" + "github.com/cbyst/AmongUsEvents/amongushandlers" "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -49,7 +49,7 @@ func main() { os.Exit(1) } - fmt.Println("Among Us Helper is now running. Press CTRL-C to exit.") + fmt.Println("Among Us Events is now running. Press CTRL-C to exit.") sc := make(chan os.Signal, 1) signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) <-sc From 18c583851c683c4c89d9b91fac037e77957166d5 Mon Sep 17 00:00:00 2001 From: cByst Date: Fri, 20 Nov 2020 23:26:38 -0500 Subject: [PATCH 4/5] Updated permission check to new role name that is created whent he bot is added --- amongushandlers/amongushandlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amongushandlers/amongushandlers.go b/amongushandlers/amongushandlers.go index 54c2312..da0bb32 100644 --- a/amongushandlers/amongushandlers.go +++ b/amongushandlers/amongushandlers.go @@ -159,7 +159,7 @@ func getAmongUsRoleID(s *discordgo.Session, guildID string) (string, error) { return "-1", err } for _, role := range roles { - if "amongusbot" == strings.ToLower(role.Name) { + if "AmongUs - Events" == strings.ToLower(role.Name) { return role.ID, nil } } From 7dee67c0968d9ac779d07d3136c13c253ce0b058 Mon Sep 17 00:00:00 2001 From: cByst Date: Sat, 21 Nov 2020 01:14:54 -0500 Subject: [PATCH 5/5] Reverting role changes and added help message for unprivileged bot access --- README.md | 6 +++-- amongushandlers/amongushandlers.go | 36 ++++++++++++++++-------------- go.sum | 5 +++-- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index edc577a..6e0c0f8 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,13 @@ Visit and authorize the bot to your discord server:
https://discord.com/oauth2/authorize?client_id=779556729343049729&scope=bot&permissions=485440 -Once the bot is authorized and added to your discord server you will need to add the server role ``AmongUs - Events`` to any user who wishes to command the bot.
+Once the bot is authorized and added to your discord server you will need to create a discord role called ``amongusbot`` the privileges of this role do not matter so you can make them as you see fit. + +This role will need to be added to any user you would like to command the bot.
## Usage -The bot responds to one main command by any user with the ``AmongUs - Events`` role. This command creates a new event in the channel the users runs it in: +The bot responds to one main command by any user with the ``amongusbot`` role. This command creates a new event in the channel the users runs it in: !CreateAmongEvent TITLE OF EVENT HERE diff --git a/amongushandlers/amongushandlers.go b/amongushandlers/amongushandlers.go index da0bb32..71dabfb 100644 --- a/amongushandlers/amongushandlers.go +++ b/amongushandlers/amongushandlers.go @@ -108,25 +108,27 @@ func commandHandler(s *discordgo.Session, m *discordgo.MessageCreate) { return } - // Check if user is privileged to command the bot - userIsPrivledged, err := isUserPrivleged(s, m.Author.ID, m.GuildID) - if err != nil { - log.Error(errors.WithMessage(err, "Issue checking if user is privileged in command handler")) - } - - // Ignore message if user is not privileged to command bot - if !userIsPrivledged { - return - } - // Check message for for command prefix to determine if the message is relevant to the bot if strings.HasPrefix(m.Content, "!CreateAmongEvent ") { - title := strings.Trim(strings.TrimPrefix(m.Content, "!CreateAmongEvent "), "\"") - - log.Infof("Creating new among event with title: %s for user: %s", title, m.Author.Username) - err = amongusevents.CreateEvent(s, title, m.ChannelID) + // Check if user is privileged to command the bot + userIsPrivledged, err := isUserPrivleged(s, m.Author.ID, m.GuildID) if err != nil { - log.Error(errors.WithMessage(err, "Error creating event in create event command handler")) + log.Error(errors.WithMessage(err, "Issue checking if user is privileged in command handler")) + } + + // Ignore message if user is not privileged to command bot + if !userIsPrivledged { + s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("<@%s> You do not have access to create Among Us Events. To create events you need the amongusbot role.", m.Author.ID)) + // tell users there not permissioned for this + return + } else { + title := strings.Trim(strings.TrimPrefix(m.Content, "!CreateAmongEvent "), "\"") + + log.Infof("Creating new among event with title: %s for user: %s", title, m.Author.Username) + err = amongusevents.CreateEvent(s, title, m.ChannelID) + if err != nil { + log.Error(errors.WithMessage(err, "Error creating event in create event command handler")) + } } } } @@ -159,7 +161,7 @@ func getAmongUsRoleID(s *discordgo.Session, guildID string) (string, error) { return "-1", err } for _, role := range roles { - if "AmongUs - Events" == strings.ToLower(role.Name) { + if "amongusbot" == strings.ToLower(role.Name) { return role.ID, nil } } diff --git a/go.sum b/go.sum index 1589eda..2ca13f4 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,16 @@ github.com/bwmarrin/discordgo v0.22.0 h1:uBxY1HmlVCsW1IuaPjpCGT6A2DBwRn0nvOguQIxDdFM= github.com/bwmarrin/discordgo v0.22.0/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M= -github.com/cbyst/AmongUsHelper v0.0.2 h1:nWblRJIC8f+F6g9fPJDtZgPLccC9cZm7QTt4KTeSpXo= -github.com/cbyst/AmongUsHelper v0.0.2/go.mod h1:BIz5A4VqB4MVO1z+mnhrjppQ606iSWLvf/wNJLl9n6Y= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=