This commit is contained in:
SuperSonic 2020-02-12 20:26:47 +08:00
parent bde19753d5
commit 1de8d802bd
5 changed files with 232 additions and 151 deletions

View file

@ -46,7 +46,7 @@ class Yuuki_Config:
def __init__(self, config_path="config.yaml"):
with open(config_path, "r") as configfile:
self.config = yaml.load(configfile, Loader=yaml.BaseLoader)
self.config = yaml.load(configfile, Loader=yaml.FullLoader)
self._yuuki_config()
def _yuuki_config(self):

View file

@ -261,9 +261,8 @@ class Yuuki_Data:
return None
SEMode_ = {}
for Mode in SEMode:
if type(Mode) != "int":
Mode = int(Mode)
SEMode_[Mode] = SEMode[Mode]
Num_Mode = int(Mode)
SEMode_[Num_Mode] = SEMode[Mode]
return SEMode_
def limitDecrease(self, limit_type, userId):

View file

@ -35,8 +35,7 @@ class Yuuki_JoinGroup:
if GroupInfo.invitee:
GroupInvite = [
Catched.mid for Catched in GroupInfo.invitee]
self.Yuuki_DynamicTools.getClient(
self.Yuuki.MyMID).acceptGroupInvitation(self.Yuuki.Seq, GroupID)
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"])

View file

