示例#1
0
 def show_category_words(self, update, context, student):
     category = student.callback_data[int(update.callback_query.data)]
     category = self.categories.get(name=category)
     category_language = self.langs.get(
         name=student.student.current_language)
     translate_language = self.langs.get(name=student.student.home_language)
     category_words = self.global_words.filter(
         category=category,
         language=category_language,
         translate_language=translate_language)
     student.callback_data = ['Add all']
     student.destination = 'Add from global word'
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=1))
     update.message.edit_text(text=category.name, reply_markup=reply_markup)
     for word in category_words:
         button_list = [
             InlineKeyboardButton(text='Add', callback_data=str(word.pk))
         ]
         reply_markup = InlineKeyboardMarkup(
             build_menu(button_list, n_cols=3))
         update.message.reply_text(
             text='Word [%s]\nPronunciation [%s]\nTranslation [%s]' %
             (word.name, word.pronunciation, word.translation),
             reply_markup=reply_markup)
     student.temp_data = {'category': category, 'words': category_words}
示例#2
0
 def add_word_category(self, update, context, student):
     student.destination = 'Add custom word'
     student.callback_data = [c.name for c in self.categories]
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=1))
     update.message.reply_text(text='Now choose category.' + self.menu_text,
                               reply_markup=reply_markup)
示例#3
0
 def menu(self, update, context, student):
     """
      Display bot menu
     :param bot: telegram.ext.Dispatcher.bot
     :param update: telegram.Update
     :param student: users.models.Student
     """
     menu_list = [
         'Add words',
         'My words',
         'Learn words',
         'Play matching',
         'Play reversed matching',
         'Play typing',
         'Play reversed typing',
         'Help',
         'Change learn language',
         'Add more learn language',
     ]
     student.callback_data = menu_list
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=2))
     student.destination = 'Menu_action'
     update.message.reply_text(text='Menu' + self.menu_text,
                               reply_markup=reply_markup)
示例#4
0
 def choose_from_presets(self, update, context, student):
     student.callback_data = [c.name for c in self.categories]
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=1))
     student.destination = 'Show category words'
     update.message.edit_text(text='Choose category' + self.menu_text,
                              reply_markup=reply_markup)
示例#5
0
def send_ask_charge(cinfo):
    print('send_ask_charge()')

    if cinfo.q1_sent is not None:
        print('[Ok] send_ask_charge()')
        return

    print('[  ] send_ask_charge()')

    button_list = [
        telegram.InlineKeyboardButton(
            'Yes',
            callback_data='Yes, the class was given! ClassInfo ID: %d' %
            cinfo.id),
        telegram.InlineKeyboardButton(
            'No',
            callback_data='No, class did not happened! ClassInfo ID: %d' %
            cinfo.id)
    ]

    reply_markup = telegram.InlineKeyboardMarkup(
        build_menu(button_list, n_cols=2))
    msg_str = 'Hi %s. Did you gave the class to student %s?' % (
        cinfo.teacher, cinfo.class_request.name)
    bot.send_message(chat_id=cinfo.chat_id,
                     text=msg_str,
                     reply_markup=reply_markup)

    cinfo.q1_sent = timezone.now()
    cinfo.save()
示例#6
0
 def add_words(self, update, context, student):
     student.callback_data = [
         'Add word by typing', 'Choose word from presets'
     ]
     student.destination = 'Add words option'
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=1))
     update.message.edit_text(text='How do you want to add word?' +
                              self.menu_text,
                              reply_markup=reply_markup)
示例#7
0
 def register_home_language(self, update, context, student):
     student.destination = 'Register current language'
     student.temp_data['home_language'] = student.callback_data[int(
         update.callback_query.data)]
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=1))
     update.callback_query.message.edit_text(
         text='Now choose your learn language')
     update.callback_query.message.reply_text(text=' -:- ',
                                              reply_markup=reply_markup)
示例#8
0
 def register_current_language(self, update, context, student):
     student.destination = 'Accept privacy policy'
     student.temp_data['current_language'] = student.callback_data[int(
         update.callback_query.data)]
     student.callback_data = ['Yes', 'No']
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=1))
     update.callback_query.message.edit_text(
         text='To use our service you need to accept Privacy Policy.'
         ' You can read it at https://linguint.pro/privacy_policy . '
         'Do you accept Privacy Policy?',
         reply_markup=reply_markup)
示例#9
0
 def view_category_words(self, update, context, student):
     student.destination = 'Manage word'
     student.callback_data = ['Change translation', 'Learn again', 'Delete word']
     for word in student.temp_data['words']:
         button_list = [InlineKeyboardButton(text='Change translation', callback_data='0,'+str(word.pk)),
                        InlineKeyboardButton(text='Delete', callback_data='2,'+str(word.pk))]
         if word.viewed and word.played_match and word.played_reversed_match and word.played_typing\
                 and word.played_reversed_typing is True:
             button_list.insert(1, InlineKeyboardButton(text='Learn again', callback_data='1,'+str(word.pk)))
         reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=3))
         update.message.reply_text(text='Word [%s] \n Pronunciation [%s]\n Translation [%s] \n' %
                                        (word.name, word.pronunciation, word.translation),
                                   reply_markup=reply_markup)
示例#10
0
 def register_first_name(self, update, context, student):
     student.destination = 'Register home language'
     student.temp_data = {
         'username': update.effective_user.id,
         'first_name': update.message.text
     }
     student.callback_data = [l.name for l in self.langs]
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=1))
     update.message.reply_text(
         text='Okay %s. Now choose your home language' %
         update.message.text,
         reply_markup=reply_markup)
