Skip to content

Latest commit

ย 

History

29 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Truth Wars - Educational Telegram Bot Game

Note (2025-07): The Drunk role has been deprecated and removed from gameplay. Any references below are for historical context only and do not reflect current gameplay.

A sophisticated Telegram bot implementing the "Truth Wars" game - an educational multiplayer social deduction experience that teaches media literacy through interactive gameplay. Players vote on headlines to determine if they're real or fake while taking on special roles with unique abilities in a strategic battle between Truth Seekers and Misinformers.

๐ŸŽฎ Game Overview

Truth Wars combines social deduction with media literacy education in an engaging 5-round format:

  • 5-8 players engage in a fixed 5-round structure (optimized for 45-minute games)
  • Trust/Flag voting on carefully curated real and fake headlines
  • Dynamic reputation system starting with 3 RP, becoming Ghost Viewer at 0 RP
  • Role-based gameplay with strategic abilities:
    • Fact Checker (Truth Team) - Gets insider info, can snipe suspected Scammers
    • Scammer (Misinformation Team) - Spreads doubt, manipulates votes
    • Influencer (Truth Team, 7+ players) - Double-weighted votes (2x voting power)
    • Normies (Truth Team) - Standard players, learn through gameplay
  • Snipe abilities for strategic shadow banning (Rounds 1-4 only)
  • Educational content seamlessly integrated through gameplay mechanics
  • Win conditions: First faction to 3 points OR highest combined reputation after 5 rounds

โœจ Key Features

๐ŸŽฏ Educational Focus

  • Real-world headlines from credible news sources
  • Carefully crafted fake news with common misinformation patterns
  • Detailed explanations after each vote revealing truth and teaching detection techniques
  • Media literacy concepts taught through gameplay and post-round explanations
  • Progressive difficulty from easy to hard headlines across 5 rounds

๐Ÿ† Reputation System

  • 3 Reputation Points starting system - lose 1 for incorrect votes, gain 1 for correct votes
  • Ghost Viewer mechanics - 0 RP players can vote but cannot speak during discussions
  • Strategic depth - Shadow banned players lose voice but retain voting power
  • Comprehensive tracking - All reputation changes logged with detailed reasoning

๐ŸŽญ Role-Based Strategy

  • Faction warfare between Truth Seekers and Misinformers
  • One-time snipe abilities (Rounds 1-4) create high-stakes tactical moments
  • Influencer mechanics - Double-weighted votes can swing close decisions (7+ players)
  • Blind rounds - Fact Checker occasionally doesn't get insider information
  • [Historical: Educational role rotation (Drunk role) was used in earlier versions]

๐Ÿ“Š Progress Tracking

  • Individual statistics - Win rates, accuracy, role performance
  • Learning analytics - Media literacy improvement over time
  • Game history - Detailed records of all games and decisions
  • Leaderboards - Top players by wins, accuracy, and learning progress

๐Ÿ—๏ธ Project Structure

truthchecker/
โ”œโ”€โ”€ bot/                    # Main bot application
โ”‚   โ”œโ”€โ”€ ai/                # AI headline generation & content curation
โ”‚   โ”‚   โ””โ”€โ”€ headline_generator.py
โ”‚   โ”œโ”€โ”€ database/          # Async SQLAlchemy models & database management
โ”‚   โ”‚   โ”œโ”€โ”€ models.py      # Complete game data models
โ”‚   โ”‚   โ””โ”€โ”€ database.py    # Database session management
โ”‚   โ”œโ”€โ”€ game/              # Core game logic & state management
โ”‚   โ”‚   โ”œโ”€โ”€ truth_wars_manager.py      # Central game orchestrator
โ”‚   โ”‚   โ”œโ”€โ”€ refined_game_states.py     # Phase-based state machine
โ”‚   โ”‚   โ””โ”€โ”€ roles.py                   # Role system & abilities
โ”‚   โ”œโ”€โ”€ handlers/          # Telegram command/message handlers
โ”‚   โ”‚   โ”œโ”€โ”€ command_handlers.py        # Basic bot commands
โ”‚   โ”‚   โ”œโ”€โ”€ truth_wars_handlers.py     # Game-specific handlers
โ”‚   โ”‚   โ”œโ”€โ”€ message_handlers.py        # Chat message processing
โ”‚   โ”‚   โ””โ”€โ”€ error_handlers.py          # Error handling & recovery
โ”‚   โ”œโ”€โ”€ utils/             # Shared utilities & configuration
โ”‚   โ”‚   โ”œโ”€โ”€ config.py      # Environment configuration
โ”‚   โ”‚   โ””โ”€โ”€ logging_config.py          # Structured logging setup
โ”‚   โ””โ”€โ”€ main.py            # Bot entry point & application setup
โ”œโ”€โ”€ docs/                  # Comprehensive documentation
โ”‚   โ”œโ”€โ”€ ARCHITECTURE.md              # Technical architecture overview
โ”‚   โ”œโ”€โ”€ DATABASE_SCHEMA_REFINED.md   # Complete database schema
โ”‚   โ”œโ”€โ”€ BOTFATHER_SETUP.md           # Bot configuration guide
โ”‚   โ”œโ”€โ”€ PROJECT_DOCUMENTATION.md     # Development documentation
โ”‚   โ”œโ”€โ”€ ROADMAP.md                   # Future development plans
โ”‚   โ”œโ”€โ”€ SETUP_GUIDE.md               # Quick setup instructions
โ”‚   โ”œโ”€โ”€ TRUTH_WARSV2.md              # Game design evolution
โ”‚   โ”œโ”€โ”€ TRUTH_WARSV3.md              # Current game design
โ”‚   โ””โ”€โ”€ V3_IMPLEMENTATION.md         # Implementation details
โ”œโ”€โ”€ tests/                 # Comprehensive test suite
โ”‚   โ”œโ”€โ”€ test_example.py    # Basic functionality tests
โ”‚   โ”œโ”€โ”€ test_truthwars_v3.py         # Game logic tests
โ”‚   โ”œโ”€โ”€ test_dm_mock.py
โ”‚   โ”œโ”€โ”€ test_duplicate_and_swap.py
โ”‚   โ”œโ”€โ”€ test_state_machine_actions.py
โ”‚   โ”œโ”€โ”€ test_state_machine_branches.py
โ”‚   โ””โ”€โ”€ test_state_machine_flow.py
โ”œโ”€โ”€ deploy/                # Deployment configurations
โ”œโ”€โ”€ run_bot.py             # Simple launcher script
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ game.db                # SQLite development database
โ””โ”€โ”€ README.md              # This file

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8+ (3.9+ recommended)
  • Telegram Bot Token (from @BotFather)
  • Group Chat (Truth Wars requires 5-8 players)

