Skip to content

aalex0372/Animated-Spoon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Animated-Spoon

Content Moderation Bot

This Telegram bot is designed for automated monitoring and filtering of messages in chats to detect offensive language. It utilizes aiogram libraries for interacting with the Telegram API, redis for data storage, and httpx for HTTP requests to the Google Perspective API and OpenAI API. The bot checks each incoming message for length and validity, then analyzes the text for offensive words. If detected, the message can be deleted or modified. Additionally, the bot uses AI to replace offensive language with neutral equivalents while preserving the message's meaning and structure. All errors are logged and sent to the administrator for further analysis and correction.

Here's a detailed breakdown of how the bot works:

Initialization and Setup:

  1. Libraries and APIs:

    The bot uses 'aiogram' library to interact with the Telegram API.

    'redis' is utilized for data storage.

    'httpx' is used for making HTTP requests.

  2. APIs and API Tokens:

    'OPENAI_API_TOKEN' for OpenAI API.

    'TELEGRAM_API_TOKEN' for Telegram API.

    'PERSPECTIVE_API_TOKEN' for Google Perspective API.

Message Handler ('handle_text_messages'):

  1. Function Purpose:

    Handles incoming text messages from users.

    Validates message length and correctness.

  2. Group Information Retrieval:

    Retrieves previously saved group information from Redis.

    Throws an exception if data is missing or invalid.

  3. Swearing Detection ('swearing_local_test'):

    Splits the message into words and checks against the loaded list of offensive words.

    If offensive words are found, calls 'handle_method' for message processing.

  4. Local Check Flow:

    If no offensive words are found locally, invokes 'perspectiveapi' for additional toxicity evaluation.

Loading Offensive Vocabulary:

Initially, the bot loads a list of offensive words from the Redis database.

Handling Methods ('handle_method'):

Executes actions based on group-specific settings:

Deletes the message.

Sends a warning.

Calls 'OpenAI' api for replacement if specified.

Perspective API Usage ('perspectiveapi'):

Sends the message text to Google Perspective API for toxicity analysis.

Compares the toxicity level against the group's defined threshold.

If the message is toxic, triggers 'handle_method'.

OpenAI API Usage ('openaiapi'):

If specified by the method, utilizes OpenAI API to replace offensive language with neutral equivalents.

Sends the processed message back to the group.

Error Logging ('log_error'):

Logs errors occurring during any stage of message processing.

Sends error messages to the bot administrator for further analysis and resolution.

Clone the Repository:

git clone https://github.com/aalex0372/Animated-Spoon.git
cd Animated-Spoon
pip install -r requirements.txt
pip install --upgrade -r requirements.txt

Conclusion:

This bot efficiently utilizes asynchronous operations to handle message processing, API calls, and real-time data management. It ensures a high degree of automation and message security within Telegram chats, effectively monitoring and filtering offensive content while preserving message integrity and structure.