-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery.py
More file actions
281 lines (242 loc) · 10.2 KB
/
query.py
File metadata and controls
281 lines (242 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import hoshino
from hoshino import priv
from .utils import *
from .search import *
from . import sv_info as sv, files
from hoshino.util import FreqLimiter
lmt = FreqLimiter(10)
@sv.on_fullmatch(('当前比赛'))
async def contest_now(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
global files
title = "当前进行的比赛:\n"
msg = await get_now_contest(files)
text = (title + getText(msg)).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('今日比赛'))
async def contest_today(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
global files
title = "今日比赛:\n"
msg = await get_today_contest(files)
text = (title + getText(msg)).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('明日比赛'))
async def contest_tomorrow(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
global files
title = "明日比赛:\n"
msg = await get_tomorrow_contest(files)
text = getText(msg)
text = (title + getText(msg)).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('opencup'))
async def contest_opencup(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
msg = await get_contest("contests.json", lambda start, end, link: "opencup" in link)
text = "opencup:\n" + getText(msg).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('leetcode','lc', '力扣'))
async def contest_leetcode(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
msg = await get_contest("contests.json", lambda start, end, link: "leetcode" in link)
text = "leetcode:\n" + getText(msg).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('ctf'))
async def contest_ctf(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
msg = await get_contest("contests.json", lambda start, end, link: any([i in link for i in ["ctftime", "hackerearth", "hackerrank"]]))
text = "ctf:\n" + getText(msg).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('topcoder'))
async def contest_topcoder(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
msg = await get_contest("contests.json", lambda start, end, link: "topcoder" in link)
text = "topcoder:\n" + getText(msg).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('atcoder', "atc"))
async def contest_atcode(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
msg = await get_contest("contests.json", lambda start, end, link: "atcoder" in link)
text = "atcoder:\n" + getText(msg).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('ucup'))
async def contest_ucup(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
msg = await get_contest("contests.json", lambda start, end, link: "ucup" in link)
text = "ucup:\n" + getText(msg).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('yukicoder', 'yuki'))
async def contest_yukicode(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
msg = await get_contest("contests.json", lambda start, end, link: "yukicoder" in link)
text = "yukicoder:\n" + getText(msg).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('codechef'))
async def contest_codechef(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
msg = await get_contest("contests.json", lambda start, end, link: "codechef" in link)
text = "codechef:\n" + getText(msg).strip()
await bot.finish(ev, message = text)
@sv.on_fullmatch(('cf', 'codeforces'))
async def contest_codeforces(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
msg = await get_contest("contests.json", lambda start, end, link: "codeforces" in link)
text = "codeforces:\n" + getText(msg).strip()
await bot.finish(ev, text)
@sv.on_fullmatch(('牛客'))
async def contest_niuke(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
text = "牛客:\n"
msg = await get_contest("niuke.json", lambda start, end, link: True)
msg += await get_contest("niuke_school.json", lambda start, end, link: True)
text += getText(msg).strip()
await bot.finish(ev, text)
@sv.on_prefix('find')
async def get_cf_msg(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
name = ev.message.extract_plain_text()
uid = ev.user_id
msg = getCfSelfMsg(name) if len(name) < 60 else "不要捣乱哦! [CQ:face,id=106]"
if "超时" in msg or "无法访问" in msg:
msg = "cf访问超时,请稍后查询qwq"
elif "找不到" in msg:
msg = "没找到这个人qwq"
elif not msg.startswith("不要捣乱哦") and not msg.endswith("[CQ:face,id=15][CQ:face,id=15]"):
msg = render_forward_msg([msg])
await bot.send_group_forward_msg(group_id=ev.group_id, messages=msg)
return
msg = f"[CQ:reply,id={ev.message_id}]" + msg
await bot.finish(ev, msg)
@sv.on_prefix('洛谷月报')
async def get_luogu_some_news(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
condition = ev.message.extract_plain_text().strip()
if condition and '-' not in condition:
bot.finish(ev, "请输入正确的格式:洛谷月报 xxxx-xx")
now = datetime.now()
year = now.year
month = now.month
try:
if condition:
year, month = map(int, condition.split('-'))
except Exception as e:
sv.logger.error(f'Error: {e}')
bot.finish(ev, "不要捣乱哦")
msg = await get_luogu_news_condition(year, month)
msg = get_luogu_news_text(msg)
bot.finish(ev, msg)
@sv.on_fullmatch('随机月报')
async def get_luogu_random_new(bot, ev):
uid = ev.user_id
if not lmt.check(uid):
await bot.finish(ev, '您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)
msg = await get_luogu_random_news()
msg = get_luogu_news_text(msg)
bot.finish(ev, msg)
# @sv.on_fullmatch('通知我', only_to_me = True)
# async def NoticeMe(bot, ev):
# message_type = session.ctx['message_type']
# if(message_type == 'private'):
# self_id = session.ctx['user_id']
# file = open('id.json', 'r', encoding='utf-8')
# js = file.read()
# id = json.loads(js)
# Id = id['user']
# ID = []
# for it in Id:
# if it == self_id:
# await session.bot.send_private_msg(user_id=session.ctx['user_id'], message="您已经被通知无需操作!")
# return
# ID.append(it)
# ID.append(self_id)
# id["user"] = ID
# print(id)
# fp = open("id.json", 'w', encoding='utf-8')
# item_json = json.dumps(id, ensure_ascii=False)
# fp.write(item_json)
# fp.close()
# file.close()
# await session.bot.send_private_msg(user_id=session.ctx['user_id'], message="将在比赛开始前一个小时通知您!")
# else:
# await session.bot.send_private_msg(user_id=session.ctx['user_id'], message="加好友才能操作哦!")
# @sv.on_fullmatch('取消通知我', only_to_me = True)
# async def NoticeMe(bot, ev):
# message_type = session.ctx['message_type']
# if(message_type == 'private'):
# self_id = session.ctx['user_id']
# file = open('id.json', 'r', encoding='utf-8')
# js = file.read()
# id = json.loads(js)
# Id = id['user']
# ID = []
# for it in Id:
# if it == self_id:
# continue
# ID.append(it)
# id["user"] = ID
# print(id)
# fp = open("id.json", 'w', encoding='utf-8')
# item_json = json.dumps(id, ensure_ascii=False)
# fp.write(item_json)
# fp.close()
# file.close()
# await session.bot.send_private_msg(user_id=session.ctx['user_id'], message="已经取消!")
# @sv.on_fullmatch('新闻', only_to_me = True)
# async def news(bot, ev):
# text = getNews()
# await session.bot.send_private_msg(user_id=1173007724, message=text)
# await session.bot.send_private_msg(user_id=1206770096, message=text)
# await session.bot.send_private_msg(user_id=743742996, message=text)
# await bot.finish(ev, text)
# message_type = session.ctx['message_type']
# if (message_type == 'group'):
# await session.bot.send_group_msg(group_id=session.ctx['group_id'], message=text)
# elif (message_type == 'private'):
# await session.bot.send_private_msg(user_id=session.ctx['user_id'], message=text)