Installation

  1. Clone the repository

    git clone https://github.com/Soba101/truthchecker.git
    cd truthchecker
  2. Install dependencies

    pip install -r requirements.txt
  3. Configure environment

    If .env.example is not present, create a .env file manually with the required variables as described below.

    Edit .env with your bot token and settings

  4. Start the bot

    python run_bot.py

Essential Configuration (.env file)

# Required: Get this from @BotFather on Telegram
TELEGRAM_BOT_TOKEN=your_bot_token_here

# Optional: Database configuration (defaults to SQLite)
DATABASE_URL=sqlite+aiosqlite:///game.db

# Optional: Environment settings
ENVIRONMENT=development
LOG_LEVEL=INFO

# Optional: AI/Content settings
OPENAI_API_KEY=your_openai_key_here  # For AI headline generation
CONTENT_MODERATION=true

๐ŸŽฏ Game Commands

Basic Commands

  • /start - Welcome message and bot introduction
  • /help - Complete game guide and instructions
  • /stats - View your personal game statistics and learning progress
  • /leaderboard - See top players by wins, accuracy, and media literacy

Game Commands (Groups Only)

  • /truthwars - Start a new Truth Wars game lobby
  • /status - Check current game status, round info, and player roles
  • /ability - View your current role, abilities, and use special powers
  • /vote - Cast elimination votes during player voting phase (if enabled)

Interactive Elements

  • Trust/Flag Buttons - Vote on headlines during voting phases
  • Snipe Targeting - Use special abilities to shadow ban opponents
  • Join/Start Game - Lobby management through inline keyboards
  • Continue Game - Progress through rounds via button presses

๐Ÿ› ๏ธ Technology Stack

  • Bot Framework: python-telegram-bot 21.5+
  • Database: SQLite with SQLAlchemy 2.0 (async ORM)
  • Configuration: Pydantic with environment variable validation
  • Logging: Structlog for structured, contextual logging
  • Testing: Pytest with async support and fixtures
  • Data Storage: JSON fields for flexible game state and analytics
  • Content: Curated real/fake headlines with educational explanations

๐Ÿ“Š Development Status

๐ŸŸข Core Features Complete

  • โœ… Full game implementation with optimized 5-round structure
  • โœ… Reputation system with 3 RP starting points and Ghost Viewer mechanics
  • โœ… Trust/Flag voting with weighted votes and accuracy tracking
  • โœ… Complete role system with Fact Checker, Scammer, Influencer, Normie
  • โœ… Snipe mechanics for strategic shadow banning (Rounds 1-4)
  • โœ… Educational content delivery via post-round explanations and gameplay (Drunk role deprecated)
  • โœ… Comprehensive statistics tracking individual and game performance
  • โœ… Database schema with complete relationship mapping and analytics support
  • โœ… Error handling and recovery mechanisms for robust gameplay
  • โœ… Performance optimization for concurrent game management

๐ŸŸก In Progress

  • ๐Ÿ”„ Advanced analytics dashboard for learning insights and improvement tracking
  • ๐Ÿ”„ Additional headline content with expanded categories and difficulty progression
  • ๐Ÿ”„ Multi-language support for international accessibility
  • ๐Ÿ”„ Tournament mode for competitive educational events

๐Ÿ”ด Future Enhancements

  • ๐Ÿ“‹ Admin controls for game moderation and content management
  • ๐Ÿ“‹ Custom headline submission system with community curation
  • ๐Ÿ“‹ Integration with fact-checking APIs for real-time content verification
  • ๐Ÿ“‹ Advanced AI opponent for single-player practice mode

