Uploaded Velasco v1.2:

- Added /speak command.
- Fixed typo at /freq.
- Fixed setting /freq 0.
This commit is contained in:
vylion 2017-09-19 13:50:16 +02:00
parent cb33edc3cd
commit 13838527bb

View file

@ -60,6 +60,7 @@ def help(bot, update):
/help - I send this message. /help - I send this message.
/count - I tell you how many messages from this chat I remember. /count - I tell you how many messages from this chat I remember.
/freq - Change the frequency of both my messages and the times I save my learned vocabulary. /freq - Change the frequency of both my messages and the times I save my learned vocabulary.
/speak - Forces me to speak.
""") """)
def about(bot, update): def about(bot, update):
@ -94,11 +95,28 @@ def read(bot, update):
chatlog.add_msg(update.message.text) chatlog.add_msg(update.message.text)
if chatlog.get_count()%chatlog.freq == 0: if chatlog.get_count()%chatlog.freq == 0:
msg = chatlog.speak() msg = chatlog.speak()
# TO DO: añadir % de que haga reply en vez de send
bot.sendMessage(chatlog.id, msg) bot.sendMessage(chatlog.id, msg)
savechat(chatlog) savechat(chatlog)
chatlogs[chatlog.id] = chatlog chatlogs[chatlog.id] = chatlog
def speak(bot, update):
global chatlogs
ident = str(update.message.chat.id)
if not ident in chatlogs:
chat = update.message.chat
title = get_chatname(chat)
chatlog = Chatlog(chat.id, chat.type, title)
else:
chatlog = chatlogs[ident]
chatlog.add_msg(update.message.text)
msg = chatlog.speak()
update.message.reply_text(msg)
savechat(chatlog)
chatlogs[chatlog.id] = chatlog
def get_chatlogs(bot, update): def get_chatlogs(bot, update):
global GUILLERMO_ID global GUILLERMO_ID
if update.message.chat.id is GUILLERMO_ID: if update.message.chat.id is GUILLERMO_ID:
@ -130,10 +148,12 @@ def set_freq(bot, update):
try: try:
value = update.message.text.split()[1] value = update.message.text.split()[1]
value = int(value) value = int(value)
if not value > 0:
raise ValueError('Tried to set 0 or negative freq value.')
chatlogs[ident].set_freq(value) chatlogs[ident].set_freq(value)
reply = "Frequency of speaking set to " + str(value) reply = "Frequency of speaking set to " + str(value)
except: except:
reply = "Format was confusing; requency not changed from " + str(chatlogs[ident].freq) reply = "Format was confusing; frequency not changed from " + str(chatlogs[ident].freq)
update.message.reply_text(reply) update.message.reply_text(reply)
def stop(bot, update): def stop(bot, update):
@ -162,6 +182,7 @@ def main():
dp.add_handler(CommandHandler("freq", set_freq)) dp.add_handler(CommandHandler("freq", set_freq))
dp.add_handler(CommandHandler("list", get_chatlogs)) dp.add_handler(CommandHandler("list", get_chatlogs))
dp.add_handler(CommandHandler("stop", stop)) dp.add_handler(CommandHandler("stop", stop))
dp.add_handler(CommandHandler("speak", speak))
# on noncommand i.e message - echo the message on Telegram # on noncommand i.e message - echo the message on Telegram
# dp.add_handler(MessageHandler(Filters.text, echo)) # dp.add_handler(MessageHandler(Filters.text, echo))