View data_process.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 如果有預設 DABTASE_URL 就建立 PostGresSQL; 反之則建立 Mem DB | |
pSQL := os.Getenv("DATABASE_URL") | |
if pSQL != "" { | |
summaryQueue = NewPGSql(pSQL) | |
} else { | |
summaryQueue = NewMemDB() | |
} | |
//.... |
View select_db.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 如果有預設 DABTASE_URL 就建立 PostGresSQL; 反之則建立 Mem DB | |
pSQL := os.Getenv("DATABASE_URL") | |
if pSQL != "" { | |
summaryQueue = NewPGSql(pSQL) | |
} else { | |
summaryQueue = NewMemDB() | |
} | |
// DB Access |
View pgsql_db.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PGSqlDB struct { | |
Db *pg.DB | |
} | |
func (mdb *PGSqlDB) ReadGroupInfo(roomID string) GroupData { | |
pgsql := &DBStorage{ | |
RoomID: roomID, | |
} | |
if ret, err := pgsql.Get(mdb); err == nil { | |
return ret.Dataset |
View memory_db.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type MemStorage map[string]GroupData | |
type MemDB struct { | |
db MemStorage | |
} | |
func (mdb *MemDB) ReadGroupInfo(roomID string) GroupData { | |
return mdb.db[roomID] | |
} |
View basic_data.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type GroupDB interface { | |
ReadGroupInfo(string) GroupData | |
AppendGroupInfo(string, MsgDetail) | |
} | |
type MsgDetail struct { | |
MsgText string | |
UserName string | |
Time time.Time | |
} |
View chatgot_summary.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// 把聊天群組裡面的訊息都捲出來(依照先後順序) | |
oriContext := "" | |
q := summaryQueue[event.Source.GroupID] | |
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")) | |
} |
View chatgpt.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
gpt3 "github.com/sashabaranov/go-gpt3" | |
) | |
View get_group_id.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
case *linebot.TextMessage: | |
// 預設訊息 | |
reply := "msg ID:" + message.ID + ":" + "Get:" + message.Text + " , \n OK!" | |
// 如果聊天機器人在群組中,開始儲存訊息。 | |
if event.Source.GroupID != "" { | |
// 先取得使用者 Display Name (也就是顯示的名稱) | |
userName := event.Source.UserID |
View gpt.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Net; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Net.Http; | |
using System.Web; |
View db.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 建立与数据库的连接 | |
db, err := sql.Open("mysql", "user:password@tcp(host:port)/dbname") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer db.Close() | |
// 查询数据库 | |
rows, err := db.Query("SELECT * FROM users") | |
if err != nil { |
NewerOlder