๐Ÿงช Testing

Run the comprehensive test suite:

# Run all tests with coverage
pytest --cov=bot --cov-report=html

# Run specific test files
pytest tests/test_example.py
pytest tests/test_truthwars_v3.py
pytest tests/test_dm_mock.py
pytest tests/test_duplicate_and_swap.py
pytest tests/test_state_machine_actions.py
pytest tests/test_state_machine_branches.py
pytest tests/test_state_machine_flow.py

# Run with verbose output
pytest -v --tb=short

๐Ÿ“– Documentation

Comprehensive documentation is available in the docs/ directory:

๐Ÿ›๏ธ Architecture & Design

๐ŸŽฎ Game Design

๐Ÿš€ Setup & Configuration

๐Ÿค Contributing

This project follows clean code principles and educational best practices:

๐Ÿ“‹ Code Standards

  • Write simple, readable code with clear documentation and comments
  • Keep files focused and modular (<200 lines when possible)
  • Test thoroughly after every meaningful change with automated tests
  • Use clear, consistent naming throughout the codebase
  • Include explanatory comments for complex logic and game mechanics

๐ŸŽฏ Development Workflow

  1. Fork the repository and create a feature branch
  2. Write tests for new functionality before implementation
  3. Implement changes following existing code patterns
  4. Update documentation to reflect changes
  5. Run full test suite to ensure no regressions
  6. Submit pull request with detailed description

๐Ÿงช Testing Requirements

  • Unit tests for all new functions and classes
  • Integration tests for game flow and database operations
  • Performance tests for concurrent game handling
  • Edge case testing for error conditions and recovery

๐ŸŽ“ Educational Goals

Truth Wars is designed to teach essential media literacy skills through engaging gameplay:

๐Ÿ“ฐ Content Evaluation

  • Source Verification - How to research and verify news source credibility
  • Fact-Checking Techniques - Using multiple sources and verification tools
  • Publication Date Awareness - Understanding timing and context of news
  • Author Credibility - Evaluating journalist expertise and bias

๐Ÿ” Critical Analysis

  • Bias Recognition - Identifying language bias, loaded terms, and framing
  • Logical Fallacy Detection - Spotting common reasoning errors
  • Evidence Assessment - Evaluating quality and relevance of supporting evidence
  • Emotional Manipulation - Recognizing appeals to fear, anger, and prejudice

๐Ÿšฉ Red Flag Detection

  • Sensationalist Headlines - Identifying clickbait and exaggerated claims
  • Suspicious Sources - Recognizing fake news websites and unreliable publishers
  • Fabricated Content - Detecting doctored images, false quotes, and manufactured stories
  • Conspiracy Theories - Understanding common patterns and logical flaws

๐Ÿง  Meta-Cognitive Skills

  • Information Seeking - Developing habits of verification and cross-referencing
  • Confirmation Bias Awareness - Recognizing and countering personal biases
  • Media Ecosystem Understanding - Learning how information spreads and mutates
  • Digital Citizenship - Responsible sharing and consumption of online content

๐Ÿ”ง Technical Features

๐ŸŽฏ Game Engine

  • Async architecture for concurrent game management
  • State machine implementation for reliable phase transitions
  • Comprehensive error handling with graceful degradation
  • Performance optimization for large group chats

๐Ÿ“Š Analytics & Learning

  • Individual progress tracking across multiple game sessions
  • Learning effectiveness measurement through accuracy improvement
  • Content performance analysis for headline difficulty optimization
  • Behavioral pattern recognition for personalized learning paths

๐Ÿ”’ Security & Privacy

  • Input validation and sanitization for all user inputs
  • Rate limiting to prevent abuse and spam
  • Minimal data collection with focus on educational analytics
  • Secure token management for bot authentication

๐Ÿ“ License

MIT License - see LICENSE file for details.

๐Ÿ†˜ Support & Troubleshooting

๐Ÿ“š Quick References

  • Setup Issues: Check Setup Guide for detailed instructions
  • Bot Configuration: See BotFather Setup for Telegram configuration
  • Game Rules: Use /help command in Telegram for complete game guide
  • Technical Issues: Check logs for error messages and debugging information

๐Ÿ› Common Issues

  • Bot not responding: Verify token and network connectivity
  • Commands showing @username: Configure privacy settings in BotFather
  • Database errors: Check file permissions and disk space
  • Group chat issues: Ensure bot has proper administrator permissions

๐Ÿ“ž Getting Help

  • Documentation: Comprehensive guides in the docs/ directory
  • Error Logs: Enable debug logging for detailed error information
  • Community: Join our development discussions and issue tracking
  • Support: Submit detailed bug reports with reproduction steps

Truth Wars - Teaching media literacy through engaging social gameplay ๐ŸŽ“๐Ÿ“ฐ๐ŸŽฎ

About

A social deduction game where players vote on real vs fake headlines, take on strategic roles, and learn how to detect misinformation through gameplay. Built in Python with async game logic, AI-generated content, and educational mechanics.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages