Browse Source

added a little of username anonymization

master
arnaucode 7 years ago
parent
commit
4b6112451b
3 changed files with 32 additions and 2 deletions
  1. +1
    -0
      .gitignore
  2. +25
    -0
      dataUtils.go
  3. +6
    -2
      matrix.go

+ 1
- 0
.gitignore

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

+ 25
- 0
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
}

+ 6
- 2
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)

Loading…
Cancel
Save