Skip to content

Commit fad4fb9

Browse files
committed
更换cache引入方式,现在handle只传data
1 parent b14698a commit fad4fb9

File tree

19 files changed

+71
-62
lines changed

19 files changed

+71
-62
lines changed

slack_bot/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def callback(kwargs):
5959

6060
for plugin_module in plugin_modules:
6161
if plugin_module.test(data):
62-
ret = plugin_module.handle(data, cache=cache)
62+
ret = plugin_module.handle(data)
6363
if not isinstance(ret, tuple):
6464
text = ret
6565
attaches = None

slack_bot/plugins/airpollution.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import json
3030
from bs4 import BeautifulSoup
3131

32+
from slack_bot.ext import cache
3233
from utils import gen_attachment
3334

3435
description = """
@@ -52,7 +53,7 @@ def test(data):
5253
return len(req) > 0
5354

5455

55-
def get_desc(cityname, cityshort, cache=None):
56+
def get_desc(cityname, cityshort):
5657
if cache is not None:
5758
r = cache.get('airpollution.%s' % (cityshort))
5859
if r:
@@ -82,16 +83,16 @@ def get_desc(cityname, cityshort, cache=None):
8283
return text, attaches
8384

8485

85-
def handle(data, cache=None, **kwargs):
86+
def handle(data):
8687
message = data['message']
8788
reqs = filter(lambda p: p[0].encode('utf-8') in message, city)
8889
req = reqs[0]
8990
try:
90-
return get_desc(req[0], req[1], cache)
91+
return get_desc(req[0], req[1])
9192
except Exception as e:
9293
print 'Error: {}'.format(e)
9394
return '空气查询失败, 请重试!', []
9495

9596

9697
if __name__ == '__main__':
97-
print handle({'message': '北京空气'}, None)
98+
print handle({'message': '北京空气'})

slack_bot/plugins/baidumap.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test(data):
194194
return REGEX.search(message)
195195

196196

197-
def handle(data, cache, **kwargs):
197+
def handle(data):
198198
app = current_app
199199
if app is None:
200200
ak = '18691b8e4206238f331ad2e1ca88357e'
@@ -241,9 +241,9 @@ def handle(data, cache, **kwargs):
241241

242242

243243
if __name__ == '__main__':
244-
print handle({'message': '我想从兆维工业园到北京南站'}, None, None)
245-
print handle({'message': '我想从人大到北京南站'}, None, None)
246-
print handle({'message': '我想从人大到豆瓣'}, None, None)
247-
print handle({'message': '我想从兆维工业园到北京南站 步行'}, None, None)
248-
print handle({'message': '我想从兆维工业园到北京南站 开车'}, None, None)
249-
print handle({'message': '从酒仙桥去798'}, None, None)
244+
print handle({'message': '我想从兆维工业园到北京南站'})
245+
print handle({'message': '我想从人大到北京南站'})
246+
print handle({'message': '我想从人大到豆瓣'})
247+
print handle({'message': '我想从兆维工业园到北京南站 步行'})
248+
print handle({'message': '我想从兆维工业园到北京南站 开车'})
249+
print handle({'message': '从酒仙桥去798'})

slack_bot/plugins/dianping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test(data):
111111
for i in ['有什么美食', '大众点评', '附近美食']])
112112

113113

114-
def handle(data, **kwargs):
114+
def handle(data):
115115
app = current_app
116116
message = data['message']
117117
if app is None:

slack_bot/plugins/earthquake.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def jw(a, b):
5656
return ','.join((aa, bb))
5757

5858

59-
def handle(data, **kwargs):
59+
def handle(data):
6060
r = urllib2.urlopen(
6161
'http://data.earthquake.cn/datashare/globeEarthquake_csn.html',
6262
timeout=5)
@@ -66,4 +66,4 @@ def handle(data, **kwargs):
6666
(t[7], jw(t[2], t[3]), ' '.join(t[0:2]), t[5], t[4], t[6])
6767

6868
if __name__ == '__main__':
69-
print handle({'message': '地震了吗?'}, None)
69+
print handle({'message': '地震了吗?'})

slack_bot/plugins/events.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import requests
77
from bs4 import BeautifulSoup
88

9+
from slack_bot.ext import cache
910
from utils import check_cache
1011

1112
description = """
@@ -224,7 +225,7 @@ def test(data):
224225
return '最近有什么活动' in data['message']
225226

226227

227-
def handle(data, cache=None, **kwargs):
228+
def handle(data):
228229
message = data['message']
229230
if not isinstance(message, unicode):
230231
message = message.decode('utf-8')
@@ -237,5 +238,5 @@ def handle(data, cache=None, **kwargs):
237238

238239

239240
if __name__ == '__main__':
240-
print handle({'message': '最近有什么活动'}, None, None)
241-
print handle({'message': '最近有什么活动 上海'}, None, None)
241+
print handle({'message': '最近有什么活动'})
242+
print handle({'message': '最近有什么活动 上海'})

slack_bot/plugins/github_issue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test(data):
1616
return 'issue' in data['message']
1717

1818

19-
def handle(data, **kwargs):
19+
def handle(data):
2020
app = current_app
2121
org_name = app.config.get('ORG_NAME', 'python-cn')
2222
repos = requests.get(REPO_API.format(org=org_name)).json()
@@ -41,4 +41,4 @@ def handle(data, **kwargs):
4141
from flask import Flask
4242
app = Flask(__name__)
4343
app.config['org_name'] = 'python-cn'
44-
print handle(None, None)
44+
print handle(None)

slack_bot/plugins/help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test(data):
2121
return 'help' in data['message']
2222

2323

24-
def handle(data, **kwargs):
24+
def handle(data):
2525
app = current_app
2626
plugin_modules = app.plugin_modules if app else []
2727
docs = []

slack_bot/plugins/movie.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test(data):
6161
any([i in data['message'] for i in ['上映', '热映', '有什么', '将']])
6262

6363

64-
def handle(data, **kwargs):
64+
def handle(data):
6565
app = current_app
6666
message = data['message']
6767
if not isinstance(message, unicode):
@@ -80,5 +80,5 @@ def handle(data, **kwargs):
8080

8181

8282
if __name__ == '__main__':
83-
print handle({'message': '最近要将上映的电影'}, None)
84-
print handle({'message': '有什么电影 上海'}, None)
83+
print handle({'message': '最近要将上映的电影'})
84+
print handle({'message': '有什么电影 上海'})

slack_bot/plugins/orz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test(data):
4242
return False
4343

4444

45-
def handle(data, **kwargs):
45+
def handle(data):
4646
mobai_icon = ':mb:'
4747
return mobai_icon * random.randrange(1, 10)
4848

0 commit comments

Comments
 (0)