Using yaml as the configure file format

This commit is contained in:
SuperSonic 2020-02-01 13:58:50 +08:00
parent 9cc8ec818b
commit dcbd4ecc5b
18 changed files with 137 additions and 110 deletions

3
.gitignore vendored
View file

@ -1,3 +1,6 @@
# Star Yuuki BOT Configuration File
config.yaml
# Star Yuuki BOT Runtime Data
data/
logs/

21
config.sample.yaml Normal file
View file

@ -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:
-

View file

@ -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']

68
libs/config.py Normal file
View file

@ -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"]

View file

@ -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 = []

View file

@ -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/.

View file

@ -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

View file

@ -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/.

View file

@ -9,7 +9,7 @@
The Language Package Contributor:
supersonictw <https://github.com/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
"""

View file

@ -9,7 +9,7 @@
The Language Package Contributor:
supersonictw <https://github.com/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
"""

View file

@ -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()

View file

@ -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/.

View file

@ -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/.

View file

@ -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/.

View file

@ -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/.

View file

@ -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,8 +83,9 @@ class Yuuki:
# LINE Login
(self.client, self.listen) = self.Connect.connect()
self.connectHeader = Yuuki_Connection.connectHeader
self.connectHeader = Yuuki_Settings.connectHeader
if self.YuukiConfigs.get("helper_LINE_ACCESS_KEYs"):
for access in self.YuukiConfigs["helper_LINE_ACCESS_KEYs"]:
self.Connect.helperConnect(access)

42
main.py
View file

@ -6,53 +6,23 @@
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__":

View file

@ -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