feat: Add ignored channels
parent
e28fffa193
commit
75b91331a7
@ -1,3 +1,4 @@
|
||||
Milen
|
||||
bot.db
|
||||
config.toml
|
||||
persistent.toml
|
||||
|
@ -0,0 +1,24 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/bwmarrin/discordgo"
|
||||
|
||||
"gitea.teamortix.com/chanbakjsd/Milen/persistent"
|
||||
"gitea.teamortix.com/chanbakjsd/Milen/util"
|
||||
)
|
||||
|
||||
func handleIgnoreChannel(dg *discordgo.Session, m *discordgo.MessageCreate, arguments []string) {
|
||||
if !util.HasAdmin(dg, m.Author.ID, m.ChannelID) {
|
||||
util.SendErrorEmbed(dg, m.ChannelID, util.ErrRequireAdmin)
|
||||
return
|
||||
}
|
||||
persistent.IgnoredChannels[m.ChannelID] = true
|
||||
}
|
||||
|
||||
func handleUnignoreChannel(dg *discordgo.Session, m *discordgo.MessageCreate, arguments []string) {
|
||||
if !util.HasAdmin(dg, m.Author.ID, m.ChannelID) {
|
||||
util.SendErrorEmbed(dg, m.ChannelID, util.ErrRequireAdmin)
|
||||
return
|
||||
}
|
||||
delete(persistent.IgnoredChannels, m.ChannelID)
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package persistent
|
||||
|
||||
type persistent struct {
|
||||
IgnoredChannels map[string]bool `toml:"ignored_channels"`
|
||||
}
|
||||
|
||||
var IgnoredChannels = make(map[string]bool)
|
@ -0,0 +1,43 @@
|
||||
package persistent
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
|
||||
"gitea.teamortix.com/chanbakjsd/Milen/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
data, err := ioutil.ReadFile("persistent.toml")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var loaded persistent
|
||||
toml.Unmarshal(data, &loaded)
|
||||
if loaded.IgnoredChannels != nil {
|
||||
IgnoredChannels = loaded.IgnoredChannels
|
||||
}
|
||||
}
|
||||
|
||||
func SaveLoop(dg *discordgo.Session) {
|
||||
for {
|
||||
time.Sleep(time.Minute)
|
||||
Save(dg)
|
||||
}
|
||||
}
|
||||
|
||||
func Save(dg *discordgo.Session) {
|
||||
file, err := os.Create("persistent.toml")
|
||||
if err != nil {
|
||||
util.ReportError(dg, err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
toml.NewEncoder(file).Encode(&persistent{
|
||||
IgnoredChannels: IgnoredChannels,
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue