Skip to content

Commit

Permalink
add WarframeAPI (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
GenesisAN committed Jan 31, 2023
1 parent 36b09b8 commit 39af90e
Show file tree
Hide file tree
Showing 7 changed files with 1,239 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,23 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 来份网易云热评

</details>
<details>
<summary>WarframeAPI</summary>

`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/warframeapi"`

- [x] wf时间同步

- [x] [金星|地球|火卫二]平原状态

- [x] .wm [物品名称]

- [x] 仲裁

- [x] 警报

- [x] 每日特惠
</details>
<details>
<summary>天气/拼音查询-名言</summary>
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
github.com/antchfx/htmlquery v1.2.5
github.com/corona10/goimagehash v1.1.0
github.com/davidscholberg/go-durationfmt v0.0.0-20170122144659-64843a2083d3
github.com/fumiama/ahsai v0.1.0
github.com/fumiama/cron v1.3.0
github.com/fumiama/go-base16384 v1.6.4
Expand All @@ -25,6 +26,7 @@ require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/jinzhu/gorm v1.9.16
github.com/jozsefsallai/gophersauce v1.0.1
github.com/lithammer/fuzzysearch v1.1.5
github.com/lucas-clemente/quic-go v0.31.1
github.com/mroth/weightedrand v1.0.0
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ github.com/d4l3k/messagediff v1.2.2-0.20190829033028-7e0a312ae40b/go.mod h1:Oozb
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davidscholberg/go-durationfmt v0.0.0-20170122144659-64843a2083d3 h1:qshMBFxVjYjzI+kwvWvgoByF3uMCvnJiaK8KslWAbr8=
github.com/davidscholberg/go-durationfmt v0.0.0-20170122144659-64843a2083d3/go.mod h1:M9fx6rAdHSYLKxXPgUXGgblb586CA7ceNrpu4DEc2No=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
Expand Down Expand Up @@ -126,6 +128,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lithammer/fuzzysearch v1.1.5 h1:Ag7aKU08wp0R9QCfF4GoGST9HbmAIeLP7xwMrOBEp1c=
github.com/lithammer/fuzzysearch v1.1.5/go.mod h1:1R1LRNk7yKid1BaQkmuLQaHruxcC4HmAH30Dh61Ih1Q=
github.com/lucas-clemente/quic-go v0.31.1 h1:O8Od7hfioqq0PMYHDyBkxU2aA7iZ2W9pjbrWuja2YR4=
github.com/lucas-clemente/quic-go v0.31.1/go.mod h1:0wFbizLgYzqHqtlyxyCaJKlE7bYgE6JQ+54TLd/Dq2g=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtb_quotation" // vtb语录
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wallet" // 钱包
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wangyiyun" // 网易云音乐热评
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/warframeapi" // warframeAPI插件
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wenben" // 文本指令大全
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wenxinAI" // 百度文心AI画图
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/word_count" // 聊天热词
Expand Down Expand Up @@ -261,7 +262,6 @@ func init() {
logrus.Infoln("[main] 从", *runcfg, "读取配置文件")
return
}

config.W = []*driver.WSClient{driver.NewWebSocketClient(*url, *token)}
config.Z = zero.Config{
NickName: append([]string{*adana}, "ATRI", "atri", "亚托莉", "アトリ"),
Expand Down
78 changes: 78 additions & 0 deletions plugin/warframeapi/gametime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package warframeapi

import (
"github.com/davidscholberg/go-durationfmt"
"sync"
"time"
)

// 游戏时间模拟
type gameTime struct {
rwm sync.RWMutex
Name string `json:"name"` //时间名称
NextTime time.Time `json:"time"` //下次更新时间
Status bool `json:"status"` //状态
StatusTrueDes string `json:"true_des"` //状态说明
StatusFalseDes string `json:"false_des"` //状态说明
DayTime int `json:"day"` //白天时长
NightTime int `json:"night"` //夜间时长
}

var (
gameTimes [3]*gameTime
)

// TimeString 根据传入的世界编号,获取对应的游戏时间文本
func (t *gameTime) String() string {
return "平原时间:" + t.daynight() + "\n" +
"下次更新:" + t.remaintime()
}

// 获取当前游戏时间状态(白天/夜晚)
func (t *gameTime) daynight() string {
t.rwm.RLock()
defer t.rwm.RUnlock()
if t.Status {
return t.StatusTrueDes
}
return t.StatusFalseDes
}

// 获取下一次时间状态更新的剩余游戏时间(x分x秒)
func (t *gameTime) remaintime() string {
t.rwm.RLock()
d := time.Until(t.NextTime)
t.rwm.RUnlock()
durStr, _ := durationfmt.Format(d, "%m分%s秒后")
return durStr
}

// 根据API返回内容修正游戏时间
func loadTime(api wfAPI) {
gameTimes = [3]*gameTime{
{Name: "地球平原", NextTime: api.CetusCycle.Expiry.Local(), Status: api.CetusCycle.IsDay, StatusTrueDes: "白天", StatusFalseDes: "夜晚", DayTime: 100 * 60, NightTime: 50 * 60},
{Name: "金星平原", NextTime: api.VallisCycle.Expiry.Local(), Status: api.VallisCycle.IsWarm, StatusTrueDes: "温暖", StatusFalseDes: "寒冷", DayTime: 400, NightTime: 20 * 60},
{Name: "火卫二平原", NextTime: api.CambionCycle.Expiry.Local(), Status: api.CambionCycle.Active == "fass", StatusTrueDes: "fass", StatusFalseDes: "vome", DayTime: 100 * 60, NightTime: 50 * 60},
}
}

// timeDet游戏时间更新
func timeDet() {
for _, v := range gameTimes {
//当前时间对比下一次游戏状态更新时间,看看还剩多少秒
nt := time.Until(v.NextTime).Seconds()
//已经过了游戏时间状态更新时间
if nt < 0 {
v.rwm.Lock()
//更新游戏状态,如果是白天就切换到晚上,反之亦然
if v.Status {
//计算下次的晚上更新时间
v.NextTime = v.NextTime.Add(time.Duration(v.NightTime) * time.Second)
} else {
//计算下次的白天更新时间
v.NextTime = v.NextTime.Add(time.Duration(v.DayTime) * time.Second)
}
v.rwm.Unlock()
}
}
}

0 comments on commit 39af90e

Please sign in to comment.