Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add WarframeAPI #541

Merged
merged 24 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,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 @@ -131,6 +131,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 @@ -260,7 +261,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
190 changes: 190 additions & 0 deletions plugin/warframeapi/gametime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package warframeapi

import (
"github.com/wdvxdr1123/ZeroBot/message"
"sync"
"time"

"github.com/davidscholberg/go-durationfmt"
)

var (
gameTimes [3]*gameTime
)

// getTimeString 根据传入的世界编号,获取对应的游戏时间文本
func getTimeString(wordType int) message.MessageSegment {
GenesisAN marked this conversation as resolved.
Show resolved Hide resolved
return message.Text(
"平原时间:", gameTimes[wordType].getStatus(), "\n",
"下次更新:", gameTimes[wordType].getTime(),
)
}

// getStatus 获取当前游戏时间状态(白天/夜晚)
func (t *gameTime) getStatus() string {
GenesisAN marked this conversation as resolved.
Show resolved Hide resolved
t.rwm.RLock()
defer t.rwm.RUnlock()
if t.Status {
return t.StatusTrueDes
}
return t.StatusFalseDes
}

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

// 游戏时间模拟初始化
//func gameTimeInit() {
// //updateWM()
// loadTime(wfapi)
// go gameRuntime()
//}

// gameRuntime 游戏时间模拟
func gameRuntime() {
GenesisAN marked this conversation as resolved.
Show resolved Hide resolved
wfapi, err := getWFAPI()
if err != nil {
println("ERROR:GetWFAPI失败,", err.Error())
GenesisAN marked this conversation as resolved.
Show resolved Hide resolved
return
}
loadTime(wfapi)
for range time.NewTicker(10 * time.Second).C {
GenesisAN marked this conversation as resolved.
Show resolved Hide resolved
timeDet()
}
}

// loadTime 根据API返回内容修正游戏时间
func loadTime(api wfAPI) {
//updateWM()
var isfass bool
if api.CambionCycle.Active == "fass" {
GenesisAN marked this conversation as resolved.
Show resolved Hide resolved
isfass = true
}
gameTimes = [3]*gameTime{
GenesisAN marked this conversation as resolved.
Show resolved Hide resolved
{sync.RWMutex{}, "地球平原", api.CetusCycle.Expiry.Local(), api.CetusCycle.IsDay, "白天", "夜晚", 100 * 60, 50 * 60},
{sync.RWMutex{}, "金星平原", api.VallisCycle.Expiry.Local(), api.VallisCycle.IsWarm, "温暖", "寒冷", 400, 20 * 60},
{sync.RWMutex{}, "火卫二平原", api.CambionCycle.Expiry.Local(), isfass, "fass", "vome", 100 * 60, 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()
}
//暂时只保留时间更新功能
//switch {
//case nt < 0:
// 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.Status = !v.Status
//
// callUser(i, v.Status, 0)
//case nt < float64(5)*60:
// callUser(i, !v.Status, 5)
//case nt < float64(15)*60:
// if i == 2 && !v.Status {
// return
// }
// callUser(i, !v.Status, 15)
//}
}
}

//TODO:订阅功能-待重做
//func callUser(i int, s bool, time int) []message.MessageSegment {
// msg := []message.MessageSegment{}
// for group, sl := range sublist {
//
// switch {
// case !sl.Min15Tips && !sl.Min5Tips && time == 15: //是否
// sublist[group].Min15Tips = true
// case sl.Min15Tips && !sl.Min5Tips && time == 5:
// sublist[group].Min5Tips = true
// case sl.Min15Tips && sl.Min5Tips && time == 0:
// sublist[group].Min15Tips = false
// sublist[group].Min5Tips = false
// default:
// return nil
// }
// //if !sl.Min15Tips && !sl.Min5Tips && time == 15 {
// // sublist[group].Min15Tips = true
// //} else if sl.Min15Tips && !sl.Min5Tips && time == 5 {
// // sublist[group].Min5Tips = true
// //} else if sl.Min15Tips && sl.Min5Tips && time == 0 {
// // sublist[group].Min15Tips = false
// // sublist[group].Min5Tips = false
// //} else {
// // return
// //}
// for qq, st := range sl.SubUser {
// if st.SubType[i] != nil {
// if *st.SubType[i] == s {
// msg = append(msg, message.At(qq))
// }
// }
// }
// if len(msg) == 0 {
// continue
// }
// if time <= 0 {
// if s {
// msg = append(msg, message.Text(fmt.Sprintf("\n%s白天(%s)到了", gameTimes[i].Name, gameTimes[i].StatusTrueDes)))
// } else {
// msg = append(msg, message.Text(fmt.Sprintf("\n%s夜晚(%s)到了", gameTimes[i].Name, gameTimes[i].StatusFalseDes)))
// }
// } else {
// if s {
// msg = append(msg, message.Text(fmt.Sprintf("\n%s距离白天(%s)还剩下%d分钟", gameTimes[i].Name, gameTimes[i].StatusTrueDes, time)))
// } else {
// msg = append(msg, message.Text(fmt.Sprintf("\n%s距离夜晚(%s)还剩下%d分钟", gameTimes[i].Name, gameTimes[i].StatusFalseDes, time)))
// }
// }
// }
// return msg
//}

// 游戏时间模拟
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"` //夜间时长
}

//type subList struct {
// SubUser map[int64]subType `json:"qq_sub"`
// Min5Tips bool `json:"min5_tips"`
// Min15Tips bool `json:"min15_tips"`
//}

//type subType struct {
// SubType map[int]*bool `json:"sub_type"`
// SubRaid bool `json:"sub_raid"`
//}
Loading