Esempio n. 1
0
 def execute(self, chat, peer, sender, args=None, attachments=None, fwd_messages=None):
     group = args['parameters'][-1]
     sender_groups = self.kristy.db.get_user_groups(chat, sender)
     if group in sender_groups:
         self.kristy.send(peer, "Вы уже состоите в этой группе")
     else:
         self.kristy.db.join_group(chat, group, sender)
         page_list = args["page_list"]
         object_groups = self.kristy.db.get_object_all_groups(chat)
         sender_groups = self.kristy.db.get_user_groups(chat, sender)
         groups_sorted = sorted([{"name": group["name"], "count": len(group["members"])} for group in object_groups if group["name"] not in sender_groups],
                                key=lambda group: (-group["count"], group["name"]))
         groups = [{"name": "{0} ({1})".format(group["name"], str(group["count"])),
                    "argument": group["name"],
                    "color": ""} for group in groups_sorted]
         response = "Успешно добавила вас"
         if not groups:
             self.kristy.send(peer, response, [], keyboards.control_keyboard(chat))
         else:
             keyboard = keyboards.choose_keyboard(chat=chat,
                                                  response="",
                                                  buttons=groups,
                                                  page_list=page_list,
                                                  action_now="подключиться_выбор",
                                                  action_to="подключиться",
                                                  action_from='управление')[1]
             self.kristy.send(peer, response, None, keyboard)
 def execute(self,
             chat,
             peer,
             sender,
             args=None,
             attachments=None,
             fwd_messages=None):
     page_list = args["page_list"]
     sender_rank = self.kristy.db.get_user_rank_val(chat, sender)
     commands_sorted = sorted(self.kristy.vkcmdmgr.commands,
                              key=lambda command:
                              (-command.min_rank.value, command.label))
     commands = [{
         "name": command.label,
         "argument": command.label,
         "color": ""
     } for command in commands_sorted
                 if not command.dm and sender_rank >= command.min_rank.value
                 ]
     if not commands:
         self.kristy.send(peer, "У вас нет прав, кек", [],
                          keyboards.information_keyboard(chat))
     else:
         response, keyboard = keyboards.choose_keyboard(
             chat=chat,
             response="Выберите команду",
             buttons=commands,
             page_list=page_list,
             action_now="команда_выбор",
             action_to='команда',
             action_from='информация')
         self.kristy.send(peer, response, None, keyboard)
    def choose_attachment(self, chat, peer, sender, page_list, response=""):
        tags_list = self.kristy.db.get_tag_attachments(chat)
        tags = []
        tags_list.sort()
        for tag in tags_list:
            attachment = self.kristy.db.get_attachment(chat, tag)
            if "creator" in attachment and sender == attachment["creator"]:
                tags.append({"name": tag, "argument": tag, "color": "green"})
            elif self.kristy.db.get_user_rank_val(
                    chat, sender) >= ranks.Rank.MODERATOR.value:
                tags.append({"name": tag, "argument": tag, "color": ""})

        if not tags:
            self.kristy.send(
                peer, "Нет вложений в беседе, которые вы можете удалить"
                if not response else response, [],
                keyboards.delete_keyboard(chat))
        else:
            response_keyboard, keyboard = keyboards.choose_keyboard(
                chat=chat,
                response="Выберите вложение",
                buttons=tags,
                page_list=page_list,
                action_now="удалить_вложение",
                action_to='удалить_вложение',
                action_from='удалить')
            self.kristy.send(peer,
                             response_keyboard if not response else response,
                             None, keyboard)
Esempio n. 4
0
 def execute(self,
             chat,
             peer,
             sender,
             args=None,
             attachments=None,
             fwd_messages=None):
     page_list = args["page_list"]
     tag = args["parameters"][-1]
     future_events = self.kristy.db.get_future_events_email(chat, tag)
     events_sorted = sorted(self.kristy.db.get_events_for_email(chat, tag),
                            key=lambda x: x["date"],
                            reverse=True)
     events = [{
         "name": datetime.strftime(event["date"], "%d.%m.%Y %H:%M"),
         "argument": event["id"],
         "color": "green" if event in future_events else ""
     } for event in events_sorted]
     if not events:
         self.kristy.send(peer, "Нету событий")
     else:
         response, keyboard = keyboards.choose_keyboard(
             chat=chat,
             response="Выберите событие",
             buttons=events,
             page_list=page_list,
             action_now="почта_событие_выбор",
             action_to='почта_событие',
             action_from='почта_тег_выбор',
             parameters=args["parameters"])
         self.kristy.send(peer, response, None, keyboard)
 def choose_email(self, chat, peer, page_list, response=""):
     tags_from_db = self.kristy.db.all_email_tags(chat)
     tags_from_db.sort()
     tags = [{
         "name":
         "{0} ({1})".format(
             tag, str(len(self.kristy.db.get_events_for_email(chat, tag)))),
         "argument":
         tag,
         "color":
         ""
     } for tag in tags_from_db]
     if not tags:
         self.kristy.send(peer,
                          "Нету тегов почты" if not response else response,
                          [], keyboards.delete_keyboard(chat))
     else:
         response_keyboard, keyboard = keyboards.choose_keyboard(
             chat=chat,
             response="Выбетите тег почты",
             buttons=tags,
             page_list=page_list,
             action_now="удалить_почту",
             action_to='удалить_почту',
             action_from='удалить')
         self.kristy.send(peer,
                          response_keyboard if not response else response,
                          None, keyboard)
