Skip to content

Commit 49736db

Browse files
authored
Merge pull request #17 from star-inc/rolling
v6.5.2-stable from Rolling
2 parents a00d0b3 + 67bc41f commit 49736db

File tree

8 files changed

+417
-132
lines changed

8 files changed

+417
-132
lines changed

COPYING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Star Yuuki BOT - Yuuki
2+
3+
This Source Code Form is subject to the terms of the Mozilla Public
4+
License, v. 2.0. If a copy of the MPL was not distributed with this
5+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
1)You can edit/copy these files, but you need to keep the original "[COPYING.md](COPYING.md)", "[LICENSE.md](LICENSE.md)" and in the program which you did it.
8+
9+
2)The copyright of [Line Services](https://line.starinc.xyz/) contents belongs to [Star Inc.](https://starinc.xyz)
10+
11+
3)Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12+
13+
4)If your using cause any legal problem, we DO NOT assume any responsibility.
14+
15+
5)Enjoy using ;)
16+
17+
This Source Code Form is "Incompatible With Secondary Licenses", as
18+
defined by the Mozilla Public License, v. 2.0.
19+
20+
Copyright 2019 [Star Inc.](https://starinc.xyz) All Rights Reserved.

COPYRIGHT.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Star Yuuki(pYthon) BOT - Yuuki
22
==================
3-
![Version](https://img.shields.io/badge/v6.5.1-OpenSource-33FF33.svg) ![License](https://img.shields.io/badge/license-MPL--2.0-FF8800.svg) ![Python](https://img.shields.io/badge/python-3.x-0066FF.svg)
3+
![Version](https://img.shields.io/badge/v6.5.2-OpenSource-FF0033.svg) ![Series](https://img.shields.io/badge/syb-Series-7700FF.svg) ![License](https://img.shields.io/badge/license-MPL--2.0-FF6600.svg) ![Python](https://img.shields.io/badge/python-3.x-0066FF.svg) ![Platform](https://img.shields.io/badge/base_on-LINE-00DD00.svg)
44

55
A Python BOT for LINE Group Protection with LINE Unofficial API.
66
![ICON](logo.png)
@@ -10,7 +10,7 @@ Yeah! This is the BOT which was the first Chinese LINE Group Security BOT.
1010
Now, it is OpenSource.
1111

1212
## License
13-
The software licensed under Mozilla Public LICENSE 2.0.
13+
The software licensed under [Mozilla Public License 2.0](LICENSE.md) with [COPYING.md](COPYING.md).
1414

1515
## Warning
1616
Some function of old version maybe will make your LINE account be banned.
@@ -21,6 +21,7 @@ Recommand Environment:
2121
Ubuntu >= 18.04
2222
python >= 3.7
2323
pip >= 19.2
24+
git >= 2.17
2425

2526
You need the "LINE Unofficial API Core for Python". (Ex:[olsb](https://github.com/star-inc/olsb_cores), [akad](https://pypi.org/project/akad), [curve](https://pypi.org/project/curve) ...)
2627

libs/data.py

Lines changed: 122 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
#!/usr/bin/python3
22
# coding=UTF-8
33

4-
import os, time, json
4+
import \
5+
os, \
6+
time,\
7+
json, \
8+
random,\
9+
requests
510
from .core.ttypes import OpType
611

12+
from .data_mds import listen as msd_listen
13+
714
from .thread_control import Yuuki_Thread
815
from .thread_control import Yuuki_Multiprocess
916

1017
class Yuuki_Data:
1118
def __init__(self, threading):
1219
self.threading = threading
1320
self.ThreadControl = Yuuki_Thread()
14-
self.MpDataControl = Yuuki_Multiprocess()
21+
MdsThreadControl = Yuuki_Multiprocess()
1522

1623
# Data
17-
if self.threading:
18-
self.Data = self.MpDataControl.dataManager.dict()
19-
else:
20-
self.Data = {}
24+
self.Data = {}
2125

2226
self.DataType = {
2327
"Global":{
@@ -79,6 +83,25 @@ def __init__(self, threading):
7983
self.Data[Type] = self.DataType[Type]
8084
f.write(json.dumps(self.Data[Type]))
8185

86+
# Python MDS
87+
88+
if self.threading:
89+
self.mdsHost = "http://localhost:2019/"
90+
self.mdsCode = "{}.{}".format(random.random(), time.time())
91+
MdsThreadControl.add(msd_listen, (self.mdsCode,))
92+
93+
# MDS Sync
94+
95+
time.sleep(1)
96+
requests.post(
97+
url=self.mdsHost,
98+
json={
99+
"code": self.mdsCode,
100+
"do": "SYC",
101+
"path": self.Data
102+
}
103+
)
104+
82105
# Log
83106

84107
self.LogType = {
@@ -111,31 +134,92 @@ def ThreadExec(self, Function, args):
111134
else:
112135
Function(*args)
113136

137+
def _mdsShake(self, do, path, data=None):
138+
if self.threading:
139+
mds = requests.post(
140+
url=self.mdsHost,
141+
json={
142+
"code": self.mdsCode,
143+
"do": do,
144+
"path": path,
145+
"data": data
146+
}
147+
)
148+
over = mds.json()
149+
assert_result = "mds - ERROR\n{} on {}".format(do, path)
150+
assert over["status"] == 200, assert_result
151+
return over
152+
else:
153+
status = {"status" : 0}
154+
return json.dumps(status)
155+
156+
def _local_query(self, query_data):
157+
if type(query_data) is list:
158+
result = self.Data
159+
query_len = len(query_data)
160+
source_data = self.Data
161+
for count, key in enumerate(query_data):
162+
if key in source_data:
163+
if count < (query_len - 1):
164+
if type(source_data.get(key)) is dict:
165+
source_data = source_data.get(key)
166+
else:
167+
result = 1
168+
break
169+
else:
170+
result = source_data.get(key)
171+
else:
172+
result = 2
173+
break
174+
175+
return result
176+
return 0
177+
178+
def _local_update(self, path, data):
179+
over = self._local_query(path)
180+
if not str(over).isnumeric():
181+
over.update(data)
182+
return False
183+
114184
def file(self, Type, Mode, Format):
115185
if Format == "Data":
116186
return open(self.DataPath + self.DataName.format(Type), Mode)
117187
elif Format == "Log":
118188
return open(self.LogPath + self.LogName.format(Type), Mode)
119189

120190
def syncData(self):
191+
if self.threading:
192+
self.Data = self.getData([])
121193
for Type in self.DataType:
122194
with self.file(Type, "w", "Data") as f:
123195
f.write(json.dumps(self.Data[Type]))
196+
return self.getData(["Global","Power"])
124197

125-
def updateData(self, Object, Input, Data):
198+
def updateData(self, path, data):
126199
if self.threading:
127-
self.ThreadExec(self._updateData, (Object, Input, Data))
200+
self.ThreadExec(self._updateData, (path, data))
128201
else:
129-
self._updateData(Object, Input, Data)
202+
self._updateData(path, data)
130203

131-
def _updateData(self, Object, Input, Data):
132-
if type(Object) == list:
133-
if Input:
134-
Object.append(Data)
135-
else:
136-
Object.remove(Data)
137-
elif type(Object) == dict:
138-
Object[Input] = Data
204+
def _updateData(self, path, data):
205+
assert path and type(path) is list, "Empty path - updateData"
206+
if len(path) == 1:
207+
origin_data = self.getData([])
208+
assert type(origin_data) is dict, "Error origin data type (1) - updateData"
209+
origin = origin_data.copy()
210+
origin[path[0]] = data
211+
path = []
212+
else:
213+
origin_data = self.getData(path[:-1])
214+
assert type(origin_data) is dict, "Error origin data type (2) - updateData"
215+
origin = origin_data.copy()
216+
origin[path[-1]] = data
217+
path = path[:-1]
218+
assert type(origin) is dict, "Error request data type - updateData"
219+
if self.threading:
220+
self._mdsShake("UPT", path, origin)
221+
else:
222+
self._local_update(path, origin)
139223

140224
def updateLog(self, Type, Data):
141225
if self.threading:
@@ -147,42 +231,39 @@ def _updateLog(self, Type, Data):
147231
with self.file(Type, "a", "Log") as f:
148232
f.write(self.LogType[Type] % Data)
149233

150-
def getTime(self, format="%b %d %Y %H:%M:%S %Z"):
234+
@staticmethod
235+
def getTime(time_format="%b %d %Y %H:%M:%S %Z"):
151236
Time = time.localtime(time.time())
152-
return time.strftime(format, Time)
153-
154-
def getData(self, Type):
155-
return self.Data[Type]
156-
157-
def getLimit(self, Type):
158-
LimitInfo = self.getData("LimitInfo")
159-
if Type == "Kick":
160-
Limit = {}
161-
for Mode in LimitInfo["KickLimit"]:
162-
Limit[Mode] = int(LimitInfo["KickLimit"][Mode])
163-
elif Type == "Cancel":
164-
Limit = {}
165-
for Mode in LimitInfo["CancelLimit"]:
166-
Limit[Mode] = int(LimitInfo["CancelLimit"][Mode])
237+
return time.strftime(time_format, Time)
238+
239+
def getData(self, path):
240+
if self.threading:
241+
return self._mdsShake("GET", path).get("data")
167242
else:
168-
Limit = None
169-
return Limit
243+
return self._local_query(path)
170244

171245
def getGroup(self, GroupID):
172-
Groups = self.getData("Group")
246+
Groups = self.getData(["Group"])
173247
if len(Groups) > 0:
174248
GroupIDs = [Group for Group in Groups]
175249
if GroupID not in GroupIDs:
176-
Groups[GroupID] = self.GroupType
250+
self.updateData(["Group", GroupID], self.GroupType)
177251
else:
178-
Groups[GroupID] = self.GroupType
179-
return Groups[GroupID]
252+
self.updateData(["Group", GroupID], self.GroupType)
253+
return self.getData(["Group", GroupID])
180254

181255
def getSEGroup(self, GroupID):
182-
SEMode = self.getGroup(GroupID).get("SEGroup")
183-
if SEMode == None:
256+
GroupData = self.getGroup(GroupID)
257+
SEMode = GroupData.get("SEGroup")
258+
if SEMode is None:
184259
return None
185260
SEMode_ = {}
186261
for Mode in SEMode:
187262
SEMode_[int(Mode)] = SEMode[Mode]
188263
return SEMode_
264+
265+
def limitDecrease(self, limit_type, userId):
266+
if self.threading:
267+
self._mdsShake("YLD", limit_type, userId)
268+
else:
269+
self.Data["LimitInfo"][limit_type][userId] -= 1

0 commit comments

Comments
 (0)