mirror of
https://salsa.debian.org/mdosch/feed-to-muc.git
synced 2024-11-22 14:08:39 +01:00
formatting
This commit is contained in:
parent
f6eec12642
commit
40c88d7867
6 changed files with 51 additions and 33 deletions
|
@ -19,7 +19,6 @@ import (
|
||||||
|
|
||||||
// Get new articles for specified feed.
|
// Get new articles for specified feed.
|
||||||
func getArticles(feedURL string, max int, noExcerpt bool, filter []string, filterMessage []string) (string, error) {
|
func getArticles(feedURL string, max int, noExcerpt bool, filter []string, filterMessage []string) (string, error) {
|
||||||
|
|
||||||
type feedCache struct {
|
type feedCache struct {
|
||||||
LastChange string
|
LastChange string
|
||||||
}
|
}
|
||||||
|
@ -36,7 +35,7 @@ func getArticles(feedURL string, max int, noExcerpt bool, filter []string, filte
|
||||||
// Create configPath if not yet existing.
|
// Create configPath if not yet existing.
|
||||||
cachePath = osCacheDir + "/feed-to-muc/"
|
cachePath = osCacheDir + "/feed-to-muc/"
|
||||||
if _, err := os.Stat(cachePath); os.IsNotExist(err) {
|
if _, err := os.Stat(cachePath); os.IsNotExist(err) {
|
||||||
err = os.MkdirAll(cachePath, 0700)
|
err = os.MkdirAll(cachePath, 0o700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Can't create cache path:", err)
|
log.Fatal("Error: Can't create cache path:", err)
|
||||||
}
|
}
|
||||||
|
@ -59,7 +58,7 @@ func getArticles(feedURL string, max int, noExcerpt bool, filter []string, filte
|
||||||
// Create cachePath if not yet existing.
|
// Create cachePath if not yet existing.
|
||||||
cachePath = home + "/.cache/feed-to-muc/"
|
cachePath = home + "/.cache/feed-to-muc/"
|
||||||
if _, err := os.Stat(cachePath); os.IsNotExist(err) {
|
if _, err := os.Stat(cachePath); os.IsNotExist(err) {
|
||||||
err = os.MkdirAll(cachePath, 0700)
|
err = os.MkdirAll(cachePath, 0o700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Can't create cache path:", err)
|
log.Fatal("Error: Can't create cache path:", err)
|
||||||
}
|
}
|
||||||
|
@ -75,7 +74,7 @@ func getArticles(feedURL string, max int, noExcerpt bool, filter []string, filte
|
||||||
log.Fatal("Error: Can't create hash for", feedURL+":", err)
|
log.Fatal("Error: Can't create hash for", feedURL+":", err)
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(cachePath); os.IsNotExist(err) {
|
if _, err := os.Stat(cachePath); os.IsNotExist(err) {
|
||||||
err = os.MkdirAll(cachePath, 0700)
|
err = os.MkdirAll(cachePath, 0o700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Can't create hash identifier for cache file:", err)
|
log.Fatal("Error: Can't create hash identifier for cache file:", err)
|
||||||
}
|
}
|
||||||
|
@ -102,7 +101,7 @@ func getArticles(feedURL string, max int, noExcerpt bool, filter []string, filte
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
file, err = os.OpenFile(cacheFile, os.O_RDWR, 0600)
|
file, err = os.OpenFile(cacheFile, os.O_RDWR, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Can't open cache file:", err)
|
log.Fatal("Error: Can't open cache file:", err)
|
||||||
}
|
}
|
||||||
|
|
7
main.go
7
main.go
|
@ -36,7 +36,6 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Read path to config from command line option.
|
// Read path to config from command line option.
|
||||||
configFilePtr := flag.String("config", "none", "path to configuration file")
|
configFilePtr := flag.String("config", "none", "path to configuration file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -91,8 +90,10 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if output != "" {
|
if output != "" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: config.Muc,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "groupchat", Text: output})
|
Remote: config.Muc,
|
||||||
|
Type: "groupchat", Text: output,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// ToDo: Save message for resend.
|
// ToDo: Save message for resend.
|
||||||
// Exit if message can not be sent.
|
// Exit if message can not be sent.
|
||||||
|
|
|
@ -21,7 +21,7 @@ func openConfig(configFilePtr *string) configuration {
|
||||||
// Create configPath if not yet existing.
|
// Create configPath if not yet existing.
|
||||||
configPath = osConfigDir + "/.config/feed-to-muc/"
|
configPath = osConfigDir + "/.config/feed-to-muc/"
|
||||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||||
err = os.MkdirAll(configPath, 0700)
|
err = os.MkdirAll(configPath, 0o700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Can't create config path: ", err)
|
log.Fatal("Error: Can't create config path: ", err)
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func openConfig(configFilePtr *string) configuration {
|
||||||
// Create configPath if not yet existing.
|
// Create configPath if not yet existing.
|
||||||
configPath = home + "/.config/feed-to-muc/"
|
configPath = home + "/.config/feed-to-muc/"
|
||||||
if _, err := os.Stat(configPath + "config.json"); os.IsNotExist(err) {
|
if _, err := os.Stat(configPath + "config.json"); os.IsNotExist(err) {
|
||||||
err = os.MkdirAll(configPath, 0700)
|
err = os.MkdirAll(configPath, 0o700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Can't create config path: ", err)
|
log.Fatal("Error: Can't create config path: ", err)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func openConfig(configFilePtr *string) configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||||
err = os.MkdirAll(configPath, 0700)
|
err = os.MkdirAll(configPath, 0o700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Can't create config path: ", err)
|
log.Fatal("Error: Can't create config path: ", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,14 +68,18 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
||||||
"\"source\": Show source code URL."
|
"\"source\": Show source code URL."
|
||||||
|
|
||||||
if v.Type == "groupchat" {
|
if v.Type == "groupchat" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: muc,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + reply})
|
Remote: muc,
|
||||||
|
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + reply,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Failed sending message to MUC:", err)
|
log.Fatal("Error: Failed sending message to MUC:", err)
|
||||||
}
|
}
|
||||||
} else if v.Type == "chat" {
|
} else if v.Type == "chat" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: v.Remote,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "chat", Text: reply})
|
Remote: v.Remote,
|
||||||
|
Type: "chat", Text: reply,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
|
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
|
||||||
}
|
}
|
||||||
|
@ -88,14 +92,18 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
||||||
"https://salsa.debian.org/mdosch/feed-to-muc"
|
"https://salsa.debian.org/mdosch/feed-to-muc"
|
||||||
|
|
||||||
if v.Type == "groupchat" {
|
if v.Type == "groupchat" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: muc,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + reply})
|
Remote: muc,
|
||||||
|
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + reply,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Failed sending message to MUC:", err)
|
log.Fatal("Error: Failed sending message to MUC:", err)
|
||||||
}
|
}
|
||||||
} else if v.Type == "chat" {
|
} else if v.Type == "chat" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: v.Remote,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "chat", Text: reply})
|
Remote: v.Remote,
|
||||||
|
Type: "chat", Text: reply,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
|
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
|
||||||
}
|
}
|
||||||
|
@ -111,14 +119,18 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
||||||
reply := "Feeds I'm following:\n" + feedList
|
reply := "Feeds I'm following:\n" + feedList
|
||||||
|
|
||||||
if v.Type == "groupchat" {
|
if v.Type == "groupchat" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: muc,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + reply})
|
Remote: muc,
|
||||||
|
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + reply,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Failed sending message to MUC:", err)
|
log.Fatal("Error: Failed sending message to MUC:", err)
|
||||||
}
|
}
|
||||||
} else if v.Type == "chat" {
|
} else if v.Type == "chat" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: v.Remote,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "chat", Text: reply})
|
Remote: v.Remote,
|
||||||
|
Type: "chat", Text: reply,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
|
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
|
||||||
}
|
}
|
||||||
|
@ -133,14 +145,18 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Type == "groupchat" {
|
if v.Type == "groupchat" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: muc,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + reply})
|
Remote: muc,
|
||||||
|
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + reply,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Failed sending message to MUC:", err)
|
log.Fatal("Error: Failed sending message to MUC:", err)
|
||||||
}
|
}
|
||||||
} else if v.Type == "chat" {
|
} else if v.Type == "chat" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: v.Remote,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "chat", Text: reply})
|
Remote: v.Remote,
|
||||||
|
Type: "chat", Text: reply,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
|
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
|
||||||
}
|
}
|
||||||
|
@ -154,14 +170,18 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Type == "groupchat" {
|
if v.Type == "groupchat" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: muc,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + contact})
|
Remote: muc,
|
||||||
|
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": " + contact,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Failed sending message to MUC:", err)
|
log.Fatal("Error: Failed sending message to MUC:", err)
|
||||||
}
|
}
|
||||||
} else if v.Type == "chat" {
|
} else if v.Type == "chat" {
|
||||||
_, err = client.Send(xmpp.Chat{Remote: v.Remote,
|
_, err = client.Send(xmpp.Chat{
|
||||||
Type: "chat", Text: contact})
|
Remote: v.Remote,
|
||||||
|
Type: "chat", Text: contact,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
|
log.Fatal("Error: Failed sending message to ", v.Remote, ": ", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
// Remove tracking parameter from URLs
|
// Remove tracking parameter from URLs
|
||||||
func removeTracking(input string) (output string, err error) {
|
func removeTracking(input string) (output string, err error) {
|
||||||
|
|
||||||
// Perform a get request to get rid of 301 forwarding through
|
// Perform a get request to get rid of 301 forwarding through
|
||||||
// services like feedproxy.google.com.
|
// services like feedproxy.google.com.
|
||||||
resp, err := http.Get(input)
|
resp, err := http.Get(input)
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
|
|
||||||
// Send a ping every 30 seconds after last successful ping to check if the MUC is still available.
|
// Send a ping every 30 seconds after last successful ping to check if the MUC is still available.
|
||||||
func pingMUC(client *xmpp.Client, botJid string, muc string, mucNick string) {
|
func pingMUC(client *xmpp.Client, botJid string, muc string, mucNick string) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
Loading…
Reference in a new issue