This commit is contained in:
SuperSonic 2020-02-10 14:36:32 +08:00
parent d5ea8c3006
commit 52600759a8
7 changed files with 317 additions and 179 deletions

View file

@ -10,8 +10,11 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
import time import time
import json import json
from ..tools import Yuuki_StaticTools, Yuuki_DynamicTools
from yuuki_core.ttypes import MIDType, ContentType, OpType from yuuki_core.ttypes import MIDType, ContentType, OpType
class Yuuki_Command: class Yuuki_Command:
def __init__(self, Yuuki): def __init__(self, Yuuki):
""" """
@ -20,64 +23,78 @@ class Yuuki_Command:
""" """
self.Yuuki = Yuuki self.Yuuki = Yuuki
self.Yuuki_StaticTools = Yuuki_StaticTools()
self.Yuuki_DynamicTools = Yuuki_DynamicTools(self.Yuuki)
def action(self, ncMessage): def action(self, ncMessage):
BlockedIgnore = (ncMessage.message.to in self.Yuuki.data.getData(["BlackList"])) or ( BlockedIgnore = (ncMessage.message.to in self.Yuuki.data.getData(["BlackList"])) or (
ncMessage.message.from_ in self.Yuuki.data.getData(["BlackList"])) ncMessage.message.from_ in self.Yuuki.data.getData(["BlackList"]))
if ('BOT_CHECK' in ncMessage.message.contentMetadata) or BlockedIgnore: if ('BOT_CHECK' in ncMessage.message.contentMetadata) or BlockedIgnore:
pass pass
elif ncMessage.message.toType == MIDType.ROOM: elif ncMessage.message.toType == MIDType.ROOM:
self.Yuuki.getClient(self.Yuuki.MyMID).leaveRoom(self.Yuuki.Seq, ncMessage.message.to) self.Yuuki_DynamicTools.getClient(self.Yuuki.MyMID).leaveRoom(
self.Yuuki.Seq, ncMessage.message.to)
elif ncMessage.message.contentType == ContentType.NONE: elif ncMessage.message.contentType == ContentType.NONE:
msgSep = ncMessage.message.text.split(" ") msgSep = ncMessage.message.text.split(" ")
if self.Yuuki.YuukiConfigs["name"] + '/Help' == ncMessage.message.text: if self.Yuuki.YuukiConfigs["name"] + '/Help' == ncMessage.message.text:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
self.Yuuki.get_text("%s\n\t%s\n\nCommands Info:\n%s\n\nPrivacy:\n%s\n\nMore Information:\n%s\n\n%s") % self.Yuuki.get_text("%s\n\t%s\n\nCommands Info:\n%s\n\nPrivacy:\n%s\n\nMore Information:\n%s\n\n%s") %
(self.Yuuki.YuukiConfigs["name"], self.Yuuki.YuukiConfigs["version"], (self.Yuuki.YuukiConfigs["name"], self.Yuuki.YuukiConfigs["version"],
self.Yuuki.YuukiConfigs["man_page"], self.Yuuki.YuukiConfigs["privacy_page"], self.Yuuki.YuukiConfigs["man_page"], self.Yuuki.YuukiConfigs["privacy_page"],
self.Yuuki.YuukiConfigs["project_url"], self.Yuuki.YuukiConfigs["copyright"])) self.Yuuki.YuukiConfigs["project_url"], self.Yuuki.YuukiConfigs["copyright"]))
elif self.Yuuki.YuukiConfigs["name"] + '/Version' == ncMessage.message.text: elif self.Yuuki.YuukiConfigs["name"] + '/Version' == ncMessage.message.text:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.YuukiConfigs["version"]) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.YuukiConfigs["version"])
elif self.Yuuki.YuukiConfigs["name"] + '/UserID' == ncMessage.message.text: elif self.Yuuki.YuukiConfigs["name"] + '/UserID' == ncMessage.message.text:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("LINE System UserID:\n") + ncMessage.message.from_) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("LINE System UserID:\n") + ncMessage.message.from_)
elif self.Yuuki.YuukiConfigs["name"] + '/GetAllHelper' == ncMessage.message.text: elif self.Yuuki.YuukiConfigs["name"] + '/GetAllHelper' == ncMessage.message.text:
if ncMessage.message.toType == MIDType.GROUP: if ncMessage.message.toType == MIDType.GROUP:
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to) GroupInfo = self.Yuuki_DynamicTools.getClient(
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] + \ self.Yuuki.MyMID).getGroup(ncMessage.message.to)
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki_StaticTools.sybGetGroupCreator(GroupInfo).mid] + \
self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"] self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]
if ncMessage.message.from_ in GroupPrivilege: if ncMessage.message.from_ in GroupPrivilege:
for userId in self.Yuuki.Connect.helper_ids: for userId in self.Yuuki.Connect.helper_ids:
self.Yuuki.sendUser(self.Yuuki.sendToWho(ncMessage), userId) self.Yuuki_DynamicTools.sendUser(
self.Yuuki_StaticTools.sendToWho(ncMessage), userId)
elif self.Yuuki.YuukiConfigs["name"] + '/Speed' == ncMessage.message.text: elif self.Yuuki.YuukiConfigs["name"] + '/Speed' == ncMessage.message.text:
Time1 = time.time() Time1 = time.time()
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Testing...")) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Testing..."))
Time2 = time.time() Time2 = time.time()
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Speed:\n %s com/s") % (Time2 - Time1,)) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Speed:\n %s com/s") % (Time2 - Time1,))
elif self.Yuuki.YuukiConfigs["name"] + '/SecurityMode' == msgSep[0]: elif self.Yuuki.YuukiConfigs["name"] + '/SecurityMode' == msgSep[0]:
if ncMessage.message.from_ in self.Yuuki.Admin: if ncMessage.message.from_ in self.Yuuki.Admin:
if len(msgSep) == 2: if len(msgSep) == 2:
if msgSep[1].isdigit() and 1 >= int(msgSep[1]) >= 0: if msgSep[1].isdigit() and 1 >= int(msgSep[1]) >= 0:
self.Yuuki.data.updateData(["Global", "SecurityService"], bool(msgSep[1])) self.Yuuki.data.updateData(
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Okay")) ["Global", "SecurityService"], bool(msgSep[1]))
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Okay"))
else: else:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Enable(True): 1\nDisable(False): 0")) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Enable(True): 1\nDisable(False): 0"))
else: else:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
str(bool(self.Yuuki.data.getData(["Global", "SecurityService"])))) str(bool(self.Yuuki.data.getData(["Global", "SecurityService"]))))
elif self.Yuuki.YuukiConfigs["name"] + '/Switch' == msgSep[0] and len(msgSep) != 1: elif self.Yuuki.YuukiConfigs["name"] + '/Switch' == msgSep[0] and len(msgSep) != 1:
if ncMessage.message.toType == MIDType.GROUP: if ncMessage.message.toType == MIDType.GROUP:
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to) GroupInfo = self.Yuuki_DynamicTools.getClient(
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] + \ self.Yuuki.MyMID).getGroup(ncMessage.message.to)
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki_StaticTools.sybGetGroupCreator(GroupInfo).mid] + \
self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"] self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]
if not self.Yuuki.data.getData(["Global", "SecurityService"]): if not self.Yuuki.data.getData(["Global", "SecurityService"]):
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
self.Yuuki.get_text("SecurityService of %s was disable") % (self.Yuuki.YuukiConfigs["name"],)) self.Yuuki.get_text("SecurityService of %s was disable") % (self.Yuuki.YuukiConfigs["name"],))
elif ncMessage.message.from_ in GroupPrivilege: elif ncMessage.message.from_ in GroupPrivilege:
status = [] status = []
@ -88,61 +105,78 @@ class Yuuki_Command:
status.append(int(code)) status.append(int(code))
elif count != 0: elif count != 0:
unknown_msg.append(code.strip()) unknown_msg.append(code.strip())
self.Yuuki.configSecurityStatus(ncMessage.message.to, status) self.Yuuki_DynamicTools.configSecurityStatus(
ncMessage.message.to, status)
if unknown_msg: if unknown_msg:
unknown_msgtext = ", ".join(unknown_msg) unknown_msgtext = ", ".join(unknown_msg)
if status: if status:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Okay")) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Okay"))
else: else:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Not Found")) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Not Found"))
if unknown_msgtext != "": if unknown_msgtext != "":
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
self.Yuuki.get_text("Notice: Unknown command line argument(s)") + "\n({})".format( self.Yuuki.get_text("Notice: Unknown command line argument(s)") + "\n({})".format(
unknown_msgtext)) unknown_msgtext))
elif self.Yuuki.YuukiConfigs["name"] + '/DisableAll' == ncMessage.message.text: elif self.Yuuki.YuukiConfigs["name"] + '/DisableAll' == ncMessage.message.text:
if ncMessage.message.toType == MIDType.GROUP: if ncMessage.message.toType == MIDType.GROUP:
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to) GroupInfo = self.Yuuki_DynamicTools.getClient(
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] + \ self.Yuuki.MyMID).getGroup(ncMessage.message.to)
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki_StaticTools.sybGetGroupCreator(GroupInfo).mid] + \
self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"] self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]
if not self.Yuuki.data.getData(["Global", "SecurityService"]): if not self.Yuuki.data.getData(["Global", "SecurityService"]):
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
self.Yuuki.get_text("SecurityService of %s was disable") % (self.Yuuki.YuukiConfigs["name"],)) self.Yuuki.get_text("SecurityService of %s was disable") % (self.Yuuki.YuukiConfigs["name"],))
elif ncMessage.message.from_ in GroupPrivilege: elif ncMessage.message.from_ in GroupPrivilege:
self.Yuuki.configSecurityStatus(ncMessage.message.to, []) self.Yuuki_DynamicTools.configSecurityStatus(
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Okay")) ncMessage.message.to, [])
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Okay"))
elif self.Yuuki.YuukiConfigs["name"] + '/ExtAdmin' == msgSep[0]: elif self.Yuuki.YuukiConfigs["name"] + '/ExtAdmin' == msgSep[0]:
if ncMessage.message.toType == MIDType.GROUP: if ncMessage.message.toType == MIDType.GROUP:
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to) GroupInfo = self.Yuuki_DynamicTools.getClient(
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] self.Yuuki.MyMID).getGroup(ncMessage.message.to)
GroupPrivilege = self.Yuuki.Admin + \
[self.Yuuki_StaticTools.sybGetGroupCreator(
GroupInfo).mid]
if len(msgSep) == 3: if len(msgSep) == 3:
if ncMessage.message.from_ in GroupPrivilege: if ncMessage.message.from_ in GroupPrivilege:
if msgSep[1] == "add": if msgSep[1] == "add":
if msgSep[2] in [Member.mid for Member in GroupInfo.members]: if msgSep[2] in [Member.mid for Member in GroupInfo.members]:
if msgSep[2] in self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]: if msgSep[2] in self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Added")) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Added"))
elif msgSep[2] not in self.Yuuki.data.getData(["BlackList"]): elif msgSep[2] not in self.Yuuki.data.getData(["BlackList"]):
origin = self.Yuuki.data.getData(["Group", GroupInfo.id, "Ext_Admin"]) origin = self.Yuuki.data.getData(
["Group", GroupInfo.id, "Ext_Admin"])
ext_admin_list = origin.copy() ext_admin_list = origin.copy()
ext_admin_list.append(msgSep[2]) ext_admin_list.append(msgSep[2])
self.Yuuki.data.updateData(["Group", GroupInfo.id, "Ext_Admin"], ext_admin_list) self.Yuuki.data.updateData(
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Okay")) ["Group", GroupInfo.id, "Ext_Admin"], ext_admin_list)
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Okay"))
else: else:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
self.Yuuki.get_text("The User(s) was in our blacklist database.")) self.Yuuki.get_text("The User(s) was in our blacklist database."))
else: else:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
self.Yuuki.get_text("Wrong UserID or the guy is not in Group")) self.Yuuki.get_text("Wrong UserID or the guy is not in Group"))
elif msgSep[1] == "delete": elif msgSep[1] == "delete":
if msgSep[2] in self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]: if msgSep[2] in self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]:
origin = self.Yuuki.data.getData(["Group", GroupInfo.id, "Ext_Admin"]) origin = self.Yuuki.data.getData(
["Group", GroupInfo.id, "Ext_Admin"])
ext_admin_list = origin.copy() ext_admin_list = origin.copy()
ext_admin_list.remove(msgSep[2]) ext_admin_list.remove(msgSep[2])
self.Yuuki.data.updateData(["Group", GroupInfo.id, "Ext_Admin"], ext_admin_list) self.Yuuki.data.updateData(
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Okay")) ["Group", GroupInfo.id, "Ext_Admin"], ext_admin_list)
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Okay"))
else: else:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Not Found")) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Not Found"))
else: else:
if self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]: if self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]:
status = "" status = ""
@ -153,22 +187,28 @@ class Yuuki_Command:
status_added.append(member.mid) status_added.append(member.mid)
for userId in self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]: for userId in self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]:
if userId not in status_added: if userId not in status_added:
status += "{}: {}\n".format(self.Yuuki.get_text("Unknown"), userId) status += "{}: {}\n".format(
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), status + self.Yuuki.get_text("\nExtend Administrator(s)")) self.Yuuki.get_text("Unknown"), userId)
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), status + self.Yuuki.get_text("\nExtend Administrator(s)"))
else: else:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Not Found")) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Not Found"))
elif self.Yuuki.YuukiConfigs["name"] + '/Status' == ncMessage.message.text: elif self.Yuuki.YuukiConfigs["name"] + '/Status' == ncMessage.message.text:
if ncMessage.message.toType == MIDType.GROUP: if ncMessage.message.toType == MIDType.GROUP:
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to) GroupInfo = self.Yuuki_DynamicTools.getClient(
group_status = self.Yuuki.data.getSEGroup(ncMessage.message.to) self.Yuuki.MyMID).getGroup(ncMessage.message.to)
group_status = self.Yuuki.data.getSEGroup(
ncMessage.message.to)
if not self.Yuuki.data.getData(["Global", "SecurityService"]): if not self.Yuuki.data.getData(["Global", "SecurityService"]):
status = self.Yuuki.get_text("SecurityService of %s was disable") % ( status = self.Yuuki.get_text("SecurityService of %s was disable") % (
self.Yuuki.YuukiConfigs["name"], self.Yuuki.YuukiConfigs["name"],
) )
elif group_status is None: elif group_status is None:
status = self.Yuuki.get_text("Default without Initialize\nMain Admin of the Group:\n%s") % ( status = self.Yuuki.get_text("Default without Initialize\nMain Admin of the Group:\n%s") % (
self.Yuuki.sybGetGroupCreator(GroupInfo).displayName, self.Yuuki_StaticTools.sybGetGroupCreator(
GroupInfo).displayName,
) )
else: else:
status = self.Yuuki.get_text("SecurityService is Listening on\n\nURL:%s\nInvite:%s\nJoin:%s\nMembers:%s\n\nMain Admin of the Group:\n%s") % ( status = self.Yuuki.get_text("SecurityService is Listening on\n\nURL:%s\nInvite:%s\nJoin:%s\nMembers:%s\n\nMain Admin of the Group:\n%s") % (
@ -176,68 +216,90 @@ class Yuuki_Command:
group_status[OpType.NOTIFIED_INVITE_INTO_GROUP], group_status[OpType.NOTIFIED_INVITE_INTO_GROUP],
group_status[OpType.NOTIFIED_ACCEPT_GROUP_INVITATION], group_status[OpType.NOTIFIED_ACCEPT_GROUP_INVITATION],
group_status[OpType.NOTIFIED_KICKOUT_FROM_GROUP], group_status[OpType.NOTIFIED_KICKOUT_FROM_GROUP],
self.Yuuki.sybGetGroupCreator(GroupInfo).displayName, self.Yuuki_StaticTools.sybGetGroupCreator(
GroupInfo).displayName,
) )
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), status) self.Yuuki_DynamicTools.sendText(
self.Yuuki_StaticTools.sendToWho(ncMessage), status)
elif self.Yuuki.YuukiConfigs["name"] + '/GroupBackup' == ncMessage.message.text: elif self.Yuuki.YuukiConfigs["name"] + '/GroupBackup' == ncMessage.message.text:
if ncMessage.message.toType == MIDType.GROUP: if ncMessage.message.toType == MIDType.GROUP:
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to) GroupInfo = self.Yuuki_DynamicTools.getClient(
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] + \ self.Yuuki.MyMID).getGroup(ncMessage.message.to)
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki_StaticTools.sybGetGroupCreator(GroupInfo).mid] + \
self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"] self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]
if ncMessage.message.from_ in GroupPrivilege: if ncMessage.message.from_ in GroupPrivilege:
GroupMembers = [User.mid for User in GroupInfo.members] GroupMembers = [User.mid for User in GroupInfo.members]
GroupInvites = None GroupInvites = None
if GroupInfo.invitee: if GroupInfo.invitee:
GroupInvites = [User.mid for User in GroupInfo.invitee] GroupInvites = [
User.mid for User in GroupInfo.invitee]
LayoutInfo = { LayoutInfo = {
"OriginID": GroupInfo.id, "OriginID": GroupInfo.id,
"Members": GroupMembers, "Members": GroupMembers,
"Invites": GroupInvites "Invites": GroupInvites
} }
self.Yuuki.sendText(ncMessage.message.from_, GroupInfo.name) self.Yuuki_DynamicTools.sendText(
self.Yuuki.sendText(ncMessage.message.from_, json.dumps(LayoutInfo)) ncMessage.message.from_, GroupInfo.name)
self.Yuuki.sendText(ncMessage.message.to, self.Yuuki.get_text("Okay")) self.Yuuki_DynamicTools.sendText(
ncMessage.message.from_, json.dumps(LayoutInfo))
self.Yuuki_DynamicTools.sendText(
ncMessage.message.to, self.Yuuki.get_text("Okay"))
elif self.Yuuki.YuukiConfigs["name"] + '/Quit' == ncMessage.message.text: elif self.Yuuki.YuukiConfigs["name"] + '/Quit' == ncMessage.message.text:
if ncMessage.message.toType == MIDType.GROUP: if ncMessage.message.toType == MIDType.GROUP:
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to) GroupInfo = self.Yuuki_DynamicTools.getClient(
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] self.Yuuki.MyMID).getGroup(ncMessage.message.to)
GroupPrivilege = self.Yuuki.Admin + \
[self.Yuuki_StaticTools.sybGetGroupCreator(
GroupInfo).mid]
if ncMessage.message.from_ in GroupPrivilege: if ncMessage.message.from_ in GroupPrivilege:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Bye Bye")) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
self.Yuuki.getClient(self.Yuuki.MyMID).leaveGroup(self.Yuuki.Seq, GroupInfo.id) ncMessage), self.Yuuki.get_text("Bye Bye"))
self.Yuuki_DynamicTools.getClient(
self.Yuuki.MyMID).leaveGroup(self.Yuuki.Seq, GroupInfo.id)
for userId in self.Yuuki.Connect.helper_ids: for userId in self.Yuuki.Connect.helper_ids:
if userId in [member.mid for member in GroupInfo.members]: if userId in [member.mid for member in GroupInfo.members]:
self.Yuuki.getClient(userId).leaveGroup(self.Yuuki.Seq, GroupInfo.id) self.Yuuki_DynamicTools.getClient(
GroupList = self.Yuuki.data.getData(["Global", "GroupJoined"]) userId).leaveGroup(self.Yuuki.Seq, GroupInfo.id)
GroupList = self.Yuuki.data.getData(
["Global", "GroupJoined"])
NewGroupList = GroupList.copy() NewGroupList = GroupList.copy()
NewGroupList.remove(GroupInfo.id) NewGroupList.remove(GroupInfo.id)
self.Yuuki.data.updateData(["Global", "GroupJoined"], NewGroupList) self.Yuuki.data.updateData(
["Global", "GroupJoined"], NewGroupList)
elif self.Yuuki.YuukiConfigs["name"] + '/Exit' == ncMessage.message.text: elif self.Yuuki.YuukiConfigs["name"] + '/Exit' == ncMessage.message.text:
if ncMessage.message.from_ in self.Yuuki.Admin: if ncMessage.message.from_ in self.Yuuki.Admin:
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Exit.")) self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
ncMessage), self.Yuuki.get_text("Exit."))
self.Yuuki.exit() self.Yuuki.exit()
elif self.Yuuki.YuukiConfigs["name"] + '/Com' == msgSep[0] and len(msgSep) != 1: elif self.Yuuki.YuukiConfigs["name"] + '/Com' == msgSep[0] and len(msgSep) != 1:
if ncMessage.message.from_ in self.Yuuki.Admin: if ncMessage.message.from_ in self.Yuuki.Admin:
try: try:
ComMsg = self.Yuuki.readCommandLine(msgSep[1:len(msgSep)]) ComMsg = self.Yuuki_StaticTools.readCommandLine(
msgSep[1:len(msgSep)])
Report = str(eval(ComMsg)) Report = str(eval(ComMsg))
except: except:
(err1, err2, err3, ErrorInfo) = self.Yuuki.errorReport() (err1, err2, err3,
Report = "Star Yuuki BOT - Eval Error:\n%s\n%s\n%s\n\n%s" % (err1, err2, err3, ErrorInfo) ErrorInfo) = self.Yuuki_StaticTools.errorReport()
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), Report) Report = "Star Yuuki BOT - Eval Error:\n%s\n%s\n%s\n\n%s" % (
err1, err2, err3, ErrorInfo)
self.Yuuki_DynamicTools.sendText(
self.Yuuki_StaticTools.sendToWho(ncMessage), Report)
elif ncMessage.message.contentType == ContentType.CONTACT: elif ncMessage.message.contentType == ContentType.CONTACT:
Catched = ncMessage.message.contentMetadata["mid"] Catched = ncMessage.message.contentMetadata["mid"]
contactInfo = self.Yuuki.getContact(Catched) contactInfo = self.Yuuki_DynamicTools.getContact(Catched)
if not contactInfo: if not contactInfo:
msg = self.Yuuki.get_text("Not Found") msg = self.Yuuki.get_text("Not Found")
elif contactInfo.mid in self.Yuuki.data.getData(["BlackList"]): elif contactInfo.mid in self.Yuuki.data.getData(["BlackList"]):
msg = "{}\n{}".format(self.Yuuki.get_text("The User(s) was in our blacklist database."), contactInfo.mid) msg = "{}\n{}".format(self.Yuuki.get_text(
"The User(s) was in our blacklist database."), contactInfo.mid)
else: else:
msg = self.Yuuki.get_text("Name:%s\nPicture URL:%s/%s\nStatusMessage:\n%s\nLINE System UserID:%s") % \ msg = self.Yuuki.get_text("Name:%s\nPicture URL:%s/%s\nStatusMessage:\n%s\nLINE System UserID:%s") % \
(contactInfo.displayName, self.Yuuki.LINE_Media_server, contactInfo.pictureStatus, (contactInfo.displayName, self.Yuuki.LINE_Media_server, contactInfo.pictureStatus,
contactInfo.statusMessage, contactInfo.mid) contactInfo.statusMessage, contactInfo.mid)
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), msg) self.Yuuki_DynamicTools.sendText(
self.Yuuki_StaticTools.sendToWho(ncMessage), msg)

