-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from jiahao42/pytorch
Update telegram bots
- Loading branch information
Showing
7 changed files
with
82 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters | ||
from chatbot import telegram_init | ||
from evaluate import evaluateExample | ||
|
||
speakers = { | ||
'cartman': '771434365:AAE8bpXZ6QMizyZxmvr6Mke6pOUFW0suN9E', | ||
'stan': '797666745:AAG5L9qHQgQIERXFf47mD1QdatLEfXH0p2c', | ||
'kyle': '798154398:AAGHAUZ8l-Zi_bMr8KrRwkZ1svju1_fW2S8', | ||
'randy': '764465736:AAHeOYQMHStGNPZ1gNaPl2dZEiuorvBi_fI', | ||
'<none>': '773092951:AAHMltKlernAmXHvO_TQ3B6mzkY1mv61rQc' | ||
} | ||
|
||
|
||
class TeleBot: | ||
def __init__(self, speaker, token): | ||
self.speaker = speaker | ||
self.token = token | ||
def run(self): | ||
searcher, word_map, speaker_id = telegram_init(self.speaker) | ||
updater = Updater(token=self.token) | ||
dispatcher = updater.dispatcher | ||
def start(bot, update): | ||
bot.send_message(chat_id=update.message.chat_id, text=evaluateExample( | ||
"", | ||
searcher, | ||
word_map, | ||
speaker_id)) | ||
start_handler = CommandHandler('start', start) | ||
dispatcher.add_handler(start_handler) | ||
def response(bot, update): | ||
bot.send_message( | ||
chat_id=update.message.chat_id, | ||
text=evaluateExample( | ||
update.message.text, | ||
searcher, | ||
word_map, | ||
speaker_id)) | ||
message_handler = MessageHandler(Filters.text, response) | ||
dispatcher.add_handler(message_handler) | ||
updater.start_polling() | ||
print(f'Telegram bot {self.speaker} has started') | ||
|
||
if __name__ == '__main__': | ||
for speaker, token in speakers.items(): | ||
bot = TeleBot(speaker, token) | ||
bot.run() | ||
|
||
|
||
|