Skip to content

Commit

Permalink
update 2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JHue58 committed Mar 31, 2022
1 parent 7d6c928 commit edf6c7b
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 99 deletions.
13 changes: 4 additions & 9 deletions ChatAdmin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import asyncio
import copy
import os
import pickle
import threading
import time

Expand Down Expand Up @@ -104,9 +105,7 @@ def getnode(data, tempdict, answerlist, group, sender, question):
time.sleep(0.8)
tempdict.pop(question)
filename = str(group) + '.cl' # 读取已缓存的词库
file = open(filename, 'w', encoding='utf-8-sig')
file.write(str(tempdict))
file.close()
pickle.dump(tempdict,open(filename, 'wb'))
simuse.Send_Message(data, sender, 2, '已清空', 1)
return None
if node == str(-1) or node == '–1':
Expand Down Expand Up @@ -155,9 +154,7 @@ def getnode(data, tempdict, answerlist, group, sender, question):
if answerlist == []:
tempdict.pop(question)
filename = str(group) + '.cl' # 读取已缓存的词库
file = open(filename, 'w', encoding='utf-8-sig')
file.write(str(tempdict))
file.close()
pickle.dump(tempdict,open(filename, 'wb'))
if templist != []:
if sendtext != '':
simuse.Send_Message(
Expand Down Expand Up @@ -305,9 +302,7 @@ def getanswer(data, sender, group, question): # 从词库中获取答案
continue
question = str(question)
filename = str(group) + '.cl' # 读取已缓存的词库
file = open(filename, 'r', encoding='utf-8-sig')
tempdict = file.read()
file.close()
tempdict=pickle.load(open(filename, 'rb'))
tempdict = eval(tempdict)
try: # 检索问题,若词库中无该问题,则函数返回-1,若有,则返回所有答案(答案列表)
#print(question)
Expand Down
47 changes: 28 additions & 19 deletions ChatAllfind.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import hashlib
import os
import pickle
import time

import xlwt
Expand Down Expand Up @@ -208,8 +209,8 @@ def createxcel(groupcldict):

#上传工作表至cos
def uploadcos(data, filename):
secret_id = 'xxxx'
secret_key = 'xxxx'
secret_id = 'XXX'
secret_key = 'XXX'
region = 'ap-shanghai'
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key)
client = CosS3Client(config)
Expand Down Expand Up @@ -348,11 +349,9 @@ def delcl(data, sender, lines_dict, nodelist,target_type=0,group=0):

