Skip to content

Commit

Permalink
Reverting role changes and added help message for unprivileged bot ac…
Browse files Browse the repository at this point in the history
…cess
  • Loading branch information
cByst committed Nov 21, 2020
1 parent 18c5838 commit 7dee67c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ Visit and authorize the bot to your discord server: <br />

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.<br />
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.<br />

## 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

Expand Down
36 changes: 19 additions & 17 deletions amongushandlers/amongushandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit 7dee67c

Please sign in to comment.