Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dshoreman committed Jun 18, 2020
2 parents b5616d6 + 60e4c73 commit 2b9db52
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Expand Up @@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]


## [1.3.0] - 2020-06-18
### Added
* Quarantine role is now able to be configured per-guild

### Fixed
* Phrasing of quarantine errors now uses correct tense


## [1.2.1] - 2020-06-18
### Changed
* Message logs in console now include guild and channel names
Expand Down Expand Up @@ -48,7 +56,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Global permission checks - messages from members without Administrator are ignored


[Unreleased]: https://github.com/dshoreman/smegbot/compare/v1.2.1...develop
[Unreleased]: https://github.com/dshoreman/smegbot/compare/v1.3.0...develop
[1.3.0]: https://github.com/dshoreman/smegbot/compare/v1.2.1...v1.3.0
[1.2.1]: https://github.com/dshoreman/smegbot/compare/v1.2.0...v1.2.1
[1.2.0]: https://github.com/dshoreman/smegbot/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/dshoreman/smegbot/compare/v1.0.1...v1.1.0
Expand Down
2 changes: 1 addition & 1 deletion cli/helpers.go
Expand Up @@ -6,7 +6,7 @@ import (
)

// Version is the current Smegbot version
const Version = "1.2.1"
const Version = "1.3.0"

// PrintLogo prints the Smegbot logo with Version info
func PrintLogo() {
Expand Down
15 changes: 11 additions & 4 deletions commands/config.go
Expand Up @@ -12,24 +12,28 @@ import (
func listConfigValues(s *dg.Session, m *dg.MessageCreate) {
config.LoadGuild(m.GuildID)

joins, parts := config.Guild.JoinChannel, config.Guild.PartChannel
joins, parts, role := config.Guild.JoinChannel, config.Guild.PartChannel, config.Guild.QuarantineRole
if joins == "" {
joins = "Not set"
}
if parts == "" {
parts = "Not set"
}
if role == "" {
role = "undefined"
}

s.ChannelMessageSend(m.ChannelID, fmt.Sprintf(
"> \n> **Current configuration**:\n> \n> `joinChannel` - <#%s>\n> `partChannel` - <#%s>\n",
joins, parts))
"> \n> **Current configuration**:\n> \n> `joinChannel` - <#%s>\n> `partChannel` - <#%s>\n> \n> `quarantineRole` - <@&%s>\n",
joins, parts, role))
}

func setConfigOption(s *dg.Session, m *dg.MessageCreate) {
config.LoadGuild(m.GuildID)

// In this regex, @! is a bot mention, @& is a role mention, @ will be a normal member and # is a channel.
save, msg := false, "Nothing to save! Did you actually change anything? :person_facepalming:"
matched, _ := regexp.MatchString(`\.config (join|part)Channel <#[0-9]+>`, m.Content)
matched, _ := regexp.MatchString(`\.config (join|part|quarantine)(Channel|Role) <(#|@&)[0-9]+>`, m.Content)
if matched {
args := strings.Fields(m.Content)
if args[1] == "joinChannel" && config.Guild.JoinChannel != args[2] {
Expand All @@ -38,6 +42,9 @@ func setConfigOption(s *dg.Session, m *dg.MessageCreate) {
} else if args[1] == "partChannel" && config.Guild.PartChannel != args[2] {
config.Guild.PartChannel = args[2][2 : len(args[2])-1]
save = true
} else if args[1] == "quarantineRole" && config.Guild.QuarantineRole != args[2] {
config.Guild.QuarantineRole = args[2][3 : len(args[2])-1]
save = true
}
} else {
msg = "That's not a valid config command :slight_frown:"
Expand Down
11 changes: 8 additions & 3 deletions commands/quarantine.go
Expand Up @@ -4,10 +4,12 @@ import (
"fmt"

dg "github.com/bwmarrin/discordgo"
"github.com/dshoreman/smegbot/config"
"github.com/dshoreman/smegbot/util"
)

func nuke(s *dg.Session, m *dg.MessageCreate) {
config.LoadGuild(m.GuildID)
sinbin := quarantineRole(s, m.ChannelID, m.GuildID)
if sinbin != "" {
u := m.Mentions[0].ID
Expand Down Expand Up @@ -43,6 +45,9 @@ func restore(s *dg.Session, m *dg.MessageCreate) {

func quarantineRole(s *dg.Session, channelID string, guildID string) string {
roles, _ := s.GuildRoles(guildID)
if config.Guild.QuarantineRole != "" {
return config.Guild.QuarantineRole
}
for _, r := range roles {
if r.Name == "Quarantine" {
return r.ID
Expand Down Expand Up @@ -80,12 +85,12 @@ func restoreRoles(s *dg.Session, g string, c string, u string) {
}

func sendSuccessOrFail(s *dg.Session, channelID string, err error, mode string, target string) {
op, result := "adding", "now in Quarantine."
op, result := "add", "now in Quarantine."
if mode == "remove" {
op, result = "removing", "back out of Quarantine!"
op, result = "remove", "back out of Quarantine!"
}
if err != nil {
s.ChannelMessageSend(channelID, "Oops! Couldn't "+op+" the **@Quarantine** role.")
s.ChannelMessageSend(channelID, "Oops! Couldn't "+op+" the configured quarantine role. Check permissions!")
fmt.Println("\nError:\n", err)
return
}
Expand Down
2 changes: 2 additions & 0 deletions config/guilds.go
Expand Up @@ -8,6 +8,8 @@ import (
type GuildConfig struct {
JoinChannel string `json:"channels.join"`
PartChannel string `json:"channels.part"`

QuarantineRole string `json:"roles.quarantine"`
}

// Guild stores a guild's configuration
Expand Down

0 comments on commit 2b9db52

Please sign in to comment.