This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
92 lines (78 loc) · 3.15 KB
/
main.py
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
import asyncio
import os
import re
from typing import Callable, Tuple
from graia.application import GraiaMiraiApplication, Session
from graia.application.entry import MemberJoinRequestEvent, MessageChain, Plain
from graia.broadcast import Broadcast
from graia.broadcast.builtin.decoraters import Depend
from graia.broadcast.exceptions import ExecutionStop
from chancechecker import chanceChecker
from verifyuid import verifyQmailUid
# Application & BCC 初始化
loop = asyncio.get_event_loop()
bcc = Broadcast(loop=loop)
app = GraiaMiraiApplication(broadcast=bcc,
connect_info=Session(
host=os.environ['graia-host'],
authKey=os.environ['graia-authkey'],
account=int(os.environ['graia-account']),
websocket=True),
enable_chat_log=False
)
class qqGroup(object):
'''QQ 群号'''
main = 586146922 # 主用户群
cafe = 651672723 # 咖啡馆
admins = 985317265 # 运营组
workInGroups = [qqGroup.main, qqGroup.cafe] # 在这些群内工作
def inGroups(*groupsList: Tuple[int]) -> Callable:
groups = list(groupsList)
def wrapper(event: MemberJoinRequestEvent) -> None:
if not event.groupId in groups:
raise ExecutionStop()
return Depend(wrapper)
@bcc.receiver(MemberJoinRequestEvent, headless_decoraters=[inGroups(*workInGroups)])
async def command_test(app: GraiaMiraiApplication, event: MemberJoinRequestEvent):
app.logger.info(f'{event.supplicant} 试图加入 {event.groupName}')
_userQq = event.supplicant
c = chanceChecker(_userQq)
if not c.hasChance:
await event.reject('由于未正确填写 UID,你的入群机会已经耗尽')
return
# 是否已在其他群中
otherGroups = workInGroups
otherGroups.remove(event.groupId) # 剩余的工作群组
inOtherGroups: bool = False
for g in otherGroups:
if await app.getMember(group=g, member_id=_userQq):
inOtherGroups = True
if inOtherGroups: # 在其他工作群组中
c.remove()
await event.accept()
return
# 验证 QQ 与 UID
_requestMessage = event.message.strip() # 除去首尾空格
_answer = re.search(r'答案:(.*)', _requestMessage) # 正则匹配 UID
_uid = _answer.group(1) # 取出 UID
if not _answer:
return
if _uid.isdigit: # UID 中只填写了数字(有效)
_status = await verifyQmailUid(_userQq, int(_uid)) # 验证
if _status == 200: # 成功
c.remove()
await event.accept()
elif _status == 403: # 手动操作
await app.sendGroupMessage(
qqGroup.admins,
MessageChain.create(
[Plain(f'{_userQq} 试图加入 {event.groupName},UID 为 {_uid}')])
)
elif _status == 404: # 找不到 UID
c.addOnce()
await event.reject(f'UID 不正确')
else:
c.addOnce()
await event.reject('UID 应为纯数字')
if __name__ == '__main__':
app.launch_blocking()