View file

@ -7,6 +7,9 @@ License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. file, You can obtain one at http://mozilla.org/MPL/2.0/.
""" """
from ..tools import Yuuki_StaticTools, Yuuki_DynamicTools
class Yuuki_JoinGroup: class Yuuki_JoinGroup:
def __init__(self, Yuuki): def __init__(self, Yuuki):
""" """
@ -15,43 +18,59 @@ class Yuuki_JoinGroup:
""" """
self.Yuuki = Yuuki self.Yuuki = Yuuki
self.Yuuki_StaticTools = Yuuki_StaticTools()
self.Yuuki_DynamicTools = Yuuki_DynamicTools(self.Yuuki)
def action(self, ncMessage): def action(self, ncMessage):
GroupInvite = [] GroupInvite = []
BlockedIgnore = ncMessage.param2 in self.Yuuki.data.getData(["BlackList"]) BlockedIgnore = ncMessage.param2 in self.Yuuki.data.getData([
if self.Yuuki.checkInInvitationList(ncMessage) and not BlockedIgnore: "BlackList"])
if self.Yuuki_DynamicTools.checkInInvitationList(ncMessage) and not BlockedIgnore:
GroupID = ncMessage.param1 GroupID = ncMessage.param1
Inviter = ncMessage.param2 Inviter = ncMessage.param2
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(GroupID) GroupInfo = self.Yuuki_DynamicTools.getClient(
self.Yuuki.MyMID).getGroup(GroupID)
if GroupInfo.members: if GroupInfo.members:
GroupMember = [Catched.mid for Catched in GroupInfo.members] GroupMember = [Catched.mid for Catched in GroupInfo.members]
GroupInfo.invitee = [] GroupInfo.invitee = []
if GroupInfo.invitee: if GroupInfo.invitee:
GroupInvite = [Catched.mid for Catched in GroupInfo.invitee] GroupInvite = [
self.Yuuki.getClient(self.Yuuki.MyMID).acceptGroupInvitation(self.Yuuki.Seq, GroupID) Catched.mid for Catched in GroupInfo.invitee]
self.Yuuki_DynamicTools.getClient(
self.Yuuki.MyMID).acceptGroupInvitation(self.Yuuki.Seq, GroupID)
if len(GroupMember) >= self.Yuuki.YuukiConfigs["GroupMebers_Demand"]: if len(GroupMember) >= self.Yuuki.YuukiConfigs["GroupMebers_Demand"]:
GroupList = self.Yuuki.data.getData(["Global", "GroupJoined"]) GroupList = self.Yuuki.data.getData(
["Global", "GroupJoined"])
NewGroupList = GroupList.copy() NewGroupList = GroupList.copy()
NewGroupList.append(GroupID) NewGroupList.append(GroupID)
self.Yuuki.data.updateData(["Global", "GroupJoined"], NewGroupList) self.Yuuki.data.updateData(
self.Yuuki.sendText(GroupID, ["Global", "GroupJoined"], NewGroupList)
self.Yuuki_DynamicTools.sendText(GroupID,
self.Yuuki.get_text("Helllo^^\nMy name is %s ><\nNice to meet you OwO") % self.Yuuki.YuukiConfigs["name"]) self.Yuuki.get_text("Helllo^^\nMy name is %s ><\nNice to meet you OwO") % self.Yuuki.YuukiConfigs["name"])
self.Yuuki.sendText(GroupID, self.Yuuki_DynamicTools.sendText(GroupID,
self.Yuuki.get_text("Type:\n\t%s/Help\nto get more information\n\nMain Admin of the Group:\n%s") % self.Yuuki.get_text("Type:\n\t%s/Help\nto get more information\n\nMain Admin of the Group:\n%s") %
(self.Yuuki.YuukiConfigs["name"], self.Yuuki.sybGetGroupCreator(GroupInfo).displayName,)) (self.Yuuki.YuukiConfigs["name"], self.Yuuki_StaticTools.sybGetGroupCreator(GroupInfo).displayName,))
self.Yuuki.getGroupTicket(GroupID, self.Yuuki.MyMID, True) self.Yuuki_DynamicTools.getGroupTicket(
GroupID, self.Yuuki.MyMID, True)
# Log # Log
self.Yuuki.data.updateLog("JoinGroup", (self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Inviter)) self.Yuuki.data.updateLog(
"JoinGroup", (self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Inviter))
else: else:
self.Yuuki.sendText(GroupID, self.Yuuki.get_text("Sorry...\nThe number of members is not satisfied (%s needed)") % self.Yuuki_DynamicTools.sendText(GroupID, self.Yuuki.get_text("Sorry...\nThe number of members is not satisfied (%s needed)") %
(self.Yuuki.YuukiConfigs["GroupMebers_Demand"],)) (self.Yuuki.YuukiConfigs["GroupMebers_Demand"],))
self.Yuuki.getClient(self.Yuuki.MyMID).leaveGroup(self.Yuuki.Seq, GroupID) self.Yuuki_DynamicTools.getClient(
self.Yuuki.MyMID).leaveGroup(self.Yuuki.Seq, GroupID)
# Log # Log
self.Yuuki.data.updateLog("JoinGroup", (self.Yuuki.data.getTime(), GroupID, "Not Join", Inviter)) self.Yuuki.data.updateLog(
"JoinGroup", (self.Yuuki.data.getTime(), GroupID, "Not Join", Inviter))
if ncMessage.param1 in self.Yuuki.data.getData(["Global", "GroupJoined"]) and not BlockedIgnore: if ncMessage.param1 in self.Yuuki.data.getData(["Global", "GroupJoined"]) and not BlockedIgnore:
for userId in self.Yuuki.Connect.helper_ids: for userId in self.Yuuki.Connect.helper_ids:
if self.Yuuki.checkInInvitationList(ncMessage, userId) or userId in GroupInvite: if self.Yuuki_DynamicTools.checkInInvitationList(ncMessage, userId) or userId in GroupInvite:
self.Yuuki.getClient(userId).acceptGroupInvitation(self.Yuuki.Seq, ncMessage.param1) self.Yuuki_DynamicTools.getClient(userId).acceptGroupInvitation(
self.Yuuki.getGroupTicket(ncMessage.param1, userId, True) self.Yuuki.Seq, ncMessage.param1)
self.Yuuki_DynamicTools.getGroupTicket(
ncMessage.param1, userId, True)
# Log # Log
self.Yuuki.data.updateLog("JoinGroup", (self.Yuuki.data.getTime(), ncMessage.param1, userId, ncMessage.param2)) self.Yuuki.data.updateLog("JoinGroup", (self.Yuuki.data.getTime(
), ncMessage.param1, userId, ncMessage.param2))
self.Yuuki.Security(ncMessage) self.Yuuki.Security(ncMessage)

