Esempio n. 1
0
 def message_new(self):
     if self.event.user_id == store.bot.user_id and self.event.from_chat:
         message: str = self.event.text.lower()
         if message.startswith(store.config.TriggerAddAudio):
             name = message.replace(store.config.TriggerAddAudio,
                                    "").strip()
             res = store.bot.api.messages.getById(
                 message_ids=self.event.message_id)["items"]
             get_id = None
             if res:
                 response = res[0]
                 reply_message = response.get("reply_message")
                 fwd_messages = response.get("fwd_messages")
                 if reply_message:
                     get_id = reply_message
                 elif fwd_messages:
                     get_id = fwd_messages[0]
             if get_id is not None and name:
                 url = GetLinkAudio(get_id)
                 if url:
                     urlretrieve(url, f"example/audios/{name}.ogg")
                     self.MessageDelete(self.event.message_id)
                     loadAudios()
                     return
         elif message.startswith(store.config.TriggerAudio):
             message = message.replace(store.config.TriggerAudio, "",
                                       1).strip()
             if message in audios:
                 cached = store.config.audio_cache.get(message)
                 if not cached:
                     cached = self.upload.audio_message(
                         f"{os.getcwd()}/example/audios/{message}.ogg",
                         peer_id=self.event.peer_id)
                     audio = cached.get("audio_message")
                     if audio:
                         store.config.audio_cache[
                             message] = f"doc{audio['owner_id']}_{audio['id']}_{audio['access_key']}"
                         store.save()
                 res = store.bot.api.messages.getById(
                     message_ids=self.event.message_id)["items"]
                 reply_to = None
                 if res:
                     response = res[0]
                     reply_message = response.get("reply_message")
                     if reply_message:
                         reply_to = reply_message['id']
                 self.MessagesSend(
                     _peer_id=self.event.peer_id,
                     attachment=store.config.audio_cache.get(message),
                     reply_to=reply_to)
                 self.MessageDelete(self.event.message_id)
Esempio n. 2
0
from vk_api.longpoll import Event, VkEventType

from configs import store
from utils import Base

store if store.config.get("TriggerDelete") else store.add_value("TriggerDelete", "ой")
store if store.config.get("TriggerTranslate") else store.add_value("TriggerTranslate", "рас")
store.save()


class Main(Base):
    __flags__ = {
        VkEventType.MESSAGE_NEW: True,
        VkEventType.MESSAGE_FLAGS_SET: False,
        VkEventType.MESSAGE_EDIT: False
    }

    def __init__(self, event: Event):
        self.disable = False
        self.event = event

    def message_new(self):
        if self.event.user_id == store.bot.user_id and self.event.from_chat:
            message = self.event.text.lower()
            if message.startswith(store.config.TriggerDelete):
                message_ = message.replace(store.config.TriggerDelete, '')
                if not len(message_):
                    message_ = str(abs(len(message_) + 1))
                if message_.isdigit():
                    res = store.bot.api.messages.getHistory(peer_id=self.event.peer_id)
Esempio n. 3
0
    def message_new(self):
        if self.event.from_chat:
            message = self.event.text.lower()
            find = CheckMarkUser(message)
            if self.event.user_id != store.bot.user_id:
                if find and self.event.peer_id not in store.config.IgnoreListMention:
                    if datetime.datetime.now() >= store.mentionLastFind:
                        if len(store.config.Answers):
                            choice_msg = random.choice(store.config.Answers)
                            try:
                                time.sleep(.3)
                                if isinstance(choice_msg, int):
                                    store.bot.api.messages.send(peer_id=self.event.peer_id, sticker_id=choice_msg,
                                                                random_id=random.randint(-1000000, 1000000))
                                else:
                                    store.bot.api.messages.send(peer_id=self.event.peer_id, message=choice_msg,
                                                                random_id=random.randint(-1000000, 1000000))
                            except Exception as s:
                                print("Отправка сообещния на упоминание:", s)
                            finally:
                                store.mentionLastFind = datetime.datetime.now() + datetime.timedelta(
                                    minutes=store.config.TimeWait)
            else:
                if message == store.config.TriggerIgnoreMention:
                    dialog_id = self.event.peer_id
                    if dialog_id in store.config.IgnoreListMention:
                        store.config.IgnoreListMention.remove(dialog_id)
                        self.MessageEdit(self.event.message_id, f"Диалог <<{dialog_id}>> удален из игнор листа.",
                                         dialog_id)
                    else:
                        store.config.IgnoreListMention.append(self.event.peer_id)
                        self.MessageEdit(self.event.message_id, f"Диалог <<{dialog_id}>> добавлен в игнор лист.",
                                         dialog_id)
                    self.run(self.MessageDelete, arg=[self.event.message_id], timeout=store.config.TimeOutDel)
                    store.save()
                    return

                elif message.startswith(store.config.TriggerAddStickers):
                    sticker_id = None
                    response = store.bot.api.messages.getById(message_ids=self.event.message_id)["items"]
                    if response:
                        response = response[0]
                        get_sticker = response.get("reply_message")
                        if get_sticker is None:
                            get_sticker = response.get("fwd_messages")
                            if get_sticker:
                                get_sticker = get_sticker[0]
                            else:
                                get_sticker = None
                        if get_sticker is not None:
                            attach = get_sticker.get("attachments")
                            if attach:
                                attach = attach[0].get("sticker")
                                if attach is not None:
                                    sticker_id = attach["sticker_id"]
                    if sticker_id is not None:
                        if sticker_id in store.config.Answers:
                            store.config.Answers.remove(sticker_id)
                            self.MessageEdit(self.event.message_id, f"Стикер <<{sticker_id}>> удален.",
                                             self.event.peer_id)
                        else:
                            store.config.Answers.append(sticker_id)
                            self.MessageEdit(self.event.message_id, f"Стикер <<{sticker_id}>> добавлен.",
                                             self.event.peer_id)
                        self.run(self.MessageDelete, arg=[self.event.message_id], timeout=store.config.TimeOutDel)
                        store.save()
