Skip to content

Commit

Permalink
read channel emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
KKopilka committed Nov 19, 2022
1 parent 34f8e04 commit 2935918
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions cmd/trash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ package main

import (
"fmt"
"io/ioutil"
"strings"

"github.com/bwmarrin/discordgo"
)

var discordBotToken = "MTAwMjI4MTI1MzM5Mjg4Nzg3OQ.GnmLD-.irU9_tc-iOxdySzpnrk6QGZC3CtJTRRZWNNIpE"
var discordBotToken string

const WasteBasketEmoji = "🗑"

func main() {
err := readBotToken()

if err != nil {
fmt.Println(err.Error())
return
}

goBot, err := discordgo.New("Bot " + discordBotToken)
if err != nil {
fmt.Println(err.Error())
Expand Down Expand Up @@ -56,19 +67,39 @@ func removeTrash(goBot *discordgo.Session, guildID string) error {
}

if len(messages) > 3 {
messageToDelete := []string{}
for _, message := range messages {
if err := goBot.ChannelMessageDelete(channel.ID, message.ID); err != nil {
fmt.Println(err.Error())
continue
}
messageToDelete = append(messageToDelete, message.ID)
}

if err := goBot.ChannelMessagesBulkDelete(channel.ID, messageToDelete); err != nil {
fmt.Println(err.Error())
continue
}
}
}
}

return nil
}

func IsChannelNeedToClean(channelName string) bool {
return channelName == "trash"
if strings.Index(channelName, WasteBasketEmoji) >= 0 {
return true
}

if strings.Index(channelName, "trash") >= 0 {
return true
}
return false
}

func readBotToken() error {
file, err := ioutil.ReadFile("bot-token")

if err != nil {
return err
}

discordBotToken = string(file)
return nil
}

0 comments on commit 2935918

Please sign in to comment.