-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnew_bot.py
466 lines (414 loc) · 15.7 KB
/
new_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
from flask import Flask, request, abort
from linebot import (
LineBotApi, WebhookHandler
)
from linebot.exceptions import (
InvalidSignatureError
)
from linebot.models import (
MessageEvent, TextMessage, TextSendMessage,
SourceUser, SourceGroup, SourceRoom,
TemplateSendMessage, ConfirmTemplate, MessageAction,
ButtonsTemplate, ImageCarouselTemplate, ImageCarouselColumn, URIAction,
PostbackAction, DatetimePickerAction,
CameraAction, CameraRollAction, LocationAction,
CarouselTemplate, CarouselColumn, PostbackEvent,
StickerMessage, StickerSendMessage, LocationMessage, LocationSendMessage,
ImageMessage, VideoMessage, AudioMessage, FileMessage,
UnfollowEvent, FollowEvent, JoinEvent, LeaveEvent, BeaconEvent,
FlexSendMessage, BubbleContainer, ImageComponent, BoxComponent,
TextComponent, SpacerComponent, IconComponent, ButtonComponent,
SeparatorComponent, QuickReply, QuickReplyButton, Base,
)
import numpy as np
from PIL import ImageGrab
import cv2
import time
import threading
from pyautogui import press, typewrite, hotkey
import cv2
import numpy as np
from matplotlib import pyplot as plt
import json
import random
import threading
#json test
jsondata = {
"type": "bubble",
"hero": {
"type": "image",
"url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_2_restaurant.png",
"size": "full",
"aspectRatio": "20:13",
"aspectMode": "cover",
"action": {
"type": "uri",
"uri": "https://linecorp.com"
}
},
"body": {
"type": "box",
"layout": "vertical",
"spacing": "md",
"action": {
"type": "uri",
"uri": "https://linecorp.com"
},
"contents": [
{
"type": "text",
"text": "Brown's Burger",
"size": "xl",
"weight": "bold"
},
{
"type": "box",
"layout": "vertical",
"spacing": "sm",
"contents": [
{
"type": "box",
"layout": "baseline",
"contents": [
{
"type": "icon",
"url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/restaurant_regular_32.png"
},
{
"type": "text",
"text": "$10.5",
"weight": "bold",
"margin": "sm",
"flex": 0
},
{
"type": "text",
"text": "400kcl",
"size": "sm",
"align": "end",
"color": "#aaaaaa"
}
]
},
{
"type": "box",
"layout": "baseline",
"contents": [
{
"type": "icon",
"url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/restaurant_large_32.png"
},
{
"type": "text",
"text": "$15.5",
"weight": "bold",
"margin": "sm",
"flex": 0
},
{
"type": "text",
"text": "550kcl",
"size": "sm",
"align": "end",
"color": "#aaaaaa"
}
]
}
]
},
{
"type": "text",
"text": "Sauce, Onions, Pickles, Lettuce & Cheese",
"color": "#aaaaaa",
"size": "xxs"
}
]
},
"footer": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "spacer",
"size": "xxl"
},
{
"type": "button",
"style": "primary",
"color": "#905c44",
"action": {
"type": "uri",
"label": "Add to Cart",
"uri": "https://linecorp.com"
}
}
]
}
}
jstr = json.dumps(jsondata)
print(jstr)
#Line app setting
app = Flask(__name__)
#0857
line_bot_api2 = LineBotApi('bWwBmKcECNbWVh1qzRo2ITtlWX96LR/aIV+rN2iRzaNIb4Axdy2mravOnYg8QZXUyYw8a7epEmKMyW+7IlWaB5DUtHNMtqcnn1+Nniu/4e83ftYW/PnfOX2HE5N+PYowuGQX0CcNW04QGxHB5NbRWwdB04t89/1O/w1cDnyilFU=')
handler2 = WebhookHandler('29d785907d4c3537c1f3ab4c9d2680eb')
@app.route("/callback", methods=['POST'])
def callback():
# get X-Line-Signature header value
signature = request.headers['X-Line-Signature']
# get request body as text
body = request.get_data(as_text=True)
app.logger.info("Request body: " + body)
# handle2 webhook body
try:
handler2.handle(body, signature)
except InvalidSignatureError:
print("Handler2")
# abort(400)
return 'OK'
@handler2.add(PostbackEvent)
def handle2_postback(event):
if event.postback.data == "註冊":
strange_id = event.source.user_id
Users_data = np.load("Database2.npy")
if any (strange_id in s[0] for s in Users_data):
for i in range(len(Users_data)):
if strange_id in Users_data[i][0]:
if Users_data[i][6] != "":
print("already register")
line_bot_api2.reply_message(event.reply_token,TextSendMessage("重複註冊!"))
else:
print("not support lineID")
line_bot_api2.reply_message(event.reply_token,TextSendMessage("尚未提供LineID,請輸入您的LineID,格式「ID=xxxxxx」。\n\n若未正確設定LineID將無法使用報牌系統。!"))
else:
print(event.source.user_id)
Users_data = np.append(Users_data, [[strange_id, "無", "無", "無", "無", "無", "", 1]], axis=0)
np.save("Database2.npy", Users_data)
line_bot_api2.reply_message(event.reply_token,TextSendMessage("請輸入您的LineID,格式「ID=xxxxxx」。\n\n若未正確設定LineID將無法使用報牌系統。"))
elif event.postback.data == '開啟':
strange_id = event.source.user_id
Users_data = np.load("Database2.npy")
open_i = 0
for i in range(len(Users_data)):
if strange_id in Users_data[i][0]:
open_i = i
break
if open_i != 0:
Users_data[open_i][7] = 1
np.save("Database2.npy", Users_data)
print("Close Notice")
line_bot_api2.reply_message(event.reply_token,TextSendMessage("報牌通知開啟!"))
elif event.postback.data == "Confirm":
strange_id = event.source.user_id
Users_data = np.load("Database2.npy")
if any (strange_id in s[0] for s in Users_data):
confirm_template_message = TemplateSendMessage(
alt_text='Confirm template',
template=ConfirmTemplate(
text='報牌通知設定',
actions=[
PostbackAction(
label='開啟通知',
data='開啟'
),
PostbackAction(
label='取消通知',
data='取消'
)
]
)
)
line_bot_api2.reply_message(event.reply_token, confirm_template_message)
else:
print("weird guy")
line_bot_api2.reply_message(event.reply_token,TextSendMessage("您尚未註冊!"))
elif event.postback.data == "取消":
strange_id = event.source.user_id
Users_data = np.load("Database2.npy")
stop_i = 0
for i in range(len(Users_data)):
if strange_id in Users_data[i][0]:
stop_i = i
break
if stop_i != 0:
Users_data[stop_i][7] = 0
np.save("Database2.npy", Users_data)
print("Close Notice")
line_bot_api2.reply_message(event.reply_token,TextSendMessage("報牌通知關閉!"))
elif event.postback.data == "使用教學":
some_onesId = event.source.user_id
line_bot_api2.push_message(some_onesId,TextSendMessage(help_strings))
elif event.postback.data == "套路清單":
strange_id = event.source.user_id
Users_data = np.load("Database2.npy")
if any (strange_id in s[0] for s in Users_data):
for i in range(len(Users_data)):
if strange_id in Users_data[i][0]:
if Users_data[i][6] != "":
list_strategys = "您的套路清單:"
for j in range(6):
if j != 0:
list_strategys += "\n\n套路"+str(j)+" = "+Users_data[i][j]
line_bot_api2.reply_message(event.reply_token,TextSendMessage(list_strategys))
else:
print("not support lineID")
line_bot_api2.reply_message(event.reply_token,TextSendMessage("尚未提供LineID,請輸入您的LineID,格式「ID=xxxxxx」。\n\n若未正確設定LineID將無法使用報牌系統。!"))
else:
print(event.source.user_id)
line_bot_api2.reply_message(event.reply_token,TextSendMessage("您尚未註冊!"))
@handler2.add(MessageEvent, message=TextMessage)
def handle2_message(event):
if event.message.text == 'flex':
bubble = BubbleContainer(
direction='ltr',
hero=ImageComponent(
url='https://example.com/cafe.jpg',
size='full',
aspect_ratio='20:13',
aspect_mode='cover',
action=URIAction(uri='http://example.com', label='label')
),
body=BoxComponent(
layout='vertical',
contents=[
# title
TextComponent(text='Brown Cafe', weight='bold', size='xl'),
# review
BoxComponent(
layout='baseline',
margin='md',
contents=[
IconComponent(size='sm', url='https://example.com/gold_star.png'),
IconComponent(size='sm', url='https://example.com/grey_star.png'),
IconComponent(size='sm', url='https://example.com/gold_star.png'),
IconComponent(size='sm', url='https://example.com/gold_star.png'),
IconComponent(size='sm', url='https://example.com/grey_star.png'),
TextComponent(text='4.0', size='sm', color='#999999', margin='md',
flex=0)
]
),
# info
BoxComponent(
layout='vertical',
margin='lg',
spacing='sm',
contents=[
BoxComponent(
layout='baseline',
spacing='sm',
contents=[
TextComponent(
text='Place',
color='#aaaaaa',
size='sm',
flex=1
),
TextComponent(
text='Shinjuku, Tokyo',
wrap=True,
color='#666666',
size='sm',
flex=5
)
],
),
BoxComponent(
layout='baseline',
spacing='sm',
contents=[
TextComponent(
text='Time',
color='#aaaaaa',
size='sm',
flex=1
),
TextComponent(
text="10:00 - 23:00",
wrap=True,
color='#666666',
size='sm',
flex=5,
),
],
),
],
)
],
),
footer=BoxComponent(
layout='vertical',
spacing='sm',
contents=[
# callAction, separator, websiteAction
SpacerComponent(size='sm'),
# callAction
ButtonComponent(
style='link',
height='sm',
action=URIAction(label='CALL', uri='tel:000000'),
),
# separator
SeparatorComponent(),
# websiteAction
ButtonComponent(
style='link',
height='sm',
action=URIAction(label='WEBSITE', uri="https://example.com")
)
]
),
)
message = FlexSendMessage(alt_text="hello", contents=bubble)
line_bot_api2.reply_message(
event.reply_token,
message
)
elif event.message.text == 'flex2':
jsonToDict = json.loads(jstr)
bubble = BubbleContainer.new_from_json_dict(jsonToDict)
message = FlexSendMessage(alt_text="hello", contents=bubble)
line_bot_api2.reply_message(
event.reply_token,
message
)
else:
message = TemplateSendMessage(
alt_text='Carousel template',
template=CarouselTemplate(
columns=[
CarouselColumn(
thumbnail_image_url='https://www.ultraegaming.com/wp-content/uploads/2017/10/%E7%99%BE%E5%AE%B6%E6%A8%82-1-2.jpg',
title='莫地百家樂',
text='歡迎使用本系統,請跟隨指示操作。',
actions=[
PostbackAction(
label='註冊會員',
data='註冊'
),
PostbackAction(
label='報牌通知設定',
data='Confirm'
)
]
),
CarouselColumn(
thumbnail_image_url='https://www.triplecrowncasinos.com/wp-content/uploads/2016/07/casinos-in-colorado.jpg',
title='您的套路',
text='您可以自訂套路,並且可設定最多五組。',
actions=[
PostbackAction(
label='套路清單',
data='套路清單'
),
PostbackTemplateAction(
label='套路設定教學',
data='使用教學'
)
]
)
]
)
)
line_bot_api2.reply_message(event.reply_token, message)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)