~kris/9p

glenda

bc7656ed7ca7d57a6c792306beb1592e346937eb — Sean Hinchee 8 years ago 1ca6d06
added unsubscribe; added regular dump tied to Listener()
2 files changed, 37 insertions(+), 2 deletions(-)

M mux.go
M x/mux/commits.go
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
}