Exemple #1
0
    def bild_post(self, type_post=None):
        db.set_user_param(self.user_id, 'mode_write', 'open add_addition')

        bild_post = buffer.get_bildpost(self.user_id)

        if type_post is None:
            type_post = bild_post.type
        if type_post == 'text':
            set_type = 'photo'
        elif type_post == 'photo':
            set_type = 'text'

        post_btn = []
        for btn in bild_post.buttons:
            if btn['type'] == 'url':
                post_btn.append(Button(btn['text'], url=btn['url']))
            elif btn['type'] == 'reaction':
                post_btn.append(Button(btn['text'], callback_data=btn['data']))
            elif btn['type'] == 'comments':
                post_btn.append(Button(btn['text'], url='google.com'))

        print('===========================================')
        print(post_btn)

        if type_post == 'text':
            bot.send_message(self.user_id,
                             bild_post.photo_url + bild_post.text,
                             reply_markup=Markup([post_btn]),
                             parse_mode='html')
        elif type_post == 'photo':
            bot.send_photo(self.user_id,
                           photo=bild_post.photo.file_id,
                           caption=bild_post.text,
                           reply_markup=Markup([post_btn]),
                           parse_mode='html')

        bts = [[Button('Готово', callback_data='open complete_post')],
               [
                   Button('Добавить кнопку',
                          callback_data='open select_type_btn')
               ]]
        if bild_post.text and bild_post.photo:
            bts.append([
                Button('revers',
                       callback_data='reopen bild_post ?type_post=' + set_type)
            ])

        bot.send_message(self.user_id,
                         '=================',
                         reply_markup=Markup(bts))

        return False, None
Exemple #2
0
    def edit_msg(self, bot, chat_id, msg_id, text, bts):
        try:
            bot.edit_message_text(chat_id=chat_id,
                                  message_id=msg_id,
                                  text=text,
                                  reply_markup=Markup(bts),
                                  parse_mode='html')

        except Exception as e:
            print('Error edit msg  in channel: ', e)
            bot.edit_message_caption(chat_id=chat_id,
                                     message_id=msg_id,
                                     caption=text,
                                     reply_markup=Markup(bts),
                                     parse_mode='html')
Exemple #3
0
        def wraper(self, msg, edit_msg=True, *args, **kwargs):
            print(func.__name__, 'KWARGS docor: ', kwargs)

            db.check_user(user_id=msg.chat.id)  # TODO
            self.user_id = msg.chat.id
            self.msg = msg

            text, buttons = func(self, *args, **kwargs)

            print('BUTTONS: ', buttons)
            if text is False:
                return
            if buttons is None:
                bts = None
            else:
                bts = Markup(buttons)

            if edit_msg:
                try:
                    bot.edit_message_text(text,
                                          chat_id=msg.chat.id,
                                          message_id=msg.message_id,
                                          parse_mode='html',
                                          reply_markup=bts)
                except Exception as e:
                    print('Error send message: ', e)
                    bot.send_message(msg.chat.id,
                                     text,
                                     parse_mode='html',
                                     reply_markup=bts)
            else:
                bot.send_message(msg.chat.id,
                                 text,
                                 parse_mode='html',
                                 reply_markup=bts)
Exemple #4
0
    def stat_start_menu():
        kb = [[
            Button("{} Статистика по вечерам".format(em("")), callback_data="")
        ], [Button("{} Статистика по играм".format(em("")), callback_data="")],
              [Button("{} Поменять город".format(em("")), callback_data="")]]

        return Markup(kb)
Exemple #5
0
 def write_answer(self, comment_id):
     db.set_user_param(self.user_id, 'mode_write',
                       'open write_answer ?comment_id=' + str(comment_id))
     bts = [[Button('Отмена', callback_data='remove_yourself')]]
     bot.send_message(self.user_id,
                      'Отправь мне текст ответа на етот коментарий:',
                      reply_markup=Markup(bts))
     return False, None
Exemple #6
0
    def write_comment(self, post_id):
        db.set_user_param(self.user_id, 'mode_write',
                          'open write_comment ?post_id=' + str(post_id))
        bts = [[Button('Отмена', callback_data='remove_yourself')]]
        bot.send_message(self.user_id,
                         'Отправь мне текст комментария:',
                         reply_markup=Markup(bts))

        return False, None
