mirror of
https://github.com/studio-neptune/yuuki.git
synced 2024-11-10 09:02:53 +08:00
Update
This commit is contained in:
parent
d8cde0b3b3
commit
f569222844
4 changed files with 29 additions and 57 deletions
|
@ -9,7 +9,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|||
from thrift.protocol import TCompactProtocol
|
||||
from thrift.transport import THttpClient
|
||||
|
||||
from yuuki_core.TalkService import Client
|
||||
from yuuki_core.TalkService import Client, TalkException
|
||||
|
||||
# NC HighSpeed Library
|
||||
try:
|
||||
|
@ -21,16 +21,14 @@ except ImportError:
|
|||
class Yuuki_Connect:
|
||||
def __init__(self, Yuuki_Configs):
|
||||
|
||||
self.helper = {}
|
||||
|
||||
self.host = Yuuki_Configs.connectInfo["Host"]
|
||||
self.com_path = Yuuki_Configs.connectInfo["Command_Path"]
|
||||
self.poll_path = Yuuki_Configs.connectInfo["LongPoll_path"]
|
||||
|
||||
self.con_header = Yuuki_Configs.connectHeader
|
||||
|
||||
self.helper = []
|
||||
self.helper_ids = []
|
||||
self.helper_authTokens = {}
|
||||
|
||||
def connect(self, listen_timeout=600000):
|
||||
transport = THttpClient.THttpClient(self.host + self.com_path)
|
||||
transport_in = THttpClient.THttpClient(self.host + self.poll_path)
|
||||
|
@ -51,41 +49,20 @@ class Yuuki_Connect:
|
|||
|
||||
return client, listen
|
||||
|
||||
def helperConnect(self, LINE_ACCESS_KEY):
|
||||
helper_ConnectHeader = self.con_header.copy()
|
||||
helper_ConnectHeader["X-Line-Access"] = LINE_ACCESS_KEY
|
||||
def helperConnect(self, auth_token):
|
||||
helper_connect_header = self.con_header.copy()
|
||||
helper_connect_header["X-Line-Access"] = auth_token
|
||||
|
||||
transport = THttpClient.THttpClient(self.host + self.com_path)
|
||||
transport.setCustomHeaders(helper_ConnectHeader)
|
||||
transport.setCustomHeaders(helper_connect_header)
|
||||
protocol = TCompactProtocol.TCompactProtocol(transport)
|
||||
client = Client(protocol)
|
||||
transport.open()
|
||||
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
profile = client.getProfile()
|
||||
|
||||
self.helper.append(client)
|
||||
self.helper_ids.append(profile.mid)
|
||||
self.helper_authTokens[profile.mid] = LINE_ACCESS_KEY
|
||||
|
||||
self.helper[profile.mid] = client
|
||||
return True
|
||||
except:
|
||||
print("Error:\n%s\nNot Acceptable\n" % (LINE_ACCESS_KEY,))
|
||||
|
||||
def helperThreadConnect(self, userId):
|
||||
if userId in self.helper_authTokens:
|
||||
LINE_ACCESS_KEY = self.helper_authTokens.get(userId)
|
||||
else:
|
||||
return None
|
||||
|
||||
helper_ConnectHeader = self.con_header.copy()
|
||||
helper_ConnectHeader["X-Line-Access"] = LINE_ACCESS_KEY
|
||||
|
||||
transport = THttpClient.THttpClient(self.host + self.com_path)
|
||||
transport.setCustomHeaders(helper_ConnectHeader)
|
||||
protocol = TCompactProtocol.TCompactProtocol(transport)
|
||||
client = Client(protocol)
|
||||
transport.open()
|
||||
|
||||
return client
|
||||
except TalkException:
|
||||
print("Error:\n%s\nNot Acceptable\n" % (auth_token,))
|
||||
|
|
|
@ -210,7 +210,9 @@ class Yuuki_Command:
|
|||
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.get_text("Unknown"),
|
||||
userId
|
||||
)
|
||||
self.Yuuki_DynamicTools.sendText(
|
||||
self.Yuuki_StaticTools.sendToWho(ncMessage),
|
||||
status + self.Yuuki.get_text("\nExtend Administrator(s)")
|
||||
|
|
|
@ -116,17 +116,10 @@ class Yuuki_DynamicTools:
|
|||
:param userId: string
|
||||
:return: TalkServiceClient
|
||||
"""
|
||||
if self.Yuuki.Threading:
|
||||
if userId == self.Yuuki.MyMID:
|
||||
(client, _) = self.Yuuki.Connect.connect()
|
||||
return client
|
||||
else:
|
||||
return self.Yuuki.Connect.helperThreadConnect(userId)
|
||||
if userId == self.Yuuki.MyMID:
|
||||
return self.Yuuki.client
|
||||
else:
|
||||
Accounts = [self.Yuuki.client] + self.Yuuki.Connect.helper
|
||||
for count, AccountUserId in enumerate(self.Yuuki.AllAccountIds):
|
||||
if AccountUserId == userId:
|
||||
return Accounts[count]
|
||||
return self.Yuuki.Connect.helper[userId]
|
||||
|
||||
def checkInInvitationList(self, ncMessage, userId=None):
|
||||
"""
|
||||
|
|
|
@ -50,16 +50,13 @@ class Yuuki:
|
|||
origin_url = "https://github.com/star-inc/star_yuuki_bot.git"
|
||||
|
||||
if self.YuukiConfigs["version_check"]:
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
git_remote = Repo('.').remote()
|
||||
update_status = git_remote.fetch()[0]
|
||||
if update_status.flags == 64:
|
||||
git_result = "New version found."
|
||||
elif update_status.flags == 4:
|
||||
git_result = "This is the latest version."
|
||||
except:
|
||||
git_result = "Something was wrong."
|
||||
git_remote = Repo('.').remote()
|
||||
update_status = git_remote.fetch()[0]
|
||||
if update_status.flags == 64:
|
||||
git_result = "New version found."
|
||||
elif update_status.flags == 4:
|
||||
git_result = "This is the latest version."
|
||||
origin_url = "\n".join(git_remote.urls)
|
||||
|
||||
return self._Announce_Dog(git_result, origin_url)
|
||||
|
||||
|
@ -68,8 +65,8 @@ class Yuuki:
|
|||
"\n{} {}\n"
|
||||
"\t===\n\n"
|
||||
"<*> {}\n\n"
|
||||
"More Information:\n"
|
||||
"{}\n\n\t\t\t\t\t"
|
||||
"Update Origin:\n"
|
||||
"\t{}\n\n\t\t\t\t\t"
|
||||
"{}\n\t{}\n".format(
|
||||
self.YuukiConfigs["name"],
|
||||
self.YuukiConfigs["version"],
|
||||
|
@ -107,7 +104,10 @@ class Yuuki:
|
|||
self.MyMID = self.profile.mid
|
||||
self.revision = self.client.getLastOpRevision()
|
||||
|
||||
self.AllAccountIds = [self.MyMID] + self.Connect.helper_ids
|
||||
self.AllAccountIds = [self.MyMID]
|
||||
|
||||
for userId in self.Connect.helper:
|
||||
self.AllAccountIds.append(userId)
|
||||
|
||||
if len(self.data.getData(["LimitInfo"])) != 2:
|
||||
self.data.updateData(["LimitInfo"], self.data.LimitType)
|
||||
|
|
Loading…
Reference in a new issue