aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/main.go b/main.go
index c43de7e..f4278c8 100644
--- a/main.go
+++ b/main.go
@@ -8,6 +8,7 @@ import (
"io/ioutil"
"log"
"net/http"
+ "path"
"path/filepath"
"regexp"
@@ -18,12 +19,12 @@ var (
baseurl = flag.String("baseurl", "gemini://m2i.omarpolo.com", "base url")
matrixOutDir = flag.String("matrix-out", "", "matrix out directory")
- matrixRe = regexp.MustCompile(`https://matrix.org/[^\s]+\.txt`)
+ matrixRe = regexp.MustCompile(`https://.*/[^\s]+\.(txt|png|jpg|jpeg|gif)`)
channel = "#gemini-it"
)
func matrix2gemini(conn *irc.Conn, line *irc.Line) {
- matches := matrixRe.FindAllString(line.Text(), -1)
+ matches := msgRe.FindAllString(line.Text(), -1)
// it's not a good idea to defer inside a loop, but we know
// len(matches) is small (usually just 1). Morover, I like
@@ -40,7 +41,8 @@ func matrix2gemini(conn *irc.Conn, line *irc.Line) {
}
defer resp.Body.Close()
- tmpfile, err := ioutil.TempFile(*matrixOutDir, "message-")
+ ext := path.Ext(link)
+ tmpfile, err := ioutil.TempFile(*matrixOutDir, "message-*" + ext)
if err != nil {
conn.Privmsg(channel, fmt.Sprintf("failed to tmpfile: %s", err))
return