File tree Expand file tree Collapse file tree 2 files changed +71
-1
lines changed
src/main/kotlin/me/lightless/izumi/plugin/timer/impl Expand file tree Collapse file tree 2 files changed +71
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,10 @@ dbFilename: izumi.sqlite
3434# ColorImage 服务需要的配置
3535colorImageKey : 11223344
3636
37+ # 天气预报需要的 key
38+ weatherKey : aabbccdd
39+
3740# SOCKS5 代理配置
3841useProxy : true
3942proxyIp : 127.0.0.1
40- proxyPort : 9050
43+ proxyPort : 9050
Original file line number Diff line number Diff line change 1+ package me.lightless.izumi.plugin.timer.impl
2+
3+ import kotlinx.coroutines.delay
4+ import me.lightless.izumi.ApplicationContext
5+ import me.lightless.izumi.plugin.timer.ITimer
6+ import org.joda.time.DateTime
7+ import org.slf4j.LoggerFactory
8+
9+ @Suppress(" unused" )
10+ class Weather : ITimer {
11+ override val name: String
12+ get() = " weather"
13+ override val period: Long
14+ get() = 60 * 1000
15+
16+ private val logger = LoggerFactory .getLogger(javaClass)
17+
18+ private val apiUrl = " https://devapi.qweather.com/v7/weather/3d"
19+
20+ // TODO 城市列表,先写死,以后增加查询功能
21+ private val cityList = listOf (
22+ " 101210101" , // 杭州
23+ " 101210106" , // 余杭区
24+ " 101210113" , // 西湖区
25+ " 101210114" , // 滨江区
26+ " 101010100" , // 北京
27+ )
28+
29+ override suspend fun process () {
30+
31+ this .logger.debug(" $name start." )
32+
33+ val bot = ApplicationContext .bot
34+ if (bot == null ) {
35+ this .logger.debug(" [$name ] bot instance is null!" )
36+ return
37+ }
38+
39+ val groupNumber = ApplicationContext .botConfig?.allowedGroups ? : emptyList()
40+ val apiKey = ApplicationContext .botConfig?.weatherKey
41+
42+ if (apiKey == null ) {
43+ this .logger.debug(" [$name ] weatherKey is null!" )
44+ return
45+ }
46+
47+ while (true ) {
48+ val datetime = DateTime ()
49+ val h = datetime.hourOfDay
50+ val m = datetime.minuteOfHour
51+
52+ // 每天晚上 7:30 发送天气预报
53+ if (h == 19 && m == 30 ) {
54+
55+ cityList.forEach {
56+ TODO ()
57+ }
58+
59+
60+ } else {
61+ delay(1000 * 60 )
62+ }
63+ }
64+
65+ }
66+
67+ }
You can’t perform that action at this time.
0 commit comments