-
Notifications
You must be signed in to change notification settings - Fork 325
Description
import vk_api
import re
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.utils import get_random_id # Импортируем get_random_id
Ваш токен доступа
TOKEN = 'Токен'
ID модератора или группы (замените на фактический числовой ID)
MODERATOR_ID = id
Инициализация сессии VK
vk_session = vk_api.VkApi(token=TOKEN)
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()
Ваш белый список ссылок
whitelist = [
'https://example.com',
'https://example.com',
'https://example.com',
'https://example.com'
]
url_pattern = re.compile(r'https?://[^\s]+')
def check_message(message, user_id):
urls = url_pattern.findall(message)
for url in urls:
if url not in whitelist:
notify_moderators(user_id)
def notify_moderators(user_id):
message = f'Я удалил сообщение от пользователя {user_id}, так как в его сообщении была подозрительная ссылка. Просьба модераторов проверить.'
try:
vk.messages.send(peer_id=MODERATOR_ID, message=message, random_id=get_random_id())
except Exception as e:
print(f"Ошибка при отправке сообщения модераторам: {e}")
def main():
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
user_id = event.from_id
text = event.text
check_message(text, user_id)
if name == 'main':
main()
ошибка: File "C:\Maf\bot.py", line 34, in main
longpoll = vk_api.longpoll.VkLongPoll(vk_session)
^^^^^^^^^^^^^^^
AttributeError: module 'vk_api' has no attribute 'longpoll'
(Все библиотеки скачаны и переустановлены неоднократно..)