From 94f8ebca4dd8ccb8a8dd066e59afc506673bb01a Mon Sep 17 00:00:00 2001 From: Groupr Date: Sat, 13 Sep 2025 15:37:34 +0000 Subject: [PATCH 1/7] Add new directory --- Dice/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Dice/.gitkeep diff --git a/Dice/.gitkeep b/Dice/.gitkeep new file mode 100644 index 0000000..e69de29 -- 2.49.1 From d51910f671e3cdf216590dd8766b3ed7c1890703 Mon Sep 17 00:00:00 2001 From: Groupr Date: Sat, 13 Sep 2025 15:40:46 +0000 Subject: [PATCH 2/7] Upload New File --- Dice/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Dice/__init__.py diff --git a/Dice/__init__.py b/Dice/__init__.py new file mode 100644 index 0000000..52f7403 --- /dev/null +++ b/Dice/__init__.py @@ -0,0 +1,5 @@ +from .dice import DicePlugin + +# The name is already set in the DicePlugin class +__version__ = "1.0.0" +__all__ = ["DicePlugin"] -- 2.49.1 From c07fe77d0cb28cb5c93b211e603ed0f21b04f516 Mon Sep 17 00:00:00 2001 From: Groupr Date: Sat, 13 Sep 2025 15:41:49 +0000 Subject: [PATCH 3/7] Upload New File --- Dice/dice.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Dice/dice.py diff --git a/Dice/dice.py b/Dice/dice.py new file mode 100644 index 0000000..9e53a57 --- /dev/null +++ b/Dice/dice.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +""" +Dice rolling plugin for UnturfDiscordBot (package entry point name: 'dice'). +Provides a /roll command and an optional mention-based listener. +""" + +import sys +import os +# Add parent directory to path to import bot module +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))) + +from random import randint +from typing import Optional + +from bot import DiscordPlugin +from discord.ext import commands +import discord +from discord import app_commands + + +def _roll(quant: int, dmax: int) -> str: + rolls = [randint(1, dmax) for _ in range(quant)] + return f"{', '.join(map(str, rolls))} for a total of {sum(rolls)}" + + +class DicePlugin(DiscordPlugin): + """Roll dice.""" + name = "Dice" # This will be the display name in /plugins + + async def initialize(self, bot: commands.Bot, config: dict): + await super().initialize(bot, config) + settings = config.get("settings", {}) + self.max_dice: int = int(settings.get("max_dice", 2)) + self.max_sides: int = int(settings.get("max_sides", 6)) + self.logger.info( + f"DicePlugin initialized (max_dice={self.max_dice}, max_sides={self.max_sides})" + ) + + async def setup(self): + @self.bot.tree.command(name="roll", description="Roll dice (e.g., 2d6)") + async def roll_cmd(interaction: discord.Interaction, quant: int = 2, sides: int = 6) -> None: + if quant < 2 or quant > self.max_dice: + await interaction.response.send_message( + f"You must roll between 2 and {self.max_dice} dice.", + ephemeral=True, + ) + return + if sides < 2 or sides > self.max_sides: + await interaction.response.send_message( + f"Dice must have between 2 and {self.max_sides} sides.", + ephemeral=True, + ) + return + + result = _roll(quant, sides) + await interaction.response.send_message( + f"🎲 Rolled {quant}d{sides}: {result}" + ) + + async def _on_message(message: discord.Message): + if message.author.bot: + return + if not self.bot.user or not self.bot.user.mentioned_in(message): + return + content = message.content.lower().replace(" ", "") + if "roll" in content and "d" in content: + try: + seg = content.split("roll", 1)[1] + if seg.startswith("s"): + seg = seg[1:] + parts = seg.strip().split("d", 1) + quant = int(''.join(ch for ch in parts[0] if ch.isdigit()) or "0") + sides = int(''.join(ch for ch in parts[1] if ch.isdigit()) or "0") + if 2 <= quant <= self.max_dice and 6 <= sides <= self.max_sides: + result = _roll(quant, sides) + await message.reply(f"🎲 Rolled {quant}d{sides}: {result}") + except Exception: + pass + + self._on_message = _on_message # type: ignore[attr-defined] + self.bot.add_listener(self._on_message, name="on_message") + + async def teardown(self): + listener = getattr(self, "_on_message", None) + if listener is not None: + try: + self.bot.remove_listener(listener, name="on_message") + except Exception: + pass + self.logger.info("DicePlugin teardown complete") -- 2.49.1 From e6595fbe0e4877ed2d23d1d412adabbbec26e8ce Mon Sep 17 00:00:00 2001 From: Groupr Date: Sat, 13 Sep 2025 15:54:33 +0000 Subject: [PATCH 4/7] Upload New File --- Dice/setup.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Dice/setup.py diff --git a/Dice/setup.py b/Dice/setup.py new file mode 100644 index 0000000..cac8f84 --- /dev/null +++ b/Dice/setup.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +""" +Setup for the Dice plugin for Unturf Discord Bot. +""" + +from setuptools import setup, find_packages + +setup( + name='unturf-dice-plugin', + version='1.0.0', + packages=find_packages(), + install_requires=[ + 'discord.py', + ], + entry_points={ + 'unturf_discord.plugins': [ + 'dice = Dice:DicePlugin', + ], + }, + description='Dice rolling plugin for Unturf Discord Bot', + long_description='Adds dice rolling functionality to the Unturf Discord Bot', + long_description_content_type='text/markdown', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: End Users/Desktop', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + ], + python_requires='>=3.8', +) -- 2.49.1 From 8e0db48fed78bc42e594e52896f5d89c3d3fec9f Mon Sep 17 00:00:00 2001 From: Groupr Date: Sat, 13 Sep 2025 15:54:47 +0000 Subject: [PATCH 5/7] Upload New File --- Dice/README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Dice/README.md diff --git a/Dice/README.md b/Dice/README.md new file mode 100644 index 0000000..a6d6cdf --- /dev/null +++ b/Dice/README.md @@ -0,0 +1,28 @@ +# Unturf Dice Plugin + +Provides a /roll command for UnturfDiscordBot to roll N dice with D sides (e.g., 2d6). + +## Install (editable) + +```bash +pip install -e ./dice +``` + +## Entry point + +- Group: `unturf_discord.plugins` +- Name: `dice` +- Target: `dice:DicePlugin` + +## Configuration + +Add to `data/plugin_config.json`: + +```json +{ + "dice": { + "enabled": true, + "settings": {"max_dice": 100, "max_sides": 1000} + } +} +``` -- 2.49.1 From f2e0e786088fb1f73a588e46c1690b49abda8a71 Mon Sep 17 00:00:00 2001 From: Groupr Date: Mon, 15 Sep 2025 13:28:15 +0000 Subject: [PATCH 6/7] Add new directory --- werewolf/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 werewolf/.gitkeep diff --git a/werewolf/.gitkeep b/werewolf/.gitkeep new file mode 100644 index 0000000..e69de29 -- 2.49.1 From 6500544ed097f52cdf285960fb08422319e4a8ff Mon Sep 17 00:00:00 2001 From: Groupr Date: Mon, 15 Sep 2025 13:30:13 +0000 Subject: [PATCH 7/7] Update file .gitkeep --- werewolf/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 werewolf/.gitkeep diff --git a/werewolf/.gitkeep b/werewolf/.gitkeep deleted file mode 100644 index e69de29..0000000 -- 2.49.1