def hello(): now = datetime.now() greet = '' twh = int(now.hour + 8) if twh > 24: twh = twh - 24 if twh < 12: greet = '早安!' elif twh < 14: greet = '午安!' elif twh < 18: greet = '下午好!' else: greet = '晚安!' casttext = name + '對大家說:大家' + greet remessage = TextSendMessage(text=casttext) userids = mongodb.get_all_userid('users') msgs = StickerSendMessage( package_id='1', #sticker_id=random.randint(1,15) sticker_id='2') line_bot_api.multicast(userids, remessage) line_bot_api.multicast(userids, msgs)
def handle_message(event): ''' 當收到使用者訊息的時候 ''' profile = line_bot_api.get_profile(event.source.user_id) name = profile.display_name uid = profile.user_id message = event.message.text print(name) print(uid) print(message) if mongodb.get_ready(uid, 'users') == 1: mongodb.update_byid(uid, {'ready': 0}, 'users') casttext = name + ' 對大家說: ' + message remessage = TextSendMessage(text=casttext) userids = mongodb.get_all_userid('users') line_bot_api.multicast(userids, remessage) return 0 if message == '群體廣播': # 設定使用者下一句話要群廣播 mongodb.update_byid(uid, {'ready': 1}, 'users') remessage = TextSendMessage(text='請問要廣播什麼呢?') line_bot_api.reply_message(event.reply_token, remessage) return 0 if re.search('Hi|hello|你好|ha', message, re.IGNORECASE): line_bot_api.reply_message(event.reply_token, TextSendMessage(text=event.message.text)) return 0 if re.search('新聞|news', event.message.text, re.IGNORECASE): dic = corwler.udn_news() columns = [] for i in range(0, 3): carousel = CarouselColumn( thumbnail_image_url=dic[i]['img'], title=dic[i]['title'], text=dic[i]['summary'], actions=[URITemplateAction(label='點我看新聞', uri=dic[i]['link'])]) columns.append(carousel) remessage = TemplateSendMessage( alt_text='Carousel template', template=CarouselTemplate(columns=columns)) line_bot_api.reply_message(event.reply_token, remessage) return 0 if re.search('Dcard|dcard', event.message.text, re.IGNORECASE): text = corwler.Dcard() line_bot_api.reply_message(event.reply_token, TextSendMessage(text=text)) return 0 if message == 'googlemap': # 取得最新評價 text = corwler.google() # 包裝訊息 remessage = TextSendMessage(text=text) # 回應使用者 line_bot_api.reply_message(event.reply_token, remessage) return 0 line_bot_api.reply_message(event.reply_token, TextSendMessage(text=event.message.text)) return 0
def handle_message(event): ''' 當收到使用者訊息的時候 ''' profile = line_bot_api.get_profile(event.source.user_id) name = profile.display_name uid = profile.user_id message = event.message.text print(name) print(uid) print(message) dic = { 'userid': uid, 'username': name, 'creattime': datetime.now(), 'mess': message } mongodb.insert_one(dic, 'message') if mongodb.get_ready(uid, 'users') == 1: mongodb.update_byid(uid, {'ready': 0}, 'users') casttext = name + ' 對大家說: ' + message remessage = TextSendMessage(text=casttext) userids = mongodb.get_all_userid('users') line_bot_api.multicast(userids, remessage) return 0 #關鍵評論網 if re.search('theNewLens', event.message.text, re.IGNORECASE): columns = [] img = 'https://image3.thenewslens.com/assets/web/cover-photo-medium.png' carousel = CarouselColumn(thumbnail_image_url=img, title='關鍵評論網新聞', text='點擊觀看類型', actions=[ MessageTemplateAction(label='科學', text='關鍵評論科學'), MessageTemplateAction(label='商業', text='關鍵評論商業'), MessageTemplateAction(label='職場', text='關鍵評論職場') ]) columns.append(carousel) remessage = TemplateSendMessage( alt_text='Carousel template', template=CarouselTemplate(columns=columns)) line_bot_api.reply_message(event.reply_token, remessage) return 0 if re.search('關鍵評論科學', event.message.text, re.IGNORECASE): dic = corwler.theNewLens('science') makeCard(dic, event) return 0 if re.search('關鍵評論商業', event.message.text, re.IGNORECASE): dic = corwler.theNewLens('business') makeCard(dic, event) return 0 if re.search('關鍵評論職場', event.message.text, re.IGNORECASE): dic = corwler.theNewLens('career') makeCard(dic, event) return 0 #科技報橘 if re.search('科技報橘ai', event.message.text, re.IGNORECASE): #人工智慧 dic = corwler.techorangeAi() makeCard(dic, event) if re.search('科技報橘全部', event.message.text, re.IGNORECASE): #全部 dic = corwler.techorange() makeCard(dic, event) #泛科學 if re.search('泛科學', event.message.text, re.IGNORECASE): dic = corwler.Pansci() makeCard(dic, event)