|
@@ -22,13 +22,13 @@ class TaleHandler:
|
|
|
self.cur_authors = [] # list of tuples (user_id, prompt_msg_id)
|
|
|
self.cur_tales = [] # list of Tale objects (tales to be added to db)
|
|
|
|
|
|
- def prompt_user(self, bot, update):
|
|
|
+ def prompt_user(self, update, context):
|
|
|
"""Prompt user to tell a tale. It will be added to database if upvoted
|
|
|
at least three times
|
|
|
"""
|
|
|
- if update.message.chat.type != Chat.GROUP:
|
|
|
- update.message.reply_text(text='We need to be in a group chat to '
|
|
|
- 'add a new tale or anecdote!')
|
|
|
+ ctype=update.message.chat.type
|
|
|
+ if update.message.chat.type != Chat.GROUP and update.message.chat.type != Chat.SUPERGROUP :
|
|
|
+ update.message.reply_text(text='You need to be in the official LCM group chat to add a new tale or anecdote!')
|
|
|
return
|
|
|
user = update.message.from_user
|
|
|
prompt_msg = update.message.reply_text(
|
|
@@ -36,7 +36,7 @@ class TaleHandler:
|
|
|
reply_markup=ForceReply(selective=True))
|
|
|
self.cur_authors.append((user.id, prompt_msg.message_id))
|
|
|
|
|
|
- def handle_new_tale(self, bot, update):
|
|
|
+ def handle_new_tale(self, update, context):
|
|
|
"""Start the upvoting procedure when a new tale is received"""
|
|
|
tale_msg = update.message
|
|
|
author = tale_msg.from_user
|
|
@@ -59,7 +59,7 @@ class TaleHandler:
|
|
|
text='Alright, I need three upvotes to add this tale to my database',
|
|
|
reply_markup=keyboard)
|
|
|
|
|
|
- def save_tale(self, bot, update):
|
|
|
+ def save_tale(self, update, context):
|
|
|
"""Add tale to db when upvoted three times"""
|
|
|
query = update.callback_query
|
|
|
voter = query.from_user
|
|
@@ -73,37 +73,26 @@ class TaleHandler:
|
|
|
|
|
|
if voter.id == t.author.id:
|
|
|
# authors cannot upvote their own story
|
|
|
- bot.answer_callback_query(
|
|
|
- callback_query_id=query.id,
|
|
|
- text="Nope, can't upvote your own tale")
|
|
|
+ query.answer(text="Nope, can't upvote your own tale")
|
|
|
elif voter.id in t.upvoters_id:
|
|
|
- bot.answer_callback_query(
|
|
|
- callback_query_id=query.id,
|
|
|
- text='One upvote per person, sorry')
|
|
|
+ query.answer(text='One upvote per person, sorry')
|
|
|
else:
|
|
|
t.upvoters_id.append(voter.id)
|
|
|
t.upvotes += 1
|
|
|
- bot.answer_callback_query(
|
|
|
- callback_query_id=query.id,
|
|
|
- text='Upvote registered')
|
|
|
+ query.answer(text='Upvote registered')
|
|
|
if t.upvotes == 3:
|
|
|
n_tale = self.db.incr('n_tales')
|
|
|
self.db.hset(str(n_tale), 'author', t.author.first_name)
|
|
|
self.db.hset(str(n_tale), 'tale', t.text)
|
|
|
- bot.editMessageText(chat_id=query.message.chat_id,
|
|
|
- message_id=query.message.message_id,
|
|
|
- text='Tale saved to database')
|
|
|
+ query.edit_message_text(text='Tale saved to database')
|
|
|
else:
|
|
|
thumb_up = u'\U0001F44D'
|
|
|
button = InlineKeyboardButton(thumb_up + str(t.upvotes),
|
|
|
callback_data=query.data)
|
|
|
keyboard = InlineKeyboardMarkup([[button]])
|
|
|
- bot.editMessageText(chat_id=query.message.chat_id,
|
|
|
- message_id=query.message.message_id,
|
|
|
- text=query.message.text,
|
|
|
- reply_markup=keyboard)
|
|
|
+ query.edit_message_text(text=query.message.text,reply_markup=keyboard)
|
|
|
|
|
|
- def tell_a_tale(self, bot, update):
|
|
|
+ def tell_a_tale(self, update, context):
|
|
|
"""Tell a tale about LCM"""
|
|
|
msg = update.message
|
|
|
n_tales = self.db.get('n_tales')
|