Esempio n. 4
0
    def message_new(self):
        if self.event.from_chat and self.event.user_id > 0:
            if self.event.user_id != store.bot.user_id:
                msg = Message(self.event.user_id, self.event.peer_id, self.event.message_id)
                if self.event.peer_id not in store.messages:
                    store.messages[self.event.peer_id] = []
                if self.event.text:
                    msg.text = self.event.text[:150]
                else:
                    if msg.access:
                        msg = GetAllAttachments(msg)
                _len = len(store.messages[self.event.peer_id])
                if _len > 500:
                    store.messages[self.event.peer_id] = store.messages[self.event.peer_id][_len - 250:]
                store.messages[self.event.peer_id].append(msg)
            else:
                if not self.event.text:
                    return
                message = self.event.message.lower()

                if message.startswith(store.config.TriggerShowLog):
                    cmd = message[len(store.config.TriggerShowLog):].strip()
                    show_only_deleted = cmd == "+"
                    response = store.bot.api.messages.getById(message_ids=self.event.message_id)["items"]
                    get_user_id = None
                    if response:
                        response = response[0]
                        reply_message = response.get("reply_message")
                        fwd_messages = response.get("fwd_messages")
                        if reply_message:
                            get_user_id = reply_message["from_id"]
                        elif fwd_messages:
                            get_user_id = fwd_messages[0]["from_id"]

                    text = f"Лог {self.GetNameUsers(get_user_id) if get_user_id else ''}:\n"
                    arr = store.messages.get(self.event.peer_id, [])
                    logs = []
                    for user in arr:
                        if user.user_id == get_user_id or not get_user_id:
                            if (show_only_deleted and user.deleted) or not show_only_deleted:
                                logs.append(user)
                    lastUser = 0
                    logs = logs if len(logs) < 10 else logs[len(logs) - 10:]
                    for user in logs:
                        a = "Вложения:\n " + "\n".join(list(set(user.attachments))) + "\n"
                        if get_user_id or (lastUser == user.user_id):
                            name = ""
                        else:
                            name = user.name + "\n"
                        lastUser = user.user_id
                        text += f"{name}{user.date} -- {user.get_edited()}" \
                                f"{user.get_deleted()} {user.text}\n" \
                                f"{a if user.attachments else ''}" \
                                f"{'' if get_user_id else ''}"
                    self.MessagesSend(self.event.peer_id, text)
                    self.MessageDelete(self.event.message_id)

                if message == store.config.TriggerToAddChatLogs:
                    if self.event.peer_id in store.config.WhiteListChat:
                        store.config.WhiteListChat.remove(self.event.peer_id)
                        self.MessageEdit(self.event.message_id, f"Беседа <<{self.event.peer_id}>> удалена.",
                                         self.event.peer_id)
                    else:
                        store.config.WhiteListChat.append(self.event.peer_id)
                        self.MessageEdit(self.event.message_id, f"Беседа <<{self.event.peer_id}>> добавлена.",
                                         self.event.peer_id)
                    self.run(target=self.MessageDelete, arg=[self.event.message_id], timeout=5)
                    store.save()

                if message == store.config.TriggerShowChatsLogs:
                    chats = "\n".join(
                        list(
                            map(lambda x: f"{x} {'✅' if self.event.peer_id == x else ''}", store.config.WhiteListChat)))
                    self.MessageEdit(self.event.message_id,
                                     f"Все чаты в которых включено получение вложений:\n {chats}", self.event.peer_id)
                    self.run(target=self.MessageDelete, arg=[self.event.message_id], timeout=10)