diff --git a/.gitignore b/.gitignore index 9605567..3315bd2 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ _testmain.go twitterConfig.json matrixConfig.json temp +*.txt \ No newline at end of file diff --git a/dataUtils.go b/dataUtils.go new file mode 100644 index 0000000..c4af61b --- /dev/null +++ b/dataUtils.go @@ -0,0 +1,25 @@ +package main + +import ( + "strconv" + "strings" +) + +func dateToHour(date string) string { + dateSplit := strings.Split(date, " ") + time := dateSplit[3] + return time +} +func getSecFromDate(date string) string { + //Fri Apr 28 17:25:22 +0000 2017 + dateSplit := strings.Split(date, " ") + time := dateSplit[3] + sec := strings.Split(time, ":")[2] + return sec +} +func anonymousName(originalName string, date string) string { + s := strings.Split(originalName, "") + //first letter and the last-1 (prelast / penĂșltima) letter + seconds + generatedName := s[0] + s[len(s)-2] + strconv.Itoa(len(s)) + return generatedName +} diff --git a/matrix.go b/matrix.go index 47a01f5..2c91e02 100644 --- a/matrix.go +++ b/matrix.go @@ -62,10 +62,14 @@ func loginMatrix() { func matrixSendMsg(senderScreenName string, message string, createdAt string) { txnId := strconv.Itoa(rand.Int()) c.Green(txnId) + + anonName := anonymousName(senderScreenName, createdAt) + hour := dateToHour(createdAt) + url := matrixConfig.Server + "/_matrix/client/r0/rooms/" + matrixConfig.RoomId + "/send/m.room.message/" + txnId + "?access_token=" + matrixToken.AccessToken jsonStr := `{ - "body":"[NEW DM] - at ` + createdAt + `\n@` + senderScreenName + `: ` + message + `", - "msgtype":"m.text" + "body":"[NEW DM] - at ` + hour + `h\n@` + anonName + `: ` + message + `", + "msgtype":"m.notice" }` b := strings.NewReader(jsonStr) req, _ := http.NewRequest("PUT", url, b)