-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Changed to ignore messages explicitly marked as "reposted" - Added ability to delete messages with specific reactions - Modified to ignore root and some domains by default - Added to add and remove domains into the list, and view domain list from Discord - Fixed typo
- Loading branch information
Showing
10 changed files
with
280 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package cmds | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/tpc3/DuckPolice/lib/config" | ||
"github.com/tpc3/DuckPolice/lib/db" | ||
"github.com/tpc3/DuckPolice/lib/embed" | ||
) | ||
|
||
const Domain = "domain" | ||
|
||
func DomainCmd(session *discordgo.Session, orgMsg *discordgo.MessageCreate, guild *config.Guild, message *string) { | ||
split := strings.SplitN(*message, " ", 2) | ||
if *message == "" { | ||
DomainUsage(session, orgMsg, guild, errors.New("not enough arguments")) | ||
} | ||
if (split[0] == "add" || split[0] == "del") && len(split) != 2 { | ||
DomainUsage(session, orgMsg, guild, errors.New("not enough arguments")) | ||
return | ||
} | ||
currentlist := config.CurrentConfig.Domain.YamlList | ||
currentmap := config.ListMap | ||
var list string | ||
var newlist []string | ||
switch split[0] { | ||
case "add": | ||
currentlist = append(currentlist, split[1]) | ||
currentmap[split[1]] = true | ||
domain := config.Domain{ | ||
Type: config.CurrentConfig.Domain.Type, | ||
YamlList: currentlist, | ||
} | ||
err := config.SaveGuild(guild, &domain) | ||
if err != nil { | ||
UnknownError(session, orgMsg, &guild.Lang, err) | ||
return | ||
} | ||
session.MessageReactionAdd(orgMsg.ChannelID, orgMsg.ID, "👍") | ||
case "del": | ||
newlist = RemoveElement(¤tlist, &split[1]) | ||
currentmap[split[1]] = false | ||
domain := config.Domain{ | ||
Type: config.CurrentConfig.Domain.Type, | ||
YamlList: newlist, | ||
} | ||
err := config.SaveGuild(guild, &domain) | ||
if err != nil { | ||
UnknownError(session, orgMsg, &guild.Lang, err) | ||
return | ||
} | ||
session.MessageReactionAdd(orgMsg.ChannelID, orgMsg.ID, "👍") | ||
case "list": | ||
for _, v := range currentlist { | ||
list += "- " + v + "\n" | ||
} | ||
embed := embed.NewEmbed(session, orgMsg) | ||
embed.Title = "Domain List" | ||
embed.Description = "```yaml\n" + list + "```" | ||
SendEmbed(session, orgMsg, embed) | ||
} | ||
err := db.SaveGuild(&orgMsg.GuildID, guild) | ||
if err != nil { | ||
UnknownError(session, orgMsg, &guild.Lang, err) | ||
return | ||
} | ||
} | ||
|
||
func RemoveElement(list *[]string, element *string) []string { | ||
currentlist := *list | ||
index := -1 | ||
for i, v := range currentlist { | ||
if v == *element { | ||
index = i | ||
break | ||
} | ||
} | ||
if index == -1 { | ||
return currentlist | ||
} | ||
return append(currentlist[:index], currentlist[index+1:]...) | ||
} | ||
|
||
func DomainUsage(session *discordgo.Session, orgMsg *discordgo.MessageCreate, guild *config.Guild, err error) { | ||
msg := embed.NewEmbed(session, orgMsg) | ||
if err != nil { | ||
msg.Title = config.Lang[guild.Lang].Error.Syntax | ||
msg.Description = err.Error() + "\n" | ||
msg.Color = embed.ColorPink | ||
} | ||
ReplyEmbed(session, orgMsg, msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package handler | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/tpc3/DuckPolice/lib/config" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func MessageReactionAdd(session *discordgo.Session, msgreact *discordgo.MessageReactionAdd) { | ||
msg, err := session.State.Message(msgreact.ChannelID, msgreact.MessageID) | ||
if err != nil { | ||
msg, err = session.ChannelMessage(msgreact.ChannelID, msgreact.MessageID) | ||
if err != nil { | ||
log.Panic("Failed to get channel message: ", err) | ||
} | ||
} | ||
|
||
if msgreact.Emoji.ID == "" && msgreact.Emoji.Name == "" { | ||
return | ||
} | ||
|
||
reactions, err := session.MessageReactions(msgreact.ChannelID, msgreact.MessageID, config.CurrentConfig.Delete.Trigger, 100, "", "") | ||
if err != nil { | ||
log.Panic("Failed to get msgreacts: ", err) | ||
} | ||
|
||
ReactionCheck(session, msgreact, msg, reactions) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/bwmarrin/discordgo" | ||
"github.com/tpc3/DuckPolice/lib/config" | ||
) | ||
|
||
func ReactionCheck(session *discordgo.Session, msgreact *discordgo.MessageReactionAdd, msg *discordgo.Message, reactions []*discordgo.User) { | ||
reacted := false | ||
for _, user := range reactions { | ||
if user.ID != session.State.User.ID { | ||
reacted = true | ||
} | ||
} | ||
|
||
if reacted && (msgreact.Emoji.ID == config.CurrentConfig.Delete.Trigger || msgreact.Emoji.Name == config.CurrentConfig.Delete.Trigger) { | ||
session.MessageReactionRemove(msgreact.ChannelID, msg.MessageReference.MessageID, config.CurrentConfig.Duplicate.React, session.State.User.ID) | ||
session.ChannelMessageDelete(msgreact.ChannelID, msgreact.MessageID) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters