diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..36ec8af
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,136 @@
+# Star Yuuki BOT Runtime Data
+data/
+logs/
+
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+pip-wheel-metadata/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+.python-version
+
+# pipenv
+# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+# However, in case of collaboration, if having platform-specific dependencies or dependencies
+# having no cross-platform support, pipenv may install dependencies that don't work, or not
+# install all needed dependencies.
+#Pipfile.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+# Pycharm
+.idea/
\ No newline at end of file
diff --git a/libs/__init__.py b/libs/__init__.py
index 1bf5746..ef635e6 100644
--- a/libs/__init__.py
+++ b/libs/__init__.py
@@ -1,4 +1,4 @@
-from .yuuki import Yuuki, Yuuki_Settings
from .connection import Yuuki_Connection
+from .yuuki import Yuuki, Yuuki_Settings
__all__ = ['Yuuki', "Yuuki_Settings", 'Yuuki_Connection']
diff --git a/libs/connection.py b/libs/connection.py
index 10c79db..e823e39 100644
--- a/libs/connection.py
+++ b/libs/connection.py
@@ -1,16 +1,18 @@
#!/usr/bin/python3
# coding=UTF-8
-from .core.TalkService import Client
-
-from thrift.transport import THttpClient
from thrift.protocol import TCompactProtocol
+from thrift.transport import THttpClient
+
+from .core.TalkService import Client
""" NC HightSpeed Lib """
try:
from thrift.protocol import fastbinary
except:
fastbinary = None
+
+
##########################################
class Yuuki_Connection:
@@ -28,6 +30,7 @@ class Yuuki_Connection:
"User-Agent": ""
}
+
class Yuuki_Connect:
def __init__(self, Yuuki_Connection):
diff --git a/libs/data.py b/libs/data.py
index c898aca..e8be2b1 100644
--- a/libs/data.py
+++ b/libs/data.py
@@ -1,18 +1,18 @@
#!/usr/bin/python3
# coding=UTF-8
-import \
- os, \
- time,\
- json, \
- random,\
- requests
+import json
+import os
+import random
+import time
+
+import requests
+
from .core.ttypes import OpType
-
from .data_mds import listen as msd_listen
-
-from .thread_control import Yuuki_Thread
from .thread_control import Yuuki_Multiprocess
+from .thread_control import Yuuki_Thread
+
class Yuuki_Data:
def __init__(self, threading):
@@ -24,30 +24,30 @@ class Yuuki_Data:
self.Data = {}
self.DataType = {
- "Global":{
- "LastResetLimitTime":None,
+ "Global": {
+ "LastResetLimitTime": None,
},
"Group": {},
- "LimitInfo":{},
- "BlackList":[]
+ "LimitInfo": {},
+ "BlackList": []
}
self.GroupType = {
- "SEGroup":None,
- "Ext_Admin":[],
- "GroupTicket":{}
+ "SEGroup": None,
+ "Ext_Admin": [],
+ "GroupTicket": {}
}
self.LimitType = {
- "KickLimit":{},
- "CancelLimit":{}
+ "KickLimit": {},
+ "CancelLimit": {}
}
self.SEGrouptype = {
- OpType.NOTIFIED_UPDATE_GROUP:False,
- OpType.NOTIFIED_INVITE_INTO_GROUP:False,
- OpType.NOTIFIED_ACCEPT_GROUP_INVITATION:False,
- OpType.NOTIFIED_KICKOUT_FROM_GROUP:False
+ OpType.NOTIFIED_UPDATE_GROUP: False,
+ OpType.NOTIFIED_INVITE_INTO_GROUP: False,
+ OpType.NOTIFIED_ACCEPT_GROUP_INVITATION: False,
+ OpType.NOTIFIED_KICKOUT_FROM_GROUP: False
}
self.DataPath = "data/"
@@ -105,10 +105,10 @@ class Yuuki_Data:
# Log
self.LogType = {
- "JoinGroup":"
%s: %s(%s) -> Inviter: %s",
- "KickEvent":"%s: %s(%s) -(%s)> Kicker: %s | Kicked: %s | Status: %s",
- "CancelEvent":"%s: %s(%s) -(%s)> Inviter: %s | Canceled: %s",
- "BlackList":"%s: %s(%s)"
+ "JoinGroup": "%s: %s(%s) -> Inviter: %s",
+ "KickEvent": "%s: %s(%s) -(%s)> Kicker: %s | Kicked: %s | Status: %s",
+ "CancelEvent": "%s: %s(%s) -(%s)> Inviter: %s | Canceled: %s",
+ "BlackList": "%s: %s(%s)"
}
self.LogPath = "logs/"
@@ -150,7 +150,7 @@ class Yuuki_Data:
assert over["status"] == 200, assert_result
return over
else:
- status = {"status" : 0}
+ status = {"status": 0}
return json.dumps(status)
def _local_query(self, query_data):
@@ -189,7 +189,7 @@ class Yuuki_Data:
for Type in self.DataType:
with self.file(Type, "w", "Data") as f:
f.write(json.dumps(self.Data[Type]))
- return self.getData(["Global","Power"])
+ return self.getData(["Global", "Power"])
def updateData(self, path, data):
if self.threading:
diff --git a/libs/data_mds.py b/libs/data_mds.py
index a9a0ace..ed522d5 100644
--- a/libs/data_mds.py
+++ b/libs/data_mds.py
@@ -19,32 +19,36 @@ from tornado.web import Application, RequestHandler
switch_data = {}
auth_code = 0
+
# Functions
def mds_exit(null=None, null_=None):
exit(0)
+
def update(path, data):
global switch_data
try:
if type(path) is list:
over = query(path)
over.get("data").update(data)
- return {"status" : 200}
- return {"status" : 400}
+ return {"status": 200}
+ return {"status": 400}
except:
return {"status": 500}
+
def delete(path, data):
global switch_data
try:
if type(path) is list:
over = query(path)
over.get("data").pop(data)
- return {"status" : 200}
- return {"status" : 400}
+ return {"status": 200}
+ return {"status": 400}
except:
return {"status": 500}
+
def query(query_data, null=None):
global switch_data
try:
@@ -55,34 +59,37 @@ def query(query_data, null=None):
if key in result:
if count < query_len:
if type(result.get(key)) is not dict:
- result = 1 #"unknown_type" + type(source_data.get(key))
+ result = 1 # "unknown_type" + type(source_data.get(key))
break
result = result.get(key)
else:
- result = 2 #"unknown_key"
+ result = 2 # "unknown_key"
break
- return {"status" : 200, "data" : result}
- return {"status" : 400}
+ return {"status": 200, "data": result}
+ return {"status": 400}
except:
return {"status": 500}
+
def sync(path, null=None):
global switch_data
try:
switch_data = path
- return {"status" : 200}
+ return {"status": 200}
except:
return {"status": 500}
+
def yuukiLimitDecrease(path, userId):
global switch_data
try:
switch_data["LimitInfo"][path][userId] -= 1
- return {"status" : 200}
+ return {"status": 200}
except:
return {"status": 500}
+
# Works
_work = {
"EXT": mds_exit,
@@ -93,6 +100,7 @@ _work = {
"YLD": yuukiLimitDecrease
}
+
class IndexHandler(RequestHandler):
def get(self):
self.write('''
@@ -109,16 +117,17 @@ class IndexHandler(RequestHandler):
if req_res.get("code") == auth_code:
result = _work[req_res.get("do")](req_res.get("path"), req_res.get("data"))
else:
- result = {"status" : 401}
+ result = {"status": 401}
if not result:
- result = {"status" : 500}
+ result = {"status": 500}
self.write(json.dumps(result))
+
# Main
def listen(code):
global auth_code
auth_code = code
- app = Application([('/',IndexHandler)])
+ app = Application([('/', IndexHandler)])
server = HTTPServer(app)
server.listen(2019)
IOLoop.current().start()
diff --git a/libs/i18n/__init__.py b/libs/i18n/__init__.py
index 2385a53..d523eca 100644
--- a/libs/i18n/__init__.py
+++ b/libs/i18n/__init__.py
@@ -4,6 +4,7 @@
from .en import English
from .zh_TW import Traditional_Chinese
+
class Yuuki_LangSetting:
def __init__(self, default):
self.default = default
diff --git a/libs/i18n/en.py b/libs/i18n/en.py
index 32ca811..561ca22 100644
--- a/libs/i18n/en.py
+++ b/libs/i18n/en.py
@@ -13,8 +13,8 @@
The software licensed under Mozilla Public License Version 2.0
"""
-class English:
+class English:
i18nText = {
"Helllo^^\nMy name is %s ><\nNice to meet you OwO": "Helllo^^\nMy name is %s ><\nNice to meet you OwO",
"Type:\n\t%s/Help\nto get more information\n\nMain Admin of the Group:\n%s": "Type:\n\t%s/Help\nto get more information\n\nMain Admin of the Group:\n%s",
diff --git a/libs/i18n/zh_TW.py b/libs/i18n/zh_TW.py
index fc57321..6155baa 100644
--- a/libs/i18n/zh_TW.py
+++ b/libs/i18n/zh_TW.py
@@ -13,8 +13,8 @@
The software licensed under Mozilla Public License Version 2.0
"""
-class Traditional_Chinese:
+class Traditional_Chinese:
i18nText = {
"Helllo^^\nMy name is %s ><\nNice to meet you OwO": "安安^^\n我是%s呦><\n請多多指教OwO",
"Type:\n\t%s/Help\nto get more information\n\nMain Admin of the Group:\n%s": "請輸入:\n\t%s/Help\n以獲得更多資訊\n\n本群組主管理員為:\n%s",
diff --git a/libs/sync.py b/libs/sync.py
new file mode 100644
index 0000000..3661471
--- /dev/null
+++ b/libs/sync.py
@@ -0,0 +1,12 @@
+#!/usr/bin/python3
+# coding=UTF-8
+
+from simplegist.simplegist import Simplegist
+
+
+class Yuuki_Sync:
+ def __init__(self):
+ self.client = Simplegist(username='USERNAME', api_token='API_TOKEN')
+
+ def initialize(self):
+ pass
diff --git a/libs/thread_control.py b/libs/thread_control.py
index ff8c7d4..4d9dc64 100644
--- a/libs/thread_control.py
+++ b/libs/thread_control.py
@@ -1,7 +1,9 @@
#!/usr/bin/python3
# coding=UTF-8
-import threading, multiprocessing
+import multiprocessing
+import threading
+
class Yuuki_Thread:
def __init__(self):
@@ -16,6 +18,7 @@ class Yuuki_Thread:
print(threading.enumerate())
print("{} add Threading\n".format(threading.current_thread()))
+
class Yuuki_Multiprocess:
def add(self, Yuuki_Func, args=()):
added_multiprocess = multiprocessing.Process(name=Yuuki_Func.__name__, target=Yuuki_Func, args=args)
diff --git a/libs/yuuki.py b/libs/yuuki.py
index 5550585..844ea30 100644
--- a/libs/yuuki.py
+++ b/libs/yuuki.py
@@ -6,11 +6,11 @@ import ntpath
import os
import platform
import random
-import requests
import socket
import time
import traceback
+import requests
from git import Repo
try:
@@ -469,7 +469,7 @@ class Yuuki:
RECEIVE_MESSAGE (26)
"""
BlockedIgnore = (ncMessage.message.to in self.data.getData(["BlackList"])) or (
- ncMessage.message.from_ in self.data.getData(["BlackList"]))
+ ncMessage.message.from_ in self.data.getData(["BlackList"]))
if ('BOT_CHECK' in ncMessage.message.contentMetadata) or BlockedIgnore:
pass
elif ncMessage.message.toType == MIDType.ROOM:
@@ -727,7 +727,7 @@ class Yuuki:
Kicker = self.kickSomeone(GroupInfo, Action)
# Log
self.data.updateLog("KickEvent", (
- self.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type))
+ self.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type))
elif ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP and Security_Access:
Canceler = "None"
if "\x1e" in Another:
@@ -739,11 +739,11 @@ class Yuuki:
Canceler = self.kickSomeone(GroupInfo, userId)
# Log
self.data.updateLog("KickEvent", (
- self.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, userId,
- ncMessage.type * 10))
+ self.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, userId,
+ ncMessage.type * 10))
# Log
self.data.updateLog("CancelEvent", (
- self.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another.replace("\x1e", ",")))
+ self.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another.replace("\x1e", ",")))
elif Another not in self.AllAccountIds + GroupPrivilege:
if GroupInfo.invitee and Another in [user.mid for user in GroupInfo.invitee]:
Canceler = self.cancelSomeone(GroupInfo, Another)
@@ -751,7 +751,8 @@ class Yuuki:
Canceler = self.kickSomeone(GroupInfo, Another)
# Log
self.data.updateLog("KickEvent", (
- self.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another, ncMessage.type * 10))
+ self.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another,
+ ncMessage.type * 10))
# Log
self.data.updateLog("CancelEvent",
(self.data.getTime(), GroupInfo.name, GroupID, Canceler, Action, Another))
@@ -764,19 +765,20 @@ class Yuuki:
Kicker = self.kickSomeone(GroupInfo, Action)
# Log
self.data.updateLog("KickEvent", (
- self.data.getTime(), GroupInfo.name, GroupID, Kicker, Kicker, Action, ncMessage.type))
+ self.data.getTime(), GroupInfo.name, GroupID, Kicker, Kicker, Action, ncMessage.type))
elif ncMessage.type == OpType.NOTIFIED_KICKOUT_FROM_GROUP:
if Action in self.Connect.helper_ids:
# Log
self.data.updateLog("KickEvent", (
- self.data.getTime(), GroupInfo.name, GroupID, Action, Action, Another, ncMessage.type * 10 + 1))
+ self.data.getTime(), GroupInfo.name, GroupID, Action, Action, Another, ncMessage.type * 10 + 1))
elif Another in self.AllAccountIds:
Kicker = "None"
try:
Kicker = self.kickSomeone(GroupInfo, Action, Another)
# Log
self.data.updateLog("KickEvent", (
- self.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type * 10 + 2))
+ self.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another,
+ ncMessage.type * 10 + 2))
assert Kicker != "None", "No Helper Found"
if GroupInfo.preventJoinByTicket:
self.Thread_Exec(self.changeGroupUrlStatus, (GroupInfo, True, Kicker))
@@ -803,7 +805,8 @@ class Yuuki:
self.data.updateData(["Global", "GroupJoined"], NewGroupList)
# Log
self.data.updateLog("KickEvent", (
- self.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type * 10 + 3))
+ self.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another,
+ ncMessage.type * 10 + 3))
BlackList = self.data.getData(["BlackList"])
if Action not in BlackList:
NewBlackList = BlackList.copy()
@@ -817,7 +820,7 @@ class Yuuki:
Kicker = self.kickSomeone(GroupInfo, Action)
# Log
self.data.updateLog("KickEvent", (
- self.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type))
+ self.data.getTime(), GroupInfo.name, GroupID, Kicker, Action, Another, ncMessage.type))
self.Thread_Exec(self.sendText, (GroupID, _("The one who was been kicked:")))
self.Thread_Exec(self.sendUser, (GroupID, Another))
diff --git a/requirements.txt b/requirements.txt
index ff98953..a651746 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,11 +1,12 @@
-certifi==2019.9.11
+simplegist==1.0.1
+certifi==2019.11.28
chardet==3.0.4
gitdb2==2.0.6
-GitPython==3.0.3
+GitPython==3.0.5
idna==2.8
requests==2.22.0
-six==1.12.0
+six==1.13.0
smmap2==2.0.5
-thrift==0.11.0
+thrift==0.13.0
tornado==6.0.3
-urllib3==1.25.6
+urllib3==1.25.7