add .moveto and .bringto commands

2023additions
Dallas Winger 2023-04-14 22:05:30 -04:00
parent 211c21c223
commit e8f401801c
No known key found for this signature in database
GPG Key ID: 59CE387CBF3FCA01
2 changed files with 92 additions and 0 deletions

View File

@ -80,6 +80,8 @@ func (c *Commands) RegisterHandlers() {
c.RegisterCommand("saveconfig", "Save Configuration to Disk", true, c.handleSaveConfig)
c.RegisterCommand("reloadconfig", "Reload Configuration", true, c.handleReloadConfig)
c.RegisterCommand("addrole", "Add a joinable role", true, c.handleAddCustomRole)
c.RegisterCommand("moveto", "Move a users message to another channel (deletes originals)", true, c.handleMoveto)
c.RegisterCommand("bringto", "Copy a users message to another channel (keeps originals) ", true, c.handleBringto)
}
func (c *Commands) ProcessCommand(s *discordgo.Session, m *discordgo.MessageCreate) error {

View File

@ -304,3 +304,93 @@ func (c *Commands) handleUnIgnoreUser(s *discordgo.Session, m *discordgo.Message
return nil
}
func (c *Commands) handleMoveto(s *discordgo.Session, m *discordgo.MessageCreate) error {
args := strings.Split(m.Content, " ")
if len(args) < 2 {
return errors.New("missing arg")
}
input := m.Content[strings.Index(m.Content, " "):len(m.Content)]
repliedTo, err := s.ChannelMessage(m.ChannelID, m.MessageReference.MessageID)
if err != nil {
return errors.New("error getting target message")
}
moveToId := ""
channels, _ := s.GuildChannels(c.Config.GuildID)
for _, c := range channels {
if c.Type != discordgo.ChannelTypeGuildText {
continue
}
if strings.Contains(input, c.ID) {
moveToId = c.ID
break
}
}
if moveToId == "" {
return errors.New("failed to link channels")
}
_, err = s.ChannelMessageSend(m.ChannelID, "Moderator <@"+m.Author.ID+"> moved <@"+repliedTo.Author.ID+">'s message to <#"+moveToId+"> to continue the conversation there")
if err != nil {
return errors.New("error announcing move")
}
_, err = s.ChannelMessageSend(moveToId, "Moderator <@"+m.Author.ID+"> moved this message from <#"+m.ChannelID+">\n\nOriginal message:\n\n <@"+repliedTo.Author.ID+">: "+repliedTo.Content)
if err != nil {
return errors.New("error moving message")
}
err = s.ChannelMessageDelete(m.ChannelID, m.ID)
if err != nil {
return errors.New("error (re)moving command message")
}
err = s.ChannelMessageDelete(m.ChannelID, m.MessageReference.MessageID)
if err != nil {
return errors.New("error (re)moving message")
}
return nil
}
func (c *Commands) handleBringto(s *discordgo.Session, m *discordgo.MessageCreate) error {
args := strings.Split(m.Content, " ")
if len(args) < 2 {
return errors.New("missing arg")
}
input := m.Content[strings.Index(m.Content, " "):len(m.Content)]
repliedTo, err := s.ChannelMessage(m.ChannelID, m.MessageReference.MessageID)
if err != nil {
return errors.New("error getting target message")
}
moveToId := ""
channels, _ := s.GuildChannels(c.Config.GuildID)
for _, c := range channels {
if c.Type != discordgo.ChannelTypeGuildText {
continue
}
if strings.Contains(input, c.ID) {
moveToId = c.ID
break
}
}
if moveToId == "" {
return errors.New("failed to link channels")
}
_, err = s.ChannelMessageSend(m.ChannelID, "<@"+m.Author.ID+"> copied <@"+repliedTo.Author.ID+">'s message to <#"+moveToId+"> to continue the conversation there.")
if err != nil {
return errors.New("error announcing move")
}
_, err = s.ChannelMessageSend(moveToId, "<@"+m.Author.ID+"> copied this message from <#"+m.ChannelID+">\n\nOriginal message:\n\n <@"+repliedTo.Author.ID+">: "+repliedTo.Content)
if err != nil {
return errors.New("error moving message")
}
return nil
}