M mux.go => mux.go +2 -0
@@ 30,6 30,8 @@ func init() {
Router.Route("subscribe", "Subscribe current channel to a given feed id.", Router.Subscribe)
+ Router.Route("unsubscribe", "Unsubscribe current channel to a given feed id.", Router.Unsubscribe)
+
Router.Route("man", "Display a given Plan 9 manual page (From 9front for now).", Router.Man)
Router.Route("about", "General information about the bot.", Router.About)
M x/mux/commits.go => x/mux/commits.go +35 -2
@@ 42,9 42,11 @@ func Listener() {
break
}
}
- time.Sleep(1 * time.Minute)
+ time.Sleep(2 * time.Minute)
}
- time.Sleep(1 * time.Minute)
+ time.Sleep(10 * time.Minute)
+ // Dump config to file regularly
+ Config.Write()
}
}
@@ 190,3 192,34 @@ func (m *Mux) Subscribe(ds *discordgo.Session, dm *discordgo.Message, ctx *Conte
return
}
+
+// a = a[:i+copy(a[i:], a[i+1:])]
+// Unsubscribe current channel to notifications from a given feed id
+func (m *Mux) Unsubscribe(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) {
+ resp := "\n"
+
+ id, _ := strconv.Atoi(ctx.Fields[len(ctx.Fields) -1])
+ if id >= 0 && id < len(Config.Feeds) {
+ // Check if subscribed
+ removed := false
+ for i, v := range Config.Subs {
+ if v.ChanID == dm.ChannelID && v.SubID == id {
+ removed = true
+ Config.Subs = Config.Subs[:i+copy(Config.Subs[i:], Config.Subs[i+1:])]
+ }
+ }
+
+ if(!removed) {
+ resp += "Denied unsubscription. Not subscribed in this channel."
+ } else {
+ resp += "Unsubscribed."
+ }
+ } else {
+ resp += "Denied unsubscription. Invalid stream id, see: list command"
+ }
+
+ resp += "\n"
+ ds.ChannelMessageSend(dm.ChannelID, resp)
+
+ return
+}