def is_going_to_2pmove(self, event): if len(self.history) % 2 == 1: if event.source.user_id != self.user1: return False else: if event.source.user_id != self.user2: return False text = event.message.text.lower() mv = self.board.is_legal_notation(text) if mv == False: push_text_message( event.source.room_id, 'Invalid notation, type \'help\' to get notation guide.') return False if len(self.history) % 2 == 1: stat = self.board.is_legal_move(mv, board.WHITE) else: stat = self.board.is_legal_move(mv, board.BLACK) if stat == False: push_text_message(event.source.room_id, 'Illegal move.') return False self.board.user_perform_move(mv, stat) self.history.append(board.Board.clone(self.board)) return True
def going_hsr_start_station(self, event=None): if event.message.type == 'text' and event.message.text in self.hsr_info.available_station: self.user.hsr_start_station = event.message.text return True else: push_text_message(self.user.user_id, '請選擇上方的車站') return False
def is_going_to_bus_start(self, event=None): if event.message.type == 'text' and event.message.text == '公車查詢': return True else: if not (event.message.type == 'text' and (event.message.text == 'reset' or event.message.text == 'bus' or event.message.text == '火車查詢' or event.message.text == '高鐵查詢')): push_text_message(self.user.user_id, '無法辨識...') return False
def is_going_to_bus_end(self, event=None): if event.message.type == 'text': if event.message.text in ['去程', '回程']: self.user.bus_direction = event.message.text estimates = self.bus_info.calculate(self.user.bus_route, self.user.bus_stops, self.user.bus_direction) contents = get_replay_flex('show_bus_time') contents['header']['contents'][0]['text'] = self.user.bus_route contents['header']['contents'][1][ 'text'] = self.user.bus_direction i = 1 # contents['body']['contents'][0]['contents'][1]['contents'][1]['borderColor'] = '#00FF00' # contents['body']['contents'][0]['contents'][1]['contents'][1]['backgroundColor'] = '#00FF00' real_time = 0 for key, value in estimates.items(): if i == 3: real_time = value[0] contents['body']['contents'][i]['contents'][2][ 'text'] = key if value[1] == 0: # 末班車已過 or 交管 contents['body']['contents'][i]['contents'][0][ 'text'] = f'{(timedelta(seconds = value[0])).seconds // 60} 分' if value[ 0] != None else '不停靠' elif value[1] == 1: contents['body']['contents'][i]['contents'][0][ 'text'] = f'{(timedelta(seconds = value[0])).seconds // 60} 分' if value[ 0] != None else '未發車' elif value[1] == 2: contents['body']['contents'][i]['contents'][0][ 'text'] = '交管不停靠' elif value[1] == 3: contents['body']['contents'][i]['contents'][0][ 'text'] = '末班車已過' elif value[1] == 4: contents['body']['contents'][i]['contents'][0][ 'text'] = '今日未營運' else: # 末班車已過 or 交管 contents['body']['contents'][i]['contents'][0][ 'text'] = '不停靠' i += 2 contents['header']['contents'][1][ 'text'] = self.user.bus_direction contents['body']['contents'][0][ 'text'] = f'預計到達時間: {int(real_time / 60)} 分鐘' if real_time != None else ' ' send_flex_message(event.reply_token, contents) return True else: push_text_message(self.user.user_id, '請輸入正確的方向') return False else: push_text_message(self.user.user_id, '請輸入正確的方向') return False
def going_bus_by_stop(self, event=None): if event.message.type != 'text': return False if event.message.text == '以站牌搜尋': return True else: # if event.message.type != 'location' and not (event.message.type == 'text' and (event.message.text == 'reset' or event.message.text == '以路線搜尋')): if not (event.message.text == 'reset' or event.message.text == '以路線搜尋'): push_text_message(self.user.user_id, '請點選上方的選項\n如要重來') return False
def going_train_time(self, event=None): if event.type == 'postback': self.user.train_date = event.postback.params['datetime'] times = self.train_info.calculate(self.user.train_start_station, self.user.train_end_station, self.user.train_date) contents = get_replay_flex('show_train_time') for t in times: copy_template = copy.deepcopy(train_time_template) copy_template['header']['contents'][0]['contents'][0][ 'contents'][1]['text'] = self.user.train_start_station copy_template['header']['contents'][0]['contents'][1][ 'contents'][1]['text'] = self.user.train_end_station copy_template['header']['contents'][1]['contents'][0][ 'text'] = f'車號 {t[2]}' # too long copy_template['header']['contents'][1]['contents'][1][ 'text'] = f'{t[3][:2]}' delay = self.train_info.delay(t[2]) if delay != 0: copy_template['body']['contents'][0]['contents'][1][ 'contents'][1]['borderColor'] = '#EF4520' copy_template['body']['contents'][0]['contents'][1][ 'contents'][1]['backgroundColor'] = '#EF4520' copy_template['body']['contents'][0]['contents'][2][ 'text'] = f'誤點 {int(delay / 60)} 分鐘' else: copy_template['body']['contents'][0]['contents'][2][ 'text'] = f'正常' td = datetime.strptime(t[1], "%H:%M") - \ datetime.strptime(t[0], "%H:%M") copy_template['body']['contents'][2][ 'text'] = f'Total: {td.seconds // 3600} hours {(td.seconds // 60) % 60} minutes' copy_template['body']['contents'][3]['contents'][0][ 'text'] = t[0] copy_template['body']['contents'][3]['contents'][2][ 'text'] = self.user.train_start_station copy_template['body']['contents'][5]['contents'][0][ 'text'] = t[1] copy_template['body']['contents'][5]['contents'][2][ 'text'] = self.user.train_end_station contents['contents'].append(copy_template) if len(times) == 0: send_text_message(event.reply_token, f"{self.user.train_date} 之後沒有可以搭乘的列車") else: send_flex_message(event.reply_token, contents) return True else: push_text_message(self.user.user_id, '請輸入正確的日期') return False
def going_train_end_station(self, event=None): if event.message.type == 'text' and event.message.text in self.train_info.available_station: if event.message.text == self.user.train_start_station: push_text_message(self.user.user_id, "起訖站不可相同") return False else: self.user.train_end_station = event.message.text return True else: push_text_message(self.user.user_id, '請選擇上方的車站') return False
def undo2(self, event): text = event.message.text.lower() if text != 'undo': return False if len(self.history) < 3: push_text_message(event.source.user_id, 'Could not undo.') return True self.history.pop() self.history.pop() self.board = self.history[len(self.history) - 1] return True
def is_going_to_requestundo(self, event): text = event.message.text.lower() if text == 'undo': if event.source.user_id == self.user1: self.undouser = self.user1 push_text_message(event.source.room_id, 'Accept undo? (y/n)') return True elif event.source.user_id == self.user2: self.undouser = self.user2 push_text_message(event.source.room_id, 'Accept undo? (y/n)') return True return False
def is_going_to_resign(self, event): text = event.message.text.lower() if text != 'resign': return False user_id = event.source.user_id if len(self.history) % 2 == 1: push_text_message(user_id, "Black Win!") else: push_text_message(user_id, "White Win!") self.board.remove(user_id) self.board = None return True
def going_bus_by_stop2(self, event=None): if event.message.type == 'text': if event.message.text not in self.bus_info.stops_to_route: push_text_message( self.user.user_id, f'找不到 {event.message.text} 站牌,目前只支援台南地區的公車站') return False else: self.user.bus_stops = event.message.text return True else: push_text_message(self.user.user_id, '請輸入公車站名字') return False
def is_going_to_2presign(self, event): text = event.message.text.lower() room_id = event.source.room_id if text == 'resign': if event.source.user_id == self.user1: push_text_message(room_id, "Black Win!") self.board.remove(room_id) return True elif event.source.user_id == self.user2: push_text_message(room_id, "White Win!") self.board.remove(room_id) return True return False
def goint_bus_by_route2(self, event=None): # get shop from number if event.message.type == 'text': if event.message.text not in self.bus_info.route_to_stops: push_text_message( self.user.user_id, f'找不到公車路線為 {event.message.text} 的公車,目前只支援台南地區的公車') return False else: self.user.bus_route = event.message.text return True else: push_text_message(self.user.user_id, '請輸入公車路線') return False
def going_bus_direction(self, event=None): # print result if self.user.bus_route == None: if event.message.type == 'text': if event.message.text in self.bus_info.route_to_stops: self.user.bus_route = event.message.text contents = get_replay_flex('bus_direction') push_flex_message(self.user.user_id, contents) return True else: push_text_message(self.user.user_id, '請點選上方的路線') return False else: push_text_message(self.user.user_id, '請點選上方的路線') return False else: if event.message.type == 'text': if event.message.text in self.bus_info.stops_to_route: self.user.bus_stops = event.message.text contents = get_replay_flex('bus_direction') push_flex_message(self.user.user_id, contents) return True else: push_text_message(self.user.user_id, '請點選上方的站牌名稱') return False else: push_text_message(self.user.user_id, '請點選上方的站牌名稱') return False
def going_hsr_time(self, event=None): if event.type == 'postback': self.user.hsr_date = event.postback.params['datetime'] times = self.hsr_info.calculate(self.user.hsr_start_station, self.user.hsr_end_station, self.user.hsr_date) contents = get_replay_flex('show_hsr_time') for t in times: copy_template = copy.deepcopy(rail_time_template) copy_template['header']['contents'][0]['contents'][0][ 'contents'][1]['text'] = self.user.hsr_start_station copy_template['header']['contents'][0]['contents'][1][ 'contents'][1]['text'] = self.user.hsr_end_station copy_template['header']['contents'][1]['contents'][0][ 'text'] = f'{t[2]}' available = self.hsr_info.available_seats( t[2], t[3], self.user.hsr_date, self.user.hsr_start_station) if not available: copy_template['body']['contents'][0]['contents'][1][ 'contents'][1]['borderColor'] = '#EF4520' copy_template['body']['contents'][0]['contents'][1][ 'contents'][1]['backgroundColor'] = '#EF4520' copy_template['body']['contents'][0]['contents'][2][ 'text'] = '沒有空位' td = datetime.strptime(t[1], "%H:%M") - \ datetime.strptime(t[0], "%H:%M") copy_template['body']['contents'][2][ 'text'] = f'Total: {td.seconds // 3600} hours {(td.seconds // 60) % 60} minutes' copy_template['body']['contents'][3]['contents'][0][ 'text'] = t[0] copy_template['body']['contents'][3]['contents'][2][ 'text'] = self.user.hsr_start_station copy_template['body']['contents'][5]['contents'][0][ 'text'] = t[1] copy_template['body']['contents'][5]['contents'][2][ 'text'] = self.user.hsr_end_station contents['contents'].append(copy_template) if len(times) == 0: send_text_message(event.reply_token, f'{self.user.hsr_date} 之後沒有可以搭乘的列車') else: send_flex_message(event.reply_token, contents) return True else: push_text_message(self.user.user_id, '請輸入正確的日期') return False
def is_going_to_cancel(self, event): text = event.message.text.lower() if text == 'cancel': if self.user1 == None and event.source.user_id == self.user2: push_text_message(event.source.room_id, 'Game canceled') return True if self.user2 == None and event.source.user_id == self.user1: push_text_message(event.source.room_id, 'Game canceled') return True push_text_message(event.source.room_id, 'Only One who creates the game can cancel.') return False
def on_enter_userplayblack(self, event): stamp = str(datetime.now().timestamp()) user_id = event.source.user_id self.board.draw(user_id, stamp) r = int((len(self.history) + 1) / 2) board_info = 'Round ' + str(r) + ', black\'s turn.' push_text_message(user_id, board_info) push_image_message(user_id, domain + '/' + user_id + '/' + stamp) if self.board.is_win(pieces.Piece.WHITE): push_text_message(user_id, 'White win!') self.board.remove(user_id) self.go_back(event) return if self.board.is_check(pieces.Piece.BLACK): push_text_message(user_id, 'Check!')
def is_going_to_replyundo(self, event): text = event.message.text.lower() if (self.undouser == self.user1 and event.source.user_id == self.user2)\ or (self.undouser == self.user2 and event.source.user_id == self.user1): if text == 'n': push_text_message(event.source.room_id, 'Reject undo.') elif text == 'y': if len(self.history) < 2: push_text_message(event.source.room_id, 'Could not undo.') else: self.history.pop() self.board = self.history[len(self.history) - 1] return True if text == 'n' or text == 'y': push_text_message(event.source.room_id, 'Only players can reply undo.') return False
def on_enter_botplaywhite(self, event): stamp = str(datetime.now().timestamp()) room_id = event.source.room_id self.board.draw(room_id, stamp) r = int((len(self.history) + 1) / 2) board_info = 'Round ' + str(r) + ', white\'s turn.' push_text_message(room_id, board_info) push_image_message(room_id, domain + '/' + room_id + '/' + stamp) if self.board.is_win(pieces.Piece.BLACK): push_text_message(room_id, 'Black win!') self.board.remove(room_id) self.go_back(event) return if self.board.is_check(pieces.Piece.WHITE): push_text_message(room_id, 'Check!') self.advance(event)
def on_enter_my_favorite(self, event): SwitchMenuTo("myfavorite", event) my_favorite_confirm(event) push_text_message(event, "這是我的最愛唷!")
def on_enter_user(self, event=None): if self.user.user_id != None: push_text_message(self.user.user_id, '歡迎使用時刻表查詢系統,輸入任意文字開始')
def on_enter_search_movie(self, event): SwitchMenuTo("searchmovie", event) push_text_message(event, "請輸入欲查詢電影!")
def on_enter_creategame(self, event): push_text_message( event.source.room_id, 'Game created. Waiting for another player to join the game.')
def on_enter_room(self, event): print("enter the room") reply_token = event.reply_token send_text_message(reply_token, "\"還是進去休息一下好了,反正看這一路上都沒有人應該不會有問題。\"男子想道。") source_id = event.source.user_id push_text_message(source_id, "稍作休息之後,男子起身便欲離開,出門之前突然看到旁邊桌上有著兩個打開的盒子,男子便好奇的上前查看。\n\"是一顆小鑽石!!但另一盒卻是一顆足有拳頭大的石頭\"男子看到桌上還留有一張紙條,紙條上寫道:\n\"有緣人,你可以隨機挑走一樣物品,就當作是我留給你的鑑別禮 By屋主\"\n[請選擇\"小鑽石\"或是\"大石頭\"]")
def on_enter_crow(self, event): print("meet the crow") reply_token = event.reply_token send_text_message(reply_token, "走著走著,發現路旁有一隻烏鴉帶著一瓶裝滿石頭的燒杯,同時不斷的把嘴巴往瓶口內塞,似乎想喝到裡面的水,你好奇的上前查看了一下,沒想到烏鴉竟然開口說話了。") source_id = event.source.user_id push_text_message(source_id, "\"年輕人,我好渴,如果你可以幫助我喝到裡面的水,我將滿足你一個願望。\"烏鴉向你求救。") if rock == 0: # don't have things on hand push_text_message(source_id, "但你身上並沒有任何東西能夠幫助到烏鴉,只能眼睜睜的看著烏鴉繼續乾著急著。\n烏鴉就此渴死了,而你則繼續流浪在這個世界,徘徊流浪著直到最後。") push_text_message(source_id, "(BAD END)\n[請輸入\"開始\"來開啟一段新的故事]") elif rock == 1: # got the diamond push_text_message(source_id, "此時的你想到了剛剛拿到的鑽石,想著這個應該可以幫助到牠,就將你拿到的鑽石丟了進去。\n沒想到鑽石太小了,丟進去竟沒有讓水位高多少,烏鴉還是喝不到牠想要的水。\n烏鴉就此渴死了,而你則繼續流浪在這個世界,徘徊流浪著直到最後。") push_text_message(source_id, "(BAD END)\n[請輸入\"開始\"來開啟一段新的故事]") else: push_text_message(source_id, "此時的你想到了剛剛拿到的石頭,想著這個應該可以幫助到牠,就將你拿到的石頭丟了進去。\n當石頭丟進燒杯後,燒杯的水剛剛好滿了,烏鴉成功喝到了水。\n\"年輕人,謝謝你,說吧你想要甚麼願望?\"滿足的烏鴉回過頭來向你問道。\n你趁機向牠說明想要回到家裡,烏鴉點點頭,叫了兩聲之後,你的腳下出現了魔法陣,此時的你才發現這隻烏鴉竟然會施展魔法!") push_text_message(source_id, "一陣頭暈目眩之後,醒來的你已經躺在家裡的床上了,剛剛的一切只不過像是夢境一般曇花一現,故事也到此結束。") push_text_message(source_id, "(TRUE END)\n[請輸入\"開始\"來開啟一段新的故事]") self.go_back_to_user()
def on_enter_game_lobby(self, event): SwitchMenuTo("gamemenu", event) push_text_message(event, "歡迎來到猜拳小遊戲") push_text_message(event, "請選擇下方選項~")
def on_enter_search_animate(self, event): SwitchMenuTo("searchanimate", event) push_text_message(event, "請輸入欲查詢動畫!")
def on_enter_user(self, event=None): print("Enter user") push_text_message(self.user, "請選擇輸入模式:\n\t1 bin hex dec\n\t2 重量單位換算\n\t3 長度單位換算\n\t4 graph")
def on_enter_main_menu(self, event): SwitchMenuTo("mainmenu", event) push_text_message(event, "歡迎來到Have Fun!") push_text_message(event, "請使用下方選單進行操作~")