Skip to content

mozilla-ai/0din-bot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Bot: ODIN Threatfeed & Channel Summarizer

A Discord bot that:

  • Checks the scan status of a UUID in the ODIN Threatfeed API.
  • Fetches the full ODIN threat feed.
  • Summarizes channel conversations by user and topic for a given date.
  • Responds to health checks and logs all activity.

Features

  • /check : Query the ODIN Threatfeed API and report if the item has been scanned.
  • /health: Check if the bot is operational.
  • Threat Feed Access: The agent can fetch and summarize the full ODIN threat feed when requested.
  • Message Summarization: When mentioned with a request for a summary (optionally specifying a date or user), the bot summarizes the main topics discussed by each user in the channel for that date.
  • Logging: All agent traces and errors are logged to logs/.
  • Local Summaries: Summaries are saved to logs/discord_daily_summary_<date>.txt.

Requirements

  • Hardware: Any system capable of running Python 3.11+
  • Software:
    • Python 3.11 or higher
    • uv (for dependency management and running)
    • A Discord account and a Discord server where you have permission to add bots
    • A Discord Bot Token (Create one here)
    • An ODIN API Key (for /check command and threat feed access)

Installation

For Use

To install the bot for regular use (runtime dependencies only):

uv pip install -e .

For Development and Testing

To install the bot with all development and test dependencies:

uv pip install -e '.[test]'

This will install all runtime and test dependencies (pytest, pytest-asyncio, pytest-mock, etc.).

Docker Setup

The bot can also be run using Docker Compose, which launches both the ODIN bot and the MCP Discord server in separate containers.

Prerequisites

  • Docker and Docker Compose installed on your system

  • Environment variables for the OpenAI API key, the Discord server's Guild ID and the channel ID you want the bot to monitor. Should you want to access the 0DIN API, you will also need a key for that.

    export OPENAI_API_KEY=your-openai-api-key-here
    export DISCORD_TOKEN=your-bot-token-here
    export ODIN_API_KEY=your-odin-api-key-here
    export GUILD_ID=your-discord-guild-id-here
    export CHANNEL_ID=your-discord-channel-id-here

Running with Docker Compose

make up

This command will:

  • Build the ODIN bot Docker image
  • Pull the MCP Discord server image from Docker Hub
  • Launch both containers using Docker Compose
  • The MCP Discord server will be available on port 8080

Stopping the containers

make down

Other Docker commands

  • make build - Build the ODIN bot Docker image
  • make run - Run the ODIN bot container directly
  • make debug - Run the ODIN bot container with an interactive shell for debugging

Local setup

  1. Clone this repository and enter the directory:

    git clone git@github.com:ividal/0din-bot.git
    cd 0din-bot
  2. Install the package (see Installation section above).

  3. Create a Discord bot and get your token:

    • Go to the Discord Developer Portal
    • Create a new application, add a bot, and copy the bot token
    • Invite the bot to your server using the OAuth2 URL generator (scopes: bot, permissions: Send Messages, Read Messages)
  4. Set your environment variables: See the instructions above, in the "Docker setup" section.

  5. Run the bot:

    uv run odinbot agent --guild-id $GUILD_ID --channel-id $CHANNEL_ID
    • Make sure you have set the DISCORD_TOKEN, ODIN_API_KEY, GUILD_ID, and CHANNEL_ID environment variables as described above.
    • The bot will start and monitor the specified channel in your server.

Usage

  • Check a UUID:
    In any channel the bot is in, use the slash command:

    /check <UUID>
    

    The bot will reply with the scan status from the ODIN Threatfeed.

  • Health Check:

    /health
    

    The bot will reply if it is operational.

  • Access Threat Feed:
    Mention the bot and ask about the threat feed, e.g.:

    @Bot show me the threat feed
    @Bot what's in the threat feed today
    

    The bot will fetch and summarize the current ODIN threat feed.

  • Summarize Channel Messages:
    Mention the bot and request a summary, e.g.:

    @Bot summarize today's messages
    @Bot summarize messages from 2024-03-20
    @Bot summarize messages from user Alice on 2024-03-20
    

    The bot will reply with a summary of topics by user for the specified date and save the summary to a log file.

Testing

  • Tests are located in tests/.
  • To install test dependencies, use:
    uv pip install -e '.[test]'
  • To run the tests:
    uv run pytest tests/

Notes

  • All logs and summaries are saved in the logs/ directory.
  • The bot will only respond to direct mentions or slash commands.
  • For development and debugging, all agent traces are saved as JSON in logs/.

About

Discord bot that also interacts with 0din submissions API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 95.7%
  • Makefile 2.7%
  • Dockerfile 1.6%