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

V0.1.0 #5

Merged
merged 5 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions .github/workflows/task-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -51,7 +51,7 @@
"dockerLabels": null,
"systemControls": null,
"privileged": null,
"name": "AmongUsHelper"
"name": "AmongUsEvents"
}
],
"placementConstraints": [],
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).<br /><br />
<div style="text-align:center"><img src="https://i.imgur.com/xmKToMd.png" width="500" /></div><br /><br />
Expand All @@ -7,7 +7,7 @@ A discord bot for organizing and planning among us games. This bot was born out

Visit and authorize the bot to your discord server: <br />

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.

Expand Down
4 changes: 2 additions & 2 deletions amongusevents/amongusevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
54 changes: 36 additions & 18 deletions amongushandlers/amongushandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package amongushandlers

import (
"fmt"
"net/url"
"strings"

"github.com/bwmarrin/discordgo"
"github.com/cbyst/AmongUsHelper/amongusevents"
"github.com/cbyst/AmongUsEvents/amongusevents"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
Expand All @@ -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) {
Expand Down Expand Up @@ -80,9 +91,13 @@ 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 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)))
}
}
}
Expand All @@ -93,24 +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 "), "\"")

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"))
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/cbyst/AmongUsHelper
module github.com/cbyst/AmongUsEvents

go 1.15

Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +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/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=
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand All @@ -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
Expand Down