delsign = 0
for group in changedict:
file = open(str(group) + '.cl', 'r', encoding='utf-8-sig')
cldict_orign = eval(file.read())
cldict_orign=pickle.load(open(str(group) + '.cl', 'rb'))
cldict = copy.deepcopy(cldict_orign)
questionlist = list(cldict_orign.keys())
file.close()
changelist = changedict[group]
for nodedict in changelist:
question = questionlist[nodedict['questionnode']]
Expand All @@ -370,9 +369,7 @@ def delcl(data, sender, lines_dict, nodelist,target_type=0,group=0):
if answerlist == []:
cldict.pop(question)
cldict_orign = cldict
file = open(str(group) + '.cl', 'w', encoding='utf-8-sig')
file.write(str(cldict_orign))
file.close()
pickle.dump(cldict_orign,open(str(group) + '.cl', 'wb'))
if changedict != {} and nofoundlines == []:
print('删除{}个条目成功'.format(delsign))
simuse.Send_Message(data, target, target_type, '删除{}个条目成功'.format(delsign), 1)
Expand Down Expand Up @@ -406,11 +403,8 @@ def findallquestion(data, sender, cllist, question, allquestion=0,group=0,target
findquestiondict = {}
findquestion[i[:-3]] = findquestiondict
try:
file = open(i, 'r', encoding='utf-8-sig')
cldict = file.read()
cldict = eval(cldict)
cldict=pickle.load(open(i, 'rb'))
questionlist = list(cldict.keys())
file.close()
except:
print('该群无词库')
simuse.Send_Message(data, target, target_type, '该群无词库', 1)
Expand Down Expand Up @@ -502,7 +496,13 @@ def findallquestion(data, sender, cllist, question, allquestion=0,group=0,target
filename = filename_lines_dict[0]
lines_dict = filename_lines_dict[1]
if allquestion == 1:
nodelist = uploadcos(data, filename)
try:
nodelist = uploadcos(data, filename)
except:
print('网络连接出错')
simuse.Send_Message(data, target, target_type, '网络连接出错', 1)
os.remove(filename + '.xls')
return None
time.sleep(1)
delcl(data, sender, lines_dict, nodelist,target_type=target_type,group=group)
return None
Expand All @@ -511,7 +511,13 @@ def findallquestion(data, sender, cllist, question, allquestion=0,group=0,target
while 1:
command = ChatAdmin.get_admin_command(data, sender=sender,group=group)
if command == str(1):
nodelist = uploadcos(data, filename)
try:
nodelist = uploadcos(data, filename)
except:
print('网络连接出错')
simuse.Send_Message(data, target, target_type, '网络连接出错', 1)
os.remove(filename + '.xls')
break
time.sleep(1)
delcl(data, sender, lines_dict, nodelist,target_type=target_type,group=group)
break
Expand Down Expand Up @@ -541,10 +547,7 @@ def findallanswer(data, sender, cllist, answer,group=0,target_type=0):
for i in cllist:
findquestiondict = {}
findquestion[i[:-3]] = findquestiondict
file = open(i, 'r', encoding='utf-8-sig')
cldict = file.read()
cldict = eval(cldict)
file.close()
cldict=pickle.load(open(i, 'rb'))
for l in answer:
for k in cldict:
questiondict = cldict[k]
Expand Down Expand Up @@ -595,7 +598,13 @@ def findallanswer(data, sender, cllist, answer,group=0,target_type=0):
while 1:
command = ChatAdmin.get_admin_command(data, sender=sender,group=group)
if command == str(1):
nodelist = uploadcos(data, filename)
try:
nodelist = uploadcos(data, filename)
except:
print('网络连接出错')
simuse.Send_Message(data, target, target_type, '网络连接出错', 1)
os.remove(filename + '.xls')
break
time.sleep(1)
delcl(data, sender, lines_dict, nodelist,target_type=target_type,group=group)
break
Expand Down
9 changes: 4 additions & 5 deletions ChatCheck.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pickle
import json
import os
import time
Expand All @@ -18,7 +19,7 @@ def getallconfig():


def checkversion():
url = 'http://XXXXX/Update'
url = 'http://124.222.165.166:19630/Update'
try:
res = requests.request('get', url=url, timeout=20)
res = json.loads(res.text)
Expand All @@ -36,10 +37,7 @@ def clcheck(filename, data, fromchat):
question_num = 0
answer_num = 0
allanswerlist = []
file = open(filename, 'r', encoding='utf-8-sig')
cldict = file.read()
file.close()
cldict = eval(cldict)
cldict=pickle.load(open(filename, 'rb'))
for i in cldict:
question_num += 1
questioninfo = cldict[i]
Expand Down Expand Up @@ -145,5 +143,6 @@ def main(data, fromchat):
sendmessagedict['nodeList'] = nodelist
simuse.Send_Message_Chain(data, fromchat, 2, sendmessagechain)
print(situation,'\n'+versiontip)
return None

#os.system('pause')
30 changes: 27 additions & 3 deletions ChatClass.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pickle
import re
import threading
import time
import traceback

import os
import simuse

version = '2.6.0'
version = '2.7.0'


# 控制台指令类
Expand Down Expand Up @@ -36,6 +37,7 @@ class commandclass():
commandtips['blackfreq <次数>'] = '#设置黑名单容错次数'
commandtips['uploadwav'] = '#上传源音频文件'
commandtips['admin'] = '#进入管理模式'
commandtips['exit'] = '#退出程序'

def __init__(self, data, input):
self.command = input.strip('*')
Expand Down Expand Up @@ -96,8 +98,10 @@ def commandhelp(self, fromchat):

# 多线程类的复写
class My_Thread(threading.Thread):

daemon=True

def run(self):
# 常驻为守护线程
try:
if self._target:
self._target(*self._args, **self._kwargs)
Expand All @@ -117,3 +121,23 @@ def run(self):
def Version():
global version
return version

# 2.7.0前版本更新需要更换词库的缓存形式
def ClChange():
filelist = os.listdir() # 获取词库列表
cllist = []
for i in filelist:
if i[-3:] == '.cl':
#print(i)
cllist.append(i)
#print(cllist)
print('正在为更新做一些准备,请稍等')
print('期间请勿关闭程序,否则将导致数据丢失!')
for i in cllist:
file=open(i,'r',encoding='utf-8-sig')
dicts=file.read()
dicts=eval(dicts)
file.close()
pickle.dump(dicts,open(i,'wb'))
print('准备完毕!')

3 changes: 2 additions & 1 deletion ChatFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,15 @@ def filtercheck(question):
#print(question)
for i in question:
if i['type'] == 'Plain':
text=i['text']
for k in Filterconfig['filter']:
k = eval(k)
for j in k:
if j['type'] == 'Plain':
if i['text'].find(j['text']) != -1:
print('已过滤,原因:与过滤名单模糊匹配')
return 0
if str(question) in Filterconfig['filter'] or command.find(text):
if str(question) in Filterconfig['filter'] or command.find(text)!=-1:
print('已过滤,原因:与过滤名单匹配')
return 0
else:
Expand Down
21 changes: 6 additions & 15 deletions ChatLearning.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Demo阶段
import copy
import os
import pickle
import time
import ChatFilter
from re import I
Expand Down Expand Up @@ -36,10 +36,7 @@ def creatquestion(question, group): # 记录问题
question = str(question)
filename = str(group) + ".cl"
try: # 读取已缓存的词库
file = open(filename, 'r', encoding='utf-8-sig')
tempdict = file.read()
file.close()
tempdict = eval(tempdict)
tempdict=pickle.load(open(filename, 'rb'))
except:
tempdict = {}
if not (question in tempdict.keys()): # 判断词库中问题是否存在,若不存在则记录问题
Expand All @@ -52,9 +49,7 @@ def creatquestion(question, group): # 记录问题
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "\n问题已记录",
filename)
#print(tempdict)
file = open(filename, 'w', encoding='utf-8-sig')
file.write(str(tempdict))
file.close()
pickle.dump(tempdict,open(filename, 'wb'))
return tempquestion # 返回未去除“url”的消息链,为记录答案做准备


Expand All @@ -69,10 +64,7 @@ def creatanswer(question, answer, group): # 记录答案
question = str(question)
answer = str(answer)
filename = str(group) + ".cl"
file = open(filename, 'r', encoding='utf-8-sig') # 读取缓存的词库
tempdict = file.read()
file.close()
tempdict = eval(tempdict)
tempdict=pickle.load(open(filename, 'rb')) # 读取缓存的词库
answertime = int(time.time())
answerdict = {"answertext": "", "time": ""}
answerdict["answertext"] = answer
Expand Down Expand Up @@ -116,11 +108,9 @@ def creatanswer(question, answer, group): # 记录答案
else: # 答案列表为空时一定是新答案,所以直接记录
questiondict["answer"].append(answerdict.copy())
tempdict[question] = questiondict
file = open(filename, 'w', encoding='utf-8-sig')
file.write(str(tempdict))
pickle.dump(tempdict,open(filename, 'wb'))
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "\n答案已记录",
filename)
file.close()


def extractmessage(data, tempdict): # 将消息链转化为字典格式(key为群号,value为消息链)
Expand Down Expand Up @@ -204,6 +194,7 @@ def main():
data = simuse.Get_data()
data = simuse.Get_Session(data)
listening(data)
return None


#main()
Expand Down
10 changes: 3 additions & 7 deletions ChatMerge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pickle
import time


Expand All @@ -13,10 +14,7 @@ def getconfig():

def Merge(Mergedict, filename):
repeatquestion_num = 0
file = open(filename, 'r', encoding='utf-8-sig')
cldict = file.read()
file.close()
cldict = eval(cldict)
cldict=pickle.load(open(filename, 'rb'))
#print(Mergedict)
try:
repeatquestion = Mergedict.keys() & cldict.keys()
Expand Down Expand Up @@ -56,9 +54,7 @@ def getfile():
except:
pass
Mergedict = Merge(Mergedict, i)
file = open('Merge.cl', 'w', encoding='utf-8-sig')
file.write(str(Mergedict))
file.close()
pickle.dump(Mergedict,open('Merge.cl', 'wb'))
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), '词库合并完成')
#print('->',end='')
#os.system('pause')
Expand Down
Loading

0 comments on commit edf6c7b

Please sign in to comment.