Go to file
Kami f717ad0f14 PoE 2 Trading Site Implementation
This update includes implementation of Path of Exile 2 trading watchlisting, allowing users to get notified on Discord about new listings within the filter criteria.
- Multiple new commands
  - `!poe2trade`
    - DMs a message containing basic usage and instructions.
  - `!poe2trade add <filter_id> [filter_name]`
    - Adds a trade filter to their watchlist.
    - New matches will be sent to the user in a DM.
  - `!poe2trade remove <filter_id | all>`
    - Removes the specified filter from their watchlist.
    - If filter_id is set to `all`, it will clear all filters from their watchlist.
  - `!poe2trade list`
    - Lists the user's watchlisted filters, along with the filter nickname (if assigned).
  - `!poe2trade pause`
    - Stops watchlisting all their filters. No processing nor notifications are performed.
  - `!poe2trade resume`
    - Resumes the watchlisting of the user.
  - `!poe2trade set <key> <value>`
    - Allows admin/owner to modify settings without restarting the bot.
  - `!poe2trade settings`
    - Allows admin/owner to view current settings.
    - Will be updated in the future to allow non-admin users to view non-sensitive settings.
- Automatic notification of new listings in a neatly-formatted embed message
  - Currently, notification embeds contain: item name, item icon, item level, item stats, listed price, seller name (and account hyperlink), filter information, and instructions on removing the filter from watchlist.
  - Notification messages are condensed to avoid spam as much as possible; multiple new listings (up to 10) will be combined into a single message containing several embeds.
- Respects rate limits to avoid getting the bot locked out.
  - These ratelimits are set by GGG and CloudFlare, and are thus very strict. This shouldn't affect usability much however.
- Several minor QoL features

Still very much in active dev, so availability may fluctuate, and features will change.
Current TODO:
- Smart price-to-stat comparison
  - Determine listing value for the user to avoid being scammed, and easily pick up good deals.
  - Will compare item stats and listing price with other items of the same name, level and quality.
- Direct listing hyperlink
  - Currently, PoE 2's trading site does not support direct item links, so this has to be done by dynamically generate a filter that will only result in the relevant listing, providing easy direct access.
2025-03-26 20:42:16 +01:00
cmd_common Reworked internal logging 2025-03-13 14:17:43 +01:00
cmd_discord PoE 2 Trading Site Implementation 2025-03-26 20:42:16 +01:00
cmd_twitch Experimental early implementation of expanded permissions system and runtime checks 2025-03-08 18:11:42 +01:00
dictionary Improved platform logging and Custom VC 2025-03-06 17:53:54 +01:00
modules Reworked internal logging 2025-03-13 14:17:43 +01:00
settings Improved platform logging and Custom VC 2025-03-06 17:53:54 +01:00
systems/adventure Added Twitch multi-channel support 2025-02-16 15:30:17 +01:00
utility PoE 2 Trading Site Implementation 2025-03-26 20:42:16 +01:00
.gitignore Big quote system overhaul 2025-02-12 00:15:39 +01:00
bot_discord.py Reworked internal logging 2025-03-13 14:17:43 +01:00
bot_twitch.py Reworked internal logging 2025-03-13 14:17:43 +01:00
bots.py Reworked internal logging 2025-03-13 14:17:43 +01:00
config.json Added search feature to `!funfact` 2025-02-14 11:42:20 +01:00
example.env Add example.env 2025-02-01 12:16:51 +00:00
globals.py CustomVC Rework 2025-03-13 16:57:23 +01:00
license.md Added BSL-1.1 license 2025-02-02 16:58:53 +01:00
permissions.json Experimental early implementation of expanded permissions system and runtime checks 2025-03-08 18:11:42 +01:00
readme.md - Added readme.md 2025-02-01 21:28:26 +01:00
requirements.txt Added basic string sanitization 2025-02-02 14:34:30 +01:00

readme.md

OokamiPup V2

A combined Discord and Twitch bot written in Python, leveraging:

  • discord.py (PyPI version discord.py or a maintained fork)
  • TwitchIO
  • aiohttp
  • python-dotenv
  • and other libraries listed in your requirements.txt.

About the bot

  • Monitors specified Twitch channels for messages and commands.
  • Connects to a specified Discord server to respond to commands and events.
  • Uses a .env file for storing sensitive credentials.
  • Uses a config.json for channel configuration, logging settings, etc.

Features

  • Discord Bot
    • Responds to commands from any channel or restricted channels (depending on your setup).
    • Automatically loads commands from cmd_discord.py.
  • Twitch Bot
    • Joins multiple Twitch channels specified in your config.json.
    • Automatically loads commands from cmd_twitch.py.
  • Simple Logging
    • Logs to the console with optional levels (DEBUG, INFO, WARNING, etc.).
  • Token Refresh
    • Automatically attempts to refresh your Twitch OAuth token if it becomes invalid.

