mirror of
https://github.com/hyper-neptune/yuuki.git
synced 2024-12-24 05:41:12 +08:00
Update
This commit is contained in:
parent
d5ea8c3006
commit
52600759a8
7 changed files with 317 additions and 179 deletions
|
@ -11,4 +11,4 @@ from .command import Yuuki_Command
|
|||
from .join_group import Yuuki_JoinGroup
|
||||
from .security import Yuuki_Security
|
||||
|
||||
__all__ = ["Yuuki_Command", "Yuuki_JoinGroup", "Yuuki_Security"]
|
||||
__all__ = ["Yuuki_Command", "Yuuki_JoinGroup", "Yuuki_Security"]
|
||||
|
|
|
@ -10,8 +10,11 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|||
import time
|
||||
import json
|
||||
|
||||
from ..tools import Yuuki_StaticTools, Yuuki_DynamicTools
|
||||
|
||||
from yuuki_core.ttypes import MIDType, ContentType, OpType
|
||||
|
||||
|
||||
class Yuuki_Command:
|
||||
def __init__(self, Yuuki):
|
||||
"""
|
||||
|
@ -20,65 +23,79 @@ class Yuuki_Command:
|
|||
"""
|
||||
self.Yuuki = Yuuki
|
||||
|
||||
self.Yuuki_StaticTools = Yuuki_StaticTools()
|
||||
self.Yuuki_DynamicTools = Yuuki_DynamicTools(self.Yuuki)
|
||||
|
||||
def action(self, ncMessage):
|
||||
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:
|
||||
pass
|
||||
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:
|
||||
|
||||
msgSep = ncMessage.message.text.split(" ")
|
||||
|
||||
if self.Yuuki.YuukiConfigs["name"] + '/Help' == ncMessage.message.text:
|
||||
self.Yuuki.sendText(self.Yuuki.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.YuukiConfigs["name"], self.Yuuki.YuukiConfigs["version"],
|
||||
self.Yuuki.YuukiConfigs["man_page"], self.Yuuki.YuukiConfigs["privacy_page"],
|
||||
self.Yuuki.YuukiConfigs["project_url"], self.Yuuki.YuukiConfigs["copyright"]))
|
||||
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.YuukiConfigs["name"], self.Yuuki.YuukiConfigs["version"],
|
||||
self.Yuuki.YuukiConfigs["man_page"], self.Yuuki.YuukiConfigs["privacy_page"],
|
||||
self.Yuuki.YuukiConfigs["project_url"], self.Yuuki.YuukiConfigs["copyright"]))
|
||||
|
||||
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:
|
||||
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:
|
||||
if ncMessage.message.toType == MIDType.GROUP:
|
||||
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to)
|
||||
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] + \
|
||||
self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]
|
||||
GroupInfo = self.Yuuki_DynamicTools.getClient(
|
||||
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"]
|
||||
if ncMessage.message.from_ in GroupPrivilege:
|
||||
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:
|
||||
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()
|
||||
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]:
|
||||
if ncMessage.message.from_ in self.Yuuki.Admin:
|
||||
if len(msgSep) == 2:
|
||||
if msgSep[1].isdigit() and 1 >= int(msgSep[1]) >= 0:
|
||||
self.Yuuki.data.updateData(["Global", "SecurityService"], bool(msgSep[1]))
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Okay"))
|
||||
self.Yuuki.data.updateData(
|
||||
["Global", "SecurityService"], bool(msgSep[1]))
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
|
||||
ncMessage), self.Yuuki.get_text("Okay"))
|
||||
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:
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage),
|
||||
str(bool(self.Yuuki.data.getData(["Global", "SecurityService"]))))
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
|
||||
str(bool(self.Yuuki.data.getData(["Global", "SecurityService"]))))
|
||||
|
||||
elif self.Yuuki.YuukiConfigs["name"] + '/Switch' == msgSep[0] and len(msgSep) != 1:
|
||||
if ncMessage.message.toType == MIDType.GROUP:
|
||||
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to)
|
||||
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] + \
|
||||
self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]
|
||||
GroupInfo = self.Yuuki_DynamicTools.getClient(
|
||||
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"]
|
||||
if not self.Yuuki.data.getData(["Global", "SecurityService"]):
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage),
|
||||
self.Yuuki.get_text("SecurityService of %s was disable") % (self.Yuuki.YuukiConfigs["name"],))
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
|
||||
self.Yuuki.get_text("SecurityService of %s was disable") % (self.Yuuki.YuukiConfigs["name"],))
|
||||
elif ncMessage.message.from_ in GroupPrivilege:
|
||||
status = []
|
||||
unknown_msg = []
|
||||
|
@ -88,61 +105,78 @@ class Yuuki_Command:
|
|||
status.append(int(code))
|
||||
elif count != 0:
|
||||
unknown_msg.append(code.strip())
|
||||
self.Yuuki.configSecurityStatus(ncMessage.message.to, status)
|
||||
self.Yuuki_DynamicTools.configSecurityStatus(
|
||||
ncMessage.message.to, status)
|
||||
if unknown_msg:
|
||||
unknown_msgtext = ", ".join(unknown_msg)
|
||||
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:
|
||||
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 != "":
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage),
|
||||
self.Yuuki.get_text("Notice: Unknown command line argument(s)") + "\n({})".format(
|
||||
unknown_msgtext))
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
|
||||
self.Yuuki.get_text("Notice: Unknown command line argument(s)") + "\n({})".format(
|
||||
unknown_msgtext))
|
||||
|
||||
elif self.Yuuki.YuukiConfigs["name"] + '/DisableAll' == ncMessage.message.text:
|
||||
if ncMessage.message.toType == MIDType.GROUP:
|
||||
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to)
|
||||
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] + \
|
||||
self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]
|
||||
GroupInfo = self.Yuuki_DynamicTools.getClient(
|
||||
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"]
|
||||
if not self.Yuuki.data.getData(["Global", "SecurityService"]):
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage),
|
||||
self.Yuuki.get_text("SecurityService of %s was disable") % (self.Yuuki.YuukiConfigs["name"],))
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
|
||||
self.Yuuki.get_text("SecurityService of %s was disable") % (self.Yuuki.YuukiConfigs["name"],))
|
||||
elif ncMessage.message.from_ in GroupPrivilege:
|
||||
self.Yuuki.configSecurityStatus(ncMessage.message.to, [])
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Okay"))
|
||||
self.Yuuki_DynamicTools.configSecurityStatus(
|
||||
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]:
|
||||
if ncMessage.message.toType == MIDType.GROUP:
|
||||
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to)
|
||||
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid]
|
||||
GroupInfo = self.Yuuki_DynamicTools.getClient(
|
||||
self.Yuuki.MyMID).getGroup(ncMessage.message.to)
|
||||
GroupPrivilege = self.Yuuki.Admin + \
|
||||
[self.Yuuki_StaticTools.sybGetGroupCreator(
|
||||
GroupInfo).mid]
|
||||
if len(msgSep) == 3:
|
||||
if ncMessage.message.from_ in GroupPrivilege:
|
||||
if msgSep[1] == "add":
|
||||
if msgSep[2] in [Member.mid for Member in GroupInfo.members]:
|
||||
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"]):
|
||||
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.append(msgSep[2])
|
||||
self.Yuuki.data.updateData(["Group", GroupInfo.id, "Ext_Admin"], ext_admin_list)
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Okay"))
|
||||
self.Yuuki.data.updateData(
|
||||
["Group", GroupInfo.id, "Ext_Admin"], ext_admin_list)
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
|
||||
ncMessage), self.Yuuki.get_text("Okay"))
|
||||
else:
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage),
|
||||
self.Yuuki.get_text("The User(s) was in our blacklist database."))
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
|
||||
self.Yuuki.get_text("The User(s) was in our blacklist database."))
|
||||
else:
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage),
|
||||
self.Yuuki.get_text("Wrong UserID or the guy is not in Group"))
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(ncMessage),
|
||||
self.Yuuki.get_text("Wrong UserID or the guy is not in Group"))
|
||||
elif msgSep[1] == "delete":
|
||||
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.remove(msgSep[2])
|
||||
self.Yuuki.data.updateData(["Group", GroupInfo.id, "Ext_Admin"], ext_admin_list)
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Okay"))
|
||||
self.Yuuki.data.updateData(
|
||||
["Group", GroupInfo.id, "Ext_Admin"], ext_admin_list)
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
|
||||
ncMessage), self.Yuuki.get_text("Okay"))
|
||||
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:
|
||||
if self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]:
|
||||
status = ""
|
||||
|
@ -153,91 +187,119 @@ class Yuuki_Command:
|
|||
status_added.append(member.mid)
|
||||
for userId in self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]:
|
||||
if userId not in status_added:
|
||||
status += "{}: {}\n".format(self.Yuuki.get_text("Unknown"), userId)
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), status + self.Yuuki.get_text("\nExtend Administrator(s)"))
|
||||
status += "{}: {}\n".format(
|
||||
self.Yuuki.get_text("Unknown"), userId)
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
|
||||
ncMessage), status + self.Yuuki.get_text("\nExtend Administrator(s)"))
|
||||
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:
|
||||
if ncMessage.message.toType == MIDType.GROUP:
|
||||
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to)
|
||||
group_status = self.Yuuki.data.getSEGroup(ncMessage.message.to)
|
||||
GroupInfo = self.Yuuki_DynamicTools.getClient(
|
||||
self.Yuuki.MyMID).getGroup(ncMessage.message.to)
|
||||
group_status = self.Yuuki.data.getSEGroup(
|
||||
ncMessage.message.to)
|
||||
if not self.Yuuki.data.getData(["Global", "SecurityService"]):
|
||||
status = self.Yuuki.get_text("SecurityService of %s was disable") % (
|
||||
self.Yuuki.YuukiConfigs["name"],
|
||||
)
|
||||
elif group_status is None:
|
||||
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:
|
||||
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") % (
|
||||
group_status[OpType.NOTIFIED_UPDATE_GROUP],
|
||||
group_status[OpType.NOTIFIED_INVITE_INTO_GROUP],
|
||||
group_status[OpType.NOTIFIED_ACCEPT_GROUP_INVITATION],
|
||||
group_status[OpType.NOTIFIED_KICKOUT_FROM_GROUP],
|
||||
self.Yuuki.sybGetGroupCreator(GroupInfo).displayName,
|
||||
)
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), status)
|
||||
group_status[OpType.NOTIFIED_UPDATE_GROUP],
|
||||
group_status[OpType.NOTIFIED_INVITE_INTO_GROUP],
|
||||
group_status[OpType.NOTIFIED_ACCEPT_GROUP_INVITATION],
|
||||
group_status[OpType.NOTIFIED_KICKOUT_FROM_GROUP],
|
||||
self.Yuuki_StaticTools.sybGetGroupCreator(
|
||||
GroupInfo).displayName,
|
||||
)
|
||||
self.Yuuki_DynamicTools.sendText(
|
||||
self.Yuuki_StaticTools.sendToWho(ncMessage), status)
|
||||
|
||||
elif self.Yuuki.YuukiConfigs["name"] + '/GroupBackup' == ncMessage.message.text:
|
||||
if ncMessage.message.toType == MIDType.GROUP:
|
||||
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to)
|
||||
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] + \
|
||||
self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]
|
||||
GroupInfo = self.Yuuki_DynamicTools.getClient(
|
||||
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"]
|
||||
if ncMessage.message.from_ in GroupPrivilege:
|
||||
GroupMembers = [User.mid for User in GroupInfo.members]
|
||||
GroupInvites = None
|
||||
if GroupInfo.invitee:
|
||||
GroupInvites = [User.mid for User in GroupInfo.invitee]
|
||||
GroupInvites = [
|
||||
User.mid for User in GroupInfo.invitee]
|
||||
LayoutInfo = {
|
||||
"OriginID": GroupInfo.id,
|
||||
"Members": GroupMembers,
|
||||
"Invites": GroupInvites
|
||||
}
|
||||
self.Yuuki.sendText(ncMessage.message.from_, GroupInfo.name)
|
||||
self.Yuuki.sendText(ncMessage.message.from_, json.dumps(LayoutInfo))
|
||||
self.Yuuki.sendText(ncMessage.message.to, self.Yuuki.get_text("Okay"))
|
||||
self.Yuuki_DynamicTools.sendText(
|
||||
ncMessage.message.from_, GroupInfo.name)
|
||||
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:
|
||||
if ncMessage.message.toType == MIDType.GROUP:
|
||||
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(ncMessage.message.to)
|
||||
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid]
|
||||
GroupInfo = self.Yuuki_DynamicTools.getClient(
|
||||
self.Yuuki.MyMID).getGroup(ncMessage.message.to)
|
||||
GroupPrivilege = self.Yuuki.Admin + \
|
||||
[self.Yuuki_StaticTools.sybGetGroupCreator(
|
||||
GroupInfo).mid]
|
||||
if ncMessage.message.from_ in GroupPrivilege:
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), self.Yuuki.get_text("Bye Bye"))
|
||||
self.Yuuki.getClient(self.Yuuki.MyMID).leaveGroup(self.Yuuki.Seq, GroupInfo.id)
|
||||
self.Yuuki_DynamicTools.sendText(self.Yuuki_StaticTools.sendToWho(
|
||||
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:
|
||||
if userId in [member.mid for member in GroupInfo.members]:
|
||||
self.Yuuki.getClient(userId).leaveGroup(self.Yuuki.Seq, GroupInfo.id)
|
||||
GroupList = self.Yuuki.data.getData(["Global", "GroupJoined"])
|
||||
self.Yuuki_DynamicTools.getClient(
|
||||
userId).leaveGroup(self.Yuuki.Seq, GroupInfo.id)
|
||||
GroupList = self.Yuuki.data.getData(
|
||||
["Global", "GroupJoined"])
|
||||
NewGroupList = GroupList.copy()
|
||||
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:
|
||||
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()
|
||||
|
||||
elif self.Yuuki.YuukiConfigs["name"] + '/Com' == msgSep[0] and len(msgSep) != 1:
|
||||
if ncMessage.message.from_ in self.Yuuki.Admin:
|
||||
try:
|
||||
ComMsg = self.Yuuki.readCommandLine(msgSep[1:len(msgSep)])
|
||||
ComMsg = self.Yuuki_StaticTools.readCommandLine(
|
||||
msgSep[1:len(msgSep)])
|
||||
Report = str(eval(ComMsg))
|
||||
except:
|
||||
(err1, err2, err3, ErrorInfo) = self.Yuuki.errorReport()
|
||||
Report = "Star Yuuki BOT - Eval Error:\n%s\n%s\n%s\n\n%s" % (err1, err2, err3, ErrorInfo)
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), Report)
|
||||
(err1, err2, err3,
|
||||
ErrorInfo) = self.Yuuki_StaticTools.errorReport()
|
||||
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:
|
||||
Catched = ncMessage.message.contentMetadata["mid"]
|
||||
contactInfo = self.Yuuki.getContact(Catched)
|
||||
contactInfo = self.Yuuki_DynamicTools.getContact(Catched)
|
||||
if not contactInfo:
|
||||
msg = self.Yuuki.get_text("Not Found")
|
||||
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:
|
||||
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.statusMessage, contactInfo.mid)
|
||||
self.Yuuki.sendText(self.Yuuki.sendToWho(ncMessage), msg)
|
||||
(contactInfo.displayName, self.Yuuki.LINE_Media_server, contactInfo.pictureStatus,
|
||||
contactInfo.statusMessage, contactInfo.mid)
|
||||
self.Yuuki_DynamicTools.sendText(
|
||||
self.Yuuki_StaticTools.sendToWho(ncMessage), msg)
|
||||
|
|
|
@ -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/.
|
||||
"""
|
||||
|
||||
from ..tools import Yuuki_StaticTools, Yuuki_DynamicTools
|
||||
|
||||
|
||||
class Yuuki_JoinGroup:
|
||||
def __init__(self, Yuuki):
|
||||
"""
|
||||
|
@ -15,43 +18,59 @@ class Yuuki_JoinGroup:
|
|||
"""
|
||||
self.Yuuki = Yuuki
|
||||
|
||||
self.Yuuki_StaticTools = Yuuki_StaticTools()
|
||||
self.Yuuki_DynamicTools = Yuuki_DynamicTools(self.Yuuki)
|
||||
|
||||
def action(self, ncMessage):
|
||||
GroupInvite = []
|
||||
BlockedIgnore = ncMessage.param2 in self.Yuuki.data.getData(["BlackList"])
|
||||
if self.Yuuki.checkInInvitationList(ncMessage) and not BlockedIgnore:
|
||||
BlockedIgnore = ncMessage.param2 in self.Yuuki.data.getData([
|
||||
"BlackList"])
|
||||
if self.Yuuki_DynamicTools.checkInInvitationList(ncMessage) and not BlockedIgnore:
|
||||
GroupID = ncMessage.param1
|
||||
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:
|
||||
GroupMember = [Catched.mid for Catched in GroupInfo.members]
|
||||
GroupInfo.invitee = []
|
||||
if GroupInfo.invitee:
|
||||
GroupInvite = [Catched.mid for Catched in GroupInfo.invitee]
|
||||
self.Yuuki.getClient(self.Yuuki.MyMID).acceptGroupInvitation(self.Yuuki.Seq, GroupID)
|
||||
GroupInvite = [
|
||||
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"]:
|
||||
GroupList = self.Yuuki.data.getData(["Global", "GroupJoined"])
|
||||
GroupList = self.Yuuki.data.getData(
|
||||
["Global", "GroupJoined"])
|
||||
NewGroupList = GroupList.copy()
|
||||
NewGroupList.append(GroupID)
|
||||
self.Yuuki.data.updateData(["Global", "GroupJoined"], NewGroupList)
|
||||
self.Yuuki.sendText(GroupID,
|
||||
self.Yuuki.get_text("Helllo^^\nMy name is %s ><\nNice to meet you OwO") % self.Yuuki.YuukiConfigs["name"])
|
||||
self.Yuuki.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.YuukiConfigs["name"], self.Yuuki.sybGetGroupCreator(GroupInfo).displayName,))
|
||||
self.Yuuki.getGroupTicket(GroupID, self.Yuuki.MyMID, True)
|
||||
self.Yuuki.data.updateData(
|
||||
["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_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.YuukiConfigs["name"], self.Yuuki_StaticTools.sybGetGroupCreator(GroupInfo).displayName,))
|
||||
self.Yuuki_DynamicTools.getGroupTicket(
|
||||
GroupID, self.Yuuki.MyMID, True)
|
||||
# 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:
|
||||
self.Yuuki.sendText(GroupID, self.Yuuki.get_text("Sorry...\nThe number of members is not satisfied (%s needed)") %
|
||||
(self.Yuuki.YuukiConfigs["GroupMebers_Demand"],))
|
||||
self.Yuuki.getClient(self.Yuuki.MyMID).leaveGroup(self.Yuuki.Seq, GroupID)
|
||||
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_DynamicTools.getClient(
|
||||
self.Yuuki.MyMID).leaveGroup(self.Yuuki.Seq, GroupID)
|
||||
# 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:
|
||||
for userId in self.Yuuki.Connect.helper_ids:
|
||||
if self.Yuuki.checkInInvitationList(ncMessage, userId) or userId in GroupInvite:
|
||||
self.Yuuki.getClient(userId).acceptGroupInvitation(self.Yuuki.Seq, ncMessage.param1)
|
||||
self.Yuuki.getGroupTicket(ncMessage.param1, userId, True)
|
||||
if self.Yuuki_DynamicTools.checkInInvitationList(ncMessage, userId) or userId in GroupInvite:
|
||||
self.Yuuki_DynamicTools.getClient(userId).acceptGroupInvitation(
|
||||
self.Yuuki.Seq, ncMessage.param1)
|
||||
self.Yuuki_DynamicTools.getGroupTicket(
|
||||
ncMessage.param1, userId, True)
|
||||
# Log
|
||||
self.Yuuki.data.updateLog("JoinGroup", (self.Yuuki.data.getTime(), ncMessage.param1, userId, ncMessage.param2))
|
||||
self.Yuuki.Security(ncMessage)
|
||||
self.Yuuki.data.updateLog("JoinGroup", (self.Yuuki.data.getTime(
|
||||
), ncMessage.param1, userId, ncMessage.param2))
|
||||
self.Yuuki.Security(ncMessage)
|
||||
|
|
|
@ -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/.
|
||||
"""
|
||||
|
||||
from ..tools import Yuuki_StaticTools, Yuuki_DynamicTools
|
||||
|
||||
from yuuki_core.ttypes import OpType
|
||||
|
||||
|
||||
class Yuuki_Security:
|
||||
def __init__(self, Yuuki):
|
||||
"""
|
||||
|
@ -20,14 +23,18 @@ class Yuuki_Security:
|
|||
"""
|
||||
self.Yuuki = Yuuki
|
||||
|
||||
self.Yuuki_StaticTools = Yuuki_StaticTools()
|
||||
self.Yuuki_DynamicTools = Yuuki_DynamicTools(self.Yuuki)
|
||||
|
||||
def action(self, ncMessage):
|
||||
Security_Access = False
|
||||
|
||||
(GroupID, Action, Another) = self.Yuuki.securityForWhere(ncMessage)
|
||||
(GroupID, Action, Another) = self.Yuuki_StaticTools.securityForWhere(ncMessage)
|
||||
SEGroup = self.Yuuki.data.getSEGroup(GroupID)
|
||||
|
||||
GroupInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getGroup(GroupID)
|
||||
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki.sybGetGroupCreator(GroupInfo).mid] + self.Yuuki.data.getGroup(GroupInfo.id)[
|
||||
GroupInfo = self.Yuuki_DynamicTools.getClient(
|
||||
self.Yuuki.MyMID).getGroup(GroupID)
|
||||
GroupPrivilege = self.Yuuki.Admin + [self.Yuuki_StaticTools.sybGetGroupCreator(GroupInfo).mid] + self.Yuuki.data.getGroup(GroupInfo.id)[
|
||||
"Ext_Admin"]
|
||||
|
||||
if Action in GroupPrivilege or Another in GroupPrivilege:
|
||||
|
@ -37,7 +44,8 @@ class Yuuki_Security:
|
|||
return
|
||||
|
||||
if SEGroup is None:
|
||||
Security_Access = self.Yuuki.data.getData(["Global", "SecurityService"])
|
||||
Security_Access = self.Yuuki.data.getData(
|
||||
["Global", "SecurityService"])
|
||||
elif 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 Another == '4':
|
||||
if not GroupInfo.preventJoinByTicket and Action not in self.Yuuki.Connect.helper_ids:
|
||||
self.Yuuki.Thread_Exec(self.Yuuki.changeGroupUrlStatus, (GroupInfo, False))
|
||||
self.Yuuki.Thread_Exec(self.Yuuki.sendText, (GroupID, self.Yuuki.get_text("DO NOT ENABLE THE GROUP URL STATUS, see you...")))
|
||||
Kicker = self.Yuuki.kickSomeone(GroupInfo, Action)
|
||||
self.Yuuki.threadExec(
|
||||
self.Yuuki_DynamicTools.changeGroupUrlStatus, (GroupInfo, False))
|
||||
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
|
||||
self.Yuuki.data.updateLog("KickEvent", (
|
||||
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"):
|
||||
if userId not in self.Yuuki.AllAccountIds + GroupPrivilege:
|
||||
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:
|
||||
Canceler = self.Yuuki.kickSomeone(GroupInfo, userId)
|
||||
Canceler = self.Yuuki_DynamicTools.kickSomeone(
|
||||
GroupInfo, userId)
|
||||
# Log
|
||||
self.Yuuki.data.updateLog("KickEvent", (
|
||||
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, userId,
|
||||
|
@ -69,23 +82,28 @@ class Yuuki_Security:
|
|||
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another.replace("\x1e", ",")))
|
||||
elif Another not in self.Yuuki.AllAccountIds + GroupPrivilege:
|
||||
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:
|
||||
Canceler = self.Yuuki.kickSomeone(GroupInfo, Another)
|
||||
Canceler = self.Yuuki_DynamicTools.kickSomeone(
|
||||
GroupInfo, Another)
|
||||
# Log
|
||||
self.Yuuki.data.updateLog("KickEvent", (
|
||||
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another,
|
||||
ncMessage.type * 10))
|
||||
# Log
|
||||
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":
|
||||
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:
|
||||
for userId in self.Yuuki.data.getData(["BlackList"]):
|
||||
if userId == Action:
|
||||
self.Yuuki.Thread_Exec(self.Yuuki.sendText, (GroupID, self.Yuuki.get_text("You are our blacklist. Bye~")))
|
||||
Kicker = self.Yuuki.kickSomeone(GroupInfo, Action)
|
||||
self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (GroupID, self.Yuuki.get_text(
|
||||
"You are our blacklist. Bye~")))
|
||||
Kicker = self.Yuuki_DynamicTools.kickSomeone(
|
||||
GroupInfo, Action)
|
||||
# Log
|
||||
self.Yuuki.data.updateLog("KickEvent", (
|
||||
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:
|
||||
Kicker = "None"
|
||||
try:
|
||||
Kicker = self.Yuuki.kickSomeone(GroupInfo, Action, Another)
|
||||
Kicker = self.Yuuki_DynamicTools.kickSomeone(
|
||||
GroupInfo, Action, Another)
|
||||
# Log
|
||||
self.Yuuki.data.updateLog("KickEvent", (
|
||||
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another,
|
||||
ncMessage.type * 10 + 2))
|
||||
assert Kicker != "None", "No Helper Found"
|
||||
if GroupInfo.preventJoinByTicket:
|
||||
self.Yuuki.Thread_Exec(self.Yuuki.changeGroupUrlStatus, (GroupInfo, True, Kicker))
|
||||
GroupTicket = self.Yuuki.getGroupTicket(GroupID, Kicker)
|
||||
self.Yuuki.threadExec(
|
||||
self.Yuuki_DynamicTools.changeGroupUrlStatus, (GroupInfo, True, Kicker))
|
||||
GroupTicket = self.Yuuki_DynamicTools.getGroupTicket(
|
||||
GroupID, Kicker)
|
||||
try:
|
||||
self.Yuuki.getClient(Another).acceptGroupInvitationByTicket(self.Yuuki.Seq, GroupID, GroupTicket)
|
||||
self.Yuuki_DynamicTools.getClient(Another).acceptGroupInvitationByTicket(
|
||||
self.Yuuki.Seq, GroupID, GroupTicket)
|
||||
except:
|
||||
if GroupInfo.preventJoinByTicket:
|
||||
self.Yuuki.changeGroupUrlStatus(GroupInfo, True, Kicker)
|
||||
GroupTicket = self.Yuuki.getGroupTicket(GroupID, Kicker, True)
|
||||
self.Yuuki.getClient(Another).acceptGroupInvitationByTicket(self.Yuuki.Seq, GroupID, GroupTicket)
|
||||
self.Yuuki_DynamicTools.changeGroupUrlStatus(
|
||||
GroupInfo, True, Kicker)
|
||||
GroupTicket = self.Yuuki_DynamicTools.getGroupTicket(
|
||||
GroupID, Kicker, True)
|
||||
self.Yuuki_DynamicTools.getClient(Another).acceptGroupInvitationByTicket(
|
||||
self.Yuuki.Seq, GroupID, GroupTicket)
|
||||
if GroupInfo.preventJoinByTicket:
|
||||
self.Yuuki.Thread_Exec(self.Yuuki.changeGroupUrlStatus, (GroupInfo, False, Another))
|
||||
self.Yuuki.getGroupTicket(GroupID, Another, True)
|
||||
self.Yuuki.threadExec(
|
||||
self.Yuuki_DynamicTools.changeGroupUrlStatus, (GroupInfo, False, Another))
|
||||
self.Yuuki_DynamicTools.getGroupTicket(
|
||||
GroupID, Another, True)
|
||||
except:
|
||||
(err1, err2, err3, ErrorInfo) = self.Yuuki.errorReport()
|
||||
(err1, err2, err3,
|
||||
ErrorInfo) = self.Yuuki_StaticTools.errorReport()
|
||||
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" %
|
||||
(err1, err2, err3, ErrorInfo))
|
||||
self.Yuuki_DynamicTools.sendText(Root, "Star Yuuki BOT - SecurityService Failure\n\n%s\n%s\n%s\n\n%s" %
|
||||
(err1, err2, err3, ErrorInfo))
|
||||
if Another == self.Yuuki.MyMID:
|
||||
GroupList = self.Yuuki.data.getData(["Global", "GroupJoined"])
|
||||
GroupList = self.Yuuki.data.getData(
|
||||
["Global", "GroupJoined"])
|
||||
NewGroupList = GroupList.copy()
|
||||
NewGroupList.remove(GroupID)
|
||||
self.Yuuki.data.updateData(["Global", "GroupJoined"], NewGroupList)
|
||||
self.Yuuki.data.updateData(
|
||||
["Global", "GroupJoined"], NewGroupList)
|
||||
# Log
|
||||
self.Yuuki.data.updateLog("KickEvent", (
|
||||
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another,
|
||||
|
@ -136,13 +166,19 @@ class Yuuki_Security:
|
|||
NewBlackList.append(Action)
|
||||
self.Yuuki.data.updateData(["BlackList"], NewBlackList)
|
||||
# Log
|
||||
self.Yuuki.data.updateLog("BlackList", (self.Yuuki.data.getTime(), Action, GroupID))
|
||||
self.Yuuki.Thread_Exec(self.Yuuki.sendText, (Action, self.Yuuki.get_text("You had been blocked by our database.")))
|
||||
self.Yuuki.data.updateLog(
|
||||
"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:
|
||||
self.Yuuki.Thread_Exec(self.Yuuki.sendText, (GroupID, self.Yuuki.get_text("DO NOT KICK, thank you ^^")))
|
||||
Kicker = self.Yuuki.kickSomeone(GroupInfo, Action)
|
||||
self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (
|
||||
GroupID, self.Yuuki.get_text("DO NOT KICK, thank you ^^")))
|
||||
Kicker = self.Yuuki_DynamicTools.kickSomeone(
|
||||
GroupInfo, Action)
|
||||
# Log
|
||||
self.Yuuki.data.updateLog("KickEvent", (
|
||||
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.Thread_Exec(self.Yuuki.sendUser, (GroupID, Another))
|
||||
self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (GroupID, self.Yuuki.get_text(
|
||||
"The one who was been kicked:")))
|
||||
self.Yuuki.threadExec(
|
||||
self.Yuuki_DynamicTools.sendUser, (GroupID, Another))
|
||||
|
|
11
libs/poll.py
11
libs/poll.py
|
@ -11,11 +11,16 @@ import time
|
|||
import socket
|
||||
import requests
|
||||
|
||||
from .tools import Yuuki_StaticTools, Yuuki_DynamicTools
|
||||
|
||||
from yuuki_core.ttypes import Operation
|
||||
|
||||
class Yuuki_Poll:
|
||||
def __init__(self, Yuuki):
|
||||
self.Yuuki = Yuuki
|
||||
|
||||
self.Yuuki_StaticTools = Yuuki_StaticTools()
|
||||
self.Yuuki_DynamicTools = Yuuki_DynamicTools(self.Yuuki)
|
||||
|
||||
self.NoWork = 0
|
||||
self.NoWorkLimit = 5
|
||||
|
@ -35,7 +40,7 @@ class Yuuki_Poll:
|
|||
while self.Power:
|
||||
try:
|
||||
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)
|
||||
|
||||
if self.NoWork >= self.NoWorkLimit:
|
||||
|
@ -54,7 +59,7 @@ class Yuuki_Poll:
|
|||
|
||||
if self.cacheOperations:
|
||||
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:
|
||||
self.Yuuki.revision = max(self.cacheOperations[-1].revision, self.cacheOperations[-2].revision)
|
||||
|
||||
|
@ -73,7 +78,7 @@ class Yuuki_Poll:
|
|||
pass
|
||||
|
||||
except:
|
||||
(err1, err2, err3, ErrorInfo) = self.Yuuki.errorReport()
|
||||
(err1, err2, err3, ErrorInfo) = self.Yuuki_StaticTools.errorReport()
|
||||
try:
|
||||
for self.ncMessage in self.cacheOperations:
|
||||
if self.ncMessage.reqSeq != -1 and self.ncMessage.revision > self.Yuuki.revision:
|
||||
|
|
|
@ -17,6 +17,7 @@ import traceback
|
|||
|
||||
from yuuki_core.ttypes import OpType, MIDType, ContentType, Group, Message
|
||||
|
||||
|
||||
class Yuuki_StaticTools:
|
||||
@staticmethod
|
||||
def sybGetGroupCreator(group):
|
||||
|
@ -39,7 +40,8 @@ class Yuuki_StaticTools:
|
|||
traceback.print_tb(err3)
|
||||
tb_info = traceback.extract_tb(err3)
|
||||
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
|
||||
|
||||
@staticmethod
|
||||
|
@ -79,6 +81,7 @@ class Yuuki_StaticTools:
|
|||
class Yuuki_DynamicTools:
|
||||
def __init__(self, Yuuki):
|
||||
self.Yuuki = Yuuki
|
||||
self.Yuuki_StaticTools = Yuuki_StaticTools()
|
||||
|
||||
def getClient(self, userId):
|
||||
if self.Yuuki.Threading:
|
||||
|
@ -117,9 +120,10 @@ class Yuuki_DynamicTools:
|
|||
else:
|
||||
result.preventJoinByTicket = True
|
||||
if userId is not None:
|
||||
self.Yuuki.getClient(userId).updateGroup(self.Yuuki.Seq, result)
|
||||
self.getClient(userId).updateGroup(self.Yuuki.Seq, result)
|
||||
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):
|
||||
group_status = self.Yuuki.data.SEGrouptype
|
||||
|
@ -135,7 +139,7 @@ class Yuuki_DynamicTools:
|
|||
self.Yuuki.data.updateData(["Group", groupId, "SEGroup"], group_status)
|
||||
|
||||
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():
|
||||
client.acceptGroupInvitation(self.Yuuki.Seq, cleanInvitations)
|
||||
client.leaveGroup(self.Yuuki.Seq, cleanInvitations)
|
||||
|
@ -143,7 +147,8 @@ class Yuuki_DynamicTools:
|
|||
def getContact(self, userId):
|
||||
if len(userId) == len(self.Yuuki.MyMID) and userId[0] == "u":
|
||||
try:
|
||||
contactInfo = self.Yuuki.getClient(self.Yuuki.MyMID).getContact(userId)
|
||||
contactInfo = self.getClient(
|
||||
self.Yuuki.MyMID).getContact(userId)
|
||||
except:
|
||||
contactInfo = False
|
||||
else:
|
||||
|
@ -159,19 +164,24 @@ class Yuuki_DynamicTools:
|
|||
else:
|
||||
assert "Error JSON data type - GroupTicket"
|
||||
if GroupTicket == "" or renew:
|
||||
GroupTicket = self.Yuuki.getClient(userId).reissueGroupTicket(GroupID)
|
||||
self.Yuuki.data.updateData(["Group", GroupID, "GroupTicket", userId], GroupTicket)
|
||||
GroupTicket = self.getClient(userId).reissueGroupTicket(GroupID)
|
||||
self.Yuuki.data.updateData(
|
||||
["Group", GroupID, "GroupTicket", userId], GroupTicket)
|
||||
return GroupTicket
|
||||
|
||||
def limitReset(self):
|
||||
for userId in self.Yuuki.AllAccountIds:
|
||||
self.Yuuki.data.updateData(["LimitInfo", "KickLimit", userId], self.Yuuki.KickLimit)
|
||||
self.Yuuki.data.updateData(["LimitInfo", "CancelLimit", userId], self.Yuuki.CancelLimit)
|
||||
self.Yuuki.data.updateData(
|
||||
["LimitInfo", "KickLimit", userId], self.Yuuki.KickLimit)
|
||||
self.Yuuki.data.updateData(
|
||||
["LimitInfo", "CancelLimit", userId], self.Yuuki.CancelLimit)
|
||||
|
||||
def cancelSomeone(self, groupInfo, userId, exceptUserId=None):
|
||||
if len(self.Yuuki.Connect.helper) >= 1:
|
||||
members = [member.mid for member in groupInfo.members if member.mid in self.Yuuki.AllAccountIds]
|
||||
accounts = self.Yuuki.dictShuffle(self.Yuuki.data.getData(["LimitInfo", "CancelLimit"]), members)
|
||||
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:
|
||||
return "None"
|
||||
if exceptUserId:
|
||||
|
@ -184,16 +194,19 @@ class Yuuki_DynamicTools:
|
|||
|
||||
Limit = self.Yuuki.data.getData(["LimitInfo", "CancelLimit", helper])
|
||||
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)
|
||||
else:
|
||||
self.Yuuki.sendText(groupInfo.id, self.Yuuki.get_text("Cancel Limit."))
|
||||
self.sendText(groupInfo.id, self.Yuuki.get_text("Cancel Limit."))
|
||||
return helper
|
||||
|
||||
def kickSomeone(self, groupInfo, userId, exceptUserId=None):
|
||||
if len(self.Yuuki.Connect.helper) >= 1:
|
||||
members = [member.mid for member in groupInfo.members if member.mid in self.Yuuki.AllAccountIds]
|
||||
accounts = self.Yuuki.dictShuffle(self.Yuuki.data.getData(["LimitInfo", "KickLimit"]), members)
|
||||
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:
|
||||
return "None"
|
||||
if exceptUserId:
|
||||
|
@ -206,15 +219,16 @@ class Yuuki_DynamicTools:
|
|||
|
||||
Limit = self.Yuuki.data.getData(["LimitInfo", "KickLimit", helper])
|
||||
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)
|
||||
else:
|
||||
self.Yuuki.sendText(groupInfo.id, self.Yuuki.get_text("Kick Limit."))
|
||||
self.sendText(groupInfo.id, self.Yuuki.get_text("Kick Limit."))
|
||||
return helper
|
||||
|
||||
def sendText(self, toid, 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):
|
||||
message = Message(
|
||||
|
@ -226,7 +240,7 @@ class Yuuki_DynamicTools:
|
|||
},
|
||||
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):
|
||||
if os.path.exists(path):
|
||||
|
@ -243,7 +257,8 @@ class Yuuki_DynamicTools:
|
|||
media_name = file_name
|
||||
else:
|
||||
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 = {
|
||||
'file': open(path, 'rb'),
|
||||
}
|
||||
|
@ -258,6 +273,7 @@ class Yuuki_DynamicTools:
|
|||
'params': json.dumps(params)
|
||||
}
|
||||
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:
|
||||
self.Yuuki.sendText(send_to, "Error!")
|
||||
self.sendText(send_to, "Error!")
|
||||
|
|
|
@ -146,7 +146,7 @@ class Yuuki:
|
|||
print("Star Yuuki BOT - Restart Error\n\nUnknown Platform")
|
||||
sys.exit(0)
|
||||
|
||||
def _Thread_Exec(self, Function, args):
|
||||
def threadExec(self, Function, args):
|
||||
if self.Threading:
|
||||
self.Thread_Control.add(Function, args)
|
||||
else:
|
||||
|
@ -155,15 +155,15 @@ class Yuuki:
|
|||
def taskDemux(self, catchedNews):
|
||||
for ncMessage in catchedNews:
|
||||
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:
|
||||
self._Thread_Exec(self.Security, (ncMessage,))
|
||||
self.threadExec(self.Security, (ncMessage,))
|
||||
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:
|
||||
self._Thread_Exec(self.Security, (ncMessage,))
|
||||
self.threadExec(self.Security, (ncMessage,))
|
||||
elif ncMessage.type == OpType.RECEIVE_MESSAGE:
|
||||
self._Thread_Exec(self.Command, (ncMessage,))
|
||||
self.threadExec(self.Command, (ncMessage,))
|
||||
|
||||
def main(self):
|
||||
handle = Yuuki_Poll(self)
|
||||
|
|
Loading…
Reference in a new issue