-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package pool | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
zero "github.com/wdvxdr1123/ZeroBot" | ||
) | ||
|
||
func init() { | ||
zero.OnMessage(zero.HasPicture).SetBlock(false).FirstPriority().Handle(func(ctx *zero.Ctx) { | ||
img, ok := ctx.State["image_url"].([]string) | ||
if !ok || len(img) == 0 { | ||
return | ||
} | ||
if !ntcachere.MatchString(img[0]) { // is not NTQQ | ||
return | ||
} | ||
rk, err := nturl(img[0]).rkey() | ||
if err != nil { | ||
logrus.Debugln("[imgpool] parse rkey error:", err, "image url:", img) | ||
return | ||
} | ||
err = rs.set(time.Minute, rk) | ||
if err != nil { | ||
logrus.Debugln("[imgpool] set rkey error:", err, "rkey:", rk) | ||
return | ||
} | ||
logrus.Debugln("[imgpool] set latest rkey:", rk) | ||
}) | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package pool | ||
|
||
import "time" | ||
|
||
const rkeykey = "__latest_rkey__" | ||
|
||
var rs *rkeystorage | ||
|
||
func init() { | ||
var err error | ||
rs.item, err = newItem(rkeykey, "") | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
type rkeystorage struct { | ||
*item | ||
lastrefresh time.Time | ||
} | ||
|
||
func (rs *rkeystorage) rkey(timeout time.Duration) (string, error) { | ||
if time.Since(rs.lastrefresh) < timeout { | ||
return rs.u, nil | ||
} | ||
err := rs.item.update() | ||
if err != nil { | ||
return "", err | ||
} | ||
rs.lastrefresh = time.Now() | ||
return rs.u, nil | ||
} | ||
|
||
func (rs *rkeystorage) set(timeout time.Duration, rkey string) error { | ||
if time.Since(rs.lastrefresh) < timeout { // 降低设置频次 | ||
return nil | ||
} | ||
rs.item.u = rkey | ||
rs.lastrefresh = time.Now() | ||
return rs.item.push("minamoto") | ||
} |