Esempio n. 6
0
 def execute(self,
             chat,
             peer,
             sender,
             args=None,
             attachments=None,
             fwd_messages=None):
     page_list = args["page_list"]
     chats_sender = self.kristy.db.get_user_chats(sender)
     chats = [{
         'name': chat_now['name'],
         "argument": chat_now['chat_id'],
         "color": "green" if chat == chat_now['chat_id'] else ""
     } for chat_now in chats_sender]
     if not chats_sender:
         self.kristy.send(peer, "Вас нет ни в одной беседе")
     else:
         response, keyboard = keyboards.choose_keyboard(
             chat=chat,
             response="Выберите беседу",
             buttons=chats,
             page_list=page_list,
             action_now="выбор_беседы",
             action_to='стартовая_клавиатура',
             action_from='настройки' if chat != -1 else None)
         self.kristy.send(peer, response, None, keyboard)
Esempio n. 7
0
def start(update, context):
    reply_markup = InlineKeyboardMarkup(choose_keyboard('main_keyboard'))

    context.bot.send_photo(
        chat_id=update.effective_chat.id,
        photo=
        'https://static.tildacdn.com/tild6232-6236-4663-b934-356533636337/Frame.jpg',
        caption='OFAM_bot Меню:',
        reply_markup=reply_markup)
Esempio n. 8
0
def button(update, context):
    query = update.callback_query
    if query.data == 'send_menu':
        query.answer()

        reply_markup = InlineKeyboardMarkup(choose_keyboard('ofam_menu'))
        context.bot.send_photo(
            chat_id=update.callback_query.from_user.id,
            photo=
            'https://static.tildacdn.com/tild6232-6236-4663-b934-356533636337/Frame.jpg',
            caption='OFAM_bot Меню:',
            reply_markup=reply_markup)
    else:
        query.answer()

        db = SQLiteAdapter('ofam_bot.sqlite')
        result = db.select_from('buttons_content', '*',
                                {'db_query': query.data})

        _, photo, text = result[0]

        reply_markup = InlineKeyboardMarkup(choose_keyboard(query.data))

        new_photo = InputMediaPhoto(media=photo)

        context.bot.edit_message_media(
            chat_id=update.effective_chat.id,
            message_id=update.callback_query.message.message_id,
            media=new_photo)

        context.bot.edit_message_caption(
            chat_id=update.effective_chat.id,
            message_id=update.callback_query.message.message_id,
            caption=text,
            parse_mode=ParseMode.HTML)

        context.bot.edit_message_reply_markup(
            chat_id=update.effective_chat.id,
            message_id=update.callback_query.message.message_id,
            reply_markup=reply_markup)
Esempio n. 9
0
 def choose_event(self, chat, peer, page_list, parameters, response=""):
     tag = parameters[-1]
     events_sorted = sorted(self.kristy.db.get_events_for_email(chat, tag), key=lambda x: x['date'], reverse=True)
     events = [{"name": datetime.strftime(event["date"], "%d.%m.%Y %H:%M"), "argument": event["id"], "color": ""} for event in events_sorted]
     if not events:
         if not response:
             response = "Нету событий \n\n"
         self.choose_email(chat, peer, page_list[:-1], response)
     else:
         response_keyboard, keyboard = keyboards.choose_keyboard(chat=chat,
                                                                 response="Выберите событие",
                                                                 buttons=events,
                                                                 page_list=page_list,
                                                                 action_now="удалить_событие",
                                                                 action_to='удалить_событие',
                                                                 action_from='удалить_событие',
                                                                 parameters=parameters)
         self.kristy.send(peer, response_keyboard if not response else response, None, keyboard)
Esempio n. 10
0
    def execute(self, chat, peer, sender, args=None, attachments=None, fwd_messages=None):
        # TODO покрасить в зелённый цвет свои вложения
        page_list = args["page_list"]
        tags_list = self.kristy.db.get_tag_attachments(chat)
        tags_list.sort()
        tags = []
        for tag in tags_list:
            attachment = self.kristy.db.get_attachment(chat, tag)
            tags.append({"name": tag,
                         "argument": tag,
                         "color": "green" if "creator" in attachment and sender == attachment["creator"] else ""})

        if not tags:
            self.kristy.send(peer, "Нет вложений в беседе", [], keyboards.information_keyboard(chat))
        else:
            response, keyboard = keyboards.choose_keyboard(chat=chat,
                                                           response="Выберите вложение",
                                                           buttons=tags,
                                                           page_list=page_list,
                                                           action_now="вложение_выбор",
                                                           action_to='вложение',
                                                           action_from='информация')
            self.kristy.send(peer, response, None, keyboard)