@ -26,151 +26,233 @@ class Yuuki_Security:
self.Yuuki_StaticTools = Yuuki_StaticTools()
self.Yuuki_DynamicTools = Yuuki_DynamicTools(self.Yuuki)
def NOTIFIED_UPDATE_GROUP(self, GroupInfo, SecurityInfo, ncMessage):
if SecurityInfo["Another"] == '4':
if not GroupInfo.preventJoinByTicket and SecurityInfo["Action"] not in self.Yuuki.Connect.helper_ids:
self.Yuuki.threadExec(
self.Yuuki_DynamicTools.changeGroupUrlStatus,
(GroupInfo, False)
)
self.Yuuki.threadExec(
self.Yuuki_DynamicTools.sendText,
(SecurityInfo["GroupID"], self.Yuuki.get_text("DO NOT ENABLE THE GROUP URL STATUS, see you..."))
)
Kicker = self.Yuuki_DynamicTools.modifyGroupMemberList(1, GroupInfo, SecurityInfo["Action"])
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(),
GroupInfo.name,
SecurityInfo["GroupID"],
Kicker,
SecurityInfo["Action"],
SecurityInfo["Another"],
ncMessage.type
))
def NOTIFIED_INVITE_INTO_GROUP(self, GroupInfo, SecurityInfo, ncMessage):
Canceler = "None"
if "\x1e" in SecurityInfo["Another"]:
for userId in SecurityInfo["Another"].split("\x1e"):
if userId not in self.Yuuki.AllAccountIds + SecurityInfo["GroupPrivilege"]:
if GroupInfo.invitee and userId in [user.mid for user in GroupInfo.invitee]:
Canceler = self.Yuuki_DynamicTools.modifyGroupMemberList(2, GroupInfo, userId)
else:
Canceler = self.Yuuki_DynamicTools.modifyGroupMemberList(1, GroupInfo, userId)
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(),
GroupInfo.name,
SecurityInfo["GroupID"],
Canceler,
SecurityInfo["Action"],
userId,
ncMessage.type * 10
))
# Log
self.Yuuki.data.updateLog("CancelEvent", (
self.Yuuki.data.getTime(),
GroupInfo.name,
SecurityInfo["GroupID"],
Canceler,
SecurityInfo["Action"],
SecurityInfo["Another"].replace("\x1e", ",")
))
elif SecurityInfo["Another"] not in self.Yuuki.AllAccountIds + SecurityInfo["GroupPrivilege"]:
if GroupInfo.invitee and SecurityInfo["Another"] in [user.mid for user in GroupInfo.invitee]:
Canceler = self.Yuuki_DynamicTools.modifyGroupMemberList(2, GroupInfo, SecurityInfo["Another"])
else:
Canceler = self.Yuuki_DynamicTools.modifyGroupMemberList(1, GroupInfo, SecurityInfo["Another"])
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, SecurityInfo["GroupID"], Canceler, SecurityInfo["Action"], SecurityInfo["Another"],
ncMessage.type * 10))
# Log
self.Yuuki.data.updateLog("CancelEvent", (
self.Yuuki.data.getTime(),
GroupInfo.name,
SecurityInfo["GroupID"],
Canceler,
SecurityInfo["Action"],
SecurityInfo["Another"]
))
if Canceler != "None":
self.Yuuki_DynamicTools.sendText(
SecurityInfo["GroupID"], self.Yuuki.get_text("Do not invite anyone...thanks"))
def NOTIFIED_ACCEPT_GROUP_INVITATION(self, GroupInfo, SecurityInfo, ncMessage):
for userId in self.Yuuki.data.getData(["BlackList"]):
if userId == SecurityInfo["Action"]:
self.Yuuki.threadExec(
self.Yuuki_DynamicTools.sendText,
(SecurityInfo["GroupID"], self.Yuuki.get_text("You are our blacklist. Bye~"))
)
Kicker = self.Yuuki_DynamicTools.modifyGroupMemberList(1, GroupInfo, SecurityInfo["Action"])
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(),
GroupInfo.name,
SecurityInfo["GroupID"],
Kicker,
Kicker,
SecurityInfo["Action"],
ncMessage.type
))
def NOTIFIED_KICKOUT_FROM_GROUP(self, GroupInfo, SecurityInfo, ncMessage):
if SecurityInfo["Action"] in self.Yuuki.Connect.helper_ids:
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(),
GroupInfo.name,
SecurityInfo["GroupID"],
SecurityInfo["Action"],
SecurityInfo["Action"],
SecurityInfo["Another"],
ncMessage.type * 10 + 1
))
elif SecurityInfo["Another"] in self.Yuuki.AllAccountIds:
Kicker = "None"
try:
Kicker = self.Yuuki_DynamicTools.modifyGroupMemberList(
1,
GroupInfo,
SecurityInfo["Action"],
SecurityInfo["Another"]
)
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(),
GroupInfo.name,
SecurityInfo["GroupID"],
Kicker,
SecurityInfo["Action"],
SecurityInfo["Another"],
ncMessage.type * 10 + 2
))
assert Kicker != "None", "No Helper Found"
if GroupInfo.preventJoinByTicket:
self.Yuuki.threadExec(
self.Yuuki_DynamicTools.changeGroupUrlStatus,
(GroupInfo, True, Kicker)
)
GroupTicket = self.Yuuki_DynamicTools.getGroupTicket(
SecurityInfo["GroupID"], Kicker)
try:
self.Yuuki_DynamicTools.getClient(SecurityInfo["Another"]).acceptGroupInvitationByTicket(
self.Yuuki.Seq,
SecurityInfo["GroupID"],
GroupTicket
)
except:
if GroupInfo.preventJoinByTicket:
self.Yuuki_DynamicTools.changeGroupUrlStatus(
GroupInfo,
True,
Kicker
)
GroupTicket = self.Yuuki_DynamicTools.getGroupTicket(
SecurityInfo["GroupID"], Kicker, True)
self.Yuuki_DynamicTools.getClient(SecurityInfo["Another"]).acceptGroupInvitationByTicket(
self.Yuuki.Seq,
SecurityInfo["GroupID"],
GroupTicket
)
if GroupInfo.preventJoinByTicket:
self.Yuuki.threadExec(
self.Yuuki_DynamicTools.changeGroupUrlStatus, (GroupInfo, False, SecurityInfo["Another"]))
self.Yuuki_DynamicTools.getGroupTicket(
SecurityInfo["GroupID"], SecurityInfo["Another"], True)
except:
(err1, err2, err3, ErrorInfo) = self.Yuuki_StaticTools.errorReport()
for Root in self.Yuuki.Admin:
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 SecurityInfo["Another"] == self.Yuuki.MyMID:
GroupList = self.Yuuki.data.getData(["Global", "GroupJoined"])
NewGroupList = GroupList.copy()
NewGroupList.remove(SecurityInfo["GroupID"])
self.Yuuki.data.updateData(["Global", "GroupJoined"], NewGroupList)
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(),
GroupInfo.name,
SecurityInfo["GroupID"],
Kicker,
SecurityInfo["Action"],
SecurityInfo["Another"],
ncMessage.type * 10 + 3
))
BlackList = self.Yuuki.data.getData(["BlackList"])
if SecurityInfo["Action"] not in BlackList:
NewBlackList = BlackList.copy()
NewBlackList.append(SecurityInfo["Action"])
self.Yuuki.data.updateData(["BlackList"], NewBlackList)
# Log
self.Yuuki.data.updateLog(
"BlackList", (self.Yuuki.data.getTime(), SecurityInfo["Action"], SecurityInfo["GroupID"]))
self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (SecurityInfo["Action"], self.Yuuki.get_text(
"You had been blocked by our database.")))
elif SecurityInfo["Security_Access"]:
self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (
SecurityInfo["GroupID"], self.Yuuki.get_text("DO NOT KICK, thank you ^^")))
Kicker = self.Yuuki_DynamicTools.modifyGroupMemberList(1, GroupInfo, SecurityInfo["Action"])
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, SecurityInfo["GroupID"], Kicker, SecurityInfo["Action"], SecurityInfo["Another"], ncMessage.type))
self.Yuuki.threadExec(self.Yuuki_DynamicTools.sendText, (SecurityInfo["GroupID"], self.Yuuki.get_text(
"The one who was been kicked:")))
self.Yuuki.threadExec(
self.Yuuki_DynamicTools.sendUser, (SecurityInfo["GroupID"], SecurityInfo["Another"]))
def action(self, ncMessage):
Security_Access = False
SecurityInfo = self.Yuuki_StaticTools.securityForWhere(ncMessage)
(GroupID, Action, Another) = self.Yuuki_StaticTools.securityForWhere(ncMessage)
SEGroup = self.Yuuki.data.getSEGroup(GroupID)
GroupInfo = self.Yuuki_DynamicTools.getClient(self.Yuuki.MyMID).getGroup(SecurityInfo["GroupID"])
SecurityInfo["GroupPrivilege"] = self.Yuuki.Admin +\
[self.Yuuki_StaticTools.sybGetGroupCreator(GroupInfo).mid] +\
self.Yuuki.data.getGroup(GroupInfo.id)["Ext_Admin"]
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:
if SecurityInfo["Action"] in SecurityInfo["GroupPrivilege"] or\
SecurityInfo["Another"] in SecurityInfo["GroupPrivilege"]:
if ncMessage.type != OpType.NOTIFIED_KICKOUT_FROM_GROUP:
return
elif Action in GroupPrivilege:
elif SecurityInfo["Action"] in SecurityInfo["GroupPrivilege"]:
return
SEGroup = self.Yuuki.data.getSEGroup(SecurityInfo["GroupID"])
if SEGroup is None:
Security_Access = self.Yuuki.data.getData(
["Global", "SecurityService"])
SecurityInfo["Security_Access"] = self.Yuuki.data.getData(["Global", "SecurityService"])
elif SEGroup[ncMessage.type]:
Security_Access = SEGroup[ncMessage.type]
SecurityInfo["Security_Access"] = SEGroup[ncMessage.type]
else:
SecurityInfo["Security_Access"] = False
if self.Yuuki.data.getData(["Global", "SecurityService"]):
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.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.modifyGroupMemberList(1, GroupInfo, Action)
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type))
elif ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP and Security_Access:
Canceler = "None"
if "\x1e" in Another:
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_DynamicTools.modifyGroupMemberList(2, GroupInfo, userId)
else:
Canceler = self.Yuuki_DynamicTools.modifyGroupMemberList(1, GroupInfo, userId)
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, userId,
ncMessage.type * 10))
# Log
self.Yuuki.data.updateLog("CancelEvent", (
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_DynamicTools.modifyGroupMemberList(2, GroupInfo, Another)
else:
Canceler = self.Yuuki_DynamicTools.modifyGroupMemberList(1, 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))
if Canceler != "None":
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.threadExec(self.Yuuki_DynamicTools.sendText, (GroupID, self.Yuuki.get_text(
"You are our blacklist. Bye~")))
Kicker = self.Yuuki_DynamicTools.modifyGroupMemberList(1, GroupInfo, Action)
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Kicker, Action, ncMessage.type))
elif ncMessage.type == OpType.NOTIFIED_KICKOUT_FROM_GROUP:
if Action in self.Yuuki.Connect.helper_ids:
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Action, Action, Another, ncMessage.type * 10 + 1))
elif Another in self.Yuuki.AllAccountIds:
Kicker = "None"
try:
Kicker = self.Yuuki_DynamicTools.modifyGroupMemberList(1, 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.threadExec(
self.Yuuki_DynamicTools.changeGroupUrlStatus, (GroupInfo, True, Kicker))
GroupTicket = self.Yuuki_DynamicTools.getGroupTicket(
GroupID, Kicker)
try:
self.Yuuki_DynamicTools.getClient(Another).acceptGroupInvitationByTicket(
self.Yuuki.Seq, GroupID, GroupTicket)
except:
if GroupInfo.preventJoinByTicket:
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.threadExec(
self.Yuuki_DynamicTools.changeGroupUrlStatus, (GroupInfo, False, Another))
self.Yuuki_DynamicTools.getGroupTicket(
GroupID, Another, True)
except:
(err1, err2, err3,
ErrorInfo) = self.Yuuki_StaticTools.errorReport()
for Root in self.Yuuki.Admin:
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"])
NewGroupList = GroupList.copy()
NewGroupList.remove(GroupID)
self.Yuuki.data.updateData(
["Global", "GroupJoined"], NewGroupList)
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another,
ncMessage.type * 10 + 3))
BlackList = self.Yuuki.data.getData(["BlackList"])
if Action not in BlackList:
NewBlackList = BlackList.copy()
NewBlackList.append(Action)
self.Yuuki.data.updateData(["BlackList"], NewBlackList)
# Log
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.threadExec(self.Yuuki_DynamicTools.sendText, (
GroupID, self.Yuuki.get_text("DO NOT KICK, thank you ^^")))
Kicker = self.Yuuki_DynamicTools.modifyGroupMemberList(1, GroupInfo, Action)
# Log
self.Yuuki.data.updateLog("KickEvent", (
self.Yuuki.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type))
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))
{
OpType.NOTIFIED_UPDATE_GROUP: self.NOTIFIED_UPDATE_GROUP,
OpType.NOTIFIED_INVITE_INTO_GROUP: self.NOTIFIED_INVITE_INTO_GROUP,
OpType.NOTIFIED_ACCEPT_GROUP_INVITATION: self.NOTIFIED_ACCEPT_GROUP_INVITATION,
OpType.NOTIFIED_KICKOUT_FROM_GROUP: self.NOTIFIED_KICKOUT_FROM_GROUP
}[ncMessage.type](GroupInfo, SecurityInfo, ncMessage)

View file

@ -62,14 +62,15 @@ class Yuuki_StaticTools:
:param ncMessage: Operation
:return: tuple
"""
if ncMessage.type == OpType.NOTIFIED_UPDATE_GROUP:
return ncMessage.param1, ncMessage.param2, ncMessage.param3
elif ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP:
return ncMessage.param1, ncMessage.param2, ncMessage.param3
elif ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION:
return ncMessage.param1, ncMessage.param2, ncMessage.param3
elif ncMessage.type == OpType.NOTIFIED_KICKOUT_FROM_GROUP:
return ncMessage.param1, ncMessage.param2, ncMessage.param3
if ncMessage.type == OpType.NOTIFIED_UPDATE_GROUP or\
ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP or\
ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION or\
ncMessage.type == OpType.NOTIFIED_KICKOUT_FROM_GROUP:
return {
"GroupID": ncMessage.param1,
"Action": ncMessage.param2,
"Another": ncMessage.param3,
}
@staticmethod
def dictShuffle(dict_object, requirement=None):