nonebot-plugin-cp-broadcast 2.2.0__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nonebot-plugin-cp-broadcast might be problematic. Click here for more details.

@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nonebot-plugin-cp-broadcast
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Codeforces、牛客、AtCoder平台比赛查询,ACMer 必备
5
5
  Home-page: https://github.com/HuParry/nonebot-plugin-cp-broadcast
6
6
  License: MIT
7
7
  Author: HuParry
8
- Author-email: huparry@outlook.com
8
+ Author-email: hu_parry@qq.com
9
9
  Requires-Python: >=3.8
10
10
  Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Programming Language :: Python :: 3
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.9
14
14
  Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
17
18
  Requires-Dist: aiosqlite (>=0.13.0,<0.14.0)
18
19
  Requires-Dist: bs4 (>=0.0.1)
19
20
  Requires-Dist: fake-useragent (>=1.1.3)
@@ -1,266 +1,264 @@
1
- from .config import Config, cp_broadcast_config
2
- from .codeforces import *
3
- from .nowcoder import *
4
- from .atcoder import *
5
- from .aiosqlite import *
6
- import datetime
7
- from datetime import timedelta
8
- from nonebot.plugin import on_fullmatch
9
- from nonebot import require, get_bot
10
- from nonebot.rule import to_me
11
- from nonebot.log import logger
12
- import asyncio
13
-
14
- cp_broadcast_list = cp_broadcast_config.cp_broadcast_list
15
- cp_broadcast_botname = cp_broadcast_config.cp_broadcast_botname
16
- cp_broadcast_time = cp_broadcast_config.cp_broadcast_time
17
- cp_broadcast_updatetime = cp_broadcast_config.cp_broadcast_updatetime
18
- cp_broadcast_cf_list = cp_broadcast_config.cp_broadcast_cf_list
19
- cp_broadcast_cf_interval = cp_broadcast_config.cp_broadcast_cf_interval
20
-
21
- from nonebot.plugin import PluginMetadata
22
-
23
- __plugin_meta__ = PluginMetadata(
24
- name="算法竞赛比赛查询",
25
- description="可以查询牛客、atcoder、codeforces平台的今天和近几天的比赛信息",
26
- usage= \
27
- "cf->查询cf比赛\n" \
28
- "@{botname} cf查询+id->查询某人信息\n" \
29
- "@{botname} cf监视+id->监视某人rating变化\n" \
30
- "@{botname} cf监视移除+id->不再监视某人rating变化\n" \
31
- "@{botname} cf监视列表->展示已监视的选手id\n" \
32
- "@{botname} cf排名->展示已监视选手的排名\n" \
33
- "@{botname} cf监视备注->给某个监视选手备注\n" \
34
- "nc/牛客->查询牛客比赛\n" \
35
- "atc->查询atcoder比赛\n" \
36
- "today->查询今天的比赛\n" \
37
- "next->查询明天之后的部分比赛\n"
38
- "update->更新比赛数据\n" \
39
- "about->{botname}的一些信息\n",
40
- type="application",
41
- homepage="https://github.com/HuParry/nonebot-plugin-cp-broadcast",
42
- config=Config,
43
- supported_adapters={"nonebot.adapters.onebot.v11"},
44
- )
45
-
46
- try:
47
- scheduler = require("nonebot_plugin_apscheduler").scheduler
48
- except BaseException:
49
- scheduler = None
50
-
51
- logger.opt(colors=True).info(
52
- "已检测到软依赖<y>nonebot_plugin_apscheduler</y>, <g>开启定时任务功能</g>"
53
- if scheduler
54
- else "未检测到软依赖<y>nonebot_plugin_apscheduler</y>, <r>禁用定时任务功能</r>"
55
- )
56
-
57
-
58
- ###列表下标0为比赛名称、下标1为比赛时间、下标2为比赛链接
59
-
60
- async def ans_today(): # today
61
- cf_list = await codeforces.get_today_data()
62
- nc_list = await nowcoder.get_today_data()
63
- atc_list = await atcoder.get_today_data()
64
-
65
- msg = ''
66
- n = 0
67
- if len(cf_list) > 0:
68
- for each in cf_list:
69
- if n == 0:
70
- msg += '◉cf比赛:\n'
71
- msg += '比赛名称:' + each.get_name() + '\n' \
72
- + '比赛时间:' + each.get_time() + '\n' \
73
- f'比赛时长:' + each.get_length() + '分钟\n'
74
- n += 1
75
- if n >= 2:
76
- break
77
- n = 0
78
- msg2 = ''
79
-
80
- if len(nc_list) > 0:
81
- # second = '{:.3f}'.format(time.time())
82
- # second2 = int(float(second)*1000)
83
- for data in nc_list:
84
- if n == 0:
85
- msg2 += '◉牛客比赛:\n'
86
- msg2 += "比赛名称:" + data.get_name() + '\n'
87
- msg2 += "比赛时间:" + data.get_time() + '\n'
88
- msg2 += "比赛时长:" + data.get_length() + '分钟\n'
89
- n += 1
90
- if n >= 2:
91
- break
92
- n = 0
93
- msg3 = ''
94
-
95
- if len(atc_list) > 0:
96
- for each in atc_list:
97
- if n == 0:
98
- msg3 += '◉atc比赛:\n'
99
- msg3 += '比赛名称:' + each.get_name() + '\n' \
100
- + '比赛时间:' + each.get_time() + '\n' \
101
- + '比赛时长:' + each.get_length() + '分钟\n'
102
-
103
- if len(cf) == 0 and len(nc) == 0 and len(atc) == 0:
104
- return f'查询出错了,稍后再尝试哦~'
105
- if msg == '' and msg2 == '' and msg3 == '':
106
- return '今天没有比赛,但也要好好做题哦~'
107
- return '找到今天的比赛如下:\n' + msg + msg2 + msg3
108
-
109
-
110
- async def ans_next():
111
- cf_list = await codeforces.get_next_data()
112
- nc_list = await nowcoder.get_next_data()
113
- atc_list = await atcoder.get_next_data()
114
- tomorrow = datetime.datetime.now().date() + timedelta(days=1)
115
- msg = ''
116
- n = 0
117
-
118
- if len(cf_list) > 0:
119
- for each in cf_list:
120
- if n == 0:
121
- msg += '◉cf比赛:\n'
122
- msg += '比赛名称:' + each.get_name() + '\n' \
123
- + '比赛时间:' + each.get_time() + '\n' \
124
- + '比赛时长:' + each.get_length() + '分钟\n'
125
- n += 1
126
- if n >= 2:
127
- break
128
- n = 0
129
- msg2 = ''
130
-
131
- if len(nc_list) > 0:
132
- for data in nc_list:
133
- if n == 0:
134
- msg2 += '◉牛客比赛:\n'
135
- msg2 += "比赛名称:" + data.get_name() + '\n'
136
- msg2 += "比赛时间:" + data.get_time() + '\n'
137
- msg2 += "比赛时长:" + data.get_length() + '分钟\n'
138
- n += 1
139
- if n >= 2:
140
- break
141
-
142
- n = 0
143
- msg3 = ''
144
-
145
- if len(atc_list) > 0:
146
- for each in atc_list:
147
- if n == 0:
148
- msg3 += '◉atc比赛:\n'
149
- msg3 += '比赛名称:' + (each.get_name()) + '\n' \
150
- + '比赛时间:' + (each.get_time()) + '\n' \
151
- + '比赛时长:' + (each.get_length()) + '分钟\n'
152
- n += 1
153
-
154
- if len(cf) == 0 and len(nc) == 0 and len(atc) == 0:
155
- return f'查询出错了,稍后再尝试哦~'
156
- if msg == '' and msg2 == '' and msg3 == '':
157
- return '接下来几天没有比赛,但也要好好做题哦~'
158
- return '找到接下来的比赛如下:\n' + msg + msg2 + msg3
159
-
160
-
161
- today_matcher = on_fullmatch('today', priority=70, block=True)
162
-
163
-
164
- @today_matcher.handle()
165
- async def _():
166
- msg = await ans_today()
167
- await today_matcher.finish(msg)
168
-
169
-
170
- next_matcher = on_fullmatch('next', priority=70, block=True)
171
-
172
-
173
- @next_matcher.handle()
174
- async def _():
175
- msg = await ans_next()
176
- await next_matcher.finish(msg)
177
-
178
-
179
- help = on_fullmatch(('help', '帮助'), block=True, priority=70, rule=to_me())
180
-
181
-
182
- @help.handle()
183
- async def help_():
184
- msg = __plugin_meta__.usage.format(botname=cp_broadcast_botname)
185
- await help.finish(msg)
186
-
187
-
188
- # 清晨自动播报比赛
189
- async def auto_broadcast():
190
- await asyncio.sleep(1)
191
- for id in cp_broadcast_list:
192
- await asyncio.sleep(2)
193
- await get_bot().send_group_msg(group_id=id, message='早上好呀!' + await ans_today())
194
-
195
-
196
- if scheduler:
197
- scheduler.add_job(auto_broadcast,
198
- "cron", hour=cp_broadcast_time['hour'], minute=cp_broadcast_time['minute'], id="auto_broadcast"
199
- )
200
-
201
-
202
- # 凌晨12点自动更新比赛信息
203
- async def update():
204
- global cf
205
- global atc
206
- global nc
207
- cf.clear()
208
- atc.clear()
209
- nc.clear()
210
-
211
- if await get_data_cf():
212
- logger.info('cf比赛信息更新成功')
213
- if await get_data_nc():
214
- logger.info('牛客比赛信息更新成功')
215
- if await get_data_atc():
216
- logger.info('atc比赛信息更新成功')
217
-
218
-
219
- if scheduler:
220
- scheduler.add_job(
221
- update, "cron", hour=cp_broadcast_updatetime['hour'], minute=cp_broadcast_updatetime['minute'], id="update"
222
- )
223
-
224
- # 更新数据
225
- update_matcher = on_fullmatch('update', priority=70, block=True)
226
-
227
-
228
- @update_matcher.handle()
229
- async def reply():
230
- await update()
231
- await update_matcher.finish('数据已更新完成')
232
-
233
-
234
- # cf分数变化提醒、cf上线提醒
235
- async def cfBroadcast():
236
- """
237
- Users = {'ratingChange': [
238
- {'handle': handle, 'remarks' : remarks,'oldRating': Rating.oldRating, 'newRating': Rating.newRating}
239
- ],
240
- 'cfOnline': [
241
- {'handle': handle, 'remarks' : remarks, 'contestId': contestId}
242
- ]}
243
- """
244
- logger.info('cf监视工作开始')
245
- messList = await returnChangeInfo()
246
- logger.info('cf监视工作完成,结果已返回')
247
-
248
- for id in cp_broadcast_cf_list:
249
- await asyncio.sleep(1)
250
- output = f"当前时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}\n"
251
- if len(messList['ratingChange']) != 0:
252
- for mess in messList['ratingChange']:
253
- output += f"cf用户 {mess['handle']} ({mess['remarks']})分数发生变化,从 {mess['oldRating']} → {mess['newRating']},变动了{int(mess['newRating'] - int(mess['oldRating']))}分!\n"
254
- await get_bot().send_group_msg(group_id=id, message=output)
255
- await asyncio.sleep(1)
256
-
257
- for mess in messList['cfOnline']:
258
- await get_bot().send_group_msg(group_id=id,
259
- message=f"卷王 {mess['handle']} ({mess['remarks']})又开始上cf做题啦!他在做{mess['contestId']}!\n")
260
- await asyncio.sleep(1)
261
-
262
-
263
- if scheduler:
264
- scheduler.add_job(
265
- cfBroadcast, "interval", minutes=cp_broadcast_cf_interval, id="cfBroadcast"
266
- )
1
+ from nonebot.adapters.onebot.v11 import Event
2
+
3
+ from .config import *
4
+ from .codeforces import *
5
+ from .nowcoder import *
6
+ from .atcoder import *
7
+ from .aiosqlite import *
8
+ from .utils import *
9
+ import datetime
10
+ from datetime import timedelta
11
+ from nonebot.plugin import on_fullmatch
12
+ from nonebot import require, get_bot
13
+ from nonebot.rule import to_me
14
+ from nonebot.log import logger
15
+ import asyncio
16
+
17
+ cp_broadcast_list = cp_broadcast_config.cp_broadcast_list
18
+ cp_broadcast_botname = cp_broadcast_config.cp_broadcast_botname
19
+ cp_broadcast_time = cp_broadcast_config.cp_broadcast_time
20
+ cp_broadcast_updatetime = cp_broadcast_config.cp_broadcast_updatetime
21
+ cp_broadcast_cf_list = cp_broadcast_config.cp_broadcast_cf_list
22
+ cp_broadcast_cf_interval = cp_broadcast_config.cp_broadcast_cf_interval
23
+
24
+ from nonebot.plugin import PluginMetadata
25
+
26
+ __plugin_meta__ = PluginMetadata(
27
+ name="算法竞赛比赛查询",
28
+ description="可以查询牛客、atcoder、codeforces平台的今天和近几天的比赛信息",
29
+ usage= \
30
+ "cf->查询cf比赛\n" \
31
+ "@{botname} cf查询+id->查询某人信息\n" \
32
+ "@{botname} cf监视+id->监视某人rating变化\n" \
33
+ "@{botname} cf监视移除+id->不再监视某人rating变化\n" \
34
+ "@{botname} cf监视列表->展示已监视的选手id\n" \
35
+ "@{botname} cf排名->展示已监视选手的排名\n" \
36
+ "@{botname} cf监视备注->给某个监视选手备注\n" \
37
+ "nc/牛客->查询牛客比赛\n" \
38
+ "atc->查询atcoder比赛\n" \
39
+ "today->查询今天的比赛\n" \
40
+ "next->查询明天之后的部分比赛\n"
41
+ "update->更新比赛数据\n" \
42
+ "about->{botname}的一些信息\n",
43
+ type="application",
44
+ homepage="https://github.com/HuParry/nonebot-plugin-cp-broadcast",
45
+ config=Config,
46
+ supported_adapters={"nonebot.adapters.onebot.v11"},
47
+ )
48
+
49
+ try:
50
+ scheduler = require("nonebot_plugin_apscheduler").scheduler
51
+ except BaseException:
52
+ scheduler = None
53
+
54
+ logger.opt(colors=True).info(
55
+ "已检测到软依赖<y>nonebot_plugin_apscheduler</y>, <g>开启定时任务功能</g>"
56
+ if scheduler
57
+ else "未检测到软依赖<y>nonebot_plugin_apscheduler</y>, <r>禁用定时任务功能</r>"
58
+ )
59
+
60
+
61
+ ###列表下标0为比赛名称、下标1为比赛时间、下标2为比赛链接
62
+
63
+ async def ans_today(): # today
64
+ cf_list = await codeforces.get_today_data()
65
+ nc_list = await nowcoder.get_today_data()
66
+ atc_list = await atcoder.get_today_data()
67
+
68
+ msg = []
69
+ n = 0
70
+ if len(cf_list) > 0:
71
+ for each in cf_list:
72
+ if n == 0:
73
+ msg.append(cf_title)
74
+ msg.append(to_context(each))
75
+
76
+ n += 1
77
+ if n >= 2:
78
+ break
79
+ n = 0
80
+ msg2 = []
81
+
82
+ if len(nc_list) > 0:
83
+ # second = '{:.3f}'.format(time.time())
84
+ # second2 = int(float(second)*1000)
85
+ for data in nc_list:
86
+ if n == 0:
87
+ msg2.append(nc_title)
88
+ msg2.append(to_context(data))
89
+ n += 1
90
+ if n >= 2:
91
+ break
92
+ n = 0
93
+ msg3 = []
94
+
95
+ if len(atc_list) > 0:
96
+ for each in atc_list:
97
+ if n == 0:
98
+ msg3.append(atc_title)
99
+ msg3.append(to_context(each))
100
+
101
+ if len(cf) == 0 and len(nc) == 0 and len(atc) == 0:
102
+ return f'查询出错了,稍后再尝试哦~'
103
+ if len(cf_list) == 0 and len(nc_list) == 0 and len(atc_list) == 0:
104
+ return '今天没有比赛,但也要好好做题哦~'
105
+ return [ '找到今天的比赛如下:', ''.join(msg), ''.join(msg2), ''.join(msg3) ]
106
+
107
+
108
+ async def ans_next():
109
+ cf_list = await codeforces.get_next_data()
110
+ nc_list = await nowcoder.get_next_data()
111
+ atc_list = await atcoder.get_next_data()
112
+ tomorrow = datetime.datetime.now().date() + timedelta(days=1)
113
+ msg = []
114
+ n = 0
115
+
116
+ if len(cf_list) > 0:
117
+ for each in cf_list:
118
+ if n == 0:
119
+ msg.append(cf_title)
120
+ msg.append(to_context(each))
121
+ n += 1
122
+ if n >= 2:
123
+ break
124
+ n = 0
125
+ msg2 = []
126
+
127
+ if len(nc_list) > 0:
128
+ for data in nc_list:
129
+ if n == 0:
130
+ msg2.append(nc_title)
131
+ msg2.append(to_context(data))
132
+ n += 1
133
+ if n >= 2:
134
+ break
135
+
136
+ n = 0
137
+ msg3 = []
138
+
139
+ if len(atc_list) > 0:
140
+ for each in atc_list:
141
+ if n == 0:
142
+ msg3.append(atc_title)
143
+ msg3.append(to_context(each))
144
+ n += 1
145
+
146
+ if len(cf) == 0 and len(nc) == 0 and len(atc) == 0:
147
+ return f'查询出错了,稍后再尝试哦~'
148
+ if len(cf_list) == 0 and len(nc_list) == 0 and len(atc_list) == 0:
149
+ return '接下来几天没有比赛,但也要好好做题哦~'
150
+ return ['找到接下来的比赛如下:', ''.join(msg), ''.join(msg2), ''.join(msg3)]
151
+
152
+
153
+ today_matcher = on_fullmatch('today', priority=70, block=True)
154
+
155
+
156
+ @today_matcher.handle()
157
+ async def _(bot: Bot, event: MessageEvent):
158
+ msg = await ans_today()
159
+ if isinstance(msg, str):
160
+ await today_matcher.finish(msg)
161
+ else:
162
+ await send_forward_msg(bot, event, "今日比赛", bot.self_id, msg)
163
+
164
+
165
+ next_matcher = on_fullmatch('next', priority=70, block=True)
166
+
167
+
168
+ @next_matcher.handle()
169
+ async def _(bot: Bot, event: MessageEvent):
170
+ msg = await ans_next()
171
+ if isinstance(msg, str):
172
+ await next_matcher.finish(msg)
173
+ else:
174
+ await send_forward_msg(bot, event, "接下来比赛", bot.self_id, msg)
175
+
176
+
177
+ help = on_fullmatch(('help', '帮助'), block=True, priority=70, rule=to_me())
178
+
179
+
180
+ @help.handle()
181
+ async def help_():
182
+ msg = __plugin_meta__.usage.format(botname=cp_broadcast_botname)
183
+ await help.finish(msg)
184
+
185
+
186
+ # 清晨自动播报比赛
187
+ async def auto_broadcast():
188
+ await asyncio.sleep(1)
189
+ for id in cp_broadcast_list:
190
+ await asyncio.sleep(2)
191
+ await get_bot().send_group_msg(group_id=id, message='早上好呀!' + await ans_today())
192
+
193
+
194
+ if scheduler:
195
+ scheduler.add_job(auto_broadcast,
196
+ "cron", hour=cp_broadcast_time['hour'], minute=cp_broadcast_time['minute'], id="auto_broadcast"
197
+ )
198
+
199
+
200
+ # 凌晨12点自动更新比赛信息
201
+ async def update():
202
+ global cf
203
+ global atc
204
+ global nc
205
+ cf.clear()
206
+ atc.clear()
207
+ nc.clear()
208
+
209
+ if await get_data_cf():
210
+ logger.info('cf比赛信息更新成功')
211
+ if await get_data_nc():
212
+ logger.info('牛客比赛信息更新成功')
213
+ if await get_data_atc():
214
+ logger.info('atc比赛信息更新成功')
215
+
216
+
217
+ if scheduler:
218
+ scheduler.add_job(
219
+ update, "cron", hour=cp_broadcast_updatetime['hour'], minute=cp_broadcast_updatetime['minute'], id="update"
220
+ )
221
+
222
+ # 更新数据
223
+ update_matcher = on_fullmatch('update', priority=70, block=True)
224
+
225
+
226
+ @update_matcher.handle()
227
+ async def reply():
228
+ await update()
229
+ await update_matcher.finish('数据已更新完成')
230
+
231
+
232
+ # cf分数变化提醒、cf上线提醒
233
+ async def cfBroadcast():
234
+ """
235
+ Users = {'ratingChange': [
236
+ {'handle': handle, 'remarks' : remarks,'oldRating': Rating.oldRating, 'newRating': Rating.newRating}
237
+ ],
238
+ 'cfOnline': [
239
+ {'handle': handle, 'remarks' : remarks, 'contestId': contestId}
240
+ ]}
241
+ """
242
+ logger.info('cf监视工作开始')
243
+ messList = await returnChangeInfo()
244
+ logger.info('cf监视工作完成,结果已返回')
245
+
246
+ for id in cp_broadcast_cf_list:
247
+ await asyncio.sleep(1)
248
+ output = f"当前时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())}\n"
249
+ if len(messList['ratingChange']) != 0:
250
+ for mess in messList['ratingChange']:
251
+ output += f"cf用户 {mess['handle']} ({mess['remarks']})分数发生变化,从 {mess['oldRating']} → {mess['newRating']},变动了{int(mess['newRating'] - int(mess['oldRating']))}分!\n"
252
+ await get_bot().send_group_msg(group_id=id, message=output)
253
+ await asyncio.sleep(1)
254
+
255
+ for mess in messList['cfOnline']:
256
+ await get_bot().send_group_msg(group_id=id,
257
+ message=f"卷王 {mess['handle']} ({mess['remarks']})又开始上cf做题啦!他在做{mess['contestId']}!\n")
258
+ await asyncio.sleep(1)
259
+
260
+
261
+ if scheduler:
262
+ scheduler.add_job(
263
+ cfBroadcast, "interval", minutes=cp_broadcast_cf_interval, id="cfBroadcast"
264
+ )