Skip to content

Gwillis442/Randomfunbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

266 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– Randomfunbot

A feature-rich Discord bot designed for entertainment and utility, with AI-powered article summarization, interactive reactions, and fun random behaviors. Built with Discord.js v14 and modern async/await patterns.

โœจ Features

๐Ÿ”— Smart Link Processing

  • Auto-Summarization: Automatically detects and summarizes articles from links using GPT
  • Interactive Reactions: Original poster can delete summaries with โŒ reaction
  • Multiple Content Sources: Supports various article formats and websites

๐ŸŽฎ Interactive Commands

  • /ping - Test bot responsiveness
  • /ask - AI-powered Q&A using OpenAI
  • /summarize - Manual article summarization
  • /slotmachine - Fun gambling game
  • /wfdropinfo - Warframe drop information
  • /ttsreply - Text-to-speech responses

๐ŸŽฒ Random Fun Features

  • Probabilistic Message Deletion: Random chance to delete messages
  • Random Reactions: Adds surprise reactions to messages
  • Random AI Responses: Contextual AI-generated replies
  • Message History Tracking: Learns from conversation patterns

๐Ÿ“Š Database Integration

  • SQLite database for user activity tracking
  • Message count monitoring
  • User interaction statistics
  • Persistent data storage

๐ŸŽจ Rich Embeds & UI

  • Custom embed messages
  • Button interactions
  • Reaction collectors
  • Canvas-based image generation

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • Docker (optional)
  • Discord Bot Token
  • OpenAI API Key

Environment Setup

  1. Clone the repository:
git clone <repository-url>
cd Randomfunbot
  1. Install dependencies:
npm install
  1. Configure environment variables: Create a .env file in the root directory:
token=YOUR_DISCORD_BOT_TOKEN
gptApiKey=YOUR_OPENAI_API_KEY
clientId=YOUR_BOT_CLIENT_ID
guildId=YOUR_GUILD_ID
linkChannelId=YOUR_LINK_CHANNEL_ID
mainChannelId=YOUR_MAIN_CHANNEL_ID
me=YOUR_USER_ID
  1. Set up Discord Bot:
    • Go to Discord Developer Portal
    • Create a new application and bot
    • Copy the bot token to your .env file
    • Enable the following bot permissions:
      • Send Messages
      • Manage Messages
      • Add Reactions
      • Read Message History
      • Use Slash Commands

๐Ÿณ Docker Deployment

# Build the image
docker build -t randomfunbot .

# Run the container
docker run -d --name randomfunbot --env-file .env randomfunbot

๐Ÿ“ฆ Local Development

# Start the bot
npm start

# Or run with nodemon for development
npm run dev

๐Ÿ› ๏ธ Configuration

Required Permissions

Your Discord bot needs these permissions:

  • โœ… Send Messages
  • โœ… Manage Messages
  • โœ… Add Reactions
  • โœ… Read Message History
  • โœ… Use Slash Commands
  • โœ… Embed Links
  • โœ… Attach Files

Environment Variables

Variable Description Required
token Discord bot token โœ…
gptApiKey OpenAI API key for AI features โœ…
clientId Discord application client ID โœ…
guildId Discord server ID โœ…
linkChannelId Channel ID for link processing โœ…
mainChannelId Main channel ID โœ…
me Your Discord user ID โœ…

๐Ÿ—๏ธ Project Structure

src/
โ”œโ”€โ”€ client.js                 # Discord client setup
โ”œโ”€โ”€ index.js                  # Bot entry point
โ”œโ”€โ”€ handlers/
โ”‚   โ”œโ”€โ”€ commandHandler/       # Slash commands
โ”‚   โ”‚   โ””โ”€โ”€ commands/         # Individual command files
โ”‚   โ”œโ”€โ”€ messageHandlers/      # Message event handlers
โ”‚   โ”‚   โ”œโ”€โ”€ linkHandler.js    # Link processing & summarization
โ”‚   โ”‚   โ”œโ”€โ”€ randomResponseHandler.js
โ”‚   โ”‚   โ””โ”€โ”€ dmHandler.js
โ”‚   โ”œโ”€โ”€ gptResponseHandler/   # AI response logic
โ”‚   โ”œโ”€โ”€ articleSummaryHandler/ # Web scraping & content extraction
โ”‚   โ””โ”€โ”€ buttonHandler/        # Button interactions
โ”œโ”€โ”€ utils/                    # Utility functions
โ””โ”€โ”€ webpage.png              # Generated screenshots
database/
โ”œโ”€โ”€ botDB.db                 # SQLite database
โ””โ”€โ”€ dbBuild.js              # Database initialization
config/
โ””โ”€โ”€ config.json             # Bot configuration

๐Ÿ”ง Development

Adding New Commands

  1. Create a new file in src/handlers/commandHandler/commands/
  2. Export a command object with data and execute properties
  3. The command will be automatically loaded

Example:

const { SlashCommandBuilder } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('example')
        .setDescription('An example command'),
    async execute(interaction) {
        await interaction.reply('Hello World!');
    },
};

Database Usage

The bot uses SQLite for data persistence. Database utilities are in database/databaseUtils/:

  • insertDB.js - Insert operations
  • updateDB.js - Update operations

AI Integration

  • Uses OpenAI GPT for article summarization and Q&A
  • Handles rate limiting and error recovery
  • Supports both chat completions and legacy models

๐Ÿ“Š Monitoring & Logs

Bot Status

The bot logs important events:

  • Startup and shutdown
  • Command executions
  • Error handling
  • Database operations
  • Article processing

Performance Notes

  • Uses Puppeteer with stealth plugin for web scraping
  • Implements connection pooling for database
  • Graceful error handling for external APIs
  • Memory-efficient reaction collectors

๐Ÿ”’ Security & Best Practices

  • โœ… Environment variables for sensitive data
  • โœ… Input validation and sanitization
  • โœ… Rate limiting protection
  • โœ… Error boundaries and logging
  • โœ… Graceful process shutdown
  • โœ… Docker containerization support

๐Ÿ› Troubleshooting

Common Issues

Bot doesn't respond to commands:

  • Check bot permissions in Discord server
  • Verify bot token is correct
  • Ensure bot is online and connected

Article summarization fails:

  • Check OpenAI API key and credits
  • Verify internet connectivity
  • Review console logs for Puppeteer errors

Database errors:

  • Ensure write permissions for database file
  • Check SQLite installation
  • Review database schema

Puppeteer/Chrome issues:

  • Install missing dependencies: apt-get install -y chromium-browser
  • Use --no-sandbox flag in Docker
  • Check available memory

Debug Mode

Set NODE_ENV=development for verbose logging.

๐Ÿ“ License

This project is licensed under the ISC License.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

๐Ÿ”— Links


About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors