Skip to content

Commit 8fa928d

Browse files
authored
optimize: gif plugin for image cache (#901) (fix #900)
修改gif插件图片保存方式
1 parent d832f9a commit 8fa928d

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

plugin/gif/context.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ func dlrange(prefix string, end int, wg *sync.WaitGroup, exit func(error)) []str
8787
}
8888

8989
// 新的上下文
90-
func newContext(user int64) *context {
90+
func newContext(user int64, atUser int64) *context {
9191
c := new(context)
92-
c.usrdir = datapath + "users/" + strconv.FormatInt(user, 10) + `/`
92+
c.usrdir = datapath + "users/" + strconv.FormatInt(atUser, 10) + `/`
9393
_ = os.MkdirAll(c.usrdir, 0755)
9494
c.headimgsdir = make([]string, 2)
95-
c.headimgsdir[0] = c.usrdir + "0.gif"
96-
c.headimgsdir[1] = c.usrdir + "1.gif"
95+
c.headimgsdir[0] = datapath + "users/" + strconv.FormatInt(atUser, 10) + ".gif"
96+
c.headimgsdir[1] = datapath + "users/" + strconv.FormatInt(user, 10) + ".gif"
9797
return c
9898
}
9999

plugin/gif/logo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ func (cc *context) prepareLogos(s ...string) error {
1414
for i, v := range s {
1515
_, err := strconv.Atoi(v)
1616
if err != nil {
17-
err = file.DownloadTo("https://gchat.qpic.cn/gchatpic_new//--"+strings.ToUpper(v)+"/0", cc.usrdir+strconv.Itoa(i)+".gif")
17+
err = file.DownloadTo("https://gchat.qpic.cn/gchatpic_new//--"+strings.ToUpper(v)+"/0", cc.headimgsdir[i])
1818
} else {
19-
err = file.DownloadTo("http://q4.qlogo.cn/g?b=qq&nk="+v+"&s=640", cc.usrdir+strconv.Itoa(i)+".gif")
19+
err = file.DownloadTo("http://q4.qlogo.cn/g?b=qq&nk="+v+"&s=640", cc.headimgsdir[i])
2020
}
2121
if err != nil {
2222
return err

plugin/gif/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ func init() { // 插件主体
152152
datapath = file.BOTPATH + "/" + en.DataFolder()
153153
en.OnRegex(`^(` + strings.Join(cmd, "|") + `)[\s\S]*?(\[CQ:(image\,file=([0-9a-zA-Z]{32}).*|at.+?(\d{5,11}))\].*|(\d+))$`).
154154
SetBlock(true).Handle(func(ctx *zero.Ctx) {
155-
c := newContext(ctx.Event.UserID)
156155
list := ctx.State["regex_matched"].([]string)
156+
atUserID, _ := strconv.ParseInt(list[4]+list[5]+list[6], 10, 64)
157+
c := newContext(ctx.Event.UserID, atUserID)
157158
err := c.prepareLogos(list[4]+list[5]+list[6], strconv.FormatInt(ctx.Event.UserID, 10))
158159
if err != nil {
159160
ctx.SendChain(message.Text("ERROR: ", err))

0 commit comments

Comments
 (0)