示例#11
0
 def add_more_learn_language(self, update, context, student):
     """
     Adding new learn language for student from list
     :param bot: telegram.ext.Dispatcher.bot
     :param update: telegram.Update
     :param student: users.models.Student
     """
     student.destination = 'Change language'
     student.callback_data = [l.name for l in self.langs]
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=1))
     update.callback_query.message.edit_text(
         'Choose your new learn language' + self.menu_text,
         reply_markup=reply_markup)
示例#12
0
 def change_learn_language(self, update, context, student):
     """
     Change student current learn language from list of all student learn languages
     :param bot: telegram.ext.Dispatcher.bot
     :param update: telegram.Update
     :param student: users.models.Student
     """
     student.destination = 'Change language'
     cats = student.student.language_set.all()
     student.callback_data = [c.name for c in cats]
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=1))
     update.callback_query.message.edit_text('Choose your learn language' +
                                             self.menu_text,
                                             reply_markup=reply_markup)
示例#13
0
 def play_matching_result(self, update, context, student):
     answer = student.callback_data[int(update.callback_query.data)]
     word = student.temp_data['answer']
     reverse = False
     learned = False
     if student.destination == 'Play matching result':
         learned = self.check_answer(word.translation, answer)
         student.destination = 'Play matching'
     else:
         reverse = True
         learned = self.check_answer(word.name, answer)
         student.destination = 'Play reversed matching'
     student.HQ.update_match_field(word, learned['update'], reverse)
     student.callback_data = ['Next']
     reply_markup = InlineKeyboardMarkup(
         build_menu(make_button_list(self, update, student), n_cols=1))
     update.message.edit_text(text=learned['text'] + self.menu_text,
                              reply_markup=reply_markup)
示例#14
0
 def learn_words(self, update, context, student):
     student.destination = 'Learn word status'
     words = student.HQ.learn_word()
     if words.count() == 0:
         update.message.edit_text(text='No words to learn')
         return
     if words.count() == 1:
         word = words[0]
     else:
         word = words[randint(0, words.count() - 1)]
     student.temp_data = {'word': word}
     button_list = [
         InlineKeyboardButton(text='Learned', callback_data='1'),
         InlineKeyboardButton(text='Not learned', callback_data='0')
     ]
     reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=2))
     text = 'Word [%s]\nPronunciation [%s]\nTranslation [%s]\n' % (
         word.name, word.pronunciation, word.translation)
     update.message.edit_text(text=text + self.menu_text,
                              reply_markup=reply_markup)
示例#15
0
 def search_word(self, update, context, student):
     result = student.HQ.search_word(word_name=update.message.text.strip())
     if result['global_word_search'] is False and result[
             'google_translate_search'] is False:
         student.temp_data['word_name'] = update.message.text.strip()
         student.destination = 'Add word translation'
         update.message.reply_text(
             text=
             'Sorry. Could not find any translation. Enter your translation:'
         )
     if result['google_translate_search'] is True:
         student.temp_data['word_name'] = result['words'].origin
         student.temp_data['translation'] = result['words'].text
         student.temp_data['pronunciation'] = result['words'].pronunciation
         student.callback_data = ['Yes', 'No']
         reply_markup = InlineKeyboardMarkup(
             build_menu(make_button_list(self, update, student), n_cols=2))
         student.destination = 'Translation option'
         update.message.reply_text(
             text='Found with internet search \n'
             'Word [%s] \n Pronunciation [%s]\n Translation [%s]' %
             (result['words'].origin, result['words'].pronunciation,
              result['words'].text))
         update.message.reply_text(text='Add custom word translation?' +
                                   self.menu_text,
                                   reply_markup=reply_markup)
     if result['global_word_search'] is True:
         # TODO: Add multiple search results
         update.message.reply_text(
             text='Found in data base search \n'
             'Word [%s] \n Pronunciation [%s]\n Translation [%s] \n Category [%s]'
             % (result['words'][0].name, result['words'][0].pronunciation,
                result['words'][0].translation,
                str([
                    cat.name
                    for cat in result['words'][0].category_set.all()
                ])))
         student.HQ.add_from_global_word(global_word=result['words'][0])
         update.message.reply_text('Word(s) added')
         self.dispatch_destination(update, context, student, 'Menu')
示例#16
0
 def play_matching(self, update, context, student):
     reverse = False if student.destination == 'Play matching' else True
     game = student.HQ.play_matching(reverse=reverse)
     if game == 'No words to play matching':
         update.message.edit_text(text='No words to play matching')
         self.dispatch_destination(update, context, student, 'Menu')
     else:
         student.temp_data = {'answer': game['answer']}
         if reverse is False:
             student.destination = 'Play matching result'
             student.callback_data = [
                 word.translation for word in game['words']
             ]
             text = game['answer'].name
         else:
             student.destination = 'Play reversed matching result'
             student.callback_data = [word.name for word in game['words']]
             text = game['answer'].translation
         reply_markup = InlineKeyboardMarkup(
             build_menu(make_button_list(self, update, student), n_cols=1))
         # Todo Improve button length
         update.message.edit_text(text=text + self.menu_text,
                                  reply_markup=reply_markup)
示例#17
0
 def my_words_option(self, update, context, student):
     choice = student.callback_data[int(update.callback_query.data)]
     student.destination = choice
     student.callback_data = student.HQ.get_student_categories()
     reply_markup = InlineKeyboardMarkup(build_menu(make_button_list(self, update, student), n_cols=1))
     update.message.edit_text(text='Now choose category.'+self.menu_text, reply_markup=reply_markup)
示例#18
0
 def my_words(self, update, context, student):
     student.callback_data = ['Look all your words', 'Look learned words']
     reply_markup = InlineKeyboardMarkup(build_menu(make_button_list(self, update, student), n_cols=2))
     student.destination = 'My words option'
     update.message.edit_text(text='My words'+self.menu_text, reply_markup=reply_markup)