diff --git a/.gitignore b/.gitignore index 36ec8af..420f5ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Star Yuuki BOT Configuration File +config.yaml + # Star Yuuki BOT Runtime Data data/ logs/ diff --git a/config.sample.yaml b/config.sample.yaml new file mode 100644 index 0000000..e961431 --- /dev/null +++ b/config.sample.yaml @@ -0,0 +1,21 @@ +Yuuki: + Default_Language: en + Admin: + - + KickLimit: 10 + CancelLimit: 10 + GroupMebers_Demand: 10 + +LINE: + Server: + Host: + Command_Path: + LongPoll_path: + + Account: + X-Line-Application: + X-Line-Access: + User-Agent: + + helper_LINE_ACCESS_KEYs: + - diff --git a/libs/__init__.py b/libs/__init__.py index 51344c3..365e21f 100644 --- a/libs/__init__.py +++ b/libs/__init__.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- """ Yuuki_Libs -(c) 2019 Star Inc. +(c) 2020 Star Inc. This Source Code Form is subject to the terms of the Mozilla Public 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 .connection import Yuuki_Connection -from .yuuki import Yuuki, Yuuki_Settings +from .yuuki import Yuuki +from .config import Yuuki_Config -__all__ = ['Yuuki', "Yuuki_Settings", 'Yuuki_Connection'] +__all__ = ['connection', 'data', 'data_mds', 'thread_control', 'Yuuki', 'Yuuki_Config'] diff --git a/libs/config.py b/libs/config.py new file mode 100644 index 0000000..06c64b0 --- /dev/null +++ b/libs/config.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +""" +Yuuki_Libs +(c) 2020 Star Inc. +This Source Code Form is subject to the terms of the Mozilla Public +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/. +""" +import yaml + + +class Yuuki_Config: + """ Configure Yuuki """ + + connectInfo = { + "Host": "", + "Command_Path": "", + "LongPoll_path": "", + } + + connectHeader = { + "X-Line-Application": "", + "X-Line-Access": "", + "User-Agent": "" + } + + systemConfig = { + "name": "Yuuki", + "version": "v6.5.3-alpha", + "version_check": True, + "project_url": "https://tinyurl.com/syb-yuuki", + "man_page": "https://tinyurl.com/yuuki-manual", + "privacy_page": "OpenSource - Licensed under MPL 2.0", + "copyright": "(c)2020 Star Inc.", + + "Seq": 0, + "Admin": [], + "SecurityService": False, + "Hour_KickLimit": 10, + "Hour_CancelLimit": 10, + "Default_Language": "en", + "GroupMebers_Demand": 100, + "helper_LINE_ACCESS_KEYs": [], + } + + def __init__(self, config_path="config.yaml"): + with open(config_path, "r") as configfile: + config = yaml.load(configfile, Loader=yaml.BaseLoader) + + if "Yuuki" in config: + for key in config["Yuuki"]: + if key in self.systemConfig: + self.systemConfig[key] = config["Yuuki"][key] + + if "Server" in config.get("LINE"): + for key in config["LINE"]["Server"]: + if key in self.systemConfig: + self.connectInfo[key] = config["LINE"]["Server"][key] + + if "Account" in config.get("LINE"): + for key in config["LINE"]["Account"]: + if key in ["X-Line-Application", "User-Agent"]: + config["LINE"]["Account"][key] = config["LINE"]["Account"][key].replace("\\t","\t") + if key in self.systemConfig: + self.connectHeader[key] = config["LINE"]["Account"][key] + + if "helper_LINE_ACCESS_KEYs" in config.get("LINE"): + self.systemConfig["helper_LINE_ACCESS_KEYs"] = config["LINE"]["helper_LINE_ACCESS_KEYs"] diff --git a/libs/connection.py b/libs/connection.py index 010a9d3..25c6a81 100644 --- a/libs/connection.py +++ b/libs/connection.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Yuuki_Libs -(c) 2019 Star Inc. +(c) 2020 Star Inc. This Source Code Form is subject to the terms of the Mozilla Public 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/. @@ -15,35 +15,18 @@ from yuuki_core.TalkService import Client try: from thrift.protocol import fastbinary except: - fastbinary = None - - + print("[No fast_binary using]") ########################################## -class Yuuki_Connection: - """ Connection Dict Type """ - - connectInfo = { - "Host": "", - "Command_Path": "", - "LongPoll_path": "" - } - - connectHeader = { - "X-Line-Application": "", - "X-Line-Access": "", - "User-Agent": "" - } - class Yuuki_Connect: - def __init__(self, Yuuki_Connection): + def __init__(self, Yuuki_Configs): - self.host = Yuuki_Connection.connectInfo["Host"] - self.com_path = Yuuki_Connection.connectInfo["Command_Path"] - self.poll_path = Yuuki_Connection.connectInfo["LongPoll_path"] + 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_Connection.connectHeader + self.con_header = Yuuki_Configs.connectHeader self.helper = [] self.helper_ids = [] diff --git a/libs/data.py b/libs/data.py index 2f1f62a..2b049c6 100644 --- a/libs/data.py +++ b/libs/data.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Yuuki_Libs -(c) 2019 Star Inc. +(c) 2020 Star Inc. This Source Code Form is subject to the terms of the Mozilla Public 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/. diff --git a/libs/data_mds.py b/libs/data_mds.py index 815ff10..68c4d30 100644 --- a/libs/data_mds.py +++ b/libs/data_mds.py @@ -20,7 +20,7 @@ auth_code = 0 # Functions -def mds_exit(null=None, null_=None): +def mds_exit(): exit(0) @@ -48,7 +48,7 @@ def delete(path, data): return {"status": 500} -def query(query_data, null=None): +def query(query_data): global switch_data try: if type(switch_data) is dict and type(query_data) is list: @@ -71,7 +71,7 @@ def query(query_data, null=None): return {"status": 500} -def sync(path, null=None): +def sync(path): global switch_data try: switch_data = path diff --git a/libs/i18n/__init__.py b/libs/i18n/__init__.py index e6cfe23..34d43e0 100644 --- a/libs/i18n/__init__.py +++ b/libs/i18n/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Yuuki_Libs -(c) 2019 Star Inc. +(c) 2020 Star Inc. This Source Code Form is subject to the terms of the Mozilla Public 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/. diff --git a/libs/i18n/en.py b/libs/i18n/en.py index 561ca22..16ca3d3 100644 --- a/libs/i18n/en.py +++ b/libs/i18n/en.py @@ -9,7 +9,7 @@ The Language Package Contributor: supersonictw - Copyright(c) 2019 Star Inc. All Rights Reserved. + Copyright(c) 2020 Star Inc. All Rights Reserved. The software licensed under Mozilla Public License Version 2.0 """ diff --git a/libs/i18n/zh_TW.py b/libs/i18n/zh_TW.py index 6155baa..0175af5 100644 --- a/libs/i18n/zh_TW.py +++ b/libs/i18n/zh_TW.py @@ -9,7 +9,7 @@ The Language Package Contributor: supersonictw - Copyright(c) 2019 Star Inc. All Rights Reserved. + Copyright(c) 2020 Star Inc. All Rights Reserved. The software licensed under Mozilla Public License Version 2.0 """ diff --git a/libs/thread_control.py b/libs/thread_control.py index 048dd6d..489efc7 100644 --- a/libs/thread_control.py +++ b/libs/thread_control.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Yuuki_Libs -(c) 2019 Star Inc. +(c) 2020 Star Inc. This Source Code Form is subject to the terms of the Mozilla Public 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/. @@ -14,17 +14,20 @@ class Yuuki_Thread: def __init__(self): self.lock = threading.Lock() - def add(self, Yuuki_Func, args=()): + @staticmethod + def add(Yuuki_Func, args=()): added_thread = threading.Thread(name=Yuuki_Func.__name__, target=Yuuki_Func, args=args) added_thread.start() - def getThreadInfo(self): + @staticmethod + def getThreadInfo(): print(threading.active_count()) print(threading.enumerate()) print("{} add Threading\n".format(threading.current_thread())) class Yuuki_Multiprocess: - def add(self, Yuuki_Func, args=()): + @staticmethod + def add(Yuuki_Func, args=()): added_multiprocess = multiprocessing.Process(name=Yuuki_Func.__name__, target=Yuuki_Func, args=args) added_multiprocess.start() diff --git a/libs/webadmin/__init__.py b/libs/webadmin/__init__.py index 49ec702..0e57a3a 100644 --- a/libs/webadmin/__init__.py +++ b/libs/webadmin/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Yuuki_Libs -(c) 2019 Star Inc. +(c) 2020 Star Inc. This Source Code Form is subject to the terms of the Mozilla Public 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/. diff --git a/libs/webadmin/api.py b/libs/webadmin/api.py index 7dd3611..9ea28b1 100644 --- a/libs/webadmin/api.py +++ b/libs/webadmin/api.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Yuuki_Libs -(c) 2019 Star Inc. +(c) 2020 Star Inc. This Source Code Form is subject to the terms of the Mozilla Public 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/. diff --git a/libs/webadmin/reader.py b/libs/webadmin/reader.py index 4917371..bd8479c 100644 --- a/libs/webadmin/reader.py +++ b/libs/webadmin/reader.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Yuuki_Libs -(c) 2019 Star Inc. +(c) 2020 Star Inc. This Source Code Form is subject to the terms of the Mozilla Public 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/. diff --git a/libs/webadmin/server.py b/libs/webadmin/server.py index 09e82e8..015eecb 100644 --- a/libs/webadmin/server.py +++ b/libs/webadmin/server.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Yuuki_Libs -(c) 2019 Star Inc. +(c) 2020 Star Inc. This Source Code Form is subject to the terms of the Mozilla Public 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/. diff --git a/libs/yuuki.py b/libs/yuuki.py index a33315d..7c77897 100644 --- a/libs/yuuki.py +++ b/libs/yuuki.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Yuuki_Libs -(c) 2019 Star Inc. +(c) 2020 Star Inc. This Source Code Form is subject to the terms of the Mozilla Public 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/. @@ -26,35 +26,12 @@ from .thread_control import Yuuki_Multiprocess from .webadmin.server import Yuuki_WebAdmin -class Yuuki_Settings: - """ Yuuki Custom Settings """ - - config = { - "name": "Yuuki", - "version": "v6.5.3-alpha", - "version_check": True, - "project_url": "https://tinyurl.com/syb-yuuki", - "man_page": "https://tinyurl.com/yuuki-manual", - "privacy_page": "OpenSource - Licensed under MPL 2.0", - "copyright": "(c)2019 Star Inc.", - - "Seq": 0, - "Admin": [], - "SecurityService": False, - "Hour_KickLimit": 10, - "Hour_CancelLimit": 10, - "Default_Language": "en", - "GroupMebers_Demand": 100, - "helper_LINE_ACCESS_KEYs": [] - } - - class Yuuki: - def __init__(self, Yuuki_Settings, Yuuki_Connection, threading=False): + def __init__(self, Yuuki_Settings, threading=False): # Static Variable - self.YuukiConfigs = Yuuki_Settings.config + self.YuukiConfigs = Yuuki_Settings.systemConfig self.Threading = threading self.Thread_Control = Yuuki_Multiprocess() @@ -69,7 +46,7 @@ class Yuuki: self.LINE_Media_server = "https://obs.line-apps.com" - self.Connect = Yuuki_Connect(Yuuki_Connection) + self.Connect = Yuuki_Connect(Yuuki_Settings) # Version Check git_result = "Unknown" @@ -106,10 +83,11 @@ class Yuuki: # LINE Login (self.client, self.listen) = self.Connect.connect() - self.connectHeader = Yuuki_Connection.connectHeader + self.connectHeader = Yuuki_Settings.connectHeader - for access in self.YuukiConfigs["helper_LINE_ACCESS_KEYs"]: - self.Connect.helperConnect(access) + if self.YuukiConfigs.get("helper_LINE_ACCESS_KEYs"): + for access in self.YuukiConfigs["helper_LINE_ACCESS_KEYs"]: + self.Connect.helperConnect(access) # Dynamic Variable diff --git a/main.py b/main.py index 5469ba5..494b6fe 100755 --- a/main.py +++ b/main.py @@ -6,54 +6,24 @@ This is a main program in SYB. It`s belong to Star Yuuki(pYthon) Bot Project of Star Neptune Bot - Version: v6.5 + Version: v6.5.3 - Copyright(c) 2019 Star Inc. All Rights Reserved. + Copyright(c) 2020 Star Inc. All Rights Reserved. The software licensed under Mozilla Public License Version 2.0 """ -Admin = [""] -KickLimit = 10 -CancelLimit = 10 -Language = "en" -LINE_ACCESS_KEY = "" -GroupMebers_Demand = 100 -helper_LINE_ACCESS_KEYs = [] +from libs import Yuuki, Yuuki_Config ########################Initializing########################## -from libs import * -Connection = Yuuki_Connection() +config = Yuuki_Config() -Connection.connectInfo = { - 'Host': '', - 'Command_Path': '', - 'LongPoll_path': '' -} - -Connection.connectHeader = { - 'X-Line-Application': '', - 'X-Line-Access': LINE_ACCESS_KEY, - 'User-Agent': '' -} - -Settings = Yuuki_Settings() - -Settings.config["Seq"] = 0 -Settings.config["Admin"] = Admin -Settings.config["SecurityService"] = True -Settings.config["Hour_KickLimit"] = KickLimit -Settings.config["Hour_CancelLimit"] = CancelLimit -Settings.config["Default_Language"] = Language -Settings.config["GroupMebers_Demand"] = GroupMebers_Demand -Settings.config["helper_LINE_ACCESS_KEYs"] = helper_LINE_ACCESS_KEYs - - -Console = Yuuki(Settings, Connection) +Console = Yuuki(config) Console.cleanMyGroupInvitations() ###########################Start!############################# + print("Star Yuuki BOT - Start Successful!") if __name__ == "__main__": - Console.Main() \ No newline at end of file + Console.Main() diff --git a/requirements.txt b/requirements.txt index 8f604f3..7218bd6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ chardet==3.0.4 gitdb2==2.0.6 GitPython==3.0.5 idna==2.8 +PyYAML==5.3 requests==2.22.0 six==1.14.0 smmap2==2.0.5