View file

@ -7,8 +7,11 @@ License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. file, You can obtain one at http://mozilla.org/MPL/2.0/.
""" """
from ..tools import Yuuki_StaticTools, Yuuki_DynamicTools
from yuuki_core.ttypes import OpType from yuuki_core.ttypes import OpType
class Yuuki_Security: class Yuuki_Security:
def __init__(self, Yuuki): def __init__(self, Yuuki):
""" """
@ -20,14 +23,18 @@ class Yuuki_Security:
""" """
self.Yuuki = Yuuki self.Yuuki = Yuuki
self.Yuuki_StaticTools = Yuuki_StaticTools()
self.Yuuki_DynamicTools = Yuuki_DynamicTools(self.Yuuki)
def action(self, ncMessage): def action(self, ncMessage):
Security_Access = False Security_Access = False
(GroupID, Action, Another) = self.Yuuki.securityForWhere(ncMessage) (GroupID, Action, Another) = self.Yuuki_StaticTools.securityForWhere(ncMessage)
SEGroup = self.Yuuki.data.getSEGroup(GroupID) SEGroup = self.Yuuki.data.getSEGroup(GroupID)
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(GroupID) GroupInfo = self.Yuuki_DynamicTools.getClient(
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] + self.Yuuki.data.getGroup(GroupInfo.id)[ self.Yuuki.MyMID).getGroup(GroupID)
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki_StaticTools.sybGetGroupCreator(GroupInfo).mid] + self.Yuuki.data.getGroup(GroupInfo.id)[
"Ext_Admin"] "Ext_Admin"]
if Action in GroupPrivilege or Another in GroupPrivilege: if Action in GroupPrivilege or Another in GroupPrivilege:
@ -37,7 +44,8 @@ class Yuuki_Security:
return return
if SEGroup is None: if SEGroup is None:
Security_Access = self.Yuuki.data.getData(["Global", "SecurityService"]) Security_Access = self.Yuuki.data.getData(
["Global", "SecurityService"])
elif SEGroup[ncMessage.type]: elif SEGroup[ncMessage.type]:
Security_Access = SEGroup[ncMessage.type] Security_Access = SEGroup[ncMessage.type]
@ -45,9 +53,12 @@ class Yuuki_Security:
if ncMessage.type == OpType.NOTIFIED_UPDATE_GROUP and Security_Access: if ncMessage.type == OpType.NOTIFIED_UPDATE_GROUP and Security_Access:
if Another == '4': if Another == '4':
if not GroupInfo.preventJoinByTicket and Action not in self.Yuuki.Connect.helper_ids: if not GroupInfo.preventJoinByTicket and Action not in self.Yuuki.Connect.helper_ids:
self.Yuuki.Thread_Exec(self.Yuuki.changeGroupUrlStatus, (GroupInfo, False)) self.Yuuki.threadExec(
self.Yuuki.Thread_Exec(self.Yuuki.sendText, (GroupID, self.Yuuki.get_text("DO NOT ENABLE THE GROUP URL STATUS, see you..."))) self.Yuuki_DynamicTools.changeGroupUrlStatus, (GroupInfo, False))
Kicker = self.Yuuki.kickSomeone(GroupInfo, Action) self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (GroupID, self.Yuuki.get_text(
"DO NOT ENABLE THE GROUP URL STATUS, see you...")))
Kicker = self.Yuuki_DynamicTools.kickSomeone(
GroupInfo, Action)
# Log # Log
self.Yuuki.data.updateLog("KickEvent", ( self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type)) self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type))
@ -57,9 +68,11 @@ class Yuuki_Security:
for userId in Another.split("\x1e"): for userId in Another.split("\x1e"):
if userId not in self.Yuuki.AllAccountIds + GroupPrivilege: if userId not in self.Yuuki.AllAccountIds + GroupPrivilege:
if GroupInfo.invitee and userId in [user.mid for user in GroupInfo.invitee]: if GroupInfo.invitee and userId in [user.mid for user in GroupInfo.invitee]:
Canceler = self.Yuuki.cancelSomeone(GroupInfo, userId) Canceler = self.Yuuki_DynamicTools.cancelSomeone(
GroupInfo, userId)
else: else:
Canceler = self.Yuuki.kickSomeone(GroupInfo, userId) Canceler = self.Yuuki_DynamicTools.kickSomeone(
GroupInfo, userId)
# Log # Log
self.Yuuki.data.updateLog("KickEvent", ( self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, userId, self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, userId,
@ -69,9 +82,11 @@ class Yuuki_Security:
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another.replace("\x1e", ","))) self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another.replace("\x1e", ",")))
elif Another not in self.Yuuki.AllAccountIds + GroupPrivilege: elif Another not in self.Yuuki.AllAccountIds + GroupPrivilege:
if GroupInfo.invitee and Another in [user.mid for user in GroupInfo.invitee]: if GroupInfo.invitee and Another in [user.mid for user in GroupInfo.invitee]:
Canceler = self.Yuuki.cancelSomeone(GroupInfo, Another) Canceler = self.Yuuki_DynamicTools.cancelSomeone(
GroupInfo, Another)
else: else:
Canceler = self.Yuuki.kickSomeone(GroupInfo, Another) Canceler = self.Yuuki_DynamicTools.kickSomeone(
GroupInfo, Another)
# Log # Log
self.Yuuki.data.updateLog("KickEvent", ( self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another, self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another,
@ -80,12 +95,15 @@ class Yuuki_Security:
self.Yuuki.data.updateLog("CancelEvent", self.Yuuki.data.updateLog("CancelEvent",
(self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another)) (self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another))
if Canceler != "None": if Canceler != "None":
self.Yuuki.sendText(GroupID, self.Yuuki.get_text("Do not invite anyone...thanks")) self.Yuuki_DynamicTools.sendText(
GroupID, self.Yuuki.get_text("Do not invite anyone...thanks"))
elif ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION and Security_Access: elif ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION and Security_Access:
for userId in self.Yuuki.data.getData(["BlackList"]): for userId in self.Yuuki.data.getData(["BlackList"]):
if userId == Action: if userId == Action:
self.Yuuki.Thread_Exec(self.Yuuki.sendText, (GroupID, self.Yuuki.get_text("You are our blacklist. Bye~"))) self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (GroupID, self.Yuuki.get_text(
Kicker = self.Yuuki.kickSomeone(GroupInfo, Action) "You are our blacklist. Bye~")))
Kicker = self.Yuuki_DynamicTools.kickSomeone(
GroupInfo, Action)
# Log # Log
self.Yuuki.data.updateLog("KickEvent", ( self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Kicker, Action, ncMessage.type)) self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Kicker, Action, ncMessage.type))
@ -97,35 +115,47 @@ class Yuuki_Security:
elif Another in self.Yuuki.AllAccountIds: elif Another in self.Yuuki.AllAccountIds:
Kicker = "None" Kicker = "None"
try: try:
Kicker = self.Yuuki.kickSomeone(GroupInfo, Action, Another) Kicker = self.Yuuki_DynamicTools.kickSomeone(
GroupInfo, Action, Another)
# Log # Log
self.Yuuki.data.updateLog("KickEvent", ( self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another,
ncMessage.type * 10 + 2)) ncMessage.type * 10 + 2))
assert Kicker != "None", "No Helper Found" assert Kicker != "None", "No Helper Found"
if GroupInfo.preventJoinByTicket: if GroupInfo.preventJoinByTicket:
self.Yuuki.Thread_Exec(self.Yuuki.changeGroupUrlStatus, (GroupInfo, True, Kicker)) self.Yuuki.threadExec(
GroupTicket = self.Yuuki.getGroupTicket(GroupID, Kicker) self.Yuuki_DynamicTools.changeGroupUrlStatus, (GroupInfo, True, Kicker))
GroupTicket = self.Yuuki_DynamicTools.getGroupTicket(
GroupID, Kicker)
try: try:
self.Yuuki.getClient(Another).acceptGroupInvitationByTicket(self.Yuuki.Seq, GroupID, GroupTicket) self.Yuuki_DynamicTools.getClient(Another).acceptGroupInvitationByTicket(
self.Yuuki.Seq, GroupID, GroupTicket)
except: except:
if GroupInfo.preventJoinByTicket: if GroupInfo.preventJoinByTicket:
self.Yuuki.changeGroupUrlStatus(GroupInfo, True, Kicker) self.Yuuki_DynamicTools.changeGroupUrlStatus(
GroupTicket = self.Yuuki.getGroupTicket(GroupID, Kicker, True) GroupInfo, True, Kicker)
self.Yuuki.getClient(Another).acceptGroupInvitationByTicket(self.Yuuki.Seq, GroupID, GroupTicket) GroupTicket = self.Yuuki_DynamicTools.getGroupTicket(
GroupID, Kicker, True)
self.Yuuki_DynamicTools.getClient(Another).acceptGroupInvitationByTicket(
self.Yuuki.Seq, GroupID, GroupTicket)
if GroupInfo.preventJoinByTicket: if GroupInfo.preventJoinByTicket:
self.Yuuki.Thread_Exec(self.Yuuki.changeGroupUrlStatus, (GroupInfo, False, Another)) self.Yuuki.threadExec(
self.Yuuki.getGroupTicket(GroupID, Another, True) self.Yuuki_DynamicTools.changeGroupUrlStatus, (GroupInfo, False, Another))
self.Yuuki_DynamicTools.getGroupTicket(
GroupID, Another, True)
except: except:
(err1, err2, err3, ErrorInfo) = self.Yuuki.errorReport() (err1, err2, err3,
ErrorInfo) = self.Yuuki_StaticTools.errorReport()
for Root in self.Yuuki.Admin: for Root in self.Yuuki.Admin:
self.Yuuki.sendText(Root, "Star Yuuki BOT - SecurityService Failure\n\n%s\n%s\n%s\n\n%s" % self.Yuuki_DynamicTools.sendText(Root, "Star Yuuki BOT - SecurityService Failure\n\n%s\n%s\n%s\n\n%s" %
(err1, err2, err3, ErrorInfo)) (err1, err2, err3, ErrorInfo))
if Another == self.Yuuki.MyMID: if Another == self.Yuuki.MyMID:
GroupList = self.Yuuki.data.getData(["Global", "GroupJoined"]) GroupList = self.Yuuki.data.getData(
["Global", "GroupJoined"])
NewGroupList = GroupList.copy() NewGroupList = GroupList.copy()
NewGroupList.remove(GroupID) NewGroupList.remove(GroupID)
self.Yuuki.data.updateData(["Global", "GroupJoined"], NewGroupList) self.Yuuki.data.updateData(
["Global", "GroupJoined"], NewGroupList)
# Log # Log
self.Yuuki.data.updateLog("KickEvent", ( self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another,
@ -136,13 +166,19 @@ class Yuuki_Security:
NewBlackList.append(Action) NewBlackList.append(Action)
self.Yuuki.data.updateData(["BlackList"], NewBlackList) self.Yuuki.data.updateData(["BlackList"], NewBlackList)
# Log # Log
self.Yuuki.data.updateLog("BlackList", (self.Yuuki.data.getTime(), Action, GroupID)) self.Yuuki.data.updateLog(
self.Yuuki.Thread_Exec(self.Yuuki.sendText, (Action, self.Yuuki.get_text("You had been blocked by our database."))) "BlackList", (self.Yuuki.data.getTime(), Action, GroupID))
self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (Action, self.Yuuki.get_text(
"You had been blocked by our database.")))
elif Security_Access: elif Security_Access:
self.Yuuki.Thread_Exec(self.Yuuki.sendText, (GroupID, self.Yuuki.get_text("DO NOT KICK, thank you ^^"))) self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (
Kicker = self.Yuuki.kickSomeone(GroupInfo, Action) GroupID, self.Yuuki.get_text("DO NOT KICK, thank you ^^")))
Kicker = self.Yuuki_DynamicTools.kickSomeone(
GroupInfo, Action)
# Log # Log
self.Yuuki.data.updateLog("KickEvent", ( self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type)) self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type))
self.Yuuki.Thread_Exec(self.Yuuki.sendText, (GroupID, self.Yuuki.get_text("The one who was been kicked:"))) self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (GroupID, self.Yuuki.get_text(
self.Yuuki.Thread_Exec(self.Yuuki.sendUser, (GroupID, Another)) "The one who was been kicked:")))
self.Yuuki.threadExec(
self.Yuuki_DynamicTools.sendUser, (GroupID, Another))

