Skip to content

Commit

Permalink
update 2.9.7
Browse files Browse the repository at this point in the history
  • Loading branch information
JHue58 committed Jun 21, 2022
1 parent 7cec5de commit d66b2f7
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 114 deletions.
9 changes: 4 additions & 5 deletions ChatAdmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def listening(data, adminlist, group):
command = messagechain[0]
if command['type'] == 'Plain' and command['text'] == 'admin':
exitadmin()
simuse.Send_Message(data, i['sender'], 2, '退出管理模式', 1)
#simuse.Send_Message(data, i['sender'], 2, '退出管理模式', 1)
break
question = messagechain
getanswer(data, i['sender'], group, question) # 获取答案
Expand All @@ -357,7 +357,7 @@ def tui(data, adminlist, group):
while 1:
time.sleep(1)
if exitadmin(1) == 0:
print('退出管理模式')
#print('退出管理模式')
return None
#return None

Expand Down Expand Up @@ -388,14 +388,13 @@ def main(data, adminlist, group, fromchat):
#print(getfilelist())
if not (group in getfilelist()):
print('<-群定位失败,未找到群', group)
print('<-退出管理模式')
if fromchat != 0:
simuse.Send_Message(data, fromchat, 2,
'群定位失败,未找到群' + str(group) + '\n' + '退出管理模式', 1)
'群定位失败,未找到群' + str(group), 1)
return None
print('<-定位到群', group)
if fromchat != 0:
tips = '定位到群' + str(group) + '\n' + '请发送“问题”,发送admin可退出管理模式'
tips = '定位到群' + str(group) + '\n' + '请发送“问题”,发送admin可退出'
simuse.Send_Message(data, fromchat, 2, tips, 1)
print('请使用管理员QQ', getconfig(1), '向bot发送消息')
tui(data, adminlist, group)
Expand Down
8 changes: 4 additions & 4 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 = 'xxx'
secret_key = 'xxx'
region = 'ap-shanghai'
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key)
client = CosS3Client(config)
Expand Down Expand Up @@ -664,9 +664,9 @@ def findallcontrol(data, sender, group=0):
while 1:
time.sleep(1)
if group == 0:
tips = '请选择你的操作\n1.查找问题\n2.查找答案\n3.查看某个群的所有词库\n4.退出管理模式'
tips = '请选择你的操作\n0.返回\n1.查找问题\n2.查找答案\n3.查看某个群的所有词库'
else:
tips = '进入管理模式\n请选择你的操作\n1.查找问题\n2.查找答案\n3.查看所有词库\n4.退出管理模式'
tips = '进入管理模式\n请选择你的操作\n1.查找问题\n2.查找答案\n3.查看所有词库\n4.返回'
simuse.Send_Message(data, target, target_type, tips, 1)
while 1:
command = ChatAdmin.get_admin_command(data,
Expand Down
20 changes: 14 additions & 6 deletions ChatClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import simuse

version = '2.9.5'
version = '2.9.7'


# 控制台指令类
Expand Down Expand Up @@ -137,13 +137,16 @@ class TimeTask():

runday=''

def __init__(self,TaskName:str) -> None:
def __init__(self,TaskName:str , TaskText:str=None) -> None:
self.Default()
TaskPath='AutoTask/{}.txt'.format(TaskName)

self.TaskName=TaskName

with open(TaskPath,'r',encoding='utf-8') as TaskFile:
TextList=TaskFile.readlines()
if TaskText==None:
TaskPath='AutoTask/{}.txt'.format(TaskName)
with open(TaskPath,'r',encoding='utf-8') as TaskFile:
TextList=TaskFile.readlines()
else:
TextList = TaskText.split('\n')
for lines in TextList:
lines = ' '.join(lines.split())
if lines=='':
Expand Down Expand Up @@ -415,6 +418,11 @@ def Config_version(self):
config['voicecharerror']='存在违规字符,转换失败'
config['voicecderror']='转换冷却中'
config['voicelengtherror']='长度超过限制'
if self.version < 297:
print('正在更新config, -> 297 请勿中途退出')
config['deletesuccess']='已从词库内删除!'
config['deletetemperror']='删除失败,该消息已不在缓存内'
config['deletefinderror']='删除失败,词库中已无法找到该答案'


return config
4 changes: 2 additions & 2 deletions ChatFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def filtercontrol(data, sender):
ExitChain=[{'type':'Plain','text':'exit'}]
while 1:
time.sleep(1)
tips = '请选择你的操作\n1.添加需过滤的关键字\n2.添加敏感关键字\n3.添加黑名单账号\n4.查看\n5.退出管理模式'
tips = '请选择你的操作\n0.返回\n1.添加需过滤的关键字\n2.添加敏感关键字\n3.添加黑名单账号\n4.查看'
simuse.Send_Message(data, sender, 2, tips, 1)
while 1:
command = ChatAdmin.get_admin_command(data, sender=sender)
Expand Down Expand Up @@ -504,7 +504,7 @@ def filtercontrol(data, sender):
simuse.Send_Message(data, sender, 2, '添加完毕', 1)
elif command == str(4):
simuse.Send_Message(data, sender, 2,
'请输入需要查看的内容\n1.过滤的关键字\n2.敏感的关键字\n3.黑名单\n4.返回',
'请输入需要查看的内容\n0.返回\n1.过滤的关键字\n2.敏感的关键字\n3.黑名单',
1)
while 1:
Filterconfig = blackcheck()
Expand Down
130 changes: 130 additions & 0 deletions ChatLearning.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from re import I

import ChatFilter
import ChatAdmin
import ChatMerge
import simuse


Expand Down Expand Up @@ -196,6 +198,134 @@ def listening(data):
time.sleep(0.5)




def custom_answer(data,fromchat):
cl_file_text='拥有的词库:\n'
cl_list=ChatAdmin.getfilelist()
for i in cl_list:
cl_file_text+=i+'\n'
simuse.Send_Message(data,fromchat,2,cl_file_text,1)
time.sleep(0.5)
simuse.Send_Message(data,fromchat,2,"请输入需要新增回复的词库昵称(不存在将会新建词库)",1)
while True:
filename = ChatAdmin.get_admin_command(data,sender=fromchat)
if filename!=None:
break
time.sleep(0.5)

filename+='.cl'
have_cl=True

try:
cldict = pickle.load(open('WordStock/' + filename, 'rb'))
except:
time.sleep(0.5)
simuse.Send_Message(data,fromchat,2,"词库不存在,将被创建",1)
have_cl=False
cldict = {}

while True:
time.sleep(0.5)
simuse.Send_Message(data,fromchat,2,"请输入问题",1)
while True:
question = ChatAdmin.get_admin_question(data,fromchat)
if question!=None:
break
time.sleep(0.5)

for i in question:
try:
i.pop('url')
except:
pass

have_question=True
try:
questiondict = cldict[str(question)]
answerlist = questiondict['answer']
except:
if have_cl:
time.sleep(0.5)
simuse.Send_Message(data,fromchat,2,"问题不存在,将被创建",1)
answerlist=[]
questiondict = {'time':int(time.time()),'answer':answerlist,'freq':9999}
have_question=False

while True:
time.sleep(0.5)
simuse.Send_Message(data,fromchat,2,"请输入答案",1)
while True:
answer = ChatAdmin.get_admin_question(data,fromchat)
if answer!=None:
break
time.sleep(0.5)
simuse.Send_Message(data,fromchat,2,"请输入答案的权重(这是一个非负的整数,越大表明抽中该答案的概率越大)",1)
while True:
while True:
weight = ChatAdmin.get_admin_command(data,sender=fromchat)
if weight!=None:
break
time.sleep(0.5)
try:
weight = int(weight)
except:
simuse.Send_Message(data,fromchat,2,"权重必须是一个非负的整数,请重新输入",1)
continue
if weight<0:
simuse.Send_Message(data,fromchat,2,"权重必须是一个非负的整数,请重新输入",1)
continue
break

if have_question:
for answerdict in answerlist:
if answerdict["answertext"]==str(answer):
answerdict['same']=weight
time.sleep(0.5)
simuse.Send_Message(data,fromchat,2,"问题中已存在该答案,已将权重修改为新值",1)
break
else:
answerdict={'answertext':str(answer),'time':int(time.time()),'same':weight}
answerlist.append(answerdict)
time.sleep(0.5)
simuse.Send_Message(data,fromchat,2,"添加完毕!",1)
else:
answerdict={'answertext':str(answer),'time':int(time.time()),'same':weight}
answerlist.append(answerdict)
cldict[str(question)]=questiondict

time.sleep(0.5)
simuse.Send_Message(data,fromchat,2,"添加完毕!",1)

pickle.dump(cldict, open('WordStock/' + filename, 'wb'))

time.sleep(0.5)
simuse.Send_Message(data,fromchat,2,"请选择:\n0.退出\n1.为该问题继续添加答案\n2.为该词库添加新的问答",1)
while True:
command = ChatAdmin.get_admin_command(data,sender=fromchat)
if command!=None:
break

if command==str(0):
ChatMerge.getfile()
return None
elif command==str(1):
continue
elif command==str(2):
break













def main():
data = simuse.Get_data()
if data["Key"] != "":
Expand Down
63 changes: 46 additions & 17 deletions ChatReply.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,32 @@ def DelType(tempdict, answerlist):
i.pop('url')
except:
pass

try:
questiondict = tempdict[str(answertext)]
weight=answerdict['same']+1
except:
try:
new_answerlist.remove(answerdict)
except:
pass
num += 1
deltype = deltype + i['type'] + ' '
weight=1

try:
if questiondict['freq'] < freqdict[i['type']]:
new_answerlist.remove(answerdict)
num += 1
deltype = deltype + i['type'] + ' '
continue
if weight < freqdict[i['type']]:
try:
questiondict = tempdict[str(answertext)]
if questiondict['freq'] < freqdict[i['type']]:
new_answerlist.remove(answerdict)
num += 1
deltype = deltype + i['type'] + ' '
continue
except:
new_answerlist.remove(answerdict)
num +=1
deltype = deltype + i['type'] + ' '
continue
else:
continue
except:
continue
pass


if num != 0:
print('已过滤{}个不符合发送要求的{}'.format(num, ','.join(set(deltype.split()))))
return new_answerlist
Expand Down Expand Up @@ -86,13 +95,13 @@ def Judge_Fast_Delete(data, TempMessage, group, messagechain, sender,messageId):
global RecallList
simuse.Recall_Message(data, SourceId)
time.sleep(1)
RecallList.append(simuse.Send_Message(data, group, 1, '已从词库内删除!', 1))
RecallList.append(simuse.Send_Message(data, group, 1, getconfig(16)['deletesuccess'], 1))
elif Delete_Sign == 0:
RecallList.append(
simuse.Send_Message(data, group, 1, '删除失败,该消息已不在缓存内', 1))
simuse.Send_Message(data, group, 1, getconfig(16)['deletetemperror'], 1))
elif Delete_Sign == -1:
RecallList.append(
simuse.Send_Message(data, group, 1, '删除失败,词库中已无法找到该答案', 1))
simuse.Send_Message(data, group, 1, getconfig(16)['deletefinderror'], 1))
RecallList.append(messageId)
return 1
else:
Expand Down Expand Up @@ -354,7 +363,7 @@ def replyanswer(data, group, answer): # 发送答案
return None

try:
answer = random.choice(answer) # 尝试从答案列表中随机抽取一个答案,若答案列表为空,则不回复
answer = random_weight(answer) # 尝试从答案列表中随机抽取一个答案,若答案列表为空,则不回复
answer = answer['answertext']
except:
print('无答案,不给予回复')
Expand Down Expand Up @@ -425,6 +434,26 @@ def replyanswer(data, group, answer): # 发送答案
print('答案发送失败')


# 以same作为权重选择
def random_weight(answerlist):

same_weight_multiple = 1 # 权重乘值
same_weight_plus = 1 # 权重加值

same_list=[]
for answerdict in answerlist:
try:
same_list.append((answerdict["same"]+same_weight_plus)*same_weight_multiple)
except:
same_list.append((0+same_weight_plus)*same_weight_multiple)
answer = random.choices(answerlist,weights=same_list,k=1)[0]
# print("权重选择器选择:",answer)
if answer!=None:
return answer
else:
return random.choice(answerlist)


def listening(data):
global RecallList
RecallList = []
Expand Down
Loading

0 comments on commit d66b2f7

Please sign in to comment.