def open_comment(bot, comment_id): comnt = db.get_comment(comment_id) bts = [] if self.user_id == comnt.user_creator_id: # btn for creator bts.append( Button(f'❤️ {comnt.liked_count}', callback_data='THIS YOUR like')) bts.append( Button('edit', callback_data='open edit_comment ?comment_id=' + str(comnt.id))) bts.append( Button('🗑', callback_data='open confirm_del ?comment_id=' + str(comnt.id))) bts.append( Button('Answer', callback_data='open write_answer ?comment_id=' + str(comnt.id))) return f'<b>{comnt.user_name}</b> {comnt.date_add}\n<i>{comnt.text_main}</i>', [ bts ] # if not none if comnt.users_liked and self.user_id in comnt.users_liked: is_liked = '💖' call_data = 'comment dislike ?comment_id=' + str(comnt.id) else: is_liked = '❤️' call_data = 'comment like ?comment_id=' + str(comnt.id) if comnt.channel_id in db.get_all_ch( self.user_id): # btn for admin channel bts.append(Button(is_liked, callback_data=call_data)) bts.append( Button('Answer', callback_data='open write_answer ?comment_id=' + str(comnt.id))) bts.append( Button('🗑', callback_data='open confirm_del ?comment_id=' + str(comnt.id))) else: # for normal user bts.append(Button(is_liked, callback_data=call_data)) bts.append( Button('Answer', callback_data='open write_answer ?comment_id=' + str(comnt.id))) text = f'<b>{comnt.user_name}</b> {comnt.date_add}\n<i>{comnt.text_main}</i>' return text, [bts]
def complete_post(self): ch_ids = db.get_all_ch(self.user_id) bts = [] for ch in ch_ids: try: ch_name = bot.get_chat(ch).title except: ch_name = ' | No admin' bts.append( [Button(ch_name, callback_data=f'send send_post ?ch_id={ch}')]) text = 'Виберите канали в которих нужно виложить пост' bts.append([Button('Отмена', callback_data='remove_yourself')]) return text, bts
def command(self, bot, msg): msg = msg.message print(msg.text) msg_txt = msg.text.split() if len(msg_txt) == 2 and msg_txt[0] == '/start': code = msg_txt[1] print(msg_txt, code) if code[0] == '0': # for new comments print(111111111111) view.write_comment(msg, post_id=code[1:]) elif code[0] == '1': # for open comment print(222222222222) view.comment(msg, comment_id=code[1:]) elif msg.text == '/start': if db.get_all_ch(msg.chat.id): view.main_menu(msg, edit_msg=False) else: view.welkom(msg, edit_msg=False)
def ch_list(self): db.set_user_param(self.user_id, 'mode_write', 'off') channels = db.get_all_ch(self.user_id) bts = [[Button(' Назад', callback_data='open main_menu')]] if channels: bts[0].append(Button(' Добавить', callback_data='open add_ch')) for ch in channels: try: ch_name = bot.get_chat(ch).title except: ch_name = ' | No admin' bts.append([ Button(ch_name, callback_data='open ch_setting ?ch_id=' + str(ch)), ]) else: bts.append([Button(' Добавить', callback_data='open add_ch')]) return 'List channel: ', bts
def add_channel(self, msg): ch_name = msg.text if len(ch_name.split('t.me/')) > 1: ch_name = ch_name.split('t.me/')[1] if not ch_name[0] == '@': ch_name = '@' + ch_name print(ch_name) try: admins = self.bot.get_chat_administrators(ch_name) ch_id = self.bot.get_chat(ch_name).id if ch_id in db.get_all_ch(msg.chat.id): result = 'ChannelExists' else: result = 'Added' except error.BadRequest as e: print('ERROR: ', e) e = str(e) if e == 'Chat not found': result = 'NotFound' elif e == 'Supergroup members are unavailable': result = 'NoAdmin' else: result = 'Added' if result == 'Added': db.add_channel(msg.chat.id, ch_id) else: ch_id = None view.add_ch_final(msg, edit_msg=True, result=result, ch_id=ch_id)