mirror of
https://github.com/studio-neptune/yuuki.git
synced 2024-09-20 16:35:56 +08:00
Update
This commit is contained in:
parent
09bfd1982d
commit
07cfafe0d9
|
@ -14,7 +14,7 @@ from yuuki_core.TalkService import Client
|
|||
""" NC HightSpeed Lib """
|
||||
try:
|
||||
from thrift.protocol import fastbinary
|
||||
except:
|
||||
except ImportError:
|
||||
print("[No fast_binary using]")
|
||||
##########################################
|
||||
|
||||
|
@ -62,6 +62,7 @@ class Yuuki_Connect:
|
|||
client = Client(protocol)
|
||||
transport.open()
|
||||
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
profile = client.getProfile()
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ def mds_exit(data):
|
|||
|
||||
def update(data):
|
||||
global switch_data
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
if type(data["path"]) is list:
|
||||
over = query({"path": data["path"]})
|
||||
|
@ -39,6 +40,7 @@ def update(data):
|
|||
|
||||
def delete(data):
|
||||
global switch_data
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
if type(data["path"]) is list:
|
||||
over = query({"path": data["path"]})
|
||||
|
@ -52,6 +54,7 @@ def delete(data):
|
|||
def query(data):
|
||||
global switch_data
|
||||
query_data = data["path"]
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
if type(switch_data) is dict and type(query_data) is list:
|
||||
result = switch_data
|
||||
|
@ -75,6 +78,7 @@ def query(data):
|
|||
|
||||
def sync(data):
|
||||
global switch_data
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
switch_data = data["path"]
|
||||
return {"status": 200}
|
||||
|
@ -84,6 +88,7 @@ def sync(data):
|
|||
|
||||
def yuukiLimitDecrease(data):
|
||||
global switch_data
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
switch_data["LimitInfo"][data["path"]][data["userId"]] -= 1
|
||||
return {"status": 200}
|
||||
|
|
|
@ -300,18 +300,38 @@ class Yuuki_Command:
|
|||
def _Com(self, ncMessage):
|
||||
msgSep = ncMessage.message.text.split(" ")
|
||||
if ncMessage.message.from_ in self.Yuuki.Admin:
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
ComMsg = self.Yuuki_StaticTools.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_StaticTools.errorReport()
|
||||
Report = "Star Yuuki BOT - Eval Error:\n%s\n%s\n%s\n\n%s" % (
|
||||
err1, err2, err3, ErrorInfo)
|
||||
(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)
|
||||
|
||||
def _text(self, ncMessage):
|
||||
Yuuki_Name = self.Yuuki.YuukiConfigs["name"]
|
||||
msgSep = ncMessage.message.text.split(" ")[0].split("/")
|
||||
actions = {
|
||||
'Help': self._Help,
|
||||
'Version': self._Version,
|
||||
'UserID': self._UserID,
|
||||
'GetAllHelper': self._GetAllHelper,
|
||||
'Speed': self._Speed,
|
||||
'SecurityMode': self._SecurityMode,
|
||||
'Switch': self._Switch,
|
||||
'DisableAll': self._DisableAll,
|
||||
'ExtAdmin': self._ExtAdmin,
|
||||
'Status': self._Status,
|
||||
'GroupBackup': self._GroupBackup,
|
||||
'Quit': self._Quit,
|
||||
'Exit': self._Exit,
|
||||
'Com': self._Com,
|
||||
}
|
||||
if Yuuki_Name == msgSep[0] and msgSep[1] in actions:
|
||||
actions[msgSep[1]](ncMessage)
|
||||
|
||||
def _contact(self, ncMessage):
|
||||
cache = ncMessage.message.contentMetadata["mid"]
|
||||
contactInfo = self.Yuuki_DynamicTools.getContact(cache)
|
||||
|
@ -342,25 +362,7 @@ class Yuuki_Command:
|
|||
)
|
||||
|
||||
elif ncMessage.message.contentType == ContentType.NONE:
|
||||
Yuuki_Name = self.Yuuki.YuukiConfigs["name"]
|
||||
msgSep = ncMessage.message.text.split(" ")
|
||||
actions = {
|
||||
Yuuki_Name + '/Help': self._Help,
|
||||
Yuuki_Name + '/Version': self._Version,
|
||||
Yuuki_Name + '/UserID': self._UserID,
|
||||
Yuuki_Name + '/GetAllHelper': self._GetAllHelper,
|
||||
Yuuki_Name + '/Speed': self._Speed,
|
||||
Yuuki_Name + '/SecurityMode': self._SecurityMode,
|
||||
Yuuki_Name + '/Switch': self._Switch,
|
||||
Yuuki_Name + '/DisableAll': self._DisableAll,
|
||||
Yuuki_Name + '/ExtAdmin': self._ExtAdmin,
|
||||
Yuuki_Name + '/Status': self._Status,
|
||||
Yuuki_Name + '/GroupBackup': self._GroupBackup,
|
||||
Yuuki_Name + '/Quit': self._Quit,
|
||||
Yuuki_Name + '/Exit': self._Exit,
|
||||
Yuuki_Name + '/Com': self._Com,
|
||||
}
|
||||
actions[msgSep[0]](ncMessage)
|
||||
self._text(ncMessage)
|
||||
|
||||
elif ncMessage.message.contentType == ContentType.CONTACT:
|
||||
self._contact(ncMessage)
|
||||
|
|
|
@ -38,6 +38,7 @@ class Yuuki_Poll:
|
|||
self.Yuuki.data.updateData(["Global", "LastResetLimitTime"], None)
|
||||
|
||||
while self.Power:
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
if time.localtime().tm_hour != self.Yuuki.data.getData(["Global", "LastResetLimitTime"]):
|
||||
self.Yuuki_DynamicTools.limitReset()
|
||||
|
@ -79,6 +80,7 @@ class Yuuki_Poll:
|
|||
|
||||
except:
|
||||
(err1, err2, err3, ErrorInfo) = self.Yuuki_StaticTools.errorReport()
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
for self.ncMessage in self.cacheOperations:
|
||||
if self.ncMessage.reqSeq != -1 and self.ncMessage.revision > self.Yuuki.revision:
|
||||
|
|
199
libs/tools.py
199
libs/tools.py
|
@ -20,22 +20,36 @@ from yuuki_core.ttypes import OpType, MIDType, ContentType, Group, Message
|
|||
|
||||
class Yuuki_StaticTools:
|
||||
@staticmethod
|
||||
def sybGetGroupCreator(group):
|
||||
if group.creator is None:
|
||||
contact = group.members[0]
|
||||
def sybGetGroupCreator(groupInfo):
|
||||
"""
|
||||
Get the LINE Group Creator
|
||||
:param groupInfo: LINE Group
|
||||
:return: LINE Contact
|
||||
"""
|
||||
if groupInfo.creator is None:
|
||||
contact = groupInfo.members[0]
|
||||
else:
|
||||
contact = group.creator
|
||||
contact = groupInfo.creator
|
||||
return contact
|
||||
|
||||
@staticmethod
|
||||
def readCommandLine(msgs):
|
||||
replymsg = ""
|
||||
"""
|
||||
Read string list as a command line
|
||||
:param msgs: List of strings
|
||||
:return: string
|
||||
"""
|
||||
reply_msg = ""
|
||||
for msg in msgs:
|
||||
replymsg = replymsg + " " + msg
|
||||
return replymsg
|
||||
reply_msg += " " + msg
|
||||
return reply_msg
|
||||
|
||||
@staticmethod
|
||||
def errorReport():
|
||||
"""
|
||||
Report errors as tuple
|
||||
:return: tuple
|
||||
"""
|
||||
err1, err2, err3 = sys.exc_info()
|
||||
traceback.print_tb(err3)
|
||||
tb_info = traceback.extract_tb(err3)
|
||||
|
@ -46,6 +60,11 @@ class Yuuki_StaticTools:
|
|||
|
||||
@staticmethod
|
||||
def securityForWhere(ncMessage):
|
||||
"""
|
||||
Return arguments for security tasks
|
||||
: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:
|
||||
|
@ -57,6 +76,12 @@ class Yuuki_StaticTools:
|
|||
|
||||
@staticmethod
|
||||
def dictShuffle(dict_object, requirement=None):
|
||||
"""
|
||||
Shuffle dicts
|
||||
:param dict_object: dict
|
||||
:param requirement: list
|
||||
:return: dict
|
||||
"""
|
||||
dict_key = [key for key in dict_object]
|
||||
random.shuffle(dict_key)
|
||||
result = {}
|
||||
|
@ -70,6 +95,11 @@ class Yuuki_StaticTools:
|
|||
|
||||
@staticmethod
|
||||
def sendToWho(ncMessage):
|
||||
"""
|
||||
Get who to send with Operation
|
||||
:param ncMessage: Operation
|
||||
:return: string
|
||||
"""
|
||||
if ncMessage.message.toType == MIDType.USER:
|
||||
return ncMessage.message.from_
|
||||
elif ncMessage.message.toType == MIDType.ROOM:
|
||||
|
@ -84,6 +114,11 @@ class Yuuki_DynamicTools:
|
|||
self.Yuuki_StaticTools = Yuuki_StaticTools()
|
||||
|
||||
def getClient(self, userId):
|
||||
"""
|
||||
Get client by account userId
|
||||
:param userId: string
|
||||
:return: TalkServiceClient
|
||||
"""
|
||||
if self.Yuuki.Threading:
|
||||
if userId == self.Yuuki.MyMID:
|
||||
(client, _) = self.Yuuki.Connect.connect()
|
||||
|
@ -97,6 +132,12 @@ class Yuuki_DynamicTools:
|
|||
return Accounts[count]
|
||||
|
||||
def checkInInvitationList(self, ncMessage, userId=None):
|
||||
"""
|
||||
Check If userId in Invitation List
|
||||
:param ncMessage: Operation
|
||||
:param userId: string
|
||||
:return: boolean
|
||||
"""
|
||||
if userId is None:
|
||||
userId = self.Yuuki.MyMID
|
||||
if ncMessage.param3 == userId:
|
||||
|
@ -110,22 +151,31 @@ class Yuuki_DynamicTools:
|
|||
inList = False
|
||||
return inList
|
||||
|
||||
def changeGroupUrlStatus(self, group, status, userId=None):
|
||||
def changeGroupUrlStatus(self, groupInfo, status, userId=None):
|
||||
"""
|
||||
Change LINE Group URL Status
|
||||
:param groupInfo: Line Group
|
||||
:param status: boolean
|
||||
:param userId: string
|
||||
:return: None
|
||||
"""
|
||||
result = Group()
|
||||
for key in group.__dict__:
|
||||
for key in groupInfo.__dict__:
|
||||
if key != "members" or key != "invitee":
|
||||
result.__dict__[key] = group.__dict__[key]
|
||||
if status:
|
||||
result.preventJoinByTicket = False
|
||||
else:
|
||||
result.preventJoinByTicket = True
|
||||
result.__dict__[key] = groupInfo.__dict__[key]
|
||||
result.preventJoinByTicket = not status
|
||||
if userId is not None:
|
||||
self.getClient(userId).updateGroup(self.Yuuki.Seq, result)
|
||||
else:
|
||||
self.getClient(self.Yuuki.MyMID).updateGroup(
|
||||
self.Yuuki.Seq, result)
|
||||
self.getClient(self.Yuuki.MyMID).updateGroup(self.Yuuki.Seq, result)
|
||||
|
||||
def configSecurityStatus(self, groupId, status):
|
||||
"""
|
||||
Configure LINE Group Security Status for Yuuki
|
||||
:param groupId: string
|
||||
:param status: boolean
|
||||
:return: None
|
||||
"""
|
||||
group_status = self.Yuuki.data.SEGrouptype
|
||||
if 0 in status:
|
||||
group_status[OpType.NOTIFIED_UPDATE_GROUP] = True
|
||||
|
@ -139,98 +189,90 @@ class Yuuki_DynamicTools:
|
|||
self.Yuuki.data.updateData(["Group", groupId, "SEGroup"], group_status)
|
||||
|
||||
def cleanMyGroupInvitations(self):
|
||||
"""
|
||||
Clean personal group invitations for LINE account
|
||||
:return: None
|
||||
"""
|
||||
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)
|
||||
|
||||
def getContact(self, userId):
|
||||
"""
|
||||
Get LINE Contact information with userId
|
||||
:param userId: string
|
||||
:return: LINE Contact
|
||||
"""
|
||||
if len(userId) == len(self.Yuuki.MyMID) and userId[0] == "u":
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
contactInfo = self.getClient(
|
||||
self.Yuuki.MyMID).getContact(userId)
|
||||
contactInfo = self.getClient(self.Yuuki.MyMID).getContact(userId)
|
||||
except:
|
||||
contactInfo = False
|
||||
else:
|
||||
contactInfo = False
|
||||
return contactInfo
|
||||
|
||||
def getGroupTicket(self, GroupID, userId, renew=False):
|
||||
def getGroupTicket(self, groupId, userId, renew=False):
|
||||
"""
|
||||
Get LINE Group Ticket with groupId and userId
|
||||
:param groupId: string
|
||||
:param userId: string
|
||||
:param renew: boolean
|
||||
:return: string
|
||||
"""
|
||||
GroupTicket = ""
|
||||
GroupData = self.Yuuki.data.getGroup(GroupID)
|
||||
GroupData = self.Yuuki.data.getGroup(groupId)
|
||||
if "GroupTicket" in GroupData:
|
||||
if GroupData["GroupTicket"].get(userId) is not None:
|
||||
GroupTicket = GroupData["GroupTicket"].get(userId)
|
||||
else:
|
||||
assert "Error JSON data type - GroupTicket"
|
||||
if GroupTicket == "" or renew:
|
||||
GroupTicket = self.getClient(userId).reissueGroupTicket(GroupID)
|
||||
GroupTicket = self.getClient(userId).reissueGroupTicket(groupId)
|
||||
self.Yuuki.data.updateData(
|
||||
["Group", GroupID, "GroupTicket", userId], GroupTicket)
|
||||
["Group", groupId, "GroupTicket", userId], GroupTicket)
|
||||
return GroupTicket
|
||||
|
||||
def limitReset(self):
|
||||
"""
|
||||
Reset Yuuki modify LINE Group Member List limits
|
||||
:return: None
|
||||
"""
|
||||
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)
|
||||
|
||||
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_StaticTools.dictShuffle(
|
||||
self.Yuuki.data.getData(["LimitInfo", "CancelLimit"]), members)
|
||||
if len(accounts) == 0:
|
||||
return "None"
|
||||
if exceptUserId:
|
||||
accounts[exceptUserId] = -1
|
||||
helper = max(accounts, key=accounts.get)
|
||||
else:
|
||||
if exceptUserId == self.Yuuki.MyMID:
|
||||
return "None"
|
||||
helper = self.Yuuki.MyMID
|
||||
def modifyGroupMemberList(self, action, groupInfo, userId, exceptUserId=None):
|
||||
"""
|
||||
Modify LINE Group Member List
|
||||
:param action: 1->kick 2->cancel
|
||||
:param groupInfo: LINE Group
|
||||
:param userId: string
|
||||
:param exceptUserId: List of userId
|
||||
:return: string
|
||||
"""
|
||||
|
||||
Limit = self.Yuuki.data.getData(["LimitInfo", "CancelLimit", helper])
|
||||
if Limit > 0:
|
||||
self.getClient(helper).cancelGroupInvitation(
|
||||
self.Yuuki.Seq, groupInfo.id, [userId])
|
||||
self.Yuuki.data.limitDecrease("CancelLimit", helper)
|
||||
else:
|
||||
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_StaticTools.dictShuffle(
|
||||
self.Yuuki.data.getData(["LimitInfo", "KickLimit"]), members)
|
||||
if len(accounts) == 0:
|
||||
return "None"
|
||||
if exceptUserId:
|
||||
accounts[exceptUserId] = -1
|
||||
helper = max(accounts, key=accounts.get)
|
||||
else:
|
||||
if exceptUserId == self.Yuuki.MyMID:
|
||||
return "None"
|
||||
helper = self.Yuuki.MyMID
|
||||
|
||||
Limit = self.Yuuki.data.getData(["LimitInfo", "KickLimit", helper])
|
||||
if Limit > 0:
|
||||
self.getClient(helper).kickoutFromGroup(
|
||||
self.Yuuki.Seq, groupInfo.id, [userId])
|
||||
self.Yuuki.data.limitDecrease("KickLimit", helper)
|
||||
else:
|
||||
self.sendText(groupInfo.id, self.Yuuki.get_text("Kick Limit."))
|
||||
return helper
|
||||
|
||||
def sendText(self, toid, msg):
|
||||
message = Message(to=toid, text=msg)
|
||||
def sendText(self, send_to, msg):
|
||||
"""
|
||||
Send text to LINE Chat
|
||||
:param send_to: string
|
||||
:param msg: string
|
||||
:return: None
|
||||
"""
|
||||
message = Message(to=send_to, text=msg)
|
||||
self.getClient(self.Yuuki.MyMID).sendMessage(self.Yuuki.Seq, message)
|
||||
|
||||
def sendUser(self, toid, userId):
|
||||
def sendUser(self, send_to, userId):
|
||||
"""
|
||||
Send LINE contact to LINE Chat
|
||||
:param send_to: string
|
||||
:param userId: string
|
||||
:return: None
|
||||
"""
|
||||
message = Message(
|
||||
contentType=ContentType.CONTACT,
|
||||
text='',
|
||||
|
@ -238,11 +280,18 @@ class Yuuki_DynamicTools:
|
|||
'mid': userId,
|
||||
'displayName': 'LINE User',
|
||||
},
|
||||
to=toid
|
||||
to=send_to
|
||||
)
|
||||
self.getClient(self.Yuuki.MyMID).sendMessage(self.Yuuki.Seq, message)
|
||||
|
||||
def sendMedia(self, send_to, send_type, path):
|
||||
"""
|
||||
Send media file to LINE Chat
|
||||
:param send_to: string
|
||||
:param send_type: string
|
||||
:param path: string
|
||||
:return: None
|
||||
"""
|
||||
if os.path.exists(path):
|
||||
file_name = ntpath.basename(path)
|
||||
file_size = len(open(path, 'rb').read())
|
||||
|
|
|
@ -49,6 +49,7 @@ class Yuuki:
|
|||
origin_url = "https://github.com/star-inc/star_yuuki_bot.git"
|
||||
|
||||
if self.YuukiConfigs["version_check"]:
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
GitRemote = Repo('.').remote()
|
||||
UpdateStatus = GitRemote.fetch()[0]
|
||||
|
|
Loading…
Reference in a new issue