feat(AI): add salted user id

This commit is contained in:
Yiyang Kang 2023-03-21 13:35:25 +08:00
parent 816ae68aeb
commit b60be9ae7e
Signed by: kkyy
GPG key ID: 80FD317ECAF06CC3
2 changed files with 18 additions and 9 deletions

View file

@ -1,6 +1,8 @@
package main
import (
"crypto/md5"
"encoding/base64"
"strconv"
"strings"
"time"
@ -234,6 +236,7 @@ func handleAssistantConversation(c tele.Context, thread []*tele.Message) error {
Messages: chatReqMsgs,
Temperature: lo.ToPtr(0.42),
MaxTokens: 2048,
User: assistantHashUserId(lastMsg.Sender.ID),
}
typingNotifyCh := setTyping(c)
@ -272,3 +275,9 @@ func assistantRemoveMention(msg, name string) string {
}
return orig
}
func assistantHashUserId(uid int64) string {
seasoned := []byte("RdnuRPqp66vtbc28QRO0ecKSLKXifz7G9UbXLoyCMpw" + strconv.FormatInt(uid, 10))
hashed := md5.Sum(seasoned) // Don't judge me
return base64.URLEncoding.EncodeToString(hashed[:])[:22]
}