added a little of username anonymization

This commit is contained in:
arnaucode
2017-06-23 04:43:23 +02:00
parent 8216ff08e8
commit 4b6112451b
3 changed files with 32 additions and 2 deletions

1
.gitignore vendored
View File

@@ -27,3 +27,4 @@ _testmain.go
twitterConfig.json
matrixConfig.json
temp
*.txt

25
dataUtils.go Normal file
View File

@@ -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
}

View File

@@ -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)