Esempio n. 11
0
 def execute(self,
             chat,
             peer,
             sender,
             args=None,
             attachments=None,
             fwd_messages=None):
     page_list = args["page_list"]
     object_groups = self.kristy.db.get_object_all_groups(chat)
     sender_groups = self.kristy.db.get_user_groups(chat, sender)
     groups_sorted = sorted([{
         "name": group["name"],
         "count": len(group["members"])
     } for group in object_groups if group["name"] in sender_groups],
                            key=lambda group:
                            (-group["count"], group["name"]))
     groups = [{
         "name":
         "{0} ({1})".format(group["name"], str(group["count"])),
         "argument":
         group["name"],
         "color":
         ""
     } for group in groups_sorted]
     if not groups:
         self.kristy.send(peer, "Вас нет в группах", [],
                          keyboards.control_keyboard(chat))
     else:
         response, keyboard = keyboards.choose_keyboard(
             chat=chat,
             response="Выберите группу",
             buttons=groups,
             page_list=page_list,
             action_now="отключиться_выбор",
             action_to='отключиться',
             action_from='управление')
         self.kristy.send(peer, response, None, keyboard)
 def execute(self,
             chat,
             peer,
             sender,
             args=None,
             attachments=None,
             fwd_messages=None):
     page_list = args["page_list"]
     object_groups = self.kristy.db.get_object_all_groups(chat)
     groups_sorted = sorted([{
         "name": group["name"],
         "count": len(group["members"])
     } for group in object_groups],
                            key=lambda group:
                            (-group["count"], group["name"]))
     sender_groups = self.kristy.db.get_user_groups(chat, sender)
     groups = [{
         "name":
         "{0} ({1})".format(group["name"], str(group["count"])),
         "argument":
         group["name"],
         "color":
         "green" if group["name"] in sender_groups else ""
     } for group in groups_sorted]
     if not groups:
         self.kristy.send(peer, "Групп не найдено", [],
                          keyboards.information_keyboard(chat))
     else:
         response, keyboard = keyboards.choose_keyboard(
             chat=chat,
             response="Выберите группу",
             buttons=groups,
             page_list=page_list,
             action_now='участники_группы_выбор',
             action_to="участники_группы",
             action_from='информация')
         self.kristy.send(peer, response, None, keyboard)
 def execute(self,
             chat,
             peer,
             sender,
             args=None,
             attachments=None,
             fwd_messages=None):
     page_list = args["page_list"]
     tags_from_db = self.kristy.db.all_email_tags(chat)
     tags_from_db.sort()
     tags = []
     for tag in tags_from_db:
         events = self.kristy.db.get_events_for_email(chat, tag)
         count_all = len(events)
         count_active = len(
             self.kristy.db.get_future_events_email(chat, tag))
         tags.append({
             "name":
             '{0} ({1}/{2})'.format(tag, count_active, count_all),
             "argument":
             tag,
             "color":
             "green" if count_active else ""
         })
     if not tags_from_db:
         self.kristy.send(peer, "Нету тегов почты", [],
                          keyboards.start_keyboard(chat))
     else:
         response, keyboard = keyboards.choose_keyboard(
             chat=chat,
             response="Выберите тег",
             buttons=tags,
             page_list=page_list,
             action_now="почта_тег_выбор",
             action_to='почта_событие_выбор',
             action_from='стартовая_клавиатура')
         self.kristy.send(peer, response, None, keyboard)
Esempio n. 14
0
 def choose_group(self, chat, peer, sender, page_list, response=""):
     object_groups = self.kristy.db.get_object_all_groups(chat)
     sender_groups = self.kristy.db.get_user_groups(chat, sender)
     rank_sender_value = self.kristy.db.get_user_rank_val(chat, sender)
     groups_sorted = sorted(
         [{
             "name": group["name"],
             "count": len(group["members"])
         } for group in object_groups if sender == group["creator"]
          or rank_sender_value >= ranks.Rank.MODERATOR.value],
         key=lambda group: (-group["count"], group["name"]))
     groups = [{
         "name":
         "{0} ({1})".format(group["name"], str(group["count"])),
         "argument":
         group["name"],
         "color":
         "green" if group["name"] in sender_groups else ""
     } for group in groups_sorted]
     if not groups:
         self.kristy.send(
             peer, "Нету групп, которые вы можете удалить"
             if not response else response, [],
             keyboards.delete_keyboard(chat))
     else:
         response_keyboard, keyboard = keyboards.choose_keyboard(
             chat=chat,
             response="Выбетите группу",
             buttons=groups,
             page_list=page_list,
             action_now="удалить_группу",
             action_to='удалить_группу',
             action_from='удалить')
         self.kristy.send(peer,
                          response_keyboard if not response else response,
                          None, keyboard)