Esempio n. 1
0
 def GET(self):
     user = db.get_user(session.uid)
     threads = db.get_threads(session.uid)
     html = render.forum(tr.text[db.get_lang(session.uid)],
                         threads[::-1],
                         user['isadm'],
                         session.page_data)
     return html
Esempio n. 2
0
 def reset(self, chatid):
     lang = db.get_lang(chatid)
     main.bot.send_message(chatid,
                           localization.get_message('n.pre', lang),
                           reply_markup=keyboards.zero,
                           parse_mode='markdown')
     main.bot.send_message(chatid,
                           localization.get_message('n.name', lang),
                           reply_markup=keyboards.zero,
                           parse_mode='markdown')
     self.substate = 0
Esempio n. 3
0
    def GET(self, tid):        
        tid = utils.dec_tid(tid)
        
        # tid can be entered in URL, so we need to verify if it is valid
        if not db.is_thread(tid):
            return 'Access denied' # page doesn't exist

        # check if current user is on the list of users of this thread
        user = db.get_user(session.uid)
        (guests, uids) = db.get_thread_users(db.get_lang(session.uid), tid)
        if uids and session.uid not in uids:
            return 'Access denied' # tid is out of the list of users

        # if page is refreshed or the user switches between edit and
        # preview mode, we want to preserve the text in textarea
        message = session.page_data['message']
        if session.page_data['preview']:
            message = utils.markdown_to_html(message)
        
        # emoticons come from http://www.veryicon.com/icons/emoticon/the-black/
        # read names of emot icons and split the list into N rows
        emots = os.listdir('static' + os.sep + 'em')
        emots = zip(*[iter(emots)]*(len(emots)//config.emots_rows))
        html = render.thread(tr.text[db.get_lang(session.uid)],
                             db.get_posts(session.uid, tid),
                             user['nick'],
                             user['name'],
                             utils.hue_to_color(user['hue']),
                             guests,
                             db.get_thread_title(tid),
                             session.page_data['preview'],
                             message,
                             emots)
                             
        # save the fact of visiting this thread in history
        db.mark_read(session.uid, tid)
        return html
Esempio n. 4
0
 def handle_message(self, chatid, message):
     lang = db.get_lang(chatid)
     if self.substate == 0:
         self.name = message
         self.substate = 1
         main.bot.send_message(chatid,
                               localization.get_message('n.phone', lang),
                               reply_markup=keyboards.zero,
                               parse_mode='markdown')
     elif self.substate == 1:
         if not (message.isdigit()):
             main.bot.send_message(
                 chatid,
                 'Wrong phone format! Only digits without spaces or symbols!',
                 reply_markup=keyboards.zero,
                 parse_mode='markdown')
             return
         self.phone = message
         self.substate = 2
         main.bot.send_message(chatid,
                               localization.get_message('n.weight', lang),
                               reply_markup=keyboards.zero,
                               parse_mode='markdown')
     elif self.substate == 2:
         if not (message.isdigit()):
             main.bot.send_message(chatid,
                                   'Wrong weight!',
                                   reply_markup=keyboards.zero,
                                   parse_mode='markdown')
             return
         self.weight = int(message)
         self.substate = 3
         main.bot.send_message(chatid,
                               localization.get_message('n.address', lang),
                               reply_markup=keyboards.zero,
                               parse_mode='markdown')
     elif self.substate == 3:
         self.address = message
         self.substate = 4
         main.bot.send_message(chatid,
                               localization.get_message('n.payed', lang),
                               reply_markup=keyboards.loc.get_keyboard(
                                   'payed', lang),
                               parse_mode='markdown')
     elif self.substate == 5:
         self.note = message
         self.substate = 10
         self.send_order_info(chatid, lang)
Esempio n. 5
0
    def handle_select(self, data, chatid):
        lang = db.get_lang(chatid)
        data = str(data)
        if self.substate == 10:
            if data == 'yes':
                main.bot.send_message(chatid,
                                      localization.get_message(
                                          'n.order_yes', lang),
                                      reply_markup=keyboards.zero,
                                      parse_mode='markdown')

                print('Sending new product to main site...')
                product_info = {
                    'm': 'common',
                    'f': 'add_product_bot',
                    'name': self.name,
                    'phone': self.phone,
                    'weight': self.weight,
                    'payed': self.payed,
                    'address': self.address,
                    'note': self.note
                }
                print(product_info)
                r = requests.post(config.site_base + 'ajax/ajaxCore.php',
                                  data=product_info)

                return_to_main_menu(chatid)
            elif data == 'no':
                main.bot.send_message(chatid,
                                      localization.get_message(
                                          'n.order_no', lang),
                                      reply_markup=keyboards.zero,
                                      parse_mode='markdown')
                return_to_main_menu(chatid)
        else:
            if (data.startswith('n.')) and (self.substate == 4):
                self.payed = int(data[len('n.'):])
                self.substate = 5
                main.bot.send_message(chatid,
                                      localization.get_message('n.note', lang),
                                      reply_markup=keyboards.zero,
                                      parse_mode='markdown')
            else:
                return
Esempio n. 6
0
    def GET(self):
        user = session.page_data['user']
        if not user:
            user = db.get_user(session.uid)
            session.page_data['user'] = user

        # generate colors specifiers to be used in HTML
        color = utils.hue_to_color(user['hue'])
        color_template = lambda c: '<button class="clink" style="background: #' + \
                                   utils.hue_to_color(float(c)/config.colorbar_len) + \
                                   '" id="color" name="color" value="' + str(c) + '">&#160;</button>'

        colors = ''.join([color_template(c) for c in range(config.colorbar_len)])

        # generate 'selected' tag for the item which corresponds to the language of current user
        languages = tr.text.keys()
        lang_selected = {lang: ['','selected'][user['lang']==lang] for lang in languages}
        
        html = render.profile(tr.text[db.get_lang(session.uid)],
                              user,
                              color,
                              colors,
                              lang_selected)
        return html
Esempio n. 7
0
 def handle_select(self, data, chatid):
     lang = db.get_lang(chatid)
     code = str(data)
     if code == 'track':
         state = MenuTrackState()
         db.set_state(chatid, state)
         main.bot.send_message(chatid,
                               localization.get_message(
                                   'enter_client_code', lang),
                               reply_markup=keyboards.zero)
     elif code == 'order':
         state = MenuNewOrderState()
         db.set_state(chatid, state)
         state.reset(chatid)
     elif code == 'info':
         main.bot.send_message(chatid,
                               localization.get_message('what_i_can', lang),
                               reply_markup=keyboards.zero)
         self.reset(chatid)
     elif code == 'manager':
         main.bot.send_message(chatid,
                               localization.get_message('manager', lang),
                               reply_markup=keyboards.zero)
         self.reset(chatid)
Esempio n. 8
0
 def GET(self):
     html = render.users(tr.text[db.get_lang(session.uid)],
                         db.get_user_list())
     return html
Esempio n. 9
0
 def reset(self, chatid):
     code = db.get_lang(chatid)
     main.bot.send_message(chatid,
                           localization.get_message('select_action', code),
                           reply_markup=keyboards.loc.get_keyboard(
                               'menu', code))
Esempio n. 10
0
    def handle_message(self, chatid, message):
        lang = db.get_lang(chatid)
        message = str(message)
        track_code = message

        r = requests.post(config.site_base + 'ajax/ajaxCore.php',
                          data={
                              'm': 'common',
                              'f': 'product_info',
                              'track_id': track_code,
                              'lang': lang
                          })
        j = {'err': '1'}
        try:
            j = json.loads(r.text)
        except:
            print('[Mishin870] Error in handle track while parse json: {}'.
                  format(r.text))
            main.bot.send_message(chatid,
                                  'Internal error: {}'.format(j['msg']),
                                  reply_markup=keyboards.zero)
            return_to_main_menu(chatid)
            return
        if j['err'] == '1':
            main.bot.send_message(chatid,
                                  'Internal error: {}'.format(j['msg']),
                                  reply_markup=keyboards.zero)
            return_to_main_menu(chatid)
            return
        j = json.loads(j['msg'])
        # it is both bad and.. fine
        ret = "{}\n{}\n\n{}\n`{}`\n\n{}{}-{}{}\n".format(
            localization.get_message('i.your_track', lang), j['name'],
            localization.get_message('i.contacts', lang), j['phone'],
            localization.get_message('i.tarif', lang), j['from'], j['to'],
            localization.get_message('i.days', lang))
        if int(j['payed']) == 1:
            ret += "`{}{}$`\n".format(
                localization.get_message('i.pricey', lang), j['price'])
        else:
            ret += "`{}{}$`\n".format(
                localization.get_message('i.price', lang), j['price'])

        ret += "{}{} {}\n\n".format(localization.get_message('i.weight', lang),
                                    j['weight'],
                                    localization.get_message('n.kgs', lang))

        pstate = int(j['state'])
        if pstate == 0:
            # головной офис
            ret += "{}\n{}. {}".format(
                localization.get_message('i.office', lang), j['date'],
                localization.get_message('i.stambul', lang))
        elif pstate >= 1:
            # терр.
            ret += "{}\n{}. {}".format(
                localization.get_message('i.terr', lang), j['date'],
                localization.get_message('i.tashkent', lang))

        main.bot.send_message(chatid,
                              ret,
                              reply_markup=keyboards.zero,
                              parse_mode='markdown')
        return_to_main_menu(chatid)
async def main(bot, message: Message):
    userlang = db.get_lang(message.chat.id, message.chat.type)
    translation = await tr(message.text, targetlang=[userlang, 'utf-16'])
    language = await tr.detect(message.text)
    await message.reply(
        constants.translate_string_two.format(translation.text, language))
Esempio n. 12
0
    "entertainment", "technology"
]

languages = ['ru', 'ua', 'us', 'ca']
languages_numbers = {'ru': '1', 'ua': '2', 'us': '3', 'ca': '4'}
country = {"ru": "Россия", "ua": "Украина", "us": "США", "ca": "Канада"}

country_en = {"ru": "Russia", "ua": "Ukrauine", "us": "USA", "ca": "Canada"}

language = {}
settings = {}
# It is needed for adding array in 'settings'
user_settings = {}

by_time_settings = {}
bot_language = get_lang()
global main_lang
main_lang = 'ru'
flag = 'none'

# Tranalastions
# Buttons
kb_buttons = {
    'eng': [
        "General", "Politics", "Sport", "Business", "Science", "Health",
        "Entertainment", "Technology", "Specify Country", "Time Settings"
    ],
    'rus': [
        "Главные", "Политика", "Спорт", "Бизнес", "Наука", "Медицина",
        "Шоу-Бизнес", "Технологии", "Указать Страну", "Настройки По Времени"
    ]