Skip to content

Instantly share code, notes, and snippets.

@kkdai
Created January 13, 2023 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkdai/2b84fb24fef3e3313cd6b963dcd26a14 to your computer and use it in GitHub Desktop.
Save kkdai/2b84fb24fef3e3313cd6b963dcd26a14 to your computer and use it in GitHub Desktop.
// 如果有預設 DABTASE_URL 就建立 PostGresSQL; 反之則建立 Mem DB
pSQL := os.Getenv("DATABASE_URL")
if pSQL != "" {
summaryQueue = NewPGSql(pSQL)
} else {
summaryQueue = NewMemDB()
}
// DB Access
q := summaryQueue.ReadGroupInfo(getGroupID(event))
for _, m := range q {
// [xxx]: 他講了什麼... 時間
oriContext = oriContext + fmt.Sprintf("[%s]: %s . %s\n", m.UserName, m.MsgText, m.Time.Local().UTC().Format("2006-01-02 15:04:05"))
}
...
// DB append
// event.Source.GroupID 就是聊天群組的 ID,並且透過聊天群組的 ID 來放入 Map 之中。
m := MsgDetail{
MsgText: message,
UserName: userName,
Time: time.Now(),
}
summaryQueue.AppendGroupInfo(getGroupID(event), m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment