commit
710b0c4353
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
@ -0,0 +1,187 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredPackages">
|
||||||
|
<value>
|
||||||
|
<list size="159">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="httpx" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="Babel" />
|
||||||
|
<item index="2" class="java.lang.String" itemvalue="sorted-nearest" />
|
||||||
|
<item index="3" class="java.lang.String" itemvalue="PyYAML" />
|
||||||
|
<item index="4" class="java.lang.String" itemvalue="marshmallow" />
|
||||||
|
<item index="5" class="java.lang.String" itemvalue="executing" />
|
||||||
|
<item index="6" class="java.lang.String" itemvalue="fisher" />
|
||||||
|
<item index="7" class="java.lang.String" itemvalue="gradio_client" />
|
||||||
|
<item index="8" class="java.lang.String" itemvalue="Pygments" />
|
||||||
|
<item index="9" class="java.lang.String" itemvalue="langchain" />
|
||||||
|
<item index="10" class="java.lang.String" itemvalue="starlette" />
|
||||||
|
<item index="11" class="java.lang.String" itemvalue="bleach" />
|
||||||
|
<item index="12" class="java.lang.String" itemvalue="jupyter_server_terminals" />
|
||||||
|
<item index="13" class="java.lang.String" itemvalue="soupsieve" />
|
||||||
|
<item index="14" class="java.lang.String" itemvalue="uvicorn" />
|
||||||
|
<item index="15" class="java.lang.String" itemvalue="jsonschema" />
|
||||||
|
<item index="16" class="java.lang.String" itemvalue="terminado" />
|
||||||
|
<item index="17" class="java.lang.String" itemvalue="comm" />
|
||||||
|
<item index="18" class="java.lang.String" itemvalue="pydub" />
|
||||||
|
<item index="19" class="java.lang.String" itemvalue="gunicorn" />
|
||||||
|
<item index="20" class="java.lang.String" itemvalue="click" />
|
||||||
|
<item index="21" class="java.lang.String" itemvalue="ipykernel" />
|
||||||
|
<item index="22" class="java.lang.String" itemvalue="nbconvert" />
|
||||||
|
<item index="23" class="java.lang.String" itemvalue="attrs" />
|
||||||
|
<item index="24" class="java.lang.String" itemvalue="contourpy" />
|
||||||
|
<item index="25" class="java.lang.String" itemvalue="psutil" />
|
||||||
|
<item index="26" class="java.lang.String" itemvalue="dataclasses-json" />
|
||||||
|
<item index="27" class="java.lang.String" itemvalue="jedi" />
|
||||||
|
<item index="28" class="java.lang.String" itemvalue="openai" />
|
||||||
|
<item index="29" class="java.lang.String" itemvalue="jupyter_server" />
|
||||||
|
<item index="30" class="java.lang.String" itemvalue="natsort" />
|
||||||
|
<item index="31" class="java.lang.String" itemvalue="asttokens" />
|
||||||
|
<item index="32" class="java.lang.String" itemvalue="platformdirs" />
|
||||||
|
<item index="33" class="java.lang.String" itemvalue="matplotlib" />
|
||||||
|
<item index="34" class="java.lang.String" itemvalue="pandavro" />
|
||||||
|
<item index="35" class="java.lang.String" itemvalue="jsonpatch" />
|
||||||
|
<item index="36" class="java.lang.String" itemvalue="httpcore" />
|
||||||
|
<item index="37" class="java.lang.String" itemvalue="referencing" />
|
||||||
|
<item index="38" class="java.lang.String" itemvalue="json5" />
|
||||||
|
<item index="39" class="java.lang.String" itemvalue="pyfaidx" />
|
||||||
|
<item index="40" class="java.lang.String" itemvalue="numpy" />
|
||||||
|
<item index="41" class="java.lang.String" itemvalue="requests" />
|
||||||
|
<item index="42" class="java.lang.String" itemvalue="fastavro" />
|
||||||
|
<item index="43" class="java.lang.String" itemvalue="grpcio-reflection" />
|
||||||
|
<item index="44" class="java.lang.String" itemvalue="jupyter-events" />
|
||||||
|
<item index="45" class="java.lang.String" itemvalue="websocket-client" />
|
||||||
|
<item index="46" class="java.lang.String" itemvalue="sqlalchemy2-stubs" />
|
||||||
|
<item index="47" class="java.lang.String" itemvalue="pysam" />
|
||||||
|
<item index="48" class="java.lang.String" itemvalue="stack-data" />
|
||||||
|
<item index="49" class="java.lang.String" itemvalue="methplotlib" />
|
||||||
|
<item index="50" class="java.lang.String" itemvalue="zipp" />
|
||||||
|
<item index="51" class="java.lang.String" itemvalue="nest-asyncio" />
|
||||||
|
<item index="52" class="java.lang.String" itemvalue="tenacity" />
|
||||||
|
<item index="53" class="java.lang.String" itemvalue="mmh3" />
|
||||||
|
<item index="54" class="java.lang.String" itemvalue="prompt-toolkit" />
|
||||||
|
<item index="55" class="java.lang.String" itemvalue="linkify-it-py" />
|
||||||
|
<item index="56" class="java.lang.String" itemvalue="websockets" />
|
||||||
|
<item index="57" class="java.lang.String" itemvalue="ipywidgets" />
|
||||||
|
<item index="58" class="java.lang.String" itemvalue="pyarrow" />
|
||||||
|
<item index="59" class="java.lang.String" itemvalue="watchfiles" />
|
||||||
|
<item index="60" class="java.lang.String" itemvalue="tornado" />
|
||||||
|
<item index="61" class="java.lang.String" itemvalue="aiofiles" />
|
||||||
|
<item index="62" class="java.lang.String" itemvalue="jsonpointer" />
|
||||||
|
<item index="63" class="java.lang.String" itemvalue="Send2Trash" />
|
||||||
|
<item index="64" class="java.lang.String" itemvalue="plotly" />
|
||||||
|
<item index="65" class="java.lang.String" itemvalue="overrides" />
|
||||||
|
<item index="66" class="java.lang.String" itemvalue="python-multipart" />
|
||||||
|
<item index="67" class="java.lang.String" itemvalue="toml" />
|
||||||
|
<item index="68" class="java.lang.String" itemvalue="mistune" />
|
||||||
|
<item index="69" class="java.lang.String" itemvalue="pandas" />
|
||||||
|
<item index="70" class="java.lang.String" itemvalue="importlib-resources" />
|
||||||
|
<item index="71" class="java.lang.String" itemvalue="toolz" />
|
||||||
|
<item index="72" class="java.lang.String" itemvalue="mpmath" />
|
||||||
|
<item index="73" class="java.lang.String" itemvalue="pyranges" />
|
||||||
|
<item index="74" class="java.lang.String" itemvalue="debugpy" />
|
||||||
|
<item index="75" class="java.lang.String" itemvalue="argon2-cffi" />
|
||||||
|
<item index="76" class="java.lang.String" itemvalue="yarl" />
|
||||||
|
<item index="77" class="java.lang.String" itemvalue="pytz" />
|
||||||
|
<item index="78" class="java.lang.String" itemvalue="moreorless" />
|
||||||
|
<item index="79" class="java.lang.String" itemvalue="Pillow" />
|
||||||
|
<item index="80" class="java.lang.String" itemvalue="notebook_shim" />
|
||||||
|
<item index="81" class="java.lang.String" itemvalue="traitlets" />
|
||||||
|
<item index="82" class="java.lang.String" itemvalue="bowler" />
|
||||||
|
<item index="83" class="java.lang.String" itemvalue="protobuf" />
|
||||||
|
<item index="84" class="java.lang.String" itemvalue="rfc3339-validator" />
|
||||||
|
<item index="85" class="java.lang.String" itemvalue="arrow" />
|
||||||
|
<item index="86" class="java.lang.String" itemvalue="mypy" />
|
||||||
|
<item index="87" class="java.lang.String" itemvalue="python-dotenv" />
|
||||||
|
<item index="88" class="java.lang.String" itemvalue="nbclient" />
|
||||||
|
<item index="89" class="java.lang.String" itemvalue="partd" />
|
||||||
|
<item index="90" class="java.lang.String" itemvalue="MarkupSafe" />
|
||||||
|
<item index="91" class="java.lang.String" itemvalue="locket" />
|
||||||
|
<item index="92" class="java.lang.String" itemvalue="tinycss2" />
|
||||||
|
<item index="93" class="java.lang.String" itemvalue="httptools" />
|
||||||
|
<item index="94" class="java.lang.String" itemvalue="frozenlist" />
|
||||||
|
<item index="95" class="java.lang.String" itemvalue="appdirs" />
|
||||||
|
<item index="96" class="java.lang.String" itemvalue="python-json-logger" />
|
||||||
|
<item index="97" class="java.lang.String" itemvalue="semantic-version" />
|
||||||
|
<item index="98" class="java.lang.String" itemvalue="filelock" />
|
||||||
|
<item index="99" class="java.lang.String" itemvalue="jupyterlab-widgets" />
|
||||||
|
<item index="100" class="java.lang.String" itemvalue="pyzmq" />
|
||||||
|
<item index="101" class="java.lang.String" itemvalue="certifi" />
|
||||||
|
<item index="102" class="java.lang.String" itemvalue="anyio" />
|
||||||
|
<item index="103" class="java.lang.String" itemvalue="Markdown" />
|
||||||
|
<item index="104" class="java.lang.String" itemvalue="sympy" />
|
||||||
|
<item index="105" class="java.lang.String" itemvalue="uvloop" />
|
||||||
|
<item index="106" class="java.lang.String" itemvalue="notebook" />
|
||||||
|
<item index="107" class="java.lang.String" itemvalue="beautifulsoup4" />
|
||||||
|
<item index="108" class="java.lang.String" itemvalue="isoduration" />
|
||||||
|
<item index="109" class="java.lang.String" itemvalue="jupyter-lsp" />
|
||||||
|
<item index="110" class="java.lang.String" itemvalue="fqdn" />
|
||||||
|
<item index="111" class="java.lang.String" itemvalue="jupyter_client" />
|
||||||
|
<item index="112" class="java.lang.String" itemvalue="orjson" />
|
||||||
|
<item index="113" class="java.lang.String" itemvalue="jupyterlab_server" />
|
||||||
|
<item index="114" class="java.lang.String" itemvalue="altair" />
|
||||||
|
<item index="115" class="java.lang.String" itemvalue="feast" />
|
||||||
|
<item index="116" class="java.lang.String" itemvalue="fonttools" />
|
||||||
|
<item index="117" class="java.lang.String" itemvalue="mdit-py-plugins" />
|
||||||
|
<item index="118" class="java.lang.String" itemvalue="widgetsnbextension" />
|
||||||
|
<item index="119" class="java.lang.String" itemvalue="charset-normalizer" />
|
||||||
|
<item index="120" class="java.lang.String" itemvalue="uc-micro-py" />
|
||||||
|
<item index="121" class="java.lang.String" itemvalue="biopython" />
|
||||||
|
<item index="122" class="java.lang.String" itemvalue="dask" />
|
||||||
|
<item index="123" class="java.lang.String" itemvalue="ffmpy" />
|
||||||
|
<item index="124" class="java.lang.String" itemvalue="langsmith" />
|
||||||
|
<item index="125" class="java.lang.String" itemvalue="numexpr" />
|
||||||
|
<item index="126" class="java.lang.String" itemvalue="gradio" />
|
||||||
|
<item index="127" class="java.lang.String" itemvalue="webcolors" />
|
||||||
|
<item index="128" class="java.lang.String" itemvalue="async-timeout" />
|
||||||
|
<item index="129" class="java.lang.String" itemvalue="SQLAlchemy" />
|
||||||
|
<item index="130" class="java.lang.String" itemvalue="sklearn" />
|
||||||
|
<item index="131" class="java.lang.String" itemvalue="cloudpickle" />
|
||||||
|
<item index="132" class="java.lang.String" itemvalue="wcwidth" />
|
||||||
|
<item index="133" class="java.lang.String" itemvalue="jupyter_core" />
|
||||||
|
<item index="134" class="java.lang.String" itemvalue="importlib-metadata" />
|
||||||
|
<item index="135" class="java.lang.String" itemvalue="rfc3986-validator" />
|
||||||
|
<item index="136" class="java.lang.String" itemvalue="typeguard" />
|
||||||
|
<item index="137" class="java.lang.String" itemvalue="ncls" />
|
||||||
|
<item index="138" class="java.lang.String" itemvalue="jsonschema-specifications" />
|
||||||
|
<item index="139" class="java.lang.String" itemvalue="rpds-py" />
|
||||||
|
<item index="140" class="java.lang.String" itemvalue="uri-template" />
|
||||||
|
<item index="141" class="java.lang.String" itemvalue="fissix" />
|
||||||
|
<item index="142" class="java.lang.String" itemvalue="urllib3" />
|
||||||
|
<item index="143" class="java.lang.String" itemvalue="jupyterlab" />
|
||||||
|
<item index="144" class="java.lang.String" itemvalue="Cython" />
|
||||||
|
<item index="145" class="java.lang.String" itemvalue="six" />
|
||||||
|
<item index="146" class="java.lang.String" itemvalue="pyTelegramBotAPI" />
|
||||||
|
<item index="147" class="java.lang.String" itemvalue="nbformat" />
|
||||||
|
<item index="148" class="java.lang.String" itemvalue="ipython" />
|
||||||
|
<item index="149" class="java.lang.String" itemvalue="dill" />
|
||||||
|
<item index="150" class="java.lang.String" itemvalue="volatile" />
|
||||||
|
<item index="151" class="java.lang.String" itemvalue="fastjsonschema" />
|
||||||
|
<item index="152" class="java.lang.String" itemvalue="prometheus-client" />
|
||||||
|
<item index="153" class="java.lang.String" itemvalue="tqdm" />
|
||||||
|
<item index="154" class="java.lang.String" itemvalue="fastapi" />
|
||||||
|
<item index="155" class="java.lang.String" itemvalue="proto-plus" />
|
||||||
|
<item index="156" class="java.lang.String" itemvalue="aiohttp" />
|
||||||
|
<item index="157" class="java.lang.String" itemvalue="grpcio" />
|
||||||
|
<item index="158" class="java.lang.String" itemvalue="async-lru" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="N803" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredIdentifiers">
|
||||||
|
<list>
|
||||||
|
<option value="random.random.choice" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="$USER_HOME$/anaconda3" />
|
||||||
|
</component>
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="ASK" />
|
||||||
|
<option name="description" value="" />
|
||||||
|
</component>
|
||||||
|
<component name="MarkdownSettingsMigration">
|
||||||
|
<option name="stateVersion" value="1" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="$USER_HOME$/anaconda3" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/vk-bot.iml" filepath="$PROJECT_DIR$/.idea/vk-bot.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,9 @@
|
|||||||
|
FROM python:3.9-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY src/ /app/src/
|
||||||
|
|
||||||
|
CMD ["python", "/app/src/main.py"]
|
@ -0,0 +1,8 @@
|
|||||||
|
version: '3.8'
|
||||||
|
services:
|
||||||
|
vk_bot:
|
||||||
|
build: .
|
||||||
|
environment:
|
||||||
|
GROUP_ID: "group_id"
|
||||||
|
ACCESS_TOKEN: "access_token"
|
||||||
|
restart: unless-stopped
|
@ -0,0 +1,3 @@
|
|||||||
|
vk_api
|
||||||
|
transformers
|
||||||
|
torch
|
@ -0,0 +1,67 @@
|
|||||||
|
import logging
|
||||||
|
import vk_api
|
||||||
|
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
|
||||||
|
import time
|
||||||
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
||||||
|
import torch
|
||||||
|
|
||||||
|
# Настройка логирования
|
||||||
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
model_path = "RUSpam/spam_deberta_v4"
|
||||||
|
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
||||||
|
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
||||||
|
GROUP_ID = ""
|
||||||
|
ACCESS_TOKEN = ""
|
||||||
|
THRESHOLD_REACTIONS = 3
|
||||||
|
|
||||||
|
def is_spam(message):
|
||||||
|
inputs = tokenizer(message, return_tensors="pt", truncation=True, max_length=256)
|
||||||
|
with torch.no_grad():
|
||||||
|
outputs = model(**inputs)
|
||||||
|
logits = outputs.logits
|
||||||
|
predicted_class = torch.argmax(logits, dim=1).item()
|
||||||
|
return predicted_class == 1
|
||||||
|
|
||||||
|
# Основной класс бота
|
||||||
|
class VkBot:
|
||||||
|
def __init__(self, group_id, token):
|
||||||
|
self.group_id = group_id
|
||||||
|
self.vk_session = vk_api.VkApi(token=token)
|
||||||
|
self.vk = self.vk_session.get_api()
|
||||||
|
self.longpoll = VkBotLongPoll(self.vk_session, group_id)
|
||||||
|
self.message_reactions = {}
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
logger.info("Бот запущен!")
|
||||||
|
for event in self.longpoll.listen():
|
||||||
|
if event.type == VkBotEventType.MESSAGE_NEW:
|
||||||
|
message = event.object['message']
|
||||||
|
user_id = message["from_id"]
|
||||||
|
peer_id = message["peer_id"]
|
||||||
|
message_id = message["conversation_message_id"]
|
||||||
|
text = message["text"]
|
||||||
|
|
||||||
|
if peer_id > 2_000_000_000 and is_spam(text):
|
||||||
|
logger.warning(f"Обнаружено спам-сообщение от пользователя {user_id}: {text}")
|
||||||
|
self.delete_message(peer_id=peer_id, user_id=user_id, message_id=message_id)
|
||||||
|
|
||||||
|
def delete_message(self, peer_id, user_id, message_id):
|
||||||
|
"""Удалить сообщение"""
|
||||||
|
if not self.is_conservation_admin(peer_id=peer_id, user_id=user_id):
|
||||||
|
self.vk.messages.delete(cmids=message_id, peer_id=peer_id)
|
||||||
|
logger.info(f"Сообщение {message_id} удалено из беседы {peer_id} пользователем {user_id}.")
|
||||||
|
|
||||||
|
def is_conservation_admin(self, peer_id, user_id):
|
||||||
|
"""Проверка пользователя на администратора беседы."""
|
||||||
|
members = self.vk.messages.getConversationMembers(peer_id=peer_id)
|
||||||
|
for member in members['items']:
|
||||||
|
if member['member_id'] == user_id:
|
||||||
|
return member['is_admin']
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Запуск бота
|
||||||
|
if __name__ == "__main__":
|
||||||
|
bot = VkBot(GROUP_ID, ACCESS_TOKEN)
|
||||||
|
bot.run()
|
Loading…
Reference in new issue