Created
October 25, 2019 15:46
-
-
Save RPHAELLA/68081e27e97953cbb547c64c5f5ab965 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys, time, telepot | |
from telepot.loop import MessageLoop | |
wordlist = None | |
abbreviationlist = None | |
userchatlist = {} | |
def handle(msg): | |
global wordlist | |
global abbreviationlist | |
global userchatlist | |
content_type, chat_type, chat_id = telepot.glance(msg) | |
#print(msg) | |
print(content_type, chat_type, chat_id) | |
if '/new' in msg['text']: | |
userchatlist[msg['from']['id']] = chat_id | |
bot.sendMessage(msg['from']['id'], 'Hello ' + msg['from']['username'] + ', please set your question using /set') | |
if '/set' in msg['text']: | |
if wordlist == None: | |
wordlist = msg['text'].split(' ') | |
wordlist.pop(0) | |
abbreviation = ' '.join(word[:1].upper() for word in wordlist) | |
abbreviationlist = abbreviation.split(' ') | |
message = "Q: " + abbreviation | |
else: | |
message = "Previous question still ongoing." | |
bot.sendMessage(userchatlist[msg['from']['id']], message) | |
if '/stop' in msg['text']: | |
wordlist = None | |
abbreviationlist = None | |
message = "Question removed." | |
bot.sendMessage(chat_id, message) | |
if '/' not in msg['text'] and wordlist != None and abbreviationlist != None: | |
guesslist = msg['text'].split(' ') | |
for index, item in enumerate(wordlist): | |
for guess in guesslist: | |
if guess.lower() == item.lower(): | |
abbreviationlist[index] = item | |
abbreviation = ' '.join(abbreviationlist) | |
bot.sendMessage(chat_id, abbreviation) | |
if wordlist == abbreviationlist: | |
bot.sendMessage(chat_id, "Abbreviation Solved!") | |
wordlist = None | |
abbreviationlist = None | |
#TOKEN = sys.argv[1] # get token from command-line | |
TOKEN = '' | |
bot = telepot.Bot(TOKEN) | |
MessageLoop(bot, handle).run_as_thread() | |
print ('Listening ...') | |
# Keep the program running. | |
while 1: | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment