-
Notifications
You must be signed in to change notification settings - Fork 1
/
lock.py
55 lines (47 loc) · 2 KB
/
lock.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
import json
import os
# 绑定公会
async def lock_clan(server, clan_name, group_id):
current_dir = os.path.join(os.path.dirname(__file__), 'config.json')
with open(current_dir, 'r', encoding='UTF-8') as af:
f_data = json.load(af)
f_data[group_id] = {}
f_data[group_id]['server'] = server
f_data[group_id]['clan_name'] = clan_name
with open(current_dir, 'w', encoding='UTF-8') as f:
json.dump(f_data, f, indent=4, ensure_ascii=False)
msg = f'QQ群:{group_id} 已成功绑定{server}服公会“{clan_name}”'
return msg
# 多个绑定选择触发
async def select_all_clan(clan_score):
num = clan_score['total']
msg = '查询到该名字为前缀的公会如下:'
for num_id in range(num):
data_id = list(clan_score['data'].keys())[num_id]
clan_name = clan_score['data'][data_id]['clan_name']
msg = msg + '\n' + str(num_id + 1) + '. ' + str(clan_name)
return msg
# 解绑公会
async def unlock_clan(group_id):
current_dir = os.path.join(os.path.dirname(__file__), 'config.json')
with open(current_dir, 'r', encoding='UTF-8') as af:
f_data = json.load(af)
clan_name = f_data[group_id]['clan_name']
f_data.pop(group_id)
with open(current_dir, 'w', encoding='UTF-8') as f:
json.dump(f_data, f, indent=4, ensure_ascii=False)
msg = f'QQ群:{group_id} 已成功解绑公会"{clan_name}"'
return msg
# 查询公会绑定
async def judge_lock(group_id):
current_dir = os.path.join(os.path.dirname(__file__), 'config.json')
with open(current_dir, 'r', encoding='UTF-8') as af:
f_data = json.load(af)
if group_id in list(f_data.keys()):
server = f_data[group_id]['server']
clan_name = f_data[group_id]['clan_name']
msg = f'本群:{group_id} 已成功绑定{server}服公会“{clan_name}”'
return msg, True
else:
msg = f'本群:{group_id} 暂未绑定任何公会'
return msg, False