Commit Diff
Diff:
c6fd4def314f51c06c6da606ec1ac303fcdd4f7b
ae97f74824d466663bbb1d408b197cb266528fa9
Commit:
ae97f74824d466663bbb1d408b197cb266528fa9
Tree:
9d116eaa32c6c7ad44cb3e20bb2fb7fcbc995d14
Author:
Omar Polo <op@omarpolo.com>
Date:
Fri Jul 30 11:42:51 2021 UTC
Message:
handle images too
commit - c6fd4def314f51c06c6da606ec1ac303fcdd4f7b
commit + ae97f74824d466663bbb1d408b197cb266528fa9
blob - c43de7e62e1ad4cb7f660bd2fe219168869da3b7
blob + f4278c87b36aa1812fbbe3004a8def0b4bbc7c43
--- main.go
+++ 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
Omar Polo