Exemple #7
0
 def statistic_reply(cls):
     kb = [[
         Button("{} Игры".format(em(":memo:")),
                callback_data="OpenGameStat")
     ],
           [
               Button("{} Вечера".format(em(":last_quarter_moon:")),
                      callback_data="OpenEveningStat")
           ]]
     return Markup(kb)
Exemple #8
0
 def start_user():
     return Markup([[
         Button("{0} Открыть статистику".format(em(":open_file_folder:")),
                callback_data="UserOpenStatistic")
     ],
                    [
                        Button("{0} Запросить доступ".format(
                            em(":question:")),
                               callback_data="GetPermissions")
                    ]])
Exemple #9
0
 def main():
     return Markup([[
         Button("{} Начать вечер".format(em(":hourglass:")),
                callback_data='start_evening')
     ],
                    [
                        Button("{} Меню рейтинга".format(em(":bar_chart:")),
                               callback_data='statistic_menu')
                    ],
                    [
                        Button("{} Меню игроков".format(em(":paperclip:")),
                               callback_data='players_menu')
                    ]])
Exemple #10
0
    def turple_list_to_kb(cls, objects, callbacks, postfix) -> Markup:
        kb = []

        for obj in objects:
            kb_line = []
            for index, attribut in enumerate(obj):
                kb_line.append(
                    Button(attribut,
                           callback_data="{}_{}".format(
                               callbacks[attribut] if attribut in callbacks
                               else attribut, postfix[index])))
            kb.append(kb_line)

        return Markup(kb)
Exemple #11
0
    def get_tg_bts(self, markup=True, config=False, ch_id=None):

        if self.bts is None:
            return []

        print(self.bts)
        bts = []
        for i, line in enumerate(self.bts):
            bts.append([])
            for btn in line:
                bts[i].append(btn.get_tg(config, ch_id))

        if markup:
            return Markup(bts)
        else:
            return bts
Exemple #12
0
    def write_comment(self, msg, post_id):
        post = db.get_post(post_id)

        db.new_comment(text=msg.text,
                       channel_id=post.channel_id,
                       user_id=msg.chat.id,
                       user_name=msg.chat.first_name,
                       post_id=post_id)

        tgph_editor.update_comments(post_id)

        bts = parse_buttons(post.buttons)

        print('>>>> ', bts)
        print('COUNT: ', post.all_comments)

        post_bts = []

        for inx, line in enumerate(json.loads(post.buttons)):
            post_bts.append([])

            for btn in line:
                if btn['type'] == 'url':
                    post_bts[inx].append(Button(btn['text'], url=btn['url']))

                elif btn['type'] == 'reaction':
                    btn_id = btn['id']
                    post_bts[inx].append(
                        Button(btn['text'].format(count=btn['count']),
                               callback_data=btn['data']))

                elif btn['type'] == 'comments':
                    print('BUTTON >>> ', btn['text'])
                    post_bts[inx].append(
                        Button(btn['text'].format(count=post.all_comments + 1),
                               url='telegra.ph/' + post.telegraph_path_top))

        print(post.channel_id, post.msg_id)
        print(post_bts)
        self.bot.edit_message_reply_markup(chat_id=int(post.channel_id),
                                           message_id=int(post.msg_id),
                                           reply_markup=Markup(post_bts))
        view.comments_sended(msg)
Exemple #13
0
    def send_post(self, bot, msg, ch_id):
        post = buffer.get_bildpost(msg.chat.id)

        if post.comments_on:
            path_new, path_top = tgph_editor.new_comments()
        else:
            path_top = path_new = None

        post_id = db.new_post(channel_id=ch_id,
                              user_creator_id=msg.chat.id,
                              buttons=parse_buttons(post.buttons),
                              comments_on=post.comments_on,
                              telegraph_path_top=path_new,
                              telegraph_path_new=path_top)

        post_btn = []
        for btn in post.buttons:
            if btn['type'] == 'url':
                post_btn.append(Button(btn['text'], url=btn['url']))

            elif btn['type'] == 'reaction':
                post_btn.append(Button(btn['text'], callback_data=btn['data']))

            elif btn['type'] == 'comments':
                post_btn.append(
                    Button(btn['text'],
                           url='t.me/KomentsBot?start=0' +
                           str(post_id)))  # 0 - new comments  > > ^

        if post.type == 'text':
            msg_send = bot.send_message(ch_id,
                                        post.text,
                                        reply_markup=Markup([post_btn]))
        elif post.type == 'photo':
            pass

        db.set_msg_id_post(post_id, msg_send.message_id)

        view.send_post_complete(msg)