View file

@ -11,12 +11,17 @@ import time
import socket import socket
import requests import requests
from .tools import Yuuki_StaticTools, Yuuki_DynamicTools
from yuuki_core.ttypes import Operation from yuuki_core.ttypes import Operation
class Yuuki_Poll: class Yuuki_Poll:
def __init__(self, Yuuki): def __init__(self, Yuuki):
self.Yuuki = Yuuki self.Yuuki = Yuuki
self.Yuuki_StaticTools = Yuuki_StaticTools()
self.Yuuki_DynamicTools = Yuuki_DynamicTools(self.Yuuki)
self.NoWork = 0 self.NoWork = 0
self.NoWorkLimit = 5 self.NoWorkLimit = 5
@ -35,7 +40,7 @@ class Yuuki_Poll:
while self.Power: while self.Power:
try: try:
if time.localtime().tm_hour != self.Yuuki.data.getData(["Global", "LastResetLimitTime"]): if time.localtime().tm_hour != self.Yuuki.data.getData(["Global", "LastResetLimitTime"]):
self.Yuuki.limitReset() self.Yuuki_DynamicTools.limitReset()
self.Yuuki.data.updateData(["Global", "LastResetLimitTime"], time.localtime().tm_hour) self.Yuuki.data.updateData(["Global", "LastResetLimitTime"], time.localtime().tm_hour)
if self.NoWork >= self.NoWorkLimit: if self.NoWork >= self.NoWorkLimit:
@ -54,7 +59,7 @@ class Yuuki_Poll:
if self.cacheOperations: if self.cacheOperations:
self.NoWork = 0 self.NoWork = 0
self.Yuuki.Thread_Exec(self.Yuuki.taskDemux, (self.cacheOperations,)) self.Yuuki.threadExec(self.Yuuki.taskDemux, (self.cacheOperations,))
if len(self.cacheOperations) > 1: if len(self.cacheOperations) > 1:
self.Yuuki.revision = max(self.cacheOperations[-1].revision, self.cacheOperations[-2].revision) self.Yuuki.revision = max(self.cacheOperations[-1].revision, self.cacheOperations[-2].revision)
@ -73,7 +78,7 @@ class Yuuki_Poll:
pass pass
except: except:
(err1, err2, err3, ErrorInfo) = self.Yuuki.errorReport() (err1, err2, err3, ErrorInfo) = self.Yuuki_StaticTools.errorReport()
try: try:
for self.ncMessage in self.cacheOperations: for self.ncMessage in self.cacheOperations:
if self.ncMessage.reqSeq != -1 and self.ncMessage.revision > self.Yuuki.revision: if self.ncMessage.reqSeq != -1 and self.ncMessage.revision > self.Yuuki.revision:

