Skip to content

Version 1.2

Latest
Compare
Choose a tag to compare
@BeyondKarto BeyondKarto released this 14 Aug 18:41
· 2 commits to main since this release
ffe9942

Telegram Bot for Points Calculation - Version 1.2

This Telegram bot is designed to count the number of characters in user messages in chats and assign points based on the length of these messages. The bot now supports additional functionality, including image point calculation, enhanced logging, and more refined data management. Only the bot owner has the rights to use special commands to manage the bot.

New Features and Updates in Version 1.2

  1. Image Points Calculation:

    • The bot now awards a fixed 10 points for each image sent in the chat, providing additional ways for users to earn points.
  2. Enhanced Data Logging:

    • Every user message, including text and images, is now logged in an Excel file on a dedicated "Messages" sheet. The logged data includes:
      • Chat ID
      • User ID
      • Username
      • Message text (or "Photo" for images)
      • Timestamp of the message
      • Message length (in characters)
      • Points earned for each message
    • The bot also logs whenever the /resetbot command is used, recording the reset action in the "Messages" sheet.
  3. Detailed Console Logging:

    • The bot provides detailed logs in the console, displaying information for each message processed:
      • Chat ID
      • User ID
      • Username
      • Message text
      • Message length
      • Points earned
  4. Refined Commands:

    • Updated command names for clarity:
      • /start is now /startbot
      • /reset is now /resetbot
      • /top is now /topbot
      • /getfile is now /getfilebot
  5. Code Improvements:

    • Added null checks and ensured that all operations handle potential null values gracefully.
    • Optimized the data management structure for better performance and reliability.
  6. Excel File Management:

    • The Excel file is updated every minute, ensuring that all data is recorded consistently.
    • The "Leaderboard" sheet tracks overall user performance, while the "Messages" sheet logs detailed message-level data.

Functionality

Points Calculation:

  • The bot calculates points for each user message based on the following logic:
    • If the message contains up to 10 characters: The user earns 0.25 points per character.
    • If the message contains between 10 and 25 characters: The user earns 0.5 points per character.
    • If the message contains between 25 and 75 characters: The user earns 0.75 points per character.
    • If the message contains more than 75 characters: The user earns 1 point per character.
    • If the message contains an image: The user earns 10 points.

Leaderboard Management:

  • The bot tracks the points earned by users in each chat and generates a leaderboard based on these data. The bot owner can view the current top 10 users using a special command.

Commands:

  • /startbot: Starts the bot and notifies that the bot begins tracking points.
  • /resetbot: Resets all tracking data in the current chat. This command can only be used by the bot owner.
  • /topbot: Shows the current top 10 users with the highest points in the chat. This command can only be used by the bot owner.
  • /getfilebot: Sends an Excel file with all points tracking data in the current chat. This command can only be used by the bot owner.

Data Storage:

  • The bot saves user points data in an Excel file, which is updated every minute. This file contains the following information:
    • Chat ID
    • User ID
    • Username
    • Number of points earned
    • Detailed message logs, including time, content, and points.

Requirements

  • .NET 5.0 or newer
  • Telegram Bot API
  • Telegram.Bot library
  • EPPlus library for working with Excel

How to Run

  1. Clone this repository.
  2. Install the required packages via NuGet:
    • Telegram.Bot
    • OfficeOpenXml
  3. Change botOwnerId in the code to your Telegram ID.
  4. Run the project using Visual Studio or the command line.

Contribution

You can contribute by creating pull requests or reporting issues in the issues section. Your suggestions for improving the bot’s functionality are welcome.