~kris/9p

glenda

ref: dbc993cb7912f6dafa6530f0a8248304cfd201fd glenda/x/mux/commits.go -rw-r--r-- 1.1 KiB
dbc993cb — Sean Hinchee test 8 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package mux

import (
	"github.com/bwmarrin/discordgo"
	"github.com/SlyMarbo/rss"
	"fmt"
	"time"
)

/* internal functions */

// Listen on the rss feed
func Listener() {
	for {
		for _, feed := range Config.Feeds {
			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)
		}
	}
}

/* Commands for Mux */

// Print last commit or 
func (m *Mux) Commits(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) {
	resp := "```\n"



	resp += "```\n"

	ds.ChannelMessageSend(dm.ChannelID, resp)

	return
}

// 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"
	
	feed, err := rss.Fetch("")

	if err != nil {
		fmt.Println("Error in reading RSS feed, see: x/mux/commits.go")
		fmt.Printf("%s\n\n", err)
	}
	
	// Might not be thread safe
	Config.Feeds = append(Config.Feeds, *feed)
	
	resp += "```\n"
	ds.ChannelMessageSend(dm.ChannelID, resp)

	return
}