View file

@ -17,6 +17,7 @@ import traceback
from yuuki_core.ttypes import OpType, MIDType, ContentType, Group, Message from yuuki_core.ttypes import OpType, MIDType, ContentType, Group, Message
class Yuuki_StaticTools: class Yuuki_StaticTools:
@staticmethod @staticmethod
def sybGetGroupCreator(group): def sybGetGroupCreator(group):
@ -39,7 +40,8 @@ class Yuuki_StaticTools:
traceback.print_tb(err3) traceback.print_tb(err3)
tb_info = traceback.extract_tb(err3) tb_info = traceback.extract_tb(err3)
filename, line, func, text = tb_info[-1] filename, line, func, text = tb_info[-1]
ErrorInfo = "occurred in\n{}\n\non line {}\nin statement {}".format(filename, line, text) ErrorInfo = "occurred in\n{}\n\non line {}\nin statement {}".format(
filename, line, text)
return err1, err2, err3, ErrorInfo return err1, err2, err3, ErrorInfo
@staticmethod @staticmethod
@ -79,6 +81,7 @@ class Yuuki_StaticTools:
class Yuuki_DynamicTools: class Yuuki_DynamicTools:
def __init__(self, Yuuki): def __init__(self, Yuuki):
self.Yuuki = Yuuki self.Yuuki = Yuuki
self.Yuuki_StaticTools = Yuuki_StaticTools()
def getClient(self, userId): def getClient(self, userId):
if self.Yuuki.Threading: if self.Yuuki.Threading:
@ -117,9 +120,10 @@ class Yuuki_DynamicTools:
else: else:
result.preventJoinByTicket = True result.preventJoinByTicket = True
if userId is not None: if userId is not None:
self.Yuuki.getClient(userId).updateGroup(self.Yuuki.Seq, result) self.getClient(userId).updateGroup(self.Yuuki.Seq, result)
else: else:
self.Yuuki.getClient(self.Yuuki.MyMID).updateGroup(self.Yuuki.Seq, result) self.getClient(self.Yuuki.MyMID).updateGroup(
self.Yuuki.Seq, result)
def configSecurityStatus(self, groupId, status): def configSecurityStatus(self, groupId, status):
group_status = self.Yuuki.data.SEGrouptype group_status = self.Yuuki.data.SEGrouptype
@ -135,7 +139,7 @@ class Yuuki_DynamicTools:
self.Yuuki.data.updateData(["Group", groupId, "SEGroup"], group_status) self.Yuuki.data.updateData(["Group", groupId, "SEGroup"], group_status)
def cleanMyGroupInvitations(self): def cleanMyGroupInvitations(self):
for client in [self.Yuuki.getClient(self.Yuuki.MyMID)] + self.Yuuki.Connect.helper: for client in [self.getClient(self.Yuuki.MyMID)] + self.Yuuki.Connect.helper:
for cleanInvitations in client.getGroupIdsInvited(): for cleanInvitations in client.getGroupIdsInvited():
client.acceptGroupInvitation(self.Yuuki.Seq, cleanInvitations) client.acceptGroupInvitation(self.Yuuki.Seq, cleanInvitations)
client.leaveGroup(self.Yuuki.Seq, cleanInvitations) client.leaveGroup(self.Yuuki.Seq, cleanInvitations)
@ -143,7 +147,8 @@ class Yuuki_DynamicTools:
def getContact(self, userId): def getContact(self, userId):
if len(userId) == len(self.Yuuki.MyMID) and userId[0] == "u": if len(userId) == len(self.Yuuki.MyMID) and userId[0] == "u":
try: try:
contactInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getContact(userId) contactInfo = self.getClient(
self.Yuuki.MyMID).getContact(userId)
except: except:
contactInfo = False contactInfo = False
else: else:
@ -159,19 +164,24 @@ class Yuuki_DynamicTools:
else: else:
assert "Error JSON data type - GroupTicket" assert "Error JSON data type - GroupTicket"
if GroupTicket == "" or renew: if GroupTicket == "" or renew:
GroupTicket = self.Yuuki.getClient(userId).reissueGroupTicket(GroupID) GroupTicket = self.getClient(userId).reissueGroupTicket(GroupID)
self.Yuuki.data.updateData(["Group", GroupID, "GroupTicket", userId], GroupTicket) self.Yuuki.data.updateData(
["Group", GroupID, "GroupTicket", userId], GroupTicket)
return GroupTicket return GroupTicket
def limitReset(self): def limitReset(self):
for userId in self.Yuuki.AllAccountIds: for userId in self.Yuuki.AllAccountIds:
self.Yuuki.data.updateData(["LimitInfo", "KickLimit", userId], self.Yuuki.KickLimit) self.Yuuki.data.updateData(
self.Yuuki.data.updateData(["LimitInfo", "CancelLimit", userId], self.Yuuki.CancelLimit) ["LimitInfo", "KickLimit", userId], self.Yuuki.KickLimit)
self.Yuuki.data.updateData(
["LimitInfo", "CancelLimit", userId], self.Yuuki.CancelLimit)
def cancelSomeone(self, groupInfo, userId, exceptUserId=None): def cancelSomeone(self, groupInfo, userId, exceptUserId=None):
if len(self.Yuuki.Connect.helper) >= 1: if len(self.Yuuki.Connect.helper) >= 1:
members = [member.mid for member in groupInfo.members if member.mid in self.Yuuki.AllAccountIds] members = [
accounts = self.Yuuki.dictShuffle(self.Yuuki.data.getData(["LimitInfo", "CancelLimit"]), members) member.mid for member in groupInfo.members if member.mid in self.Yuuki.AllAccountIds]
accounts = self.Yuuki_StaticTools.dictShuffle(
self.Yuuki.data.getData(["LimitInfo", "CancelLimit"]), members)
if len(accounts) == 0: if len(accounts) == 0:
return "None" return "None"
if exceptUserId: if exceptUserId:
@ -184,16 +194,19 @@ class Yuuki_DynamicTools:
Limit = self.Yuuki.data.getData(["LimitInfo", "CancelLimit", helper]) Limit = self.Yuuki.data.getData(["LimitInfo", "CancelLimit", helper])
if Limit > 0: if Limit > 0:
self.Yuuki.getClient(helper).cancelGroupInvitation(self.Yuuki.Seq, groupInfo.id, [userId]) self.getClient(helper).cancelGroupInvitation(
self.Yuuki.Seq, groupInfo.id, [userId])
self.Yuuki.data.limitDecrease("CancelLimit", helper) self.Yuuki.data.limitDecrease("CancelLimit", helper)
else: else:
self.Yuuki.sendText(groupInfo.id, self.Yuuki.get_text("Cancel Limit.")) self.sendText(groupInfo.id, self.Yuuki.get_text("Cancel Limit."))
return helper return helper
def kickSomeone(self, groupInfo, userId, exceptUserId=None): def kickSomeone(self, groupInfo, userId, exceptUserId=None):
if len(self.Yuuki.Connect.helper) >= 1: if len(self.Yuuki.Connect.helper) >= 1:
members = [member.mid for member in groupInfo.members if member.mid in self.Yuuki.AllAccountIds] members = [
accounts = self.Yuuki.dictShuffle(self.Yuuki.data.getData(["LimitInfo", "KickLimit"]), members) member.mid for member in groupInfo.members if member.mid in self.Yuuki.AllAccountIds]
accounts = self.Yuuki_StaticTools.dictShuffle(
self.Yuuki.data.getData(["LimitInfo", "KickLimit"]), members)
if len(accounts) == 0: if len(accounts) == 0:
return "None" return "None"
if exceptUserId: if exceptUserId:
@ -206,15 +219,16 @@ class Yuuki_DynamicTools:
Limit = self.Yuuki.data.getData(["LimitInfo", "KickLimit", helper]) Limit = self.Yuuki.data.getData(["LimitInfo", "KickLimit", helper])
if Limit > 0: if Limit > 0:
self.Yuuki.getClient(helper).kickoutFromGroup(self.Yuuki.Seq, groupInfo.id, [userId]) self.getClient(helper).kickoutFromGroup(
self.Yuuki.Seq, groupInfo.id, [userId])
self.Yuuki.data.limitDecrease("KickLimit", helper) self.Yuuki.data.limitDecrease("KickLimit", helper)
else: else:
self.Yuuki.sendText(groupInfo.id, self.Yuuki.get_text("Kick Limit.")) self.sendText(groupInfo.id, self.Yuuki.get_text("Kick Limit."))
return helper return helper
def sendText(self, toid, msg): def sendText(self, toid, msg):
message = Message(to=toid, text=msg) message = Message(to=toid, text=msg)
self.Yuuki.getClient(self.Yuuki.MyMID).sendMessage(self.Yuuki.Seq, message) self.getClient(self.Yuuki.MyMID).sendMessage(self.Yuuki.Seq, message)
def sendUser(self, toid, userId): def sendUser(self, toid, userId):
message = Message( message = Message(
@ -226,7 +240,7 @@ class Yuuki_DynamicTools:
}, },
to=toid to=toid
) )
self.Yuuki.getClient(self.Yuuki.MyMID).sendMessage(self.Yuuki.Seq, message) self.getClient(self.Yuuki.MyMID).sendMessage(self.Yuuki.Seq, message)
def sendMedia(self, send_to, send_type, path): def sendMedia(self, send_to, send_type, path):
if os.path.exists(path): if os.path.exists(path):
@ -243,7 +257,8 @@ class Yuuki_DynamicTools:
media_name = file_name media_name = file_name
else: else:
media_name = 'media' media_name = 'media'
message_id = self.Yuuki.getClient(self.Yuuki.MyMID).sendMessage(self.Yuuki.Seq, message).id message_id = self.getClient(self.Yuuki.MyMID).sendMessage(
self.Yuuki.Seq, message).id
files = { files = {
'file': open(path, 'rb'), 'file': open(path, 'rb'),
} }
@ -258,6 +273,7 @@ class Yuuki_DynamicTools:
'params': json.dumps(params) 'params': json.dumps(params)
} }
url = self.Yuuki.LINE_Media_server + '/talk/m/upload.nhn' url = self.Yuuki.LINE_Media_server + '/talk/m/upload.nhn'
r = requests.post(url, headers=self.Yuuki.connectHeader, data=data, files=files) r = requests.post(
url, headers=self.Yuuki.connectHeader, data=data, files=files)
if r.status_code != 201: if r.status_code != 201:
self.Yuuki.sendText(send_to, "Error!") self.sendText(send_to, "Error!")

