2019-08-22 18:33:10 +08:00
|
|
|
|
#!/usr/bin/python3
|
|
|
|
|
# coding=UTF-8
|
|
|
|
|
|
2019-08-24 11:46:28 +08:00
|
|
|
|
import os, time, \
|
|
|
|
|
requests, \
|
|
|
|
|
json, ntpath,\
|
2019-08-25 09:44:10 +08:00
|
|
|
|
traceback
|
2019-08-24 11:46:28 +08:00
|
|
|
|
|
2019-08-22 18:33:10 +08:00
|
|
|
|
|
2019-08-24 14:48:16 +08:00
|
|
|
|
from .core.TalkService import *
|
2019-08-23 18:12:41 +08:00
|
|
|
|
from .connection import Yuuki_Connect
|
|
|
|
|
|
2019-08-24 14:43:16 +08:00
|
|
|
|
from .data import Yuuki_Data
|
|
|
|
|
|
2019-08-23 18:12:41 +08:00
|
|
|
|
from .i18n import Yuuki_LangSetting
|
2019-08-22 18:33:10 +08:00
|
|
|
|
|
2019-08-24 21:07:55 +08:00
|
|
|
|
class Yuuki_Settings:
|
|
|
|
|
""" Yuuki Custom Settings """
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
"Seq": 0,
|
|
|
|
|
"Admin": [],
|
2019-08-25 08:47:47 +08:00
|
|
|
|
"SecurityService": False,
|
2019-08-24 22:19:26 +08:00
|
|
|
|
"Hour_KickLimit": 10,
|
2019-08-25 01:46:03 +08:00
|
|
|
|
"Hour_CancelLimit": 10,
|
2019-08-24 21:07:55 +08:00
|
|
|
|
"Default_Language": "en",
|
|
|
|
|
"GroupMebers_Demand": 100,
|
|
|
|
|
"helper_LINE_ACCESS_KEYs": []
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-22 18:33:10 +08:00
|
|
|
|
class Yuuki:
|
2019-08-24 21:07:55 +08:00
|
|
|
|
def __init__(self, Yuuki_Settings, Yuuki_Connection):
|
|
|
|
|
self.YuukiConfigs = Yuuki_Settings.config
|
|
|
|
|
|
|
|
|
|
self.Seq = self.YuukiConfigs["Seq"]
|
|
|
|
|
self.Admin = self.YuukiConfigs["Admin"]
|
|
|
|
|
|
2019-08-24 22:19:26 +08:00
|
|
|
|
self.KickLimit = self.YuukiConfigs["Hour_KickLimit"]
|
2019-08-25 01:46:03 +08:00
|
|
|
|
self.CancelLimit = self.YuukiConfigs["Hour_CancelLimit"]
|
2019-08-24 22:19:26 +08:00
|
|
|
|
|
2019-08-24 14:43:16 +08:00
|
|
|
|
self.data = Yuuki_Data()
|
2019-08-24 21:07:55 +08:00
|
|
|
|
self.i18n = Yuuki_LangSetting(self.YuukiConfigs["Default_Language"])
|
2019-08-23 18:12:41 +08:00
|
|
|
|
|
2019-08-22 18:33:10 +08:00
|
|
|
|
self.LINE_Media_server = "https://obs.line-apps.com"
|
|
|
|
|
|
2019-08-23 18:12:41 +08:00
|
|
|
|
self.Connect = Yuuki_Connect(Yuuki_Connection)
|
2019-08-22 18:33:10 +08:00
|
|
|
|
|
2019-08-22 18:52:24 +08:00
|
|
|
|
(self.client, self.listen) = self.Connect.connect()
|
2019-08-22 18:33:10 +08:00
|
|
|
|
self.connectHeader = Yuuki_Connection.connectHeader
|
|
|
|
|
|
2019-08-24 21:07:55 +08:00
|
|
|
|
for access in self.YuukiConfigs["helper_LINE_ACCESS_KEYs"]:
|
2019-08-22 18:52:24 +08:00
|
|
|
|
self.Connect.helperConnect(access)
|
|
|
|
|
|
2019-08-25 08:47:47 +08:00
|
|
|
|
self.SecurityService = self.YuukiConfigs["SecurityService"]
|
2019-08-25 01:46:03 +08:00
|
|
|
|
|
2019-08-25 09:03:38 +08:00
|
|
|
|
self.MyMID = self.client.getProfile().mid
|
|
|
|
|
|
2019-08-25 08:47:47 +08:00
|
|
|
|
for userId in [self.MyMID] + self.Connect.helper_ids:
|
2019-08-25 01:46:03 +08:00
|
|
|
|
if len(self.data.getData("LimitInfo")) != 2:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
self.data.updateData(self.data.getLimit("Kick"), userId, self.KickLimit)
|
|
|
|
|
self.data.updateData(self.data.getLimit("Cancel"), userId, self.CancelLimit)
|
2019-08-24 22:19:26 +08:00
|
|
|
|
|
2019-08-23 18:12:41 +08:00
|
|
|
|
global _
|
2019-08-24 11:29:31 +08:00
|
|
|
|
_ = self.i18n._
|
|
|
|
|
|
|
|
|
|
# Basic Func
|
2019-08-23 18:12:41 +08:00
|
|
|
|
|
2019-08-24 12:21:50 +08:00
|
|
|
|
def exit(self, restart=False):
|
2019-08-22 18:33:10 +08:00
|
|
|
|
if restart:
|
2019-08-23 18:12:41 +08:00
|
|
|
|
with open(".cache.sh", "w") as c:
|
|
|
|
|
c.write(sys.executable + " ./main.py")
|
2019-08-22 18:33:10 +08:00
|
|
|
|
os.system("sh .cache.sh")
|
|
|
|
|
os.system("rm .cache.sh")
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
else:
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
2019-08-24 14:43:16 +08:00
|
|
|
|
def sybGetGroupCreator(self, group):
|
|
|
|
|
if group.creator == None:
|
|
|
|
|
contact = group.members[0]
|
|
|
|
|
else:
|
|
|
|
|
contact = group.creator
|
|
|
|
|
return contact
|
|
|
|
|
|
2019-08-22 18:33:10 +08:00
|
|
|
|
def readCommandLine(self, msgs):
|
|
|
|
|
replymsg = ""
|
|
|
|
|
for msg in msgs:
|
|
|
|
|
replymsg = replymsg + " " + msg
|
|
|
|
|
return replymsg
|
|
|
|
|
|
2019-08-25 01:46:03 +08:00
|
|
|
|
def checkInInvitationList(self, ncMessage, userId=None):
|
|
|
|
|
if userId == None:
|
|
|
|
|
userId = self.MyMID
|
|
|
|
|
if ncMessage.param3 == userId:
|
2019-08-22 18:33:10 +08:00
|
|
|
|
inList = True
|
|
|
|
|
elif "\x1e" in ncMessage.param3:
|
|
|
|
|
if self.MyMID in ncMessage.param3.split("\x1e"):
|
|
|
|
|
inList = True
|
|
|
|
|
else:
|
|
|
|
|
inList = False
|
|
|
|
|
else:
|
|
|
|
|
inList = False
|
|
|
|
|
return inList
|
|
|
|
|
|
|
|
|
|
def changeGroupUrlStatus(self, group, stat):
|
|
|
|
|
if stat == True:
|
|
|
|
|
us = False
|
|
|
|
|
else:
|
|
|
|
|
us = True
|
|
|
|
|
group.members, group.invitee = None, None
|
|
|
|
|
group.preventJoinByTicket = us
|
2019-08-24 11:29:31 +08:00
|
|
|
|
self.client.updateGroup(self.Seq, group)
|
2019-08-22 18:33:10 +08:00
|
|
|
|
|
2019-08-24 23:06:28 +08:00
|
|
|
|
def enableSecurityStatus(self, groupId, status):
|
|
|
|
|
group_status = self.data.SEGrouptype
|
|
|
|
|
if 0 in status:
|
|
|
|
|
group_status[OpType.NOTIFIED_UPDATE_GROUP] = True
|
|
|
|
|
if 1 in status:
|
|
|
|
|
group_status[OpType.NOTIFIED_INVITE_INTO_GROUP] = True
|
|
|
|
|
if 2 in status:
|
|
|
|
|
group_status[OpType.NOTIFIED_ACCEPT_GROUP_INVITATION] = True
|
|
|
|
|
if 3 in status:
|
|
|
|
|
group_status[OpType.NOTIFIED_KICKOUT_FROM_GROUP] = True
|
|
|
|
|
|
|
|
|
|
self.data.updateData(self.data.getGroup(groupId), "SEGroup", group_status)
|
|
|
|
|
|
|
|
|
|
def disableSecurityStatus(self, groupId, status):
|
|
|
|
|
group_status = self.data.SEGrouptype
|
|
|
|
|
if 0 in status:
|
|
|
|
|
group_status[OpType.NOTIFIED_UPDATE_GROUP] = False
|
|
|
|
|
if 1 in status:
|
|
|
|
|
group_status[OpType.NOTIFIED_INVITE_INTO_GROUP] = False
|
|
|
|
|
if 2 in status:
|
|
|
|
|
group_status[OpType.NOTIFIED_ACCEPT_GROUP_INVITATION] = False
|
|
|
|
|
if 3 in status:
|
|
|
|
|
group_status[OpType.NOTIFIED_KICKOUT_FROM_GROUP] = False
|
|
|
|
|
|
|
|
|
|
self.data.updateData(self.data.getGroup(groupId), "SEGroup", group_status)
|
|
|
|
|
|
2019-08-22 18:33:10 +08:00
|
|
|
|
def cleanMyGroupInvitations(self):
|
|
|
|
|
for cleanInvitations in self.client.getGroupIdsInvited():
|
2019-08-24 11:29:31 +08:00
|
|
|
|
self.client.acceptGroupInvitation(self.Seq, cleanInvitations)
|
|
|
|
|
self.client.leaveGroup(self.Seq, cleanInvitations)
|
2019-08-22 18:33:10 +08:00
|
|
|
|
|
2019-08-24 22:19:26 +08:00
|
|
|
|
def getContact(self, userId):
|
2019-08-25 02:04:49 +08:00
|
|
|
|
if len(userId) == len(self.MyMID) and userId[0] == "u":
|
2019-08-22 18:33:10 +08:00
|
|
|
|
try:
|
2019-08-24 22:19:26 +08:00
|
|
|
|
contactInfo = self.getContact(userId)
|
2019-08-22 18:33:10 +08:00
|
|
|
|
except:
|
|
|
|
|
contactInfo = False
|
|
|
|
|
else:
|
|
|
|
|
contactInfo = False
|
|
|
|
|
return contactInfo
|
|
|
|
|
|
2019-08-24 17:22:23 +08:00
|
|
|
|
def securityForWhere(self, Message):
|
|
|
|
|
if Message.type == OpType.NOTIFIED_UPDATE_GROUP:
|
2019-08-25 09:03:38 +08:00
|
|
|
|
return Message.param1, Message.param2
|
2019-08-24 17:22:23 +08:00
|
|
|
|
elif Message.type == OpType.NOTIFIED_INVITE_INTO_GROUP:
|
2019-08-25 09:03:38 +08:00
|
|
|
|
return Message.param1, Message.param2
|
2019-08-24 17:22:23 +08:00
|
|
|
|
elif Message.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION:
|
2019-08-25 09:03:38 +08:00
|
|
|
|
return Message.param1, Message.param2
|
2019-08-24 17:22:23 +08:00
|
|
|
|
elif Message.type == OpType.NOTIFIED_KICKOUT_FROM_GROUP:
|
2019-08-25 09:03:38 +08:00
|
|
|
|
return Message.param1, Message.param2
|
2019-08-24 17:22:23 +08:00
|
|
|
|
|
2019-08-24 22:19:26 +08:00
|
|
|
|
def getClientByMid(self, userId):
|
|
|
|
|
Accounts = [self.client] + self.Connect.helper
|
|
|
|
|
for count, AccountUserId in enumerate([self.MyMID] + self.Connect.helper_ids):
|
|
|
|
|
if AccountUserId == userId:
|
|
|
|
|
return Accounts[count]
|
|
|
|
|
|
2019-08-25 01:46:03 +08:00
|
|
|
|
def limitReset(self):
|
2019-08-25 08:47:47 +08:00
|
|
|
|
for userId in [self.MyMID] + self.Connect.helper_ids:
|
2019-08-25 01:46:03 +08:00
|
|
|
|
if len(self.data.getData("LimitInfo")) != 2:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
self.data.updateData(self.data.getLimit("Kick"), userId, self.KickLimit)
|
|
|
|
|
self.data.updateData(self.data.getLimit("Cancel"), userId, self.CancelLimit)
|
2019-08-25 01:46:03 +08:00
|
|
|
|
|
2019-08-25 08:47:47 +08:00
|
|
|
|
def cancelSomeone(self, groupId, userId, exceptUserId=None):
|
2019-08-25 01:46:03 +08:00
|
|
|
|
if len(self.Connect.helper) >= 1:
|
2019-08-25 02:04:49 +08:00
|
|
|
|
accounts = self.data.getLimit("Cancel")
|
2019-08-25 08:47:47 +08:00
|
|
|
|
if exceptUserId:
|
|
|
|
|
accounts[exceptUserId] = -1
|
2019-08-25 01:46:03 +08:00
|
|
|
|
helper = max(accounts, key=accounts.get)
|
|
|
|
|
else:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
if exceptUserId == self.MyMID:
|
|
|
|
|
return
|
|
|
|
|
helper = self.MyMID
|
2019-08-25 01:46:03 +08:00
|
|
|
|
|
2019-08-25 02:04:49 +08:00
|
|
|
|
if self.data.getLimit("Cancel")[helper] > 0:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
self.getClientByMid(helper).cancelGroupInvitation(self.Seq, groupId, [userId])
|
2019-08-25 02:04:49 +08:00
|
|
|
|
self.data.getLimit("Cancel")[helper] -= 1
|
2019-08-25 01:46:03 +08:00
|
|
|
|
self.data.syncData()
|
|
|
|
|
else:
|
|
|
|
|
self.sendText(groupId, _("Cancel Limit."))
|
2019-08-24 22:19:26 +08:00
|
|
|
|
|
2019-08-25 08:47:47 +08:00
|
|
|
|
def kickSomeone(self, groupId, userId, exceptUserId=None):
|
2019-08-24 22:19:26 +08:00
|
|
|
|
if len(self.Connect.helper) >= 1:
|
2019-08-25 02:04:49 +08:00
|
|
|
|
accounts = self.data.getLimit("Kick")
|
2019-08-25 08:47:47 +08:00
|
|
|
|
if exceptUserId:
|
|
|
|
|
accounts[exceptUserId] = -1
|
2019-08-24 22:19:26 +08:00
|
|
|
|
helper = max(accounts, key=accounts.get)
|
|
|
|
|
else:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
if exceptUserId == self.MyMID:
|
|
|
|
|
return
|
|
|
|
|
helper = self.MyMID
|
2019-08-24 22:19:26 +08:00
|
|
|
|
|
2019-08-25 02:04:49 +08:00
|
|
|
|
if self.data.getLimit("Kick")[helper] > 0:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
self.getClientByMid(helper).kickoutFromGroup(self.Seq, groupId, [userId])
|
2019-08-25 02:04:49 +08:00
|
|
|
|
self.data.getLimit("Kick")[helper] -= 1
|
2019-08-25 01:46:03 +08:00
|
|
|
|
self.data.syncData()
|
2019-08-24 22:19:26 +08:00
|
|
|
|
else:
|
|
|
|
|
self.sendText(groupId, _("Kick Limit."))
|
|
|
|
|
|
2019-08-22 18:33:10 +08:00
|
|
|
|
def sendToWho(self, Message):
|
|
|
|
|
if Message.message.toType == MIDType.USER:
|
|
|
|
|
return Message.message.from_
|
|
|
|
|
elif Message.message.toType == MIDType.ROOM:
|
|
|
|
|
return Message.message.to
|
|
|
|
|
elif Message.message.toType == MIDType.GROUP:
|
|
|
|
|
return Message.message.to
|
|
|
|
|
|
|
|
|
|
def sendText(self, toid, msg):
|
2019-08-24 11:29:31 +08:00
|
|
|
|
message = Message(to=toid, text=msg)
|
|
|
|
|
self.client.sendMessage(self.Seq, message)
|
2019-08-22 18:33:10 +08:00
|
|
|
|
|
2019-08-24 22:19:26 +08:00
|
|
|
|
def sendUser(self, toid, userId):
|
|
|
|
|
message = Message(
|
|
|
|
|
contentType=ContentType.CONTACT,
|
|
|
|
|
text='',
|
|
|
|
|
contentMetadata={
|
|
|
|
|
'mid': userId,
|
|
|
|
|
'displayName': 'LINE User',
|
|
|
|
|
},
|
|
|
|
|
to=toid
|
|
|
|
|
)
|
2019-08-24 11:29:31 +08:00
|
|
|
|
self.client.sendMessage(self.Seq, message)
|
2019-08-22 18:33:10 +08:00
|
|
|
|
|
|
|
|
|
def sendMedia(self, toid, type, path):
|
|
|
|
|
if os.path.exists(path):
|
|
|
|
|
file_name = ntpath.basename(path)
|
|
|
|
|
file_size = len(open(path, 'rb').read())
|
|
|
|
|
message = Message(to=toid, text=None)
|
|
|
|
|
message.contentType = type
|
|
|
|
|
message.contentPreview = None
|
|
|
|
|
message.contentMetadata = {
|
|
|
|
|
'FILE_NAME': str(file_name),
|
|
|
|
|
'FILE_SIZE': str(file_size),
|
|
|
|
|
}
|
|
|
|
|
if type == ContentType.FILE:
|
|
|
|
|
media_name = file_name
|
|
|
|
|
else:
|
|
|
|
|
media_name = 'media'
|
|
|
|
|
message_id = self.client.sendMessage(self.Seq, message).id
|
|
|
|
|
files = {
|
|
|
|
|
'file': open(path, 'rb'),
|
|
|
|
|
}
|
|
|
|
|
params = {
|
|
|
|
|
'name': media_name,
|
|
|
|
|
'oid': message_id,
|
|
|
|
|
'size': file_size,
|
|
|
|
|
'type': ContentType._VALUES_TO_NAMES[type].lower(),
|
|
|
|
|
'ver': '1.0',
|
|
|
|
|
}
|
|
|
|
|
data = {
|
|
|
|
|
'params': json.dumps(params)
|
|
|
|
|
}
|
|
|
|
|
url = self.LINE_Media_server + '/talk/m/upload.nhn'
|
|
|
|
|
r = requests.post(url, headers=self.connectHeader, data=data, files=files)
|
|
|
|
|
if r.status_code != 201:
|
2019-08-24 11:29:31 +08:00
|
|
|
|
self.sendText(toid, "Error!")
|
|
|
|
|
|
|
|
|
|
# Task
|
2019-08-22 18:33:10 +08:00
|
|
|
|
|
2019-08-24 15:23:10 +08:00
|
|
|
|
def JoinGroup(self, ncMessage):
|
|
|
|
|
"""
|
|
|
|
|
ToDo Type:
|
|
|
|
|
NOTIFIED_INVITE_INTO_GROUP (13)
|
|
|
|
|
"""
|
|
|
|
|
if self.checkInInvitationList(ncMessage):
|
|
|
|
|
GroupID = ncMessage.param1
|
|
|
|
|
Inviter = ncMessage.param2
|
|
|
|
|
GroupInfo = self.client.getGroup(GroupID)
|
|
|
|
|
GroupMember = [Catched.mid for Catched in GroupInfo.members]
|
|
|
|
|
if GroupInfo.members:
|
|
|
|
|
self.client.acceptGroupInvitation(self.Seq, GroupID)
|
2019-08-24 21:07:55 +08:00
|
|
|
|
if len(GroupMember) >= self.YuukiConfigs["GroupMebers_Demand"]:
|
2019-08-24 15:23:10 +08:00
|
|
|
|
self.data.updateLog("JoinGroup", (self.data.getTime(), GroupInfo.name, GroupID, Inviter))
|
|
|
|
|
self.sendText(GroupID, _("Helllo^^\nMy name is Yuuki ><\nNice to meet you OwO"))
|
|
|
|
|
self.sendText(GroupID, _("Admin of the Group:\n%s") %
|
|
|
|
|
(self.sybGetGroupCreator(GroupInfo).displayName,))
|
2019-08-25 01:46:03 +08:00
|
|
|
|
# Log
|
2019-08-24 15:23:10 +08:00
|
|
|
|
else:
|
2019-08-24 21:07:55 +08:00
|
|
|
|
self.sendText(GroupID, _("Sorry...\nThe number of members is not satisfied (%s needed)") %
|
|
|
|
|
(self.YuukiConfigs["GroupMebers_Demand"],))
|
2019-08-24 15:23:10 +08:00
|
|
|
|
self.client.leaveGroup(self.Seq, GroupID)
|
2019-08-25 01:46:03 +08:00
|
|
|
|
# Log
|
|
|
|
|
for userId in self.Connect.helper_ids:
|
|
|
|
|
if self.checkInInvitationList(ncMessage, userId):
|
2019-08-25 09:44:10 +08:00
|
|
|
|
self.getClientByMid(userId).acceptGroupInvitation(self.Seq, ncMessage.param1)
|
2019-08-25 01:46:03 +08:00
|
|
|
|
# Log
|
|
|
|
|
self.Security(ncMessage)
|
2019-08-24 15:23:10 +08:00
|
|
|
|
|
|
|
|
|
def Commands(self, ncMessage):
|
|
|
|
|
"""
|
|
|
|
|
ToDo Type:
|
|
|
|
|
RECEIVE_MESSAGE (26)
|
|
|
|
|
"""
|
|
|
|
|
if 'BOT_CHECK' in ncMessage.message.contentMetadata:
|
|
|
|
|
pass
|
|
|
|
|
elif ncMessage.message.toType == MIDType.ROOM:
|
|
|
|
|
self.client.leaveRoom(self.Seq, ncMessage.message.to)
|
|
|
|
|
elif ncMessage.message.contentType == ContentType.NONE:
|
2019-08-24 23:06:28 +08:00
|
|
|
|
msgSep = ncMessage.message.text.split(" ")
|
|
|
|
|
if 'Yuuki/UserID' == ncMessage.message.text:
|
2019-08-24 15:23:10 +08:00
|
|
|
|
self.sendText(self.sendToWho(ncMessage), _("LINE System UserID:\n") + ncMessage.message.from_)
|
|
|
|
|
elif 'Yuuki/Speed' == ncMessage.message.text:
|
|
|
|
|
Time1 = time.time()
|
|
|
|
|
self.sendText(self.sendToWho(ncMessage), _("Testing..."))
|
|
|
|
|
Time2 = time.time()
|
2019-08-24 15:29:49 +08:00
|
|
|
|
self.sendText(self.sendToWho(ncMessage), _("Speed:\n%ss") % (Time2 - Time1,))
|
2019-08-25 08:47:47 +08:00
|
|
|
|
elif 'Yuuki/SecurityMode' == msgSep[0]:
|
2019-08-25 09:44:10 +08:00
|
|
|
|
if ncMessage.message.from_ in self.Admin:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
if len(msgSep) == 2:
|
|
|
|
|
try:
|
|
|
|
|
status = int(msgSep[1])
|
|
|
|
|
self.SecurityService = bool(status)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
self.sendText(self.sendToWho(ncMessage), bool(self.SecurityService))
|
2019-08-24 23:06:28 +08:00
|
|
|
|
elif 'Yuuki/Enable' == msgSep[0]:
|
|
|
|
|
if ncMessage.message.toType == MIDType.GROUP:
|
2019-08-25 09:56:06 +08:00
|
|
|
|
GroupInfo = self.client.getGroup(ncMessage.message.to)
|
|
|
|
|
GroupPrivilege = self.Admin + [self.sybGetGroupCreator(GroupInfo)] + self.data.getGroup(GroupInfo.id)["Ext_Admin"]
|
2019-08-25 09:44:10 +08:00
|
|
|
|
if ncMessage.message.from_ in GroupPrivilege:
|
|
|
|
|
status = []
|
|
|
|
|
for code in msgSep:
|
|
|
|
|
try:
|
|
|
|
|
status.append(int(code))
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
self.enableSecurityStatus(ncMessage.message.to, status)
|
|
|
|
|
self.sendText(self.sendToWho(ncMessage), _("Okay"))
|
2019-08-24 23:06:28 +08:00
|
|
|
|
elif 'Yuuki/Disable' == msgSep[0]:
|
|
|
|
|
if ncMessage.message.toType == MIDType.GROUP:
|
2019-08-25 09:56:06 +08:00
|
|
|
|
GroupInfo = self.client.getGroup(ncMessage.message.to)
|
|
|
|
|
GroupPrivilege = self.Admin + [self.sybGetGroupCreator(GroupInfo)] + self.data.getGroup(GroupInfo.id)["Ext_Admin"]
|
2019-08-25 09:44:10 +08:00
|
|
|
|
if ncMessage.message.from_ in GroupPrivilege:
|
|
|
|
|
status = []
|
|
|
|
|
for code in msgSep:
|
|
|
|
|
try:
|
|
|
|
|
status.append(int(code))
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
self.disableSecurityStatus(ncMessage.message.to, status)
|
|
|
|
|
self.sendText(self.sendToWho(ncMessage), _("Okay"))
|
|
|
|
|
elif 'Yuuki/ExtAdmin' == msgSep[0]:
|
|
|
|
|
if ncMessage.message.toType == MIDType.GROUP:
|
2019-08-25 09:56:06 +08:00
|
|
|
|
GroupInfo = self.client.getGroup(ncMessage.message.to)
|
|
|
|
|
GroupPrivilege = self.Admin + [self.sybGetGroupCreator(GroupInfo)]
|
2019-08-25 09:44:10 +08:00
|
|
|
|
if ncMessage.message.from_ in GroupPrivilege:
|
|
|
|
|
if msgSep[1] == "add":
|
|
|
|
|
if msgSep[2] in [Member.mid for Member in GroupInfo.members]:
|
2019-08-25 09:56:06 +08:00
|
|
|
|
self.data.updateData(self.data.getGroup(GroupInfo.id), "Ext_Admin", msgSep[2])
|
2019-08-25 09:44:10 +08:00
|
|
|
|
self.sendText(self.sendToWho(ncMessage), _("Okay"))
|
|
|
|
|
else:
|
|
|
|
|
self.sendText(self.sendToWho(ncMessage), _("Wrong UserID or the guy is not in Group"))
|
|
|
|
|
elif msgSep[1] == "delete":
|
2019-08-25 09:56:06 +08:00
|
|
|
|
self.data.updateData(self.data.getGroup(GroupInfo.id), "Ext_Admin", msgSep[2])
|
2019-08-25 09:44:10 +08:00
|
|
|
|
self.sendText(self.sendToWho(ncMessage), _("Okay"))
|
|
|
|
|
else:
|
2019-08-25 09:56:06 +08:00
|
|
|
|
self.sendText(self.sendToWho(ncMessage), self.data.getGroup(GroupInfo.id)["Ext_Admin"])
|
2019-08-25 01:46:03 +08:00
|
|
|
|
elif 'Yuuki/Status' == ncMessage.message.text:
|
|
|
|
|
if ncMessage.message.toType == MIDType.GROUP:
|
2019-08-25 09:56:06 +08:00
|
|
|
|
GroupInfo = self.client.getGroup(ncMessage.message.to)
|
2019-08-25 01:46:03 +08:00
|
|
|
|
group_status = self.data.getSEGroup(ncMessage.message.to)
|
|
|
|
|
if group_status == None:
|
2019-08-25 09:58:20 +08:00
|
|
|
|
status = _("Disable without Initialize\nAdmin of the Group:\n%s") % (
|
2019-08-25 09:59:31 +08:00
|
|
|
|
self.sybGetGroupCreator(GroupInfo).displayName,
|
2019-08-25 09:58:20 +08:00
|
|
|
|
)
|
2019-08-25 01:46:03 +08:00
|
|
|
|
else:
|
2019-08-25 09:56:06 +08:00
|
|
|
|
status = _("URL:%s\nInvite:%s\nJoin:%s\nMembers:%s\n\nAdmin of the Group:\n%s") % (
|
2019-08-25 01:46:03 +08:00
|
|
|
|
group_status[OpType.NOTIFIED_UPDATE_GROUP],
|
2019-08-25 02:07:16 +08:00
|
|
|
|
group_status[OpType.NOTIFIED_INVITE_INTO_GROUP],
|
2019-08-25 08:47:47 +08:00
|
|
|
|
group_status[OpType.NOTIFIED_ACCEPT_GROUP_INVITATION],
|
2019-08-25 01:46:03 +08:00
|
|
|
|
group_status[OpType.NOTIFIED_KICKOUT_FROM_GROUP],
|
2019-08-25 09:59:31 +08:00
|
|
|
|
self.sybGetGroupCreator(GroupInfo).displayName,
|
2019-08-25 01:46:03 +08:00
|
|
|
|
)
|
|
|
|
|
self.sendText(self.sendToWho(ncMessage), status)
|
2019-08-24 15:23:10 +08:00
|
|
|
|
elif 'Yuuki/Quit' == ncMessage.message.text:
|
|
|
|
|
if ncMessage.message.toType == MIDType.GROUP:
|
2019-08-25 09:56:06 +08:00
|
|
|
|
GroupInfo = self.client.getGroup(ncMessage.message.to)
|
|
|
|
|
GroupPrivilege = self.Admin + [self.sybGetGroupCreator(GroupInfo)] + self.data.getGroup(GroupInfo.id)["Ext_Admin"]
|
2019-08-25 09:44:10 +08:00
|
|
|
|
if ncMessage.message.from_ in GroupPrivilege:
|
2019-08-25 09:56:06 +08:00
|
|
|
|
self.sendText(self.sendToWho(ncMessage), _("Bye Bye"))
|
|
|
|
|
self.client.leaveGroup(self.Seq, GroupInfo.id)
|
2019-08-24 15:23:10 +08:00
|
|
|
|
elif 'Yuuki/Exit' == ncMessage.message.text:
|
2019-08-25 09:44:10 +08:00
|
|
|
|
if ncMessage.message.from_ in self.Admin:
|
|
|
|
|
self.sendText(self.sendToWho(ncMessage), _("Exit."))
|
|
|
|
|
self.exit()
|
2019-08-24 23:17:08 +08:00
|
|
|
|
elif 'Yuuki/Com' == msgSep[0] and len(msgSep) != 1:
|
|
|
|
|
if ncMessage.message.from_ in self.Admin:
|
|
|
|
|
ComMsg = self.readCommandLine(msgSep[1:len(msgSep)])
|
|
|
|
|
self.sendText(self.sendToWho(ncMessage), str(eval(ComMsg)))
|
2019-08-24 15:23:10 +08:00
|
|
|
|
|
|
|
|
|
def Security(self, ncMessage):
|
|
|
|
|
"""
|
|
|
|
|
ToDo Type:
|
|
|
|
|
NOTIFIED_UPDATE_GROUP (11)
|
|
|
|
|
NOTIFIED_INVITE_INTO_GROUP (13)
|
|
|
|
|
NOTIFIED_ACCEPT_GROUP_INVITATION (17)
|
|
|
|
|
NOTIFIED_KICKOUT_FROM_GROUP (19)
|
|
|
|
|
"""
|
2019-08-25 09:03:38 +08:00
|
|
|
|
(GroupID, Action) = self.securityForWhere(ncMessage)
|
2019-08-24 22:19:26 +08:00
|
|
|
|
SEGroup = self.data.getSEGroup(GroupID)
|
2019-08-24 17:22:23 +08:00
|
|
|
|
|
2019-08-25 09:03:38 +08:00
|
|
|
|
if Action in self.Admin:
|
|
|
|
|
return
|
|
|
|
|
|
2019-08-24 22:31:36 +08:00
|
|
|
|
if SEGroup == None:
|
|
|
|
|
return
|
|
|
|
|
|
2019-08-25 08:47:47 +08:00
|
|
|
|
if SEGroup[ncMessage.type] and self.SecurityService:
|
2019-08-24 17:22:23 +08:00
|
|
|
|
if ncMessage.type == OpType.NOTIFIED_UPDATE_GROUP:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
if ncMessage.param3 == 3:
|
|
|
|
|
GroupInfo = self.client.getGroup(GroupID)
|
|
|
|
|
if not GroupInfo.preventJoinByTicket:
|
|
|
|
|
self.changeGroupUrlStatus(GroupInfo, False)
|
|
|
|
|
self.kickSomeone(GroupID, ncMessage.param2)
|
2019-08-24 17:22:23 +08:00
|
|
|
|
elif ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
if "\x1e" in ncMessage.param3:
|
|
|
|
|
for userId in ncMessage.param3.split("\x1e"):
|
|
|
|
|
if userId not in self.MyMID + self.Connect.helper_ids:
|
|
|
|
|
self.cancelSomeone(GroupID, userId)
|
|
|
|
|
elif ncMessage.param3 not in self.MyMID + self.Connect.helper_ids:
|
|
|
|
|
self.cancelSomeone(GroupID, ncMessage.param3)
|
|
|
|
|
# Log
|
2019-08-24 17:22:23 +08:00
|
|
|
|
elif ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION:
|
2019-08-25 01:46:03 +08:00
|
|
|
|
for userId in self.data.getData("BlackList"):
|
|
|
|
|
if userId == ncMessage.param2:
|
|
|
|
|
self.kickSomeone(GroupID, userId)
|
|
|
|
|
# Log
|
2019-08-24 17:22:23 +08:00
|
|
|
|
elif ncMessage.type == OpType.NOTIFIED_KICKOUT_FROM_GROUP:
|
2019-08-24 22:19:26 +08:00
|
|
|
|
if ncMessage.param2 in self.Connect.helper_ids:
|
2019-08-25 01:46:03 +08:00
|
|
|
|
# Log
|
|
|
|
|
pass
|
2019-08-24 22:19:26 +08:00
|
|
|
|
else:
|
|
|
|
|
if ncMessage.param3 in [self.MyMID] + self.Connect.helper_ids:
|
2019-08-25 01:46:03 +08:00
|
|
|
|
try:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
self.kickSomeone(GroupID, ncMessage.param2, ncMessage.param3)
|
2019-08-25 01:46:03 +08:00
|
|
|
|
# Log
|
|
|
|
|
except:
|
|
|
|
|
# Log
|
|
|
|
|
pass
|
|
|
|
|
self.data.updateData(self.data.getData("BlackList"), True, ncMessage.param2)
|
2019-08-24 22:19:26 +08:00
|
|
|
|
else:
|
|
|
|
|
self.sendText(GroupID, _("Bye Bye"))
|
|
|
|
|
self.kickSomeone(GroupID, ncMessage.param2)
|
2019-08-25 08:47:47 +08:00
|
|
|
|
elif self.SecurityService:
|
|
|
|
|
if ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP:
|
|
|
|
|
for userId in self.data.getData("BlackList"):
|
|
|
|
|
if self.checkInInvitationList(ncMessage, userId):
|
|
|
|
|
self.cancelSomeone(GroupID, userId)
|
|
|
|
|
# Log
|
|
|
|
|
elif ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION:
|
|
|
|
|
for userId in self.data.getData("BlackList"):
|
|
|
|
|
if userId == ncMessage.param2:
|
|
|
|
|
self.kickSomeone(GroupID, userId)
|
|
|
|
|
# Log
|
2019-08-24 15:23:10 +08:00
|
|
|
|
|
|
|
|
|
# Main
|
|
|
|
|
|
|
|
|
|
def Main(self):
|
2019-08-22 18:33:10 +08:00
|
|
|
|
NoWork = 0
|
|
|
|
|
catchedNews = []
|
|
|
|
|
ncMessage = Operation()
|
|
|
|
|
Revision = self.client.getLastOpRevision()
|
2019-08-25 09:09:57 +08:00
|
|
|
|
if "LastResetLimitTime" not in self.data.getData("Global"):
|
|
|
|
|
self.data.getData("Global")["LastResetLimitTime"] = None
|
2019-08-25 08:47:47 +08:00
|
|
|
|
if self.data.getData("Global")["LastResetLimitTime"] == None:
|
|
|
|
|
self.data.updateData(self.data.getData("Global"), "LastResetLimitTime", time.localtime().tm_hour)
|
2019-08-22 18:33:10 +08:00
|
|
|
|
while True:
|
|
|
|
|
try:
|
2019-08-25 08:47:47 +08:00
|
|
|
|
if time.localtime().tm_hour != self.data.getData("Global")["LastResetLimitTime"]:
|
2019-08-25 02:44:17 +08:00
|
|
|
|
self.limitReset()
|
2019-08-25 08:47:47 +08:00
|
|
|
|
self.data.updateData(self.data.getData("Global"), "LastResetLimitTime", time.localtime().tm_hour)
|
2019-08-22 18:33:10 +08:00
|
|
|
|
if NoWork == 300:
|
|
|
|
|
Revision = self.client.getLastOpRevision()
|
|
|
|
|
catchedNews = self.listen.fetchOperations(Revision, 50)
|
|
|
|
|
if catchedNews:
|
|
|
|
|
NoWork = 0
|
|
|
|
|
for ncMessage in catchedNews:
|
2019-08-24 15:23:10 +08:00
|
|
|
|
if ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP:
|
2019-08-24 11:29:31 +08:00
|
|
|
|
self.JoinGroup(ncMessage)
|
2019-08-24 22:19:26 +08:00
|
|
|
|
elif ncMessage.type == OpType.NOTIFIED_KICKOUT_FROM_GROUP:
|
|
|
|
|
self.Security(ncMessage)
|
2019-08-25 02:16:55 +08:00
|
|
|
|
elif ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION:
|
|
|
|
|
self.Security(ncMessage)
|
|
|
|
|
elif ncMessage.type == OpType.NOTIFIED_UPDATE_GROUP:
|
|
|
|
|
self.Security(ncMessage)
|
2019-08-24 15:23:10 +08:00
|
|
|
|
elif ncMessage.type == OpType.RECEIVE_MESSAGE:
|
|
|
|
|
self.Commands(ncMessage)
|
2019-08-22 18:33:10 +08:00
|
|
|
|
if ncMessage.reqSeq != -1:
|
|
|
|
|
Revision = max(Revision, ncMessage.revision)
|
|
|
|
|
else:
|
|
|
|
|
NoWork = NoWork + 1
|
|
|
|
|
except SystemExit:
|
|
|
|
|
self.exit()
|
|
|
|
|
except EOFError:
|
|
|
|
|
pass
|
|
|
|
|
except:
|
|
|
|
|
err1, err2, err3 = sys.exc_info()
|
2019-08-24 11:46:28 +08:00
|
|
|
|
traceback.print_tb(err3)
|
|
|
|
|
tb_info = traceback.extract_tb(err3)
|
|
|
|
|
filename, line, func, text = tb_info[-1]
|
2019-08-24 11:53:21 +08:00
|
|
|
|
ErrorInfo = "occurred in\n{}\n\non line {}\nin statement {}".format(filename, line, text)
|
2019-08-22 18:33:10 +08:00
|
|
|
|
try:
|
|
|
|
|
if catchedNews and ncMessage:
|
|
|
|
|
Finded = False
|
|
|
|
|
for Catched in catchedNews:
|
|
|
|
|
if Catched.revision == ncMessage.revision:
|
|
|
|
|
Finded = True
|
|
|
|
|
if Finded:
|
|
|
|
|
Revision = Catched.revision
|
|
|
|
|
break
|
|
|
|
|
if not Finded:
|
|
|
|
|
Revision = self.client.getLastOpRevision()
|
2019-08-23 18:12:41 +08:00
|
|
|
|
for Root in self.Admin:
|
2019-08-24 11:53:21 +08:00
|
|
|
|
self.sendText(Root, "Star Yuuki BOT - Something was wrong...\nError:\n%s\n%s\n%s\n\n%s" %
|
2019-08-24 11:46:28 +08:00
|
|
|
|
(err1, err2, err3, ErrorInfo))
|
2019-08-22 18:33:10 +08:00
|
|
|
|
except:
|
2019-08-24 11:53:21 +08:00
|
|
|
|
print("Star Yuuki BOT - Damage!\nError:\n%s\n%s\n%s\n\n%s" % (err1, err2, err3, ErrorInfo))
|
2019-08-22 18:33:10 +08:00
|
|
|
|
self.exit()
|