Skip to content

Commit

Permalink
update 3.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
JHue58 committed Feb 8, 2023
1 parent 1f1ecbb commit fe66c00
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 354 deletions.
23 changes: 11 additions & 12 deletions ChatAdmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,14 @@ def get_admin_command(data, adminlist=0, sender=0, group=0):


def exitadmin(getadminsign=0):
file = open('config.clc', 'r', encoding='utf-8-sig')
config = json_load(file)
file.close()

config = json_load('config.clc')

if getadminsign == 1:
return config['admin']
config['admin'] = 0
file = open('config.clc', 'w', encoding='utf-8-sig')
json_dump(config, file, indent=3, ensure_ascii=False)
file.close()
json_dump(config, 'config.clc', indent=3, ensure_ascii=False)



def getnode(data, tempdict, answerlist, group, sender, question):
Expand All @@ -107,7 +106,7 @@ def getnode(data, tempdict, answerlist, group, sender, question):
time.sleep(0.8)
tempdict.pop(question)
filename = str(group) + '.cl' # 读取已缓存的词库
pickle_dump(tempdict, open('WordStock/' + filename, 'wb'))
pickle_dump(tempdict, 'WordStock/' + filename)
simuse.Send_Message(data, sender, 2, '已清空', 1)
return None
if node == str(-1) or node == '–1':
Expand Down Expand Up @@ -156,7 +155,7 @@ def getnode(data, tempdict, answerlist, group, sender, question):
if answerlist == []:
tempdict.pop(question)
filename = str(group) + '.cl' # 读取已缓存的词库
pickle_dump(tempdict, open('WordStock/' + filename, 'wb'))
pickle_dump(tempdict, 'WordStock/' + filename)
if templist != []:
if sendtext != '':
simuse.Send_Message(
Expand All @@ -183,9 +182,9 @@ def getnode(data, tempdict, answerlist, group, sender, question):


def getconfig(adminnum=0):
file = open('config.clc', 'r', encoding='utf-8-sig')
config = json_load(file)
file.close()

config = json_load('config.clc')

if adminnum == 1:
return config['Administrator']
admin = config['admin']
Expand Down Expand Up @@ -303,7 +302,7 @@ def getanswer(data, sender, group, question): # 从词库中获取答案
continue
question = str(question)
filename = str(group) + '.cl' # 读取已缓存的词库
tempdict = pickle_load(open('WordStock/' + filename, 'rb'))
tempdict = pickle_load('WordStock/' + filename)
try: # 检索问题,若词库中无该问题,则函数返回-1,若有,则返回所有答案(答案列表)
#print(question)
questiondict = tempdict[question]
Expand Down
11 changes: 5 additions & 6 deletions ChatAllfind.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ def createxcel(groupcldict):

#上传工作表至cos
def uploadcos(data, filename):
secret_id = 'xxx'
secret_key = 'xxx'
secret_id = 'XX'
secret_key = 'XX'
region = 'ap-shanghai'
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key)
client = CosS3Client(config)
Expand Down Expand Up @@ -357,7 +357,7 @@ def delcl(data, sender, lines_dict, nodelist, target_type=0, group=0):
delsign = 0
for group in changedict:
cldict_orign = pickle_load(
open('WordStock/' + str(group) + '.cl', 'rb'))
'WordStock/' + str(group) + '.cl')
cldict = copy.deepcopy(cldict_orign)
questionlist = list(cldict_orign.keys())
changelist = changedict[group]
Expand All @@ -377,8 +377,7 @@ def delcl(data, sender, lines_dict, nodelist, target_type=0, group=0):
if answerlist == []:
cldict.pop(question)
cldict_orign = cldict
pickle_dump(cldict_orign, open('WordStock/' + str(group) + '.cl',
'wb'))
pickle_dump(cldict_orign, 'WordStock/' + str(group) + '.cl')
if changedict != {} and nofoundlines == []:
print('删除{}个条目成功'.format(delsign))
simuse.Send_Message(data, target, target_type,
Expand Down Expand Up @@ -575,7 +574,7 @@ def findallanswer(data, sender, cllist, answer, group=0, target_type=0):
for i in cllist:
findquestiondict = {}
findquestion[i[:-3]] = findquestiondict
cldict = pickle_load(open('WordStock/' + i, 'rb'))
cldict = pickle_load('WordStock/' + i)
for l in answer:
for k in cldict:
questiondict = cldict[k]
Expand Down
15 changes: 10 additions & 5 deletions ChatCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@


def getallconfig():
file = open('config.clc', 'r', encoding='utf-8-sig')
config = json_load(file)
file.close()

config = json_load('config.clc')

return config


Expand All @@ -36,7 +36,7 @@ def clcheck(filename, data, fromchat):
question_num = 0
answer_num = 0
allanswerlist = []
cldict = pickle_load(open('WordStock/' + filename, 'rb'))
cldict = pickle_load('WordStock/' + filename)
for i in cldict:
question_num += 1
questioninfo = cldict[i]
Expand Down Expand Up @@ -121,6 +121,11 @@ def main(data, fromchat):
cosmatchtip = cosmatchtip.format('开启')
else:
cosmatchtip = cosmatchtip.format('关闭')
atreplytip = '艾特回复:{}'
if config['atreply'] == 1:
atreplytip = atreplytip.format('开启')
else:
atreplytip = atreplytip.format('关闭')

replychancetip = '回复触发概率:{}%'.format(config['replychance'])
replywaittip = '回复等待时间:{:g}±{:g}秒'.format(config['replywait'][0],
Expand Down Expand Up @@ -169,7 +174,7 @@ def main(data, fromchat):
check_version[1])
else:
versiontip = "未连接至ChatLearning服务器"
situation = learningtip + '\n' + replytip + '\n' + voicereplytip + '\n' + golbetip + '\n' +cosmatchtip+'\n'+ replychancetip + '\n' + replywaittip + '\n' + replycdtip + '\n' +cosmatchingtip+'\n'+ voicereplychancetip + '\n' + synthesizertip + '\n' + mergetimetip + '\n' + intervaltip + '\n' + blackfreqtip + '\n' + tempmessagenumtip + '\n' + botnametip + '\n' + replylengthtip
situation = learningtip + '\n' + replytip + '\n' + voicereplytip + '\n' + golbetip + '\n' +cosmatchtip+'\n'+atreplytip+'\n'+ replychancetip + '\n' + replywaittip + '\n' + replycdtip + '\n' +cosmatchingtip+'\n'+ voicereplychancetip + '\n' + synthesizertip + '\n' + mergetimetip + '\n' + intervaltip + '\n' + blackfreqtip + '\n' + tempmessagenumtip + '\n' + botnametip + '\n' + replylengthtip
situationchain = [{'type': 'Plain', 'text': situation}]
typefreq_message = [{'type': 'Plain', 'text': typefreqtip}]
siglereply_message = [{'type': 'Plain', 'text': singlereplytip}]
Expand Down
67 changes: 28 additions & 39 deletions ChatClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,35 @@

import simuse

version = '3.0.2'
version = '3.0.3'

filename_set= set()
lock = threading.Lock()


def lock(filename):
while True:
if not(filename in filename_set):
break
time.sleep(0.1)
filename_set.add(filename)

def release_lock(filename):
filename_set.remove(filename)

def pickle_dump(obj, file):
lock(file.name)
pickle.dump(obj, file)
release_lock(file.name)
file.close()
def pickle_dump(obj, path):
with lock:
with open(path,'wb') as file:
pickle.dump(obj, file)
return True


def pickle_load(file):
lock(file.name)
obj = pickle.load(file)
release_lock(file.name)
file.close()
def pickle_load(path):
with lock:
with open(path,'rb') as file:
obj = pickle.load(file)
return obj


def json_dump(obj, file, indent=3, ensure_ascii=False):
lock(file.name)
json.dump(obj, file, indent=indent, ensure_ascii=ensure_ascii)
release_lock(file.name)
file.close()
def json_dump(obj, path, indent=3, ensure_ascii=False):
with lock:
with open(path,'w',encoding='utf-8-sig') as file:
json.dump(obj, file, indent=indent, ensure_ascii=ensure_ascii)
return True


def json_load(file):
lock(file.name)
obj = json.load(file)
release_lock(file.name)
file.close()
def json_load(path):
with lock:
with open(path,'r',encoding='utf-8-sig') as file:
obj = json.load(file)
return obj

class Platform:
Expand Down Expand Up @@ -100,6 +85,7 @@ class commandclass():
commandtips['cosmatch'] = '#开启/关闭问题余弦相似度计算'
commandtips['learning <秒>'] = '#设定词库链间隔时间'
commandtips['reply <%>'] = '#设定回复的触发几率'
commandtips['atreply'] = '#开启/关闭艾特回复'
commandtips['reply -s <%> <群号>'] = '#单独设定回复触发几率'
commandtips['reply -d <群号>'] = '#清除单独设定的回复触发几率'
commandtips['replywait <基准时间> <浮动时间>'] = '#设定回复的等待时间'
Expand Down Expand Up @@ -436,7 +422,7 @@ def Version():

def stop_run():

config = json_load(open('config.clc', 'r', encoding='utf-8-sig'))
config = json_load('config.clc')
sign = config["stopsign"]

if sign == 0:
Expand Down Expand Up @@ -509,7 +495,7 @@ def ClChange(self):
dicts = file.read()
dicts = eval(dicts)
file.close()
pickle_dump(dicts, open(i, 'wb'))
pickle_dump(dicts, i)
print('准备完毕!')

def Cl_version(self):
Expand All @@ -529,24 +515,24 @@ def Cl_version(self):
if self.version < 280:
print('正在更新词库版本,{} -> 280 请勿中途退出'.format(self.version))
for i in cllist:
dicts = pickle_load(open(i, 'rb'))
dicts = pickle_load(i)
for k in dicts.keys():
questiondict = dicts[k]
if not ('freq' in questiondict.keys()):
questiondict['freq'] = 1
pickle_dump(dicts, open(i, 'wb'))
pickle_dump(dicts, i)
shutil.move(i, 'WordStock/' + i)

# 3.0.0前版本更新需要为词库Key添加"regular"正则判断键
if self.version < 300:
print('正在更新词库版本,{} -> 300 请勿中途退出'.format(self.version))
for i in cllist:
dicts = pickle_load(open('WordStock/'+i, 'rb'))
dicts = pickle_load('WordStock/'+i)
for k in dicts.keys():
questiondict = dicts[k]
if not ('regular' in questiondict.keys()):
questiondict['regular'] = False
pickle_dump(dicts, open('WordStock/'+i, 'wb'))
pickle_dump(dicts, 'WordStock/'+i)



Expand Down Expand Up @@ -596,5 +582,8 @@ def Config_version(self):
print('正在更新config, -> 302 请勿中途退出')
config['botname'] = ['我']
config['replylength'] = 100
if self.version < 303:
print('正在更新config, -> 303 请勿中途退出')
config['atreply'] = 1

return config
10 changes: 5 additions & 5 deletions ChatDelete.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def Delete(data, sender):

def Merge(Mergedict, filename):
version_error = 0
cldict = pickle_load(open('WordStock/' + filename, 'rb'))
cldict = pickle_load('WordStock/' + filename)
#print(Mergedict)
try:
repeatquestion = Mergedict.keys() & cldict.keys()
Expand All @@ -95,7 +95,7 @@ def Merge(Mergedict, filename):


def Delete_freq(Mergedict, filename):
cldict = pickle_load(open('WordStock/' + filename, 'rb'))
cldict = pickle_load('WordStock/' + filename)
freqdel_num = 0
for question in Mergedict:
questiondict = Mergedict[question]
Expand All @@ -105,12 +105,12 @@ def Delete_freq(Mergedict, filename):
freqdel_num += 1
except:
continue
pickle_dump(cldict, open('WordStock/' + filename, 'wb'))
pickle_dump(cldict, 'WordStock/' + filename)
return freqdel_num


def Delete_Filter(filename):
cldict = pickle_load(open('WordStock/' + filename, 'rb'))
cldict = pickle_load('WordStock/' + filename)
question_list = list(cldict.keys())
filterdel_num = 0
for question in question_list:
Expand All @@ -126,5 +126,5 @@ def Delete_Filter(filename):
if ChatFilter.filtercheck(eval(answertext), display=False) == 0:
answerlist_origin.remove(answerdict)
filterdel_num += 1
pickle_dump(cldict, open('WordStock/' + filename, 'wb'))
pickle_dump(cldict, 'WordStock/' + filename)
return filterdel_num
Loading

0 comments on commit fe66c00

Please sign in to comment.