View file

@ -146,7 +146,7 @@ class Yuuki:
print("Star Yuuki BOT - Restart Error\n\nUnknown Platform") print("Star Yuuki BOT - Restart Error\n\nUnknown Platform")
sys.exit(0) sys.exit(0)
def _Thread_Exec(self, Function, args): def threadExec(self, Function, args):
if self.Threading: if self.Threading:
self.Thread_Control.add(Function, args) self.Thread_Control.add(Function, args)
else: else:
@ -155,15 +155,15 @@ class Yuuki:
def taskDemux(self, catchedNews): def taskDemux(self, catchedNews):
for ncMessage in catchedNews: for ncMessage in catchedNews:
if ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP: if ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP:
self._Thread_Exec(self.JoinGroup, (ncMessage,)) self.threadExec(self.JoinGroup, (ncMessage,))
elif ncMessage.type == OpType.NOTIFIED_KICKOUT_FROM_GROUP: elif ncMessage.type == OpType.NOTIFIED_KICKOUT_FROM_GROUP:
self._Thread_Exec(self.Security, (ncMessage,)) self.threadExec(self.Security, (ncMessage,))
elif ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION: elif ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION:
self._Thread_Exec(self.Security, (ncMessage,)) self.threadExec(self.Security, (ncMessage,))
elif ncMessage.type == OpType.NOTIFIED_UPDATE_GROUP: elif ncMessage.type == OpType.NOTIFIED_UPDATE_GROUP:
self._Thread_Exec(self.Security, (ncMessage,)) self.threadExec(self.Security, (ncMessage,))
elif ncMessage.type == OpType.RECEIVE_MESSAGE: elif ncMessage.type == OpType.RECEIVE_MESSAGE:
self._Thread_Exec(self.Command, (ncMessage,)) self.threadExec(self.Command, (ncMessage,))
def main(self): def main(self):
handle = Yuuki_Poll(self) handle = Yuuki_Poll(self)