Exemple #14
0
    def select_type_btn(self, ch_id=''):
        if ch_id:
            ch_id_ = '&ch_id=' + ch_id
            ch_id_url = '?ch_id=' + ch_id

        bts = [
            [Button('Отмена', callback_data='remove_yourself None')],
            [
                Button('Url', callback_data=f'open add_btn_url ' + ch_id_url),
                Button('Reaction',
                       callback_data='open add_btn_name ?type_btn=reaction' +
                       ch_id_)
            ],
            [
                Button('Komments',
                       callback_data='open add_btn_name ?type_btn=comments' +
                       ch_id_)
            ]
        ]
        bot.send_message(self.user_id,
                         'Виберите тип кнопки',
                         reply_markup=Markup(bts))
        return False, None
Exemple #15
0
    def button_handler(self, bot, msg, from_user, btn_id):
        buttons = db.get_post_buttons(ch_id=msg.chat.id, msg_id=msg.message_id)
        pprint(buttons)

        post_btn = []
        for i, line in enumerate(buttons):
            post_btn.append([])
            for btn in line:
                if btn['type'] == 'url':
                    post_btn[i].append(Button(btn['text'], url=btn['url']))

                elif btn['type'] == 'reaction':

                    if int(btn_id) == btn['id']:

                        if from_user in btn['users_liked']:
                            btn['users_liked'].remove(from_user)
                            btn['count'] -= 1

                        else:
                            btn['users_liked'].append(from_user)
                            btn['count'] += 1

                    post_btn[i].append(
                        Button(btn['text'].format(count=btn['count']),
                               callback_data=btn['data']))

                elif btn['type'] == 'comments':
                    post_btn[i].append(
                        Button(btn['text'].format(count=btn['count']),
                               url=btn.url))

        bot.editMessageReplyMarkup(chat_id=msg.chat.id,
                                   message_id=msg.message_id,
                                   reply_markup=Markup(post_btn))
        db.set_buttons_post(msg.chat.id, msg.message_id, buttons)
Exemple #16
0
    def players(cls, members, postfix="", emoji=None):
        kb = []
        if emoji is None:
            emoji = em(":x:")

        id_postfix = ""
        if isinstance(postfix, tuple) and len(postfix) > 1:
            id_postfix = postfix[0]
            postfix = postfix[1]

        if isinstance(emoji, list) and len(emoji) < len(members):
            emoji = em(":x:")

        if isinstance(members, dict):
            members = members.values()

        for member in members:
            kb.append([
                Button(member.name, callback_data=str(member.id) + id_postfix),
                Button((emoji
                        if not isinstance(emoji, list) else em(emoji.pop())),
                       callback_data=str(member.id) + postfix)
            ])
        return Markup(kb)
Exemple #17
0
 def get(self) -> Markup:
     if len(self._buttons[-1]) == 0:
         self._buttons = self._buttons[:-1]
     return Markup(self._buttons)
Exemple #18
0
 def start_callback(self, bot: Bot, update: Update):
     markup = Markup(
         [[Button(text=str(self.tree.get(uid=1)), callback_data=str(1))]])
     bot.send_message(chat_id=update.message.chat_id,
                      text="Hello. It's zontik.ru",
                      reply_markup=markup)
Exemple #19
0
 def get(self) -> Markup:
     #buttons = [self._buttons[self._inline_count * line: self._inline_count * (line + 1)]
     #          for line in range(ceil(len(self._buttons) // self._inline_count))]
     return Markup(self._buttons)
Exemple #20
0
 def approve(cls, param):
     return Markup([[Button(em(":ok:"), callback_data=param + "_approve")]])
Exemple #21
0
 def choose(cls, callback_prefix, params):
     kb = [([[
         Button(param, callback_data="{}.{}".format(callback_prefix, param))
     ]]) for param in params]
     return Markup(kb)
Exemple #22
0
 def confirm(cls):
     return Markup([[
         Button("Да", callback_data="yes"),
         Button("Нет", callback_data="no")
     ]])
Exemple #23
0
 def button(cls, text, callback=""):
     return Markup([[Button(text, callback_data=callback)]])