M TODO => TODO +5 -0
@@ 1,3 1,4 @@
+Features
* g!sum acid(1)
* g!man acid(1) or g!man 1 acid
* rss feed subscription (tracking commits)
@@ 5,3 6,7 @@
* 9front/plan9 source searching
* various cat-v fetches (harmful, page search [get lucky])
* Auto-propaganda processing for images (Black and White -> (9)-ify)
+
+--
+Problems
+* Move feed caching to another file than the .cfg (seriously this is a fcking mess)
M main.go => main.go +4 -2
@@ 77,9 77,11 @@ func main() {
}
// Init Mux daemons
+ // Problem child Listener is
go mux.Listener()
- go mux.CommMux()
- go CommMux()
+
+// go mux.CommMux()
+// go CommMux()
go mux.Config.Init()
Session.UpdateStatus(0, "with #cat-v")
M mux.go => mux.go +7 -1
@@ 19,10 19,16 @@ func init() {
Router.Route("help", "Display this message.", Router.Help)
Router.Route("fortune", "Display fortunes. Bonus files are (theo troll rsc bullshit terry rob).", Router.Fortunes)
+
+ Router.Route("subscribe", "Subscribe to an RSS feed.", Router.Subscribe)
+
+ Router.Route("list", "List RSS feeds Glenda is subscribed to by id.", Router.List)
+
+ Router.Route("last", "Show the last commit for a given RSS feed by id.", Router.Last)
Router.Route("dump", "Dump config to file.", Router.Dump)
Router.Route("about", "General information about the bot.", Router.About)
+
}
-
M x/mux/commits.go => x/mux/commits.go +52 -6
@@ 5,6 5,8 @@ import (
"github.com/SlyMarbo/rss"
"fmt"
"time"
+ "strings"
+ "strconv"
)
/* internal functions */
@@ 13,24 15,52 @@ import (
func Listener() {
for {
for _, feed := range Config.Feeds {
+ fmt.Print("Printing feed: ", feed, "\n")
err := feed.Update()
if err != nil {
fmt.Println("Error in updating RSS feed, see: x/mux/commits.go")
fmt.Printf("%s\n\n", err)
}
- time.Sleep(1000 * time.Second)
+ time.Sleep(10 * time.Minute)
}
+ time.Sleep(10 * time.Minute)
}
}
/* Commands for Mux */
-// Print last commit or
-func (m *Mux) Commits(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) {
- resp := "```\n"
+// Print last commit for a given feed (by subscribed id int [See: List(...)])
+func (m *Mux) Last(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) {
+ resp += "**" + Config.Feeds[id].Title + ": **" + "\n"
+ resp += Config.Feeds[id].Items[ len(Config.Feeds[id].Items) -1].Date.String() + "\n\n"
+ resp += "`" + Config.Feeds[id].Items[ len(Config.Feeds[id].Items) -1].Title + "`" + "\n"
+ //resp += Config.Feeds[id].Items[ len(Config.Feeds[id].Items) -1].Summary + "\n"
+ //resp += Config.Feeds[id].Items[ len(Config.Feeds[id].Items) -1].Content + "\n"
+ resp += "\n" + Config.Feeds[id].Items[ len(Config.Feeds[id].Items) -1].Link + "\n"
+ } else {
+ resp += "Denied fetch. Invalid stream id, see: list command"
+ }
+
+ resp += "\n"
+
+ ds.ChannelMessageSend(dm.ChannelID, resp)
+
+ return
+}
+// List all subscribed feeds
+// Print last commit for a given feed
+func (m *Mux) List(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) {
+ resp := "```\n"
+ for p, v := range Config.Feeds {
+ resp += strconv.Itoa(p) + ": " + v.Title + "\n"
+ }
resp += "```\n"
@@ 42,18 72,34 @@ func (m *Mux) Commits(ds *discordgo.Session, dm *discordgo.Message, ctx *Context
// Subscribe to a feed
func (m *Mux) Subscribe(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) {
//http://code.9front.org/hg/plan9front/rss-log
- // TODO -- check if feed is already subscribed to
resp := "```\n"
+ // URL to feed should be last item
+ url := ctx.Fields[len(ctx.Fields) -1]
+ fmt.Println("Proposed subscribe for: ", url)
+
+ for _, v := range Config.Feeds {
+ if strings.Contains(url, v.Link) {
+ resp += "Denied! Feed already subscribed to."
+ resp += "```\n"
+ ds.ChannelMessageSend(dm.ChannelID, resp)
+ return
+ }
+ }
- feed, err := rss.Fetch("")
+ feed, err := rss.Fetch(url)
if err != nil {
fmt.Println("Error in reading RSS feed, see: x/mux/commits.go")
fmt.Printf("%s\n\n", err)
+ resp += "Denied! Could not parse feed."
+ resp += "```\n"
+ ds.ChannelMessageSend(dm.ChannelID, resp)
+ return
}
// Might not be thread safe
Config.Feeds = append(Config.Feeds, *feed)
+ resp += "Subscribed."
resp += "```\n"
ds.ChannelMessageSend(dm.ChannelID, resp)
M x/mux/config.go => x/mux/config.go +2 -2
@@ 45,7 45,7 @@ func (c *Configuration) Write() (rerr error) {
rerr = err
}
}
-
+
return
}
@@ 53,6 53,7 @@ func (c *Configuration) Write() (rerr error) {
func (c *Configuration) Read() (rerr error) {
RD:
f, err := os.Open("./cfg/glenda.cfg")
+ defer f.Close()
if err != nil {
if strings.Contains(err.Error(), "no such file or directory") {
// danger: this can go infinite
@@ 71,7 72,6 @@ func (c *Configuration) Read() (rerr error) {
fmt.Printf("%s\n", err)
rerr = err
Config.Write()
- goto RD
}
}