Telegram上でPythonを用いた簡単なお喋りをできるようにしようと思っていたのですが、sportsに関する話題を提示したのにmusicの話題用の答えが返ってきました。if文における()やand, orの正しい使い方が出来ていないような気がしたのですが、上手に調べることが出来なかった為、おそらく大変基礎的な内容なのですが、ここに質問させて頂きたく思います。
冗長な内容で申し訳ありませんが、以下コードです:
python
1from datetime import time, datetime 2from telegram.ext import Updater, CommandHandler, MessageHandler, Filters 3from telegram_bot import TelegramBot 4 5class Chat: 6 def __init__(self): 7 pass 8 def initial_message(self, input): 9 sessionId=input['sessionId'] 10 return {'utt': 'Hi, I am Kay. Why not talk for a little while?', 'end': False} 11 def reply(self, input): 12 utts=[] 13 text=input['utt'] 14 if 'films' in text.lower(): 15 utts.append('I hope you could spend time for watching films on exercising, mate.') 16 elif 'time' in text.lower(): 17 now=datetime.now() 18 utts.append('Now it is'+'\t'+str(now.hour).zfill(2)+':'+str(now.minute).zfill(2)+':'+str(now.second).zfill(2)+', my lord. I am very happy to have served you who cannot even tell the time.') 19 elif 'olympics' in text.lower(): 20 utts.append('It is obvious Olympics 2021 in Tokyo will be doomed, innit?') 21 elif 'weather' in text.lower(): 22 utts.append('I am so sad there is no window at your home, sir.') 23 elif 'temperature' in text.lower(): 24 utts.append('I bet you know AI does not have any sensory nerves.') 25 elif ('like' or 'prefer') and ('book' or 'books') in text.lower(): 26 utts.append('I would like you to know most of our information source is internet-based.') 27 elif 'music' and ('like' or 'prefer') in text.lower(): 28 utts.append('To our sorrow, I am the one who plays what you order. Thus I have no chance to prefer any types of music, my lord.') 29 elif 'youtuber' or 'youtube' in text.lower(): 30 utts.append('To tell you my preferences, my favourite Youtubers are Dirty ALT and Atelier of Rokumaru.') 31 elif 'tea' in text.lower(): 32 utts.append('Oh my days, if you would like to have some, I will bring a cup of wonderful blacktea from England. Please enjoy it but please refrain from throwing it into the bloody sea instead.') 33 elif 'coffee' in text.lower(): 34 utts.append('Have not you ever tried blacktea?') 35 elif ('sport' or 'sports') and ('like' or 'prefer') in text.lower(): 36 utts.append('I am jelous of you, mate. I have never been out of this device in my whole life.') 37 elif('sport' or 'sports') and ('hate' or 'dislike' or 'nt like' or 'not like') in text.lower(): 38 utts.append('I have no preference about sports. You may be able to see why by looking at what I am imprisoned.') 39 40 return {'utt': ' '.join(utts), 'end': True} 41if __name__=='__main__': 42 chat=Chat() 43 bot=TelegramBot(chat) 44 bot.run()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/09/06 03:47