Prerequisites

  • Python 3.8+ (or a compatible Python 3 version—ensure asyncio.run is supported).
  • A Twitch Developer application (for your Client ID and Client Secret).
  • A Discord application/bot token.
  • A working pip or pipenv/poetry for installing dependencies.

Installation

Clone this repository (or download the source code):

  1. git clone https://git.ookamikun.tv/kami/OokamiPupV2.git (Clone repository)
  2. cd OokamiPupV2 (Navigate into the project folder)
  3. pip install -r requirements.txt (Install project dependancies)

Create your .env file in the project root (same folder as bots.py). It should look like:

DISCORD_BOT_TOKEN=YourDiscordBotToken
TWITCH_CLIENT_ID=YourTwitchAppClientID
TWITCH_CLIENT_SECRET=YourTwitchAppClientSecret
TWITCH_BOT_TOKEN=YourTwitchOAuthToken
TWITCH_REFRESH_TOKEN=YourTwitchRefreshToken

Note: Your Twitch OAuth/Refresh tokens typically come from generating them through the Twitch Developer Console.

Set up your config.json with your preferred channels, logging levels, etc. For example:

{
  "twitch_channels": ["mychannel", "anotherchannel"],
  "log_levels": ["INFO", "WARNING", "ERROR", "CRITICAL", "FATAL"]
}

twitch_channels is a list of channel names for your bot to join on Twitch. log_levels controls what messages get logged to console (The lowest "DEBUG" level can be added if needed).

Directory Overview

A quick rundown of the important files:

.
├── bots.py                # Main entry point: initializes/starts both Discord and Twitch bots
├── bot_discord.py         # Discord bot implementation (using discord.py)
├── bot_twitch.py          # Twitch bot implementation (using TwitchIO)
├── cmd_common/            # Platform-independant command logic
│   └── common_commands.py # Common low-level commands file
├── cmd_discord.py         # Command definitions for Discord
├── cmd_twitch.py          # Command definitions for Twitch
├── config.json            # Bot configuration (channels, logging levels, etc.)
├── .env                   # Environment variables for tokens (DO NOT commit this)
├── requirements.txt       # Python dependencies
└── README.md              # You are here

Usage

  1. Edit your environment variables in the .env file (tokens, client IDs, secrets, etc.).
  2. Edit your config.json to list the Twitch channels and your logging preferences.
  3. Run the bot: python bots.py
  4. Check the console output:
    • You should see logs indicating that the Discord bot is online (Discord bot is online as ...).
    • You should also see logs about the Twitch bot joining channels (Twitch bot connected) — assuming everything is configured correctly.

Testing Commands

Discord:

Open your Discord server, type your command prefix (e.g., !) + the command name (e.g., !ping).

Twitch:

In one of the channels specified in twitch_channels, type !ping (or whichever commands you have set up in cmd_twitch.py).

If your commands do not respond

  • Confirm the bot has correct roles/permissions in Discord (especially if it needs to read/send messages in specific channels).
  • Confirm your Twitch OAuth token is valid.
  • Check for logs or errors in the console.

Adding or Editing Commands

General Commands:

low-level commands can be made in cmd_common/common_commands.py, alternatively separated into separate files in that folder.

These are command logic meant to support both platforms, eg. the !ping command.

Discord:

  • Open cmd_discord.py and define new commands using the standard @bot.command() decorators from discord.ext.commands.
  • Make sure cmd_discord.setup(bot) registers them with your DiscordBot.

Twitch:

  • Open cmd_twitch.py and define new commands using the @bot.command() decorators from twitchio.ext.commands.
  • Ensure cmd_twitch.setup(bot) properly registers them with TwitchBot.

Troubleshooting

  • No logs from the Twitch bot

    • Ensure that youre calling await bot.start() (not bot.run() and await bot.start() together).
    • If you only see the Discord bot logs, verify that your .env variables are loaded and valid (TWITCH_CLIENT_ID, TWITCH_CLIENT_SECRET, TWITCH_BOT_TOKEN, TWITCH_REFRESH_TOKEN).
    • Confirm that you have internet connectivity and that the Twitch IRC service isnt blocked by a firewall.
  • Token refresh issues

    • If you see repeated warnings about “Invalid or unauthorized Access Token,” double-check your TWITCH_REFRESH_TOKEN and TWITCH_CLIENT_SECRET are correct.
    • The bot attempts to refresh automatically; if it still fails, manually re-generate tokens from the Twitch Developer Console.
  • "Cannot write to closing transport"

    • Make sure you do not call connect() manually before start() in TwitchIO.

Contributing

  • Fork the repository
  • Create a new branch (git checkout -b feature/myfeature)
  • Make changes and commit (git commit -am 'Add new feature')
  • Push to the branch (git push origin feature/myfeature)
  • Create a new Pull Request in Git