33 Commits

Author SHA1 Message Date
07b436ed8c Add DataManager and Logging cogs; enhance existing features
- Updated `.gitignore` to include `cython_debug/`.
- Introduced `DataManager` class for data retention policies.
- Added logging functionality for server events in `logging.py`.
- Refactored `hiring.py` and improved order submission in `kofishop.py`.
- Added new cogs: `MORS`, `ServiceReview`, and `StaffMsg`.
- Updated `info.json` for new cogs and modified `__init__.py` files for setup.
2025-09-23 02:36:33 -04:00
01a484ddb6 Merge pull request 'feat: add advanced translator cog with proxy and languages' (#13) from translator into main
Reviewed-on: #13
2025-09-23 01:17:12 -04:00
acb71337fa Merge pull request 'feat: add welcome modes including solstira support' (#12) from welcomer into main
Reviewed-on: #12
2025-09-23 01:16:08 -04:00
81f2eee409 feat: add multiple discord bot cogs
Adds new cogs including DataManager, Hiring, KofiShop, Logging, ModMail, MORS, ServiceReview, StaffMsg, and Translator to enhance bot functionality for data management, hiring processes, logging events, and more.
2025-09-23 00:28:29 -04:00
c2367369f1 feat: add welcome modes including solstira support
Introduces 'normal' and 'solstira' modes to the welcomer cog.
Normal mode retains configurable channel and message.
Solstira mode provides hardcoded channel and complex embed for events.
2025-09-22 23:54:58 -04:00
0e5afcb999 feat: add advanced translator cog with proxy and languages
Introduces multilingual translation cog supporting fantasy languages
Adds proxying features for role-playing with sonas and auto-translation
Includes admin commands for managing custom languages and context menus

Replaces basic translation with enhanced functionality for Discord bot
2025-09-22 23:23:57 -04:00
b27a734e3c Merge pull request 'feat: add translator cog for fantasy languages' (#9) from translator into main
Reviewed-on: #9
2025-09-21 04:28:34 -04:00
9ad286b671 Update translator/translator.py
Unicode Error Fix
2025-09-21 04:27:45 -04:00
b186a9c119 Merge pull request 'feat: add translator cog for fantasy languages' (#10) from translator into main
Reviewed-on: #10
2025-09-21 04:24:11 -04:00
d3ee48112a feat: add translator cog for fantasy languages
Implements commands for translating text into roleplay languages like Valspiren, Elvish, and Draconic, ported from a web application.
2025-09-21 04:22:21 -04:00
48c3793768 refactor: rename directory to kofishop 2025-09-20 21:14:42 -04:00
141efc4253 Update info.json 2025-09-20 21:02:18 -04:00
61b81068ba Update kofi-shop/kofishop.py 2025-09-20 20:58:46 -04:00
a0df694243 Update kofi-shop/__init__.py 2025-09-20 20:58:17 -04:00
ca7dba5af6 Merge pull request 'feat: Add Hiring cog for ticket-based applications' (#8) from hiring into main
Reviewed-on: #8
2025-09-20 20:49:41 -04:00
d65197e552 Merge pull request 'feat: implement KofiShop cog for Discord bot integration' (#7) from kofishop into main
Reviewed-on: #7
2025-09-20 20:48:58 -04:00
0909717fb6 Merge pull request 'feat: add configurable forum-based ModMail system' (#6) from modmail into main
Reviewed-on: #6
2025-09-20 20:48:38 -04:00
84a2b41a79 feat: Add Hiring cog for ticket-based applications
Introduces a Discord cog to manage staff and PM hiring through interactive tickets, forms, and buttons. Includes modals for Staff, PM, and HPM applications, as well as commands for posting hiring messages and configuring categories and channels.
2025-09-20 20:47:25 -04:00
82e48c2383 feat: implement KofiShop cog for Discord bot integration
Introduces a new cog to manage Ko-fi shop orders, reviews, and waitlists.
Users can submit orders and reviews via interactive modals.
Administrators can configure channels and add users to the waitlist.
2025-09-20 20:46:32 -04:00
2d199d9247 feat: add configurable forum-based ModMail system
Introduces a new cog that handles user DMs by creating threads in a designated forum channel.

Enables staff to reply in threads to send messages back to users anonymously.

Includes commands to configure settings, enable/disable the system, and close threads.

Improves moderation by streamlining ticket management in Discord forums.
2025-09-20 20:45:15 -04:00
f546eaa633 Merge pull request 'feat: implement configurable welcomer cog with settings' (#5) from welcomer into main
Reviewed-on: #5
2025-09-11 19:53:02 -04:00
e552ba7552 feat: implement configurable welcomer cog with settings
Refactors simple welcomer to support custom messages, channels, and toggles.

Adds command group for admins to manage server-specific settings, placeholders for personalization, and built-in safety checks for permissions and channel validity.

Enhances event handling with better error management and logging.
2025-09-11 19:46:27 -04:00
e0330148c2 Merge pull request 'feat: add welcomer cog for greeting new members' (#4) from welcomer into main
Reviewed-on: #4
2025-09-11 17:30:02 -04:00
3955e61a62 Merge pull request 'iservice' (#3) from iservice into main
Reviewed-on: #3
2025-09-11 17:29:20 -04:00
a3e210a7ce Merge pull request 'feat: add initial files for KofiShop cog' (#2) from kofishop into main
Reviewed-on: #2
2025-09-11 17:29:02 -04:00
5fd4e08d90 Merge pull request 'kbump' (#1) from kbump into main
Reviewed-on: #1
2025-09-11 17:28:31 -04:00
8a7621836f feat: add welcomer cog for greeting new members
Introduces a simple cog that welcomes new users via customizable messages in designated channels, enhancing community engagement.

Handles channel selection with fallbacks and includes error resilience for permission issues.
2025-09-11 17:24:56 -04:00
eec57c7e23 feat: adds ServiceReview cog
Introduces functionality for users to submit independent service reviews, sent to a designated staff channel.

Includes metadata and initial structure files.
2025-09-11 17:24:31 -04:00
e0958f6f2a feat: Add RPG cog with character and inventory features
Sets up RPG system as a Redbot cog with core mechanics
Implements character creation, class selection, and stat management
Adds action commands for attacking and healing
Provides inventory and shop functionality for item management
Introduces interactive UI menus for user engagement
2025-09-11 17:23:45 -04:00
859ac84b68 feat: add password protection cog for channels
Adds new Discord bot cog enabling password-protected channels.
Includes verification, channel management, whitelist/blacklist,
and admin password recovery features.
2025-09-11 17:22:36 -04:00
5ed8002b40 feat: add Mass Outreach & Review System
Introduces multi-step workflow for user outreach, time selection, and mass reviews with temporary data storage for process efficiency.
2025-09-11 17:21:42 -04:00
c94667ee52 feat: Adds ModMail cog with core setup
Introduces a private, forum-based ModMail system for relaying user DMs to staff threads, enhancing moderation and support through persistent message storage.

Relies on 'rich' requirement for better formatting; includes metadata for easy installation and help integration.
2025-09-11 17:18:22 -04:00
83facc2fb9 feat: add initial files for KofiShop cog 2025-09-11 17:17:40 -04:00
92 changed files with 4440 additions and 1 deletions

2
.gitignore vendored
View File

@@ -179,3 +179,5 @@ cython_debug/
.vs/ .vs/
pyproject.toml pyproject.toml
treegen.py

4
datamanager/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
from .datamanager import DataManager
async def setup(bot):
await bot.add_cog(DataManager(bot))

128
datamanager/datamanager.py Normal file
View File

@@ -0,0 +1,128 @@
import discord
from redbot.core import commands, Config
import datetime
from typing import Dict, Optional, Literal
from discord.ext import tasks
SUPPORTED_COGS = Literal["ModMail", "Hiring", "ServiceReview", "StaffMsg", "Logging"]
class DataManager(commands.Cog):
"""
A cog to automatically manage and purge old data from other cogs.
"""
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, identifier=1234567894, force_registration=True)
default_guild = {
"policies": {} # {cog_name: days}
}
self.config.register_guild(**default_guild)
self.data_purge_loop.start()
def cog_unload(self):
self.data_purge_loop.cancel()
@tasks.loop(hours=24)
async def data_purge_loop(self):
"""Periodically purges old data based on configured policies."""
await self.bot.wait_until_ready()
all_guilds = self.bot.guilds
for guild in all_guilds:
policies = await self.config.guild(guild).policies()
if not policies:
continue
for cog_name, days in policies.items():
cog = self.bot.get_cog(cog_name)
if not cog or not hasattr(cog, "config"):
continue
retention_delta = datetime.timedelta(days=days)
# Determine the correct config group to purge
# This needs to match what we defined in the other cogs
data_group_name = ""
if cog_name == "ModMail":
data_group_name = "closed_threads"
elif cog_name == "Hiring":
data_group_name = "closed_applications"
elif cog_name == "ServiceReview":
data_group_name = "reviews"
elif cog_name in ["StaffMsg", "Logging"]:
data_group_name = "logged_events"
if not data_group_name:
continue
async with cog.config.guild(guild).get_attr(data_group_name)() as data_log:
to_delete = []
for entry_id, timestamp_str in data_log.items():
try:
entry_timestamp = datetime.datetime.fromisoformat(timestamp_str)
if (datetime.datetime.now(datetime.timezone.utc) - entry_timestamp) > retention_delta:
to_delete.append(entry_id)
except (ValueError, TypeError):
continue # Skip invalid timestamps
for entry_id in to_delete:
del data_log[entry_id]
# --- SETTINGS COMMANDS ---
@commands.group(aliases=["dmset"]) # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def datamanagerset(self, ctx: commands.Context):
"""Configure DataManager settings."""
pass
@datamanagerset.command(name="policy")
async def set_purge_policy(self, ctx: commands.Context, cog_name: SUPPORTED_COGS, days: int):
"""
Set the data retention policy for a cog.
Use 0 days to disable purging for a cog.
"""
if not ctx.guild:
return
if days < 0:
await ctx.send("Please provide a non-negative number of days.")
return
async with self.config.guild(ctx.guild).policies() as policies:
if days == 0:
if cog_name in policies:
del policies[cog_name]
await ctx.send(f"Purge policy for `{cog_name}` has been removed.")
else:
await ctx.send(f"No purge policy was set for `{cog_name}`.")
else:
policies[cog_name] = days
await ctx.send(f"Data from `{cog_name}` will now be purged after {days} days.")
@datamanagerset.command(name="view")
async def view_policies(self, ctx: commands.Context):
"""View the current data retention policies."""
if not ctx.guild:
return
policies = await self.config.guild(ctx.guild).policies()
if not policies:
await ctx.send("No data retention policies have been set for this server.")
return
embed = discord.Embed(
title="Data Retention Policies",
color=await ctx.embed_color()
)
description = "Data from the following cogs will be automatically purged after the specified duration:"
for cog_name, days in policies.items():
description += f"\n- **{cog_name}**: {days} days"
embed.description = description
await ctx.send(embed=embed)
async def setup(bot):
await bot.add_cog(DataManager(bot))

17
datamanager/info.json Normal file
View File

@@ -0,0 +1,17 @@
{
"author": [
"unstableCogs"
],
"install_msg": "Thank you for installing the Data Manager cog! Please use the setup commands to configure your data retention policies.",
"name": "DataManager",
"short": "A cog to manage long-term data retention.",
"description": "Provides tools to automatically purge or archive old data from other cogs to prevent database bloat.",
"tags": [
"data",
"database",
"utility",
"admin"
],
"requirements": [],
"end_user_data_statement": "This cog reads and deletes data from other cogs based on administrator configuration. It does not store any unique user data itself."
}

4
hiring/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
from .hiring import setup
# This function is required for the cog to be loaded by Red.
# It simply imports the setup function from the main cog file.

277
hiring/hiring.py Normal file
View File

@@ -0,0 +1,277 @@
import discord
from redbot.core import commands, Config, app_commands
from typing import Literal, Optional, TYPE_CHECKING, Type
import datetime
if TYPE_CHECKING:
from redbot.core.bot import Red
# --- Modals for the Application Forms ---
class StaffApplicationModal(discord.ui.Modal, title="Staff Application"):
chosen_plan = discord.ui.TextInput(label="What plan are you interested in?")
tox_level = discord.ui.TextInput(label="What is your toxicity level tolerance?")
describe_server = discord.ui.TextInput(label="Please describe your server.", style=discord.TextStyle.paragraph)
server_link = discord.ui.TextInput(label="Server Invite Link")
def __init__(self, ticket_channel: discord.TextChannel):
super().__init__()
self.ticket_channel = ticket_channel
async def on_submit(self, interaction: discord.Interaction):
cog: Optional["Hiring"] = interaction.client.get_cog("Hiring") # type: ignore
if not cog:
await interaction.response.send_message("Hiring cog not loaded.", ephemeral=True)
return
embed = discord.Embed(title="New Staff Application", color=discord.Color.blue())
embed.set_author(name=interaction.user.name, icon_url=interaction.user.display_avatar.url)
embed.add_field(name="Chosen Plan", value=self.chosen_plan.value, inline=False)
embed.add_field(name="Toxicity Level", value=self.tox_level.value, inline=False)
embed.add_field(name="Server Description", value=self.describe_server.value, inline=False)
embed.add_field(name="Server Link", value=self.server_link.value, inline=False)
await self.ticket_channel.send(embed=embed)
await interaction.response.send_message("Your staff application has been submitted.", ephemeral=True)
await interaction.response.send_message("Your application has been submitted!", ephemeral=True)
if isinstance(interaction.channel, discord.TextChannel):
await interaction.channel.send(embed=embed)
class PMApplicationModal(discord.ui.Modal, title="PM Application"):
ad = discord.ui.TextInput(label="Your Ad", style=discord.TextStyle.paragraph)
reqs = discord.ui.TextInput(label="Your Requirements", style=discord.TextStyle.paragraph)
tox_level = discord.ui.TextInput(label="What is your toxicity level tolerance?")
chosen_plan = discord.ui.TextInput(label="What plan are you interested in?")
def __init__(self, ticket_channel: discord.TextChannel):
super().__init__()
self.ticket_channel = ticket_channel
async def on_submit(self, interaction: discord.Interaction):
cog: Optional["Hiring"] = interaction.client.get_cog("Hiring") # type: ignore
if not cog:
await interaction.response.send_message("Hiring cog not loaded.", ephemeral=True)
return
embed = discord.Embed(title="New PM Application", color=discord.Color.green())
embed.set_author(name=interaction.user.name, icon_url=interaction.user.display_avatar.url)
embed.add_field(name="Ad", value=f"```\n{self.ad.value}\n```", inline=False)
embed.add_field(name="Requirements", value=f"```\n{self.reqs.value}\n```", inline=False)
embed.add_field(name="Toxicity Level", value=self.tox_level.value, inline=False)
embed.add_field(name="Chosen Plan", value=self.chosen_plan.value, inline=False)
await self.ticket_channel.send(embed=embed)
await interaction.response.send_message("Your PM application has been submitted.", ephemeral=True)
class HPMApplicationModal(discord.ui.Modal, title="HPM Application"):
ad = discord.ui.TextInput(label="Your Ad", style=discord.TextStyle.paragraph)
reqs = discord.ui.TextInput(label="Your Requirements", style=discord.TextStyle.paragraph)
def __init__(self, ticket_channel: discord.TextChannel):
super().__init__()
self.ticket_channel = ticket_channel
async def on_submit(self, interaction: discord.Interaction):
cog: Optional["Hiring"] = interaction.client.get_cog("Hiring") # type: ignore
if not cog:
await interaction.response.send_message("Hiring cog not loaded.", ephemeral=True)
return
embed = discord.Embed(title="New HPM Application", color=discord.Color.purple())
embed.set_author(name=interaction.user.name, icon_url=interaction.user.display_avatar.url)
embed.add_field(name="Ad", value=f"```\n{self.ad.value}\n```", inline=False)
embed.add_field(name="Requirements", value=f"```\n{self.reqs.value}\n```", inline=False)
await self.ticket_channel.send(embed=embed)
await interaction.response.send_message("Your HPM application has been submitted.", ephemeral=True)
# --- Views with Buttons ---
async def create_ticket(interaction: discord.Interaction, ticket_type: str, modal_class: Type[discord.ui.Modal]):
"""Helper function to create a ticket, used by multiple views."""
cog: Optional["Hiring"] = interaction.client.get_cog("Hiring") # type: ignore
if not cog:
await interaction.response.send_message("The Hiring cog is not loaded.", ephemeral=True)
return
guild = interaction.guild
if not guild:
await interaction.response.send_message("This action can only be performed in a server.", ephemeral=True)
return
category_id_raw = await cog.config.guild(guild).get_raw(f"{ticket_type}_category")
if not isinstance(category_id_raw, int):
await interaction.response.send_message(f"The category for '{ticket_type}' applications has not been set correctly.", ephemeral=True)
return
category = guild.get_channel(category_id_raw)
if not isinstance(category, discord.CategoryChannel):
await interaction.response.send_message(f"The configured category for '{ticket_type}' is invalid.", ephemeral=True)
return
assert isinstance(interaction.user, discord.Member)
try:
thread_name = f"{ticket_type}-application-{interaction.user.name}"
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
interaction.user: discord.PermissionOverwrite(read_messages=True, send_messages=True)
}
ticket_channel = await category.create_text_channel(name=thread_name, overwrites=overwrites)
modal_instance = modal_class(ticket_channel) # type: ignore
await interaction.response.send_modal(modal_instance)
async with cog.config.guild(guild).closed_applications() as closed_apps:
closed_apps[str(ticket_channel.id)] = datetime.datetime.now(datetime.timezone.utc).isoformat()
except discord.Forbidden:
if not interaction.response.is_done():
await interaction.response.send_message("I don't have permission to create channels in that category.", ephemeral=True)
except Exception as e:
if not interaction.response.is_done():
await interaction.response.send_message(f"An unexpected error occurred: {e}", ephemeral=True)
# --- Button Views for Commands ---
class HireView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.cog = cog
@discord.ui.button(label="Staff", style=discord.ButtonStyle.primary, custom_id="staff_apply_button_persistent")
async def staff_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await create_ticket(interaction, "staff", StaffApplicationModal)
@discord.ui.button(label="PM", style=discord.ButtonStyle.secondary, custom_id="pm_apply_button_persistent")
async def pm_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await create_ticket(interaction, "pm", PMApplicationModal)
@discord.ui.button(label="HPM", style=discord.ButtonStyle.success, custom_id="hpm_apply_button_persistent")
async def hpm_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await create_ticket(interaction, "hpm", HPMApplicationModal)
class WorkView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
self.cog = cog
@discord.ui.button(label="Apply for PM Position", style=discord.ButtonStyle.green, custom_id="work_apply_pm_persistent")
async def work_apply_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await create_ticket(interaction, "pm", PMApplicationModal)
# --- Main Cog Class ---
class Hiring(commands.Cog):
"""
A cog for handling staff hiring applications.
"""
def __init__(self, bot: "Red"):
self.bot = bot
default_guild = {
"staff_category": None,
"pm_category": None,
"hpm_category": None,
"work_channel": None,
"closed_applications": {}
}
self.config.register_guild(**default_guild)
# We need to make sure the views are persistent so buttons work after a restart
self.bot.add_view(HireView(self))
self.bot.add_view(WorkView(self))
async def cog_load(self):
self.bot.add_view(HireView())
self.bot.add_view(WorkView())
# --- Commands ---
@commands.hybrid_command() # type: ignore
@app_commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def hire(self, ctx: commands.Context):
"""Sends the hiring application view."""
view = HireView()
embed = discord.Embed(
title="Hiring Applications",
description="Please select the position you are applying for below.",
color=await ctx.embed_color()
)
await ctx.send(embed=embed, view=view)
@commands.hybrid_command() # type: ignore
@app_commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def work(self, ctx: commands.Context):
"""Posts the persistent PM application button."""
guild = ctx.guild
if not guild:
return
work_channel_id = await self.config.guild(guild).work_channel()
if not work_channel_id:
await ctx.send("The work channel has not been set. Please use `/hiringset workchannel`.")
return
channel = guild.get_channel(work_channel_id)
if not isinstance(channel, discord.TextChannel):
await ctx.send("The configured work channel is invalid.")
return
view = WorkView()
embed = discord.Embed(
title="Partnership Manager Applications",
description="Click the button below to apply for a Partnership Manager (PM) position.",
color=discord.Color.green()
)
try:
await channel.send(embed=embed, view=view)
await ctx.send(f"Application message posted in {channel.mention}.", ephemeral=True)
except discord.Forbidden:
await ctx.send("I don't have permission to send messages in that channel.", ephemeral=True)
# --- Settings Commands ---
@commands.group(aliases=["hset"]) # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def hiringset(self, ctx: commands.Context):
"""Configure Hiring settings."""
pass
@hiringset.command(name="staffcategory")
async def set_staff_category(self, ctx: commands.Context, category: discord.CategoryChannel):
"""Set the category for Staff applications."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).staff_category.set(category.id)
await ctx.send(f"Staff application category set to **{category.name}**.")
@hiringset.command(name="pmcategory")
async def set_pm_category(self, ctx: commands.Context, category: discord.CategoryChannel):
"""Set the category for PM applications."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).pm_category.set(category.id)
await ctx.send(f"PM application category set to **{category.name}**.")
@hiringset.command(name="hpmcategory")
async def set_hpm_category(self, ctx: commands.Context, category: discord.CategoryChannel):
"""Set the category for HPM applications."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).hpm_category.set(category.id)
await ctx.send(f"HPM application category set to **{category.name}**.")
@hiringset.command(name="workchannel")
async def set_work_channel(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel for the /work command announcements."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).work_channel.set(channel.id)
await ctx.send(f"Work announcement channel set to {channel.mention}.")
async def setup(bot):
await bot.add_cog(Hiring(bot))

15
hiring/info.json Normal file
View File

@@ -0,0 +1,15 @@
{
"author": [ "unstableCogs" ],
"install_msg": "Thank you for installing the Hiring cog! Use `[p]help Hiring` for a list of commands.",
"name": "Hiring",
"short": "A ticket-based system for staff and PM applications.",
"description": "Provides /hire and /work commands to manage the staff and PM hiring process through a ticket system with forms and buttons.",
"tags": [
"hiring",
"tickets",
"utility",
"modmail"
],
"requirements": [],
"end_user_data_statement": "This cog stores user IDs and the content of their applications for the duration of the hiring process."
}

View File

@@ -1,6 +1,6 @@
{ {
"author" : ["KWUK"], "author" : ["KWUK"],
"install_msg" : "Thank you for installing my repo! If you need support, create an issue on Gitea or ping me in KWDS.", "install_msg" : "Thank you for installing my repo! If you need support, create an issue on Gitea or ping me in KWDS. Cogs: hiring, kbump, kofishop, modmail, mors, pp, rpg, iservice, welcomer. ",
"name" : "unstable-cogs", "name" : "unstable-cogs",
"short" : "Cogs for Red-DiscordBot!", "short" : "Cogs for Red-DiscordBot!",
"description" : "Cogs for Red-DiscordBot!", "description" : "Cogs for Red-DiscordBot!",

0
kofishop/README.md Normal file
View File

1
kofishop/__init__.py Normal file
View File

@@ -0,0 +1 @@
from .kofishop import setup

16
kofishop/info.json Normal file
View File

@@ -0,0 +1,16 @@
{
"author": [ "unstableCogs" ],
"install_msg": "Thank you for installing the Ko-fi Shop cog! Use `[p]help KofiShop` for commands.",
"name": "KofiShop",
"short": "An interactive front-end for a Ko-fi store.",
"description": "Allows users to place orders and submit reviews for items available on the client's Ko-fi store. This cog acts as a bridge to an external shop.",
"tags": [
"kofi",
"shop",
"store",
"review",
"utility"
],
"requirements": [ "rich" ],
"end_user_data_statement": "This cog persistently stores user IDs, order details, and submitted reviews to manage shop history and transactions."
}

175
kofishop/kofishop.py Normal file
View File

@@ -0,0 +1,175 @@
import discord
from redbot.core import commands, Config
from redbot.core.bot import Red
from typing import Optional
# --- Modals for the Commands ---
class OrderModal(discord.ui.Modal, title="Commission/Shop Order"):
def __init__(self, cog: "KofiShop"):
super().__init__()
self.cog = cog
comm_type = discord.ui.TextInput(label="What type of commission/item is this?")
payment_status = discord.ui.TextInput(label="Is this free or paid?")
description = discord.ui.TextInput(label="Please describe your request.", style=discord.TextStyle.paragraph)
questions = discord.ui.TextInput(label="Any questions for the artist?", style=discord.TextStyle.paragraph, required=False)
async def on_submit(self, interaction: discord.Interaction):
if not interaction.guild:
return await interaction.response.send_message("This must be used in a server.", ephemeral=True)
order_channel_id = await self.cog.config.guild(interaction.guild).order_channel()
if not order_channel_id:
return await interaction.response.send_message("The order channel has not been set by an admin.", ephemeral=True)
order_channel = interaction.guild.get_channel(order_channel_id)
if not isinstance(order_channel, discord.TextChannel):
return await interaction.response.send_message("The configured order channel is invalid.", ephemeral=True)
embed = discord.Embed(
title="New Order Placed",
description=f"Submitted by {interaction.user.mention}",
color=0x00ff00 # Green for new orders
)
embed.add_field(name="Item/Commission Type", value=self.comm_type.value, inline=False)
embed.add_field(name="Payment Status", value=self.payment_status.value, inline=False)
embed.add_field(name="Description", value=self.description.value, inline=False)
if self.questions.value:
embed.add_field(name="Questions", value=self.questions.value, inline=False)
try:
await order_channel.send(embed=embed)
await interaction.response.send_message("Your order has been successfully submitted!", ephemeral=True)
except discord.Forbidden:
await interaction.response.send_message("I don't have permission to send messages in the order channel.", ephemeral=True)
class ReviewModal(discord.ui.Modal, title="Leave a Review"):
def __init__(self, cog: "KofiShop"):
super().__init__()
self.cog = cog
item_name = discord.ui.TextInput(label="What item/commission are you reviewing?")
rating = discord.ui.TextInput(label="Rating (e.g., 10/10)")
review_text = discord.ui.TextInput(label="Your Review", style=discord.TextStyle.paragraph)
async def on_submit(self, interaction: discord.Interaction):
if not interaction.guild:
return await interaction.response.send_message("This must be used in a server.", ephemeral=True)
review_channel_id = await self.cog.config.guild(interaction.guild).review_channel()
if not review_channel_id:
return await interaction.response.send_message("The review channel has not been set by an admin.", ephemeral=True)
review_channel = interaction.guild.get_channel(review_channel_id)
if not isinstance(review_channel, discord.TextChannel):
return await interaction.response.send_message("The configured review channel is invalid.", ephemeral=True)
embed = discord.Embed(
title=f"New Review for: {self.item_name.value}",
description=f"Submitted by {interaction.user.mention}",
color=0xadd8e6 # Pastel Blue
)
embed.add_field(name="Rating", value=self.rating.value, inline=False)
embed.add_field(name="Review", value=self.review_text.value, inline=False)
try:
await review_channel.send(embed=embed)
await interaction.response.send_message("Thank you! Your review has been submitted.", ephemeral=True)
except discord.Forbidden:
await interaction.response.send_message("I don't have permission to send messages in the review channel.", ephemeral=True)
class KofiShop(commands.Cog):
"""
A cog to manage Ko-fi shop orders and reviews.
"""
def __init__(self, bot: Red):
self.bot = bot
self.config = Config.get_conf(self, identifier=5566778899, force_registration=True)
default_guild = {
"order_channel": None,
"review_channel": None,
"waitlist_channel": None
}
self.config.register_guild(**default_guild)
# --- Commands ---
@commands.hybrid_command()
@commands.guild_only()
async def order(self, ctx: commands.Context):
"""Place an order for a shop or commission item."""
if not ctx.interaction:
return
# We pass `self` (the cog instance) to the modal
await ctx.interaction.response.send_modal(OrderModal(self))
@commands.hybrid_command()
@commands.guild_only()
async def review(self, ctx: commands.Context):
"""Leave a review for a completed shop or commission item."""
if not ctx.interaction:
return
await ctx.interaction.response.send_modal(ReviewModal(self))
@commands.hybrid_command() # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def waitlist(self, ctx: commands.Context, user: discord.Member, *, item: str):
"""Add a user and their requested item to the waitlist."""
if not ctx.guild or not isinstance(ctx.channel, discord.TextChannel):
return await ctx.send("This command must be used in a server's text channel.", ephemeral=True)
waitlist_channel_id = await self.config.guild(ctx.guild).waitlist_channel()
if not waitlist_channel_id:
return await ctx.send("The waitlist channel has not been set by an admin.", ephemeral=True)
waitlist_channel = ctx.guild.get_channel(waitlist_channel_id)
if not isinstance(waitlist_channel, discord.TextChannel):
return await ctx.send("The configured waitlist channel is invalid.", ephemeral=True)
message = f"**{item}** ིྀ {user.mention} ✧ in {ctx.channel.mention}"
try:
await waitlist_channel.send(message)
await ctx.send(f"{user.mention} has been added to the waitlist for '{item}'.", ephemeral=True)
except discord.Forbidden:
await ctx.send(f"I don't have permission to send messages in the waitlist channel.", ephemeral=True)
# --- Settings Commands ---
@commands.group(aliases=["kset"]) # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def kofiset(self, ctx: commands.Context):
"""
Configure the KofiShop settings.
"""
pass
@kofiset.command(name="orderchannel")
async def kofiset_order(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel where new orders will be sent."""
if not ctx.guild: return
await self.config.guild(ctx.guild).order_channel.set(channel.id)
await ctx.send(f"Order channel has been set to {channel.mention}.")
@kofiset.command(name="reviewchannel")
async def kofiset_review(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel where new reviews will be sent."""
if not ctx.guild: return
await self.config.guild(ctx.guild).review_channel.set(channel.id)
await ctx.send(f"Review channel has been set to {channel.mention}.")
@kofiset.command(name="waitlistchannel")
async def kofiset_waitlist(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel where waitlist notifications will be sent."""
if not ctx.guild: return
await self.config.guild(ctx.guild).waitlist_channel.set(channel.id)
await ctx.send(f"Waitlist channel has been set to {channel.mention}.")
async def setup(bot: Red):
await bot.add_cog(KofiShop(bot))

4
logging/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
from .logging import Logging
async def setup(bot):
await bot.add_cog(Logging(bot))

17
logging/info.json Normal file
View File

@@ -0,0 +1,17 @@
{
"author": [
"unstableCogs"
],
"install_msg": "Thank you for installing the Logging cog! Please configure a log channel to begin.",
"name": "Logging",
"short": "A cog for comprehensive server event logging.",
"description": "Logs various server events (joins, leaves, message edits/deletes, etc.) to a designated channel for moderation and auditing purposes.",
"tags": [
"logging",
"moderation",
"utility",
"events"
],
"requirements": [],
"end_user_data_statement": "This cog does not persistently store any user data."
}

276
logging/logging.py Normal file
View File

@@ -0,0 +1,276 @@
import discord
from redbot.core import commands, Config
import datetime
from typing import Dict, Optional, Union
class Logging(commands.Cog):
"""
A cog for comprehensive server event logging.
"""
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, identifier=1234567893, force_registration=True)
default_guild = {
"log_channel": None,
"logged_events": {}, # For DataManager
"enabled_events": {
"on_message_delete": True,
"on_message_edit": True,
"on_member_join": True,
"on_member_remove": True,
"on_member_update": True,
"on_voice_state_update": True,
"on_invite_create": True,
},
}
self.config.register_guild(**default_guild)
async def _send_log(self, guild: discord.Guild, embed: discord.Embed, event_name: str):
"""Helper function to send logs."""
enabled_events = await self.config.guild(guild).enabled_events()
if not enabled_events.get(event_name, False):
return
log_channel_id = await self.config.guild(guild).log_channel()
if not log_channel_id:
return
log_channel = guild.get_channel(log_channel_id)
if isinstance(log_channel, discord.TextChannel):
try:
log_message = await log_channel.send(embed=embed)
if event_name in ["on_message_delete", "on_message_edit"]:
async with self.config.guild(guild).logged_events() as events:
events[str(log_message.id)] = datetime.datetime.now(
datetime.timezone.utc
).isoformat()
except discord.Forbidden:
pass # Bot lacks permissions
# --- SETTINGS COMMANDS ---
@commands.group(aliases=["logset"]) # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def loggingset(self, ctx: commands.Context):
"""Configure logging settings."""
pass
@loggingset.command(name="channel")
async def set_log_channel(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel where logs will be sent."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).log_channel.set(channel.id)
await ctx.send(f"Log channel has been set to {channel.mention}")
@loggingset.command(name="toggle")
async def toggle_log_event(self, ctx: commands.Context, event: str):
"""Toggle logging for a specific event."""
if not ctx.guild:
return
valid_events = list((await self.config.guild(ctx.guild).enabled_events()).keys())
if event not in valid_events:
await ctx.send(f"Invalid event. Valid events are: `{'`, `'.join(valid_events)}`")
return
async with self.config.guild(ctx.guild).enabled_events() as events:
current_status = events.get(event, False)
events[event] = not current_status
new_status = "enabled" if not current_status else "disabled"
await ctx.send(f"Logging for `{event}` has been {new_status}.")
# --- EVENT LISTENERS ---
@commands.Cog.listener()
async def on_message_delete(self, message: discord.Message):
"""Log when a message is deleted."""
if message.author.bot or not message.guild:
return
location = ""
if isinstance(message.channel, (discord.TextChannel, discord.Thread)):
location = message.channel.mention
elif isinstance(message.channel, discord.DMChannel):
location = f"DM with {message.channel.recipient}"
elif isinstance(message.channel, discord.GroupChannel):
location = f"Group DM ({message.channel.id})"
else:
location = f"Channel ID: {message.channel.id}"
embed = discord.Embed(
description=f"**Message deleted in {location}**\n{message.content or 'No text content.'}",
color=discord.Color.red(),
timestamp=datetime.datetime.now(datetime.timezone.utc),
)
embed.set_author(
name=f"{message.author.name} ({message.author.id})",
icon_url=message.author.display_avatar.url,
)
await self._send_log(message.guild, embed, "on_message_delete")
@commands.Cog.listener()
async def on_message_edit(self, before: discord.Message, after: discord.Message):
"""Log when a message is edited."""
if before.author.bot or not before.guild or before.content == after.content:
return
location = ""
if isinstance(before.channel, (discord.TextChannel, discord.Thread)):
location = before.channel.mention
elif isinstance(before.channel, discord.DMChannel):
location = f"DM with {before.channel.recipient}"
elif isinstance(before.channel, discord.GroupChannel):
location = f"Group DM ({before.channel.id})"
else:
location = f"Channel ID: {before.channel.id}"
embed = discord.Embed(
description=f"**Message edited in {location}** [Jump to Message]({after.jump_url})",
color=discord.Color.orange(),
timestamp=datetime.datetime.now(datetime.timezone.utc),
)
embed.set_author(
name=f"{before.author.name} ({before.author.id})",
icon_url=before.author.display_avatar.url,
)
embed.add_field(name="Before", value=before.content or "Empty", inline=False)
embed.add_field(name="After", value=after.content or "Empty", inline=False)
await self._send_log(before.guild, embed, "on_message_edit")
@commands.Cog.listener()
async def on_member_join(self, member: discord.Member):
"""Log when a user joins the server."""
embed = discord.Embed(
description=f"**{member.mention} has joined the server.**",
color=discord.Color.green(),
timestamp=datetime.datetime.now(datetime.timezone.utc),
)
embed.set_author(
name=f"{member.name} ({member.id})", icon_url=member.display_avatar.url
)
await self._send_log(member.guild, embed, "on_member_join")
@commands.Cog.listener()
async def on_member_remove(self, member: discord.Member):
"""Log when a user leaves the server."""
embed = discord.Embed(
description=f"**{member.mention} has left the server.**",
color=discord.Color.dark_red(),
timestamp=datetime.datetime.now(datetime.timezone.utc),
)
embed.set_author(
name=f"{member.name} ({member.id})", icon_url=member.display_avatar.url
)
await self._send_log(member.guild, embed, "on_member_remove")
@commands.Cog.listener()
async def on_member_update(self, before: discord.Member, after: discord.Member):
"""Log when a member's roles or nickname changes."""
guild = after.guild
if before.nick != after.nick:
embed = discord.Embed(
description=f"**{after.mention} changed their nickname.**",
color=discord.Color.blue(),
timestamp=datetime.datetime.now(datetime.timezone.utc),
)
embed.set_author(
name=f"{after.name} ({after.id})", icon_url=after.display_avatar.url
)
embed.add_field(name="Before", value=before.nick or "None", inline=False)
embed.add_field(name="After", value=after.nick or "None", inline=False)
await self._send_log(guild, embed, "on_member_update")
if before.roles != after.roles:
added_roles = [r.mention for r in after.roles if r not in before.roles]
removed_roles = [r.mention for r in before.roles if r not in after.roles]
if added_roles or removed_roles:
embed = discord.Embed(
description=f"**{after.mention}'s roles were updated.**",
color=discord.Color.blue(),
timestamp=datetime.datetime.now(datetime.timezone.utc),
)
embed.set_author(
name=f"{after.name} ({after.id})",
icon_url=after.display_avatar.url,
)
if added_roles:
embed.add_field(
name="Added Roles", value=", ".join(added_roles), inline=False
)
if removed_roles:
embed.add_field(
name="Removed Roles",
value=", ".join(removed_roles),
inline=False,
)
await self._send_log(guild, embed, "on_member_update")
@commands.Cog.listener()
async def on_voice_state_update(
self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState
):
"""Log when a user's voice state changes."""
if before.channel == after.channel:
return # Ignore mutes, deafens, etc. for now
guild = member.guild
action = ""
if before.channel and not after.channel:
action = f"left voice channel {before.channel.mention}."
elif not before.channel and after.channel:
action = f"joined voice channel {after.channel.mention}."
elif before.channel and after.channel:
action = f"moved from {before.channel.mention} to {after.channel.mention}."
if action:
embed = discord.Embed(
description=f"**{member.mention} {action}**",
color=discord.Color.light_grey(),
timestamp=datetime.datetime.now(datetime.timezone.utc),
)
embed.set_author(
name=f"{member.name} ({member.id})", icon_url=member.display_avatar.url
)
await self._send_log(guild, embed, "on_voice_state_update")
@commands.Cog.listener()
async def on_invite_create(self, invite: discord.Invite):
"""Log when an invite is created."""
guild = invite.guild
if not guild or not isinstance(guild, discord.Guild):
return
inviter_str = "Unknown User"
if invite.inviter and isinstance(invite.inviter, (discord.User, discord.Member)):
inviter_str = invite.inviter.mention
elif invite.inviter:
inviter_str = f"User ({invite.inviter.id})"
channel_str = "Unknown Channel"
if invite.channel and isinstance(invite.channel, (discord.abc.GuildChannel)):
if hasattr(invite.channel, 'mention'):
channel_str = invite.channel.mention
else:
channel_str = f"`{invite.channel.name}`"
elif invite.channel:
channel_str = f"Channel ID: {invite.channel.id}"
embed = discord.Embed(
title="Invite Created",
description=f"Invite `{invite.code}` to {channel_str} created by {inviter_str}.",
color=discord.Color.teal(),
timestamp=datetime.datetime.now(datetime.timezone.utc),
)
embed.add_field(name="Max Uses", value=invite.max_uses or "Unlimited")
embed.add_field(
name="Max Age",
value=f"{invite.max_age // 3600} hours" if invite.max_age else "Permanent",
)
await self._send_log(guild, embed, "on_invite_create")
async def setup(bot):
await bot.add_cog(Logging(bot))

0
modmail/README.md Normal file
View File

1
modmail/__init__.py Normal file
View File

@@ -0,0 +1 @@
from .modmail import setup

16
modmail/info.json Normal file
View File

@@ -0,0 +1,16 @@
{
"author": [ "unstableCogs" ],
"install_msg": "Thank you for installing the ModMail cog! Please use `[p]help ModMail` for setup commands.",
"name": "ModMail",
"short": "A private, forum-based ModMail system.",
"description": "A comprehensive ModMail system that relays user DMs to a private forum channel for staff to review and respond to. This serves as the core for all ticket-based interactions.",
"tags": [
"modmail",
"moderation",
"support",
"tickets",
"utility"
],
"requirements": [ "rich" ],
"end_user_data_statement": "This cog persistently stores user IDs and message content from ModMail threads for moderation and support history."
}

218
modmail/modmail.py Normal file
View File

@@ -0,0 +1,218 @@
import discord
from redbot.core import commands, Config
from redbot.core.bot import Red
from typing import Optional
class ModMail(commands.Cog):
"""
A configurable, forum-based ModMail system.
"""
def __init__(self, bot: Red):
self.bot = bot
# Initialize Red's Config system for storing settings per-server.
self.config = Config.get_conf(self, identifier=9876543210, force_registration=True)
# Define the default settings for each server.
default_guild = {
"modmail_forum": None, # The ID of the forum channel for tickets
"enabled": False, # Whether the system is on or off
"active_threads": {} # A dictionary to track {user_id: thread_id}
}
# Register the default settings.
self.config.register_guild(**default_guild)
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
"""
This is the core event listener. It handles both incoming DMs from users
and outgoing replies from staff.
"""
# Ignore messages from bots to prevent loops.
if message.author.bot:
return
# --- Part 1: Handling DMs from Users ---
if isinstance(message.channel, discord.DMChannel):
await self.handle_dm(message)
# --- Part 2: Handling Replies from Staff ---
elif isinstance(message.channel, discord.Thread):
await self.handle_staff_reply(message)
async def handle_dm(self, message: discord.Message):
"""Handles messages sent directly to the bot."""
# Find a mutual server with the user.
guild = next((g for g in self.bot.guilds if g.get_member(message.author.id)), None)
if not guild:
return
settings = await self.config.guild(guild).all()
if not settings["enabled"] or not settings["modmail_forum"]:
return
forum_channel = guild.get_channel(settings["modmail_forum"])
if not isinstance(forum_channel, discord.ForumChannel):
return
active_threads = settings["active_threads"]
user_id_str = str(message.author.id)
# Check if the user already has an active thread.
if user_id_str in active_threads:
thread_id = active_threads[user_id_str]
thread = guild.get_thread(thread_id)
if thread:
# Relay the message to the existing thread.
await thread.send(f"**{message.author.display_name}:** {message.content}")
await message.add_reaction("")
return
else:
# The thread was deleted, so we clean up our records.
async with self.config.guild(guild).active_threads() as threads:
del threads[user_id_str]
# Create a new thread for the user.
try:
thread_name = f"ModMail | {message.author.name}"
embed = discord.Embed(
title=f"New ModMail Thread",
description=f"**User:** {message.author.mention} (`{message.author.id}`)",
color=0xadd8e6 # Light grey pastel blue
)
embed.add_field(name="Initial Message", value=message.content, inline=False)
embed.set_footer(text="Staff can reply in this thread to send a message.")
thread_with_message = await forum_channel.create_thread(name=thread_name, embed=embed)
thread = thread_with_message.thread
async with self.config.guild(guild).active_threads() as threads:
threads[user_id_str] = thread.id
await message.channel.send("Your message has been received, and a ModMail ticket has been opened. Staff will be with you shortly.")
await message.add_reaction("")
except discord.Forbidden:
print(f"ModMail: I don't have permission to create threads in {forum_channel.name}.")
except Exception as e:
print(f"ModMail: An unexpected error occurred: {e}")
async def handle_staff_reply(self, message: discord.Message):
"""Handles messages sent by staff inside a ModMail thread."""
guild = message.guild
if not guild:
return
active_threads = await self.config.guild(guild).active_threads()
# Find which user this thread belongs to by checking our records.
thread_id_str = str(message.channel.id)
user_id = None
for uid, tid in active_threads.items():
if str(tid) == thread_id_str:
user_id = int(uid)
break
if not user_id:
# This is a regular thread, not a ModMail thread we're tracking.
return
user = guild.get_member(user_id)
if not user:
# User might have left the server.
await message.channel.send("⚠️ **Error:** Could not find the user. They may have left the server.")
return
# Send the staff's message to the user's DMs.
try:
embed = discord.Embed(
description=message.content,
color=0xadd8e6 # Light grey pastel blue
)
embed.set_author(name="Staff Response") # Anonymize the staff member
await user.send(embed=embed)
await message.add_reaction("📨") # Add a mail icon to show it was sent
except discord.Forbidden:
await message.channel.send("⚠️ **Error:** I could not send a DM to this user. They may have DMs disabled.")
except Exception as e:
await message.channel.send(f"⚠️ **Error:** An unexpected error occurred: {e}")
# --- Settings and Management Commands ---
@commands.group(aliases=["mmset"]) # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def modmailset(self, ctx: commands.Context):
"""
Configure the ModMail settings for this server.
"""
pass
@modmailset.command(name="forum")
async def modmailset_forum(self, ctx: commands.Context, channel: discord.ForumChannel):
"""Set the forum channel where ModMail tickets will be created."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).modmail_forum.set(channel.id)
await ctx.send(f"The ModMail forum has been set to {channel.mention}.")
@modmailset.command(name="toggle")
async def modmailset_toggle(self, ctx: commands.Context):
"""Enable or disable the ModMail system on this server."""
if not ctx.guild:
return
current_status = await self.config.guild(ctx.guild).enabled()
new_status = not current_status
await self.config.guild(ctx.guild).enabled.set(new_status)
status_text = "enabled" if new_status else "disabled"
await ctx.send(f"The ModMail system has been {status_text}.")
@modmailset.command(name="close")
async def modmailset_close(self, ctx: commands.Context, *, reason: Optional[str] = "No reason provided."):
"""
Close the current ModMail thread.
You must run this command inside the thread you wish to close.
"""
if not ctx.guild or not isinstance(ctx.channel, discord.Thread):
await ctx.send("This command can only be run inside a ModMail thread.")
return
active_threads = await self.config.guild(ctx.guild).active_threads()
thread_id_str = str(ctx.channel.id)
user_id = None
for uid, tid in active_threads.items():
if str(tid) == thread_id_str:
user_id = int(uid)
break
if not user_id:
await ctx.send("This does not appear to be an active ModMail thread.")
return
# Clean up our records.
async with self.config.guild(ctx.guild).active_threads() as threads:
del threads[str(user_id)]
# Notify the user.
user = self.bot.get_user(user_id)
if user:
try:
embed = discord.Embed(
title="ModMail Ticket Closed",
description=f"Your ticket has been closed by staff.\n\n**Reason:** {reason}",
color=0xadd8e6
)
await user.send(embed=embed)
except discord.Forbidden:
pass # Can't notify user if DMs are closed
# Archive the thread.
await ctx.send(f"Ticket closed by {ctx.author.mention}. Archiving thread...")
await ctx.channel.edit(archived=True, locked=True)
# This required function allows Red to load the cog.
async def setup(bot: Red):
await bot.add_cog(ModMail(bot))

0
mors/README.md Normal file
View File

4
mors/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
from .mors import MORS
async def setup(bot):
await bot.add_cog(MORS(bot))

18
mors/info.json Normal file
View File

@@ -0,0 +1,18 @@
{
"author": [
"unstableCogs"
],
"install_msg": "Thank you for installing the Mass Outreach & Review System cog!",
"name": "MORS",
"short": "A multi-step system for mass outreach and reviews.",
"description": "Manages a complete workflow for user outreach, including ad submission, time selection, and final reviews.",
"tags": [
"mass",
"outreach",
"review",
"tickets",
"utility"
],
"requirements": [],
"end_user_data_statement": "This cog stores user IDs, ticket information, and submitted reviews persistently for record-keeping purposes."
}

444
mors/mors.py Normal file
View File

@@ -0,0 +1,444 @@
import discord
import asyncio
from redbot.core import commands, Config, app_commands
from typing import TYPE_CHECKING, Optional
if TYPE_CHECKING:
from redbot.core.bot import Red
# --- UI Components ---
class AdSubmissionModal(discord.ui.Modal, title="MORS Ad Submission"):
ad_text = discord.ui.TextInput(
label="Your Server Advertisement",
style=discord.TextStyle.paragraph,
placeholder="Please enter the full text of your ad here.",
required=True,
max_length=2000,
)
ad_link = discord.ui.TextInput(
label="Your Server Invite Link",
placeholder="https://discord.gg/your-invite",
required=True,
max_length=100,
)
def __init__(self, cog: "MORS"):
super().__init__()
self.cog = cog
async def on_submit(self, interaction: discord.Interaction):
guild = interaction.guild
if not guild:
await interaction.response.send_message("Something went wrong.", ephemeral=True)
return
conf = self.cog.config.guild(guild)
ad_channel_id = await conf.ad_channel()
if not ad_channel_id:
await interaction.response.send_message(
"The MORS system has not been fully configured by an administrator.",
ephemeral=True
)
return
ad_channel = guild.get_channel(ad_channel_id)
if not isinstance(ad_channel, discord.TextChannel):
await interaction.response.send_message(
"The configured ad channel is invalid. Please contact an administrator.",
ephemeral=True
)
return
try:
thread = await ad_channel.create_thread(
name=f"mors-ticket-{interaction.user.name}",
type=discord.ChannelType.private_thread
)
await thread.add_user(interaction.user)
except (discord.Forbidden, discord.HTTPException):
await interaction.response.send_message(
"I don't have permissions to create private threads in the ad channel.",
ephemeral=True
)
return
await thread.send(f"Welcome {interaction.user.mention}! Your MORS ticket has been created and is awaiting admin approval.")
await thread.send(f"For easy access on mobile, your thread ID is: `{thread.id}`")
async with conf.active_tickets() as active_tickets:
active_tickets[str(interaction.user.id)] = {
"thread_id": thread.id,
"ad_text": self.ad_text.value,
"ad_link": self.ad_link.value,
"status": "pending_approval"
}
await interaction.response.send_message("Your submission has been received and is awaiting approval!", ephemeral=True)
class TimeSelect(discord.ui.Select):
def __init__(self, cog: "MORS"):
self.cog = cog
options = [
discord.SelectOption(label="30 Minutes", value="30m"),
discord.SelectOption(label="1 Hour", value="1h"),
discord.SelectOption(label="2 Hours", value="2h"),
discord.SelectOption(label="3 Hours", value="3h"),
discord.SelectOption(label="4 Hours (Bypass Only)", value="4h"),
discord.SelectOption(label="Once a Week (Bypass Only)", value="ovn"),
]
super().__init__(placeholder="Select the advertisement duration...", min_values=1, max_values=1, options=options)
async def callback(self, interaction: discord.Interaction):
guild = interaction.guild
if not guild or not isinstance(interaction.user, discord.Member):
await interaction.response.send_message("An error occurred.", ephemeral=True)
return
member = interaction.user
selected_time = self.values[0]
conf = self.cog.config.guild(guild)
# Logic for bypass role and cooldowns will be added here
bypass_role_id = await conf.bypass_role()
has_bypass = False
if bypass_role_id:
bypass_role = guild.get_role(bypass_role_id)
if bypass_role and bypass_role in member.roles:
has_bypass = True
if selected_time in ["4h", "ovn"] and not has_bypass:
await interaction.response.send_message("You do not have the required role for this duration.", ephemeral=True)
return
async with conf.active_tickets() as active_tickets:
user_id_str = str(interaction.user.id)
if user_id_str not in active_tickets:
await interaction.response.send_message("You don't have an active MORS ticket.", ephemeral=True)
return
thread_id = active_tickets[user_id_str]["thread_id"]
thread = guild.get_thread(thread_id)
if not thread:
await interaction.response.send_message("Could not find your ticket thread.", ephemeral=True)
del active_tickets[user_id_str]
return
try:
await thread.edit(name=f"n2p-{selected_time}-{interaction.user.name}")
# Logic to add the role will go here once the role ID is configured
except discord.Forbidden:
await interaction.response.send_message("I don't have permission to rename your ticket thread.", ephemeral=True)
return
# Send confirmation messages
queue_channel_id = await conf.queue_channel()
if queue_channel_id:
queue_channel = guild.get_channel(queue_channel_id)
if isinstance(queue_channel, discord.TextChannel):
queue_link = f"https://discord.com/channels/{guild.id}/{queue_channel.id}"
await queue_channel.send(f"{thread.mention} :mooncatblue: {interaction.user.mention} queued for __{selected_time}__ *!*")
await thread.send(f":81407babybluebutterfly: you're in the [queue]({queue_link}) *!* \n-# **p.s using invites command is __required__ for sep to state invites. no reply to pings within 3 days or inv cmnd done will get you suspended from massing.**")
await interaction.response.send_message(f"You have selected: {selected_time}", ephemeral=True)
if self.view:
self.view.stop()
class TimeSelectionView(discord.ui.View):
def __init__(self, cog: "MORS"):
super().__init__(timeout=180)
self.add_item(TimeSelect(cog))
class ReviewModal(discord.ui.Modal, title="MORS Review Submission"):
service_type = discord.ui.TextInput(label="What service type did you use?")
rating = discord.ui.TextInput(label="Rating (1-10)", max_length=2)
review_text = discord.ui.TextInput(label="Your Review", style=discord.TextStyle.paragraph, max_length=1500)
toxicity = discord.ui.TextInput(label="Toxicity Level (ntox/stox)")
def __init__(self, cog: "MORS"):
super().__init__()
self.cog = cog
async def on_submit(self, interaction: discord.Interaction):
guild = interaction.guild
if not guild:
await interaction.response.send_message("An error occurred.", ephemeral=True)
return
review_channel_id = await self.cog.config.guild(guild).review_channel()
if not review_channel_id:
await interaction.response.send_message("The review channel has not been configured.", ephemeral=True)
return
review_channel = guild.get_channel(review_channel_id)
if not isinstance(review_channel, discord.TextChannel):
await interaction.response.send_message("The configured review channel is invalid.", ephemeral=True)
return
embed = discord.Embed(
title="New MORS Review",
color=discord.Color.green()
)
embed.set_author(name=interaction.user.name, icon_url=interaction.user.display_avatar.url)
embed.add_field(name="Service Type", value=self.service_type.value, inline=False)
embed.add_field(name="Rating", value=f"{self.rating.value}/10", inline=True)
embed.add_field(name="Toxicity", value=self.toxicity.value, inline=True)
embed.add_field(name="Review", value=self.review_text.value, inline=False)
try:
await review_channel.send(embed=embed)
except discord.Forbidden:
# This would only happen if permissions changed mid-process
pass
await interaction.response.send_message("Your review has been submitted! This ticket will close shortly.", ephemeral=True)
class MORS(commands.Cog):
"""
Mass Outreach & Review System
"""
def __init__(self, bot: "Red"):
self.bot = bot
self.config = Config.get_conf(self, identifier=1234567894, force_registration=True)
default_guild = {
"ad_channel": None,
"review_channel": None,
"done_channel": None,
"queue_channel": None, # Added for queue messages
"access_role": None,
"bypass_role": None,
"active_tickets": {}
}
self.config.register_guild(**default_guild)
# --- User Commands ---
@app_commands.command()
@app_commands.guild_only()
async def game(self, interaction: discord.Interaction):
"""Start the mass outreach process by submitting an ad."""
guild = interaction.guild
if not guild:
return
if not isinstance(interaction.user, discord.Member):
await interaction.response.send_message("This command can only be used by server members.", ephemeral=True)
return
member = interaction.user
access_role_id = await self.config.guild(guild).access_role()
if access_role_id:
access_role = guild.get_role(access_role_id)
if access_role and access_role not in member.roles:
await interaction.response.send_message(
f"You need the {access_role.name} role to use this command.",
ephemeral=True
)
return
modal = AdSubmissionModal(cog=self)
await interaction.response.send_modal(modal)
@app_commands.command()
@app_commands.guild_only()
async def over(self, interaction: discord.Interaction):
"""Select your advertisement duration."""
guild = interaction.guild
if not guild:
return
active_tickets = await self.config.guild(guild).active_tickets()
if str(interaction.user.id) not in active_tickets:
await interaction.response.send_message(
"You need to start the process with `/game` before you can use this command.",
ephemeral=True
)
return
view = TimeSelectionView(cog=self)
await interaction.response.send_message("Please select your desired ad duration from the dropdown below:", view=view, ephemeral=True)
@app_commands.command(name="pudding-head")
@app_commands.guild_only()
async def pudding_head(self, interaction: discord.Interaction):
"""Submit your final review for the MORS process."""
guild = interaction.guild
if not guild:
return
active_tickets = await self.config.guild(guild).active_tickets()
if str(interaction.user.id) not in active_tickets:
await interaction.response.send_message(
"You do not have an active MORS ticket to review.",
ephemeral=True
)
return
modal = ReviewModal(cog=self)
await interaction.response.send_modal(modal)
# --- Admin Commands ---
@app_commands.command()
@app_commands.guild_only()
@app_commands.describe(member="The user whose ad you want to post.")
@app_commands.default_permissions(manage_guild=True)
async def posted(self, interaction: discord.Interaction, member: discord.Member):
"""Approves and posts a user's submitted ad."""
guild = interaction.guild
if not guild:
return
conf = self.config.guild(guild)
ad_channel_id = await conf.ad_channel()
if not ad_channel_id:
await interaction.response.send_message("Ad channel not configured.", ephemeral=True)
return
ad_channel = guild.get_channel(ad_channel_id)
if not isinstance(ad_channel, discord.TextChannel):
await interaction.response.send_message("Configured ad channel is invalid.", ephemeral=True)
return
async with conf.active_tickets() as active_tickets:
user_id_str = str(member.id)
if user_id_str not in active_tickets:
await interaction.response.send_message(f"{member.name} has no pending ad.", ephemeral=True)
return
ticket_data = active_tickets[user_id_str]
ad_embed = discord.Embed(
title="New Server Advertisement",
description=ticket_data.get("ad_text", "No ad text provided."),
color=discord.Color.blue()
)
ad_embed.add_field(name="Invite Link", value=ticket_data.get("ad_link", "No link provided."))
ad_embed.set_author(name=member.name, icon_url=member.display_avatar.url)
try:
ad_message = await ad_channel.send(embed=ad_embed)
await ad_message.pin()
active_tickets[user_id_str]["status"] = "posted"
except discord.Forbidden:
await interaction.response.send_message("I lack permissions to post or pin in the ad channel.", ephemeral=True)
return
await interaction.response.send_message(f"Ad for {member.name} has been posted and pinned. Remember to set a reminder.", ephemeral=True)
@app_commands.command()
@app_commands.guild_only()
@app_commands.describe(member="The user whose ticket you want to finalize.")
@app_commands.default_permissions(manage_guild=True)
async def done(self, interaction: discord.Interaction, member: discord.Member):
"""Admin command to finalize and close a MORS ticket."""
guild = interaction.guild
if not guild:
return
conf = self.config.guild(guild)
done_channel_id = await conf.done_channel()
if not done_channel_id:
await interaction.response.send_message("The 'done' channel is not configured.", ephemeral=True)
return
done_channel = guild.get_channel(done_channel_id)
if not isinstance(done_channel, discord.TextChannel):
await interaction.response.send_message("The configured 'done' channel is invalid.", ephemeral=True)
return
async with conf.active_tickets() as active_tickets:
user_id_str = str(member.id)
if user_id_str not in active_tickets:
await interaction.response.send_message(f"{member.name} does not have an active MORS ticket.", ephemeral=True)
return
ticket_data = active_tickets.pop(user_id_str) # Remove ticket from active list
thread_id = ticket_data.get("thread_id")
ad_link = ticket_data.get("ad_link", "Not available")
thread = guild.get_thread(thread_id) if thread_id else None
# Send embed to done channel
done_embed = discord.Embed(
description=f"Advertisement period is complete for {member.mention}.",
color=discord.Color.teal()
)
done_embed.add_field(name="Server Ad Link", value=ad_link, inline=False)
# Client mentioned "image", will need clarification on what image to include.
await done_channel.send(embed=done_embed)
if thread:
await thread.send(f"{member.mention}, your MORS process is complete! Please submit your review with `/pudding-head`.")
await thread.send("This ticket will be archived in 60 seconds.")
await interaction.response.send_message(f"Finalizing ticket for {member.name}. The thread will be archived in 60 seconds.", ephemeral=True)
await asyncio.sleep(60)
try:
await thread.edit(archived=True, locked=True)
except discord.Forbidden:
await thread.send("I don't have permission to archive this thread.")
else:
await interaction.response.send_message(f"Finalizing ticket for {member.name}. Could not find original thread to archive.", ephemeral=True)
# --- Settings Commands ---
@commands.group() # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def morsset(self, ctx: commands.Context):
"""Configure MORS settings."""
pass
@morsset.command(name="adchannel")
async def set_ad_channel(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel where ads are posted."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).ad_channel.set(channel.id)
await ctx.send(f"Ad channel has been set to {channel.mention}")
@morsset.command(name="reviewchannel")
async def set_review_channel(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel where final reviews are sent."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).review_channel.set(channel.id)
await ctx.send(f"Review channel has been set to {channel.mention}")
@morsset.command(name="donechannel")
async def set_done_channel(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel for the /done command embeds."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).done_channel.set(channel.id)
await ctx.send(f"Done channel has been set to {channel.mention}")
@morsset.command(name="queuechannel")
async def set_queue_channel(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel for queue confirmation messages."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).queue_channel.set(channel.id)
await ctx.send(f"Queue channel has been set to {channel.mention}")
@morsset.command(name="accessrole")
async def set_access_role(self, ctx: commands.Context, role: discord.Role):
"""Set the role required to use the /game command."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).access_role.set(role.id)
await ctx.send(f"Access role has been set to {role.name}")
@morsset.command(name="bypassrole")
async def set_bypass_role(self, ctx: commands.Context, role: discord.Role):
"""Set the bypass role for MORS cooldowns."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).bypass_role.set(role.id)
await ctx.send(f"Bypass role has been set to {role.name}")

5
pp/__init__.py Normal file
View File

@@ -0,0 +1,5 @@
from .passwdprotect import Passwd
async def setup(bot):
cog = Passwd(bot)
await bot.add_cog(cog)

10
pp/info.json Normal file
View File

@@ -0,0 +1,10 @@
{
"author": ["kitsunic"],
"description": "A cog for password protected channels",
"end_user_data_statement": "This cog stores user, avatar, and guild data. A simple delete request to bot to remove your data or guild data",
"install_msg": "Thanks for installing & testing.",
"min_bot_version": "3.5.0",
"short": "A pwd channel protection cog",
"tags": ["embed"],
"type": "COG"
}

366
pp/passwdprotect.py Normal file
View File

@@ -0,0 +1,366 @@
import discord
import hashlib
import asyncio
import random
import string
import datetime
from redbot.core import commands, checks, Config
class Passwd(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, identifier=50204090) # Unique identifier
# Default settings within the config
default_guild = {
"password_channels": {},
"password_attempts": {},
"admin_channel": None,
"password_recovery_requests": {},
"channel_data": {},
"whitelist": [],
"blacklist": [],
}
self.config.register_guild(**default_guild)
#
# -------------------------------------------------------------------------------------------------------------
#
@commands.group(name="passwdprotect", aliases=["pwd"])
async def passwdprotect(self, ctx):
"""Password management commands"""
if not ctx.invoked_subcommand:
await ctx.send("Missing subcommand.")
#
# -------------------------------------------------------------------------------------------------------------
#
@passwdprotect.command(name="verify", aliases=["ver"])
async def verify(self, ctx, password: str):
"""Verifies the password for the current channel."""
channel = ctx.channel
async with self.config.guild(ctx.guild).password_channels() as password_channels:
if channel.id in password_channels:
stored_hash = password_channels[channel.id]["password_hash"]
provided_hash = hashlib.sha256(password.encode("utf-8")).hexdigest()
if stored_hash == provided_hash:
# Password verified successfully
role_id = password_channels[channel.id]["role_id"]
role = ctx.guild.get_role(role_id)
if role:
await ctx.author.add_roles(role)
await ctx.send(f"Password verified! You now have access to {channel.mention}.")
else:
await ctx.send("Password verified, but the access role seems to be missing. Please contact an admin.")
else:
await ctx.send("Incorrect password.")
else:
await ctx.send("This channel is not password protected.")
@passwdprotect.group(name="channels", aliases=["chs", "--ch"])
async def channels(self, ctx):
"""Manage protected channels"""
if not ctx.invoked_subcommand:
await ctx.send("Invalid subcommand.")
#
# -------------------------------------------------------------------------------------------------------------
#
@channels.command(name="add", aliases=["+"])
@commands.has_permissions(manage_channels=True)
async def channels_add(self, ctx, channel: discord.TextChannel, password: str):
"""Adds a password to a channel"""
hashed_password = self.generate_hashed_password(password)
async with self.config.guild(ctx.guild).password_channels() as password_channels:
# Check if the channel already has a password
if channel.id in password_channels:
await ctx.send(f"{channel.mention} already has a password. Use the `remove` command first.")
return
# Create the role
role_name = f"{channel.name}_access"
role = await ctx.guild.create_role(name=role_name)
# Grant permissions to the role
await channel.set_permissions(role, view_channel=True, send_messages=True)
await channel.set_permissions(ctx.guild.default_role, view_channel=False, read_message_history=False) # Restrict access for default role
# Store password, channel ID, and role ID in the config
password_channels[channel.id] = {
"password_hash": hashed_password,
"role_id": role.id
}
await ctx.send(f"Password set for {channel.mention}")
#
# -------------------------------------------------------------------------------------------------------------
#
@channels.command(name="remove", aliases=["-"])
@commands.has_permissions(manage_channels=True)
async def channels_remove(self, ctx, channel: discord.TextChannel):
"""Removes the password from a text channel."""
async with self.config.guild(ctx.guild).password_channels() as password_channels:
if channel.id in password_channels:
# Delete the channel's data from the config
del password_channels[channel.id]
# Delete the associated role (optional)
role_id = channel.get("role_id")
if role_id:
role = ctx.guild.get_role(role_id)
if role:
await role.delete()
await ctx.send(f"Password removed from {channel.mention}")
else:
await ctx.send(f"{channel.mention} does not have a password.")
@channels.command(name="fails", aliases=["--fail"])
@commands.has_permissions(manage_guild=True)
async def channels_fails(self, ctx, limit: int = None):
"""Sets or checks the maximum failed password attempts."""
# ... handle failed attempt limit ...
#
# -------------------------------------------------------------------------------------------------------------
#
@channels.command(name="whitelist", aliases=["wlist"])
@commands.has_permissions(manage_guild=True)
async def channels_white(self, ctx, subcommand: str, user_or_role: discord.Object = None):
"""Manages the whitelist."""
guild_id = str(ctx.guild.id)
password_collection = self.get_password_collection(guild_id)
if not user_or_role:
await ctx.send("Please specify a user or role to add/remove.")
return
if subcommand == "add":
await self.add_to_whitelist(password_collection, user_or_role)
elif subcommand == "remove":
await self.remove_from_whitelist(password_collection, user_or_role)
else:
await ctx.send("Invalid subcommand. Use `add` or `remove`.")
#
# -------------------------------------------------------------------------------------------------------------
#
@channels.command(name="blacklist", aliases=["blist"])
@commands.has_permissions(manage_guild=True)
async def channels_black(self, ctx, subcommand: str, user_or_role: discord.Object = None):
"""Manages the blacklist."""
if not user_or_role:
await ctx.send("Please specify a user or role to add/remove.")
return
if subcommand == "add":
await self.add_to_blacklist(ctx, user_or_role)
elif subcommand == "remove":
await self.remove_from_blacklist(ctx, user_or_role)
else:
await ctx.send("Invalid subcommand. Use `add` or `remove`.")
#
# -------------------------------------------------------------------------------------------------------------
#
@passwdprotect.group(name="admin", aliases=["adm"])
async def admin(self, ctx):
"""Admin commands for password protection"""
if not ctx.invoked_subcommand:
await ctx.send("Missing subcommand.")
#
# -------------------------------------------------------------------------------------------------------------
#
@admin.command(name="recover", aliases=["rec"])
async def admin_recover(self, ctx):
"""Initiates password recovery process."""
requests = await self.config.guild(ctx.guild).password_recovery_requests()
if not requests:
await ctx.send("No pending password recovery requests.")
return
admin_channel_id = await self.config.guild(ctx.guild).admin_channel()
if not admin_channel_id:
await ctx.send("Admin notification channel not set. Use `[p]passwdprotect admin notify` to set it.")
return
admin_channel = self.bot.get_channel(admin_channel_id)
# Add Approve/Deny buttons using View
view = ui.View()
view.add_item(ui.Button(style=discord.ButtonStyle.green, label="Approve", custom_id=f"approve_{user_id}_{channel.id}"))
view.add_item(ui.Button(style=discord.ButtonStyle.red, label="Deny", custom_id=f"deny_{user_id}_{channel.id}"))
for user_id, request_data in requests.items():
user = self.bot.get_user(int(user_id))
channel = self.bot.get_channel(request_data["channel_id"])
timestamp = request_data["timestamp"]
# Log the request to the admin channel
embed = discord.Embed(title="Password Recovery Request", color=discord.Color.gold())
embed.add_field(name="User", value=user.mention if user else f"User ID: {user_id}", inline=False)
embed.add_field(name="Server", value=ctx.guild.name, inline=False)
embed.add_field(name="Channel", value=channel.mention if channel else f"Channel ID: {request_data['channel_id']}", inline=False)
embed.add_field(name="Highest Role", value=user.top_role.mention if user else "Unknown", inline=False)
embed.set_footer(text=f"Requested at {timestamp}")
# Add Approve/Deny buttons
view = SimpleView()
view.add_item(Button(style=discord.ButtonStyle.green, label="Approve", custom_id=f"approve_{user_id}_{channel.id}"))
view.add_item(Button(style=discord.ButtonStyle.red, label="Deny", custom_id=f"deny_{user_id}_{channel.id}"))
# Ping the role (if set) in the admin channel
role_to_ping = await self.config.guild(ctx.guild).get_raw("admin_role") # Assuming you store the role ID in config
if role_to_ping:
await admin_channel.send(f"<@&{role_to_ping}>", embed=embed, view=view)
else:
await admin_channel.send(embed=embed, view=view)
#
# -------------------------------------------------------------------------------------------------------------
#
@admin.command(name="notify", aliases=["noti"])
@commands.has_permissions(manage_guild=True)
async def admin_notify(self, ctx, channel: discord.TextChannel = None):
"""Sets or removes the admin notification channel."""
if channel:
# Set the admin notification channel
await self.config.guild(ctx.guild).admin_channel.set(channel.id)
await ctx.send(f"Admin notification channel set to {channel.mention}")
else:
# Remove the admin notification channel
await self.config.guild(ctx.guild).admin_channel.set(None)
await ctx.send("Admin notification channel removed.")
#
# -------------------------------------------------------------------------------------------------------------
#
@commands.Cog.listener()
async def on_interaction(self, interaction, channel: discord.TextChannel):
if interaction.type == discord.InteractionType.component:
custom_id = interaction.data["custom_id"]
if custom_id.startswith("approve_") or custom_id.startswith("deny_"):
action, user_id, channel_id = custom_id.split("_")
user_id = int(user_id)
channel_id = int(channel_id)
async with self.config.guild(interaction.guild).password_recovery_requests() as requests:
if user_id in requests:
del requests[user_id] # Remove the request
if action == "approve":
temp_code = self.generate_temporary_access_code() # Implement this function
expiry_time = datetime.datetime.now() + datetime.timedelta(hours=1) # 1-hour validity
async with self.config.guild(interaction.guild).temp_access_codes() as temp_codes:
temp_codes[temp_code] = {"user_id": user_id, "channel_id": channel_id, "expiry": expiry_time.isoformat()}
user = self.bot.get_user(user_id)
if user:
await user.send(f"Here's your temporary access code for channel {channel.mention}: `{temp_code}`. It's valid for 1 hour.")
elif user:
await interaction.response.send_message(f"Approved password recovery for {user.mention if user else user_id} on channel {channel.mention}. Temporary code sent.", ephemeral=True)
else:
await interaction.response.send_message("Channel data not found. Cannot reset password.", ephemeral=True)
#
# -------------------------------------------------------------------------------------------------------------
#
# Helper functions
def generate_hashed_password(self, password):
# This remains the same, no changes needed
return hashlib.sha256(password.encode("utf-8")).hexdigest()
#
# -------------------------------------------------------------------------------------------------------------
#
async def set_channel_password(self, ctx: commands.Context, channel_id, password):
"""Sets the password for a channel using the config.
Args:
ctx (commands.Context): The command context to access guild information.
channel_id (int): The ID of the channel.
password (str): The password to set.
"""
hashed_password = self.generate_hashed_password(password)
async with self.config.guild(ctx.guild).password_channels() as password_channels:
password_channels[channel_id] = {
"password_hash": hashed_password
}
#
# -------------------------------------------------------------------------------------------------------------
#
def generate_temporary_access_code(self):
"""Generates a temporary access code."""
characters = string.ascii_letters + string.digits
code = ''.join(random.choice(characters) for i in range(10)) # 10-character code
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
return f"{code}-{timestamp}"
#
# -------------------------------------------------------------------------------------------------------------
#
async def add_to_whitelist(self, ctx, collection, user_or_role):
"""Adds a user or role to the whitelist."""
async with self.config.guild(ctx.guild).whitelist() as whitelist:
user_or_role_id = user_or_role.id
if any(item["id"] == user_or_role_id for item in whitelist):
await ctx.send(f"{user_or_role} is already in the whitelist.")
return
whitelist.append({"id": user_or_role_id, "type": "user" if isinstance(user_or_role, discord.Member) else "role"})
embed = discord.Embed(title="Whitelist Confirmation", description=f"Are you sure you want to add {user_or_role} to the whitelist?")
embed.add_field(name="Action", value="Add to Whitelist")
embed.set_footer(text="React with ✅ to confirm or ❌ to cancel.")
confirmation_msg = await ctx.send(embed=embed)
try:
reaction, user = await ctx.wait_for('reaction_add', timeout=30.0, check=lambda r, u: r.message.id == confirmation_msg.id and u == ctx.author and str(r.emoji) in ['', ''])
if str(reaction.emoji) == '':
await confirmation_msg.delete()
await ctx.send(f"{user_or_role} added to the whitelist.")
else:
await confirmation_msg.delete()
await ctx.send("Action cancelled.")
except asyncio.TimeoutError:
await confirmation_msg.delete()
await ctx.send("Confirmation timed out. Action cancelled.")
#
# -------------------------------------------------------------------------------------------------------------
#
async def remove_from_whitelist(self, ctx, collection, user_or_role):
"""Removes a user or role from the whitelist."""
async with self.config.guild(ctx.guild).whitelist() as whitelist:
user_or_role_id = user_or_role.id
whitelist[:] = [item for item in whitelist if item["id"] != user_or_role_id]
await ctx.send(f"{user_or_role} removed from the whitelist.")
#
# -------------------------------------------------------------------------------------------------------------
#
async def add_to_blacklist(self, ctx, user_or_role):
"""Adds a user or role to the blacklist."""
async with self.config.guild(ctx.guild).blacklist() as blacklist:
user_or_role_id = user_or_role.id
if any(item["id"] == user_or_role_id for item in blacklist):
await ctx.send(f"{user_or_role} is already in the blacklist.")
return
blacklist.append({"id": user_or_role_id, "type": "user" if isinstance(user_or_role, discord.Member) else "role"})
await ctx.send(f"{user_or_role} added to the blacklist.")
#
# -------------------------------------------------------------------------------------------------------------
#
async def remove_from_blacklist(self, ctx, user_or_role):
"""Removes a user or role from the blacklist."""
async with self.config.guild(ctx.guild).blacklist() as blacklist:
user_or_role_id = user_or_role.id
blacklist[:] = [item for item in blacklist if item["id"] != user_or_role_id]
await ctx.send(f"{user_or_role} removed from the blacklist.")
#
# -------------------------------------------------------------------------------------------------------------
#
async def cog_load(self):
self.bot.add_listener(self.on_cog_reload_error, "Package loading failed")
self.bot.add_listener(self.on_cog_reload_error, "SyntaxError:")
self.bot.add_listener(self.on_cog_reload_error, "IndentationError:")
#
# -------------------------------------------------------------------------------------------------------------
#
async def on_cog_reload_error(self, ctx, error):
error_message = f"Error reloading cog '{ctx.cog.qualified_name}':\n```{error}```"
self.error_logs.append(error_message)

6
rpg/__init__.py Normal file
View File

@@ -0,0 +1,6 @@
from .rpg import RPG
async def setup(bot):
cog = RPG(bot)
await bot.add_cog(cog)
await bot.add_cog(cog.commands)

126
rpg/actions.py Normal file
View File

@@ -0,0 +1,126 @@
import asyncio
import random
import discord
from .check import Check
from redbot.core import commands, Config
from .inventory import RPGInventory
from typing import Literal
class RPGActions:
"""
Implements the core RPG mechanics and actions.
"""
def __init__(self, rpg_cog):
self.rpg_cog = rpg_cog
self.inventory = RPGInventory(rpg_cog)
async def create_character(self, interaction: discord.Interaction, user, character_name):
"""
Creates a new character for the user.
"""
# Character Name Validation
check = Check(interaction, length=30)
if not check.length_under(interaction.message) or not character_name.isalnum():
return await self.rpg_cog.send_message(interaction, "Invalid character name. Please choose a name between 2 and 30 characters long, containing only letters and numbers.")
# Retrieve the 'characters' group
characters_group = self.rpg_cog.config.member(user).characters
# Then, get all characters within that group (await the .all() call)
existing_characters = await characters_group.all()
# Check for duplicate character names (case-insensitive)
if any(existing_name.lower() == character_name.lower() for existing_name in existing_characters):
return await self.rpg_cog.send_message(interaction, f"You already have a character named '{character_name}'. Choose another name.")
# Retrieve available classes from config
try:
available_classes = await self.rpg_cog.config.guild(user.guild).get_raw("classes", default=[])
except KeyError:
return await self.rpg_cog.send_message(interaction, "No classes have been configured yet. Please contact an admin.")
if not available_classes:
return await self.rpg_cog.send_message(interaction, "No classes are available yet. Please contact an admin.")
# Prompt user to choose a class
class_options = "\n".join([f"{i+1}. {class_name}" for i, class_name in enumerate(available_classes)])
await self.rpg_cog.send_message(interaction, f"Choose a class for your character:\n{class_options}")
def check(m):
return m.author == user and m.channel == interaction.channel and m.content.isdigit() and 1 <= int(m.content) <= len(available_classes)
try:
class_choice = await self.rpg_cog.bot.wait_for("message", check=check, timeout=30.0)
except asyncio.TimeoutError:
return await self.rpg_cog.send_message(interaction, "Class selection timed out. Character creation canceled.")
selected_class = available_classes[int(class_choice.content) - 1]
# Retrieve default stats for the selected class
try:
default_stats = await self.rpg_cog.config.guild(user.guild).get_raw("characters", "classes", selected_class, "stats")
except KeyError:
return await self.rpg_cog.send_message(interaction, f"Default stats for class '{selected_class}' haven't been configured yet. Please contact an admin.")
# Create character data
character_data = {
"name": character_name,
"class": [selected_class], # Store the selected class
"level": 1,
"experience": 0,
"stats": default_stats.copy(),
"inventory": [],
"equipment": {},
"skills": [],
"gold": 0,
"max_health": 100,
"health": 100,
"mana": 50,
"max_mana": 50,
}
# Store character data in config
await characters_group.set_raw(character_name, value=character_data)
await self.rpg_cog.config.member(user).active_character.set(character_name)
await interaction.response.send_message(interaction, f"Character '{character_name}' (Class: {selected_class}) created for {user.mention}!")
async def attack(self, ctx, attacker, target):
"""
Handles the attack action.
"""
# Check if attacker and target have active characters
if not await self._has_active_character(ctx, attacker):
return
if not await self._has_active_character(ctx, target):
return
attacker_data = await self.rpg_cog.config.member(attacker).active_character
target_data = await self.rpg_cog.config.member(target).active_character
# ... (rest of the attack logic)
async def heal(self, ctx, user):
"""
Handles the heal action.
"""
# ... (rest of the heal logic)
# Helper function to check if a user has an active character
async def _has_active_character(self, ctx, user):
active_character = await self.rpg_cog.config.member(user).active_character
if not active_character:
await self.rpg_cog.send_message(ctx, f"{user.mention}, you don't have an active character. Create one using `[p]create_character <name>`.")
return False
return True
async def use_item(self, ctx, user, item_name):
"""
Handles the use of an item from the inventory.
"""
# ... (logic to check if the user has the item and handle its effects)
# Remove the used item from the inventory
await self.inventory.remove_item(ctx, user, item_name)

94
rpg/check.py Normal file
View File

@@ -0,0 +1,94 @@
from redbot.core import Config, commands
from collections.abc import Iterable
import validators as vals
import logging
import discord
log = logging.getLogger("red.rpg")
class Check:
def __init__(self, ctx_or_interaction, custom: Iterable = None, length: int = None):
self.ctx_or_interaction = ctx_or_interaction # Store the context or interaction object
self.custom = custom
self.length = length
def _get_author(self):
"""
Helper function to get the author from either ctx or interaction.
"""
if isinstance(self.ctx_or_interaction, commands.Context):
return self.ctx_or_interaction.author
elif isinstance(self.ctx_or_interaction, discord.Interaction):
return self.ctx_or_interaction.user
else:
log.error(f"Unexpected object type in Check._get_author: {type(self.ctx_or_interaction)}")
return None
def same(self, m):
author = self._get_author()
if author is None:
return False # Handle the case where author couldn't be determined
if isinstance(m, discord.Message):
return author == m.author
elif isinstance(m, discord.Interaction):
return author == m.user
else:
log.error(f"Unexpected object type in Check.same: {type(m)}")
return False
def comfirm(self, m):
return self.same(m) and m.content.lower() in ("yes", "no")
def valid_int(self, m):
return self.same and m.content.isdigit()
def valid_float(self, m):
try:
return self.same(m) and float(m.content) >= 1
except ValueError:
return False
def positive(self, m):
return self.same(m) and m.content.isdigit() and int(m.content) > 0
def role(self, m):
roles = [r.name for r in self.ctx.guild.roles if r.name != "Bot"]
return self.same(m) and m.content in roles
def member(self, m):
return self.same(m) and m.content in [x.name for x in self.ctx.guild.members]
def length_under(self, m):
try:
if isinstance(m, discord.Message):
content = m.content
elif isinstance(m, discord.Interaction):
content = m.data['components'][0]['components'][0]['value'] # Access modal input value
else:
raise ValueError("Unsupported object type for length_under check")
return self.same(m) and len(content) <= self.length
except TypeError:
raise ValueError("Length was not specified in Check")
def valid_image_url(self, m):
url = m.content.strip()
if not vals.url(url):
return False
valid_extensions = (".jpg", ".jpeg", ".png", ".gif")
if not any(url.lower().endswith(ext) for ext in valid_extensions):
return False
return True
def content(self, m):
try:
return self.same(m) and m.content in self.custom
except TypeError:
raise ValueError("A custom iterable was not set in Check")

21
rpg/commands.py Normal file
View File

@@ -0,0 +1,21 @@
import discord
from redbot.core import commands
from .menu import RPGMenu
class RPGCommands(commands.Cog):
"""
Handles user commands (primarily menus) for the RPG system.
"""
def __init__(self, rpg_cog, bot):
self.rpg_cog = rpg_cog
self.bot = bot
super().__init__()
@commands.command(name="menu")
async def menu_command(self, ctx):
"""
Display the RPG menu.
"""
view = RPGMenu(self.rpg_cog)
await ctx.send("Choose an action:", view=view)

11
rpg/info.json Normal file
View File

@@ -0,0 +1,11 @@
{
"author" : ["UnstableKitsune (unstablekitsune)"],
"install _msg" : "Oh you installed me! How dare you obtain me! return me right now!",
"name" : "RPG",
"short" : "Its a TTRPG",
"requirements" : [""],
"permissions" : [""],
"tags" : [""],
"min_python_version" : [3, 1, 1],
"end_user_data_statement" : ""
}

80
rpg/inventory.py Normal file
View File

@@ -0,0 +1,80 @@
import discord
from redbot.core import commands, Config
class RPGInventory:
"""
Manages character inventories for the RPG system.
"""
def __init__(self, rpg_cog):
self.rpg_cog = rpg_cog
super().__init__()
@commands.group()
async def inventory(self, ctx):
"""Main RPG command group."""
pass
@inventory.command(name="add")
async def add_item(self, ctx, user: discord.Member, item_name, quantity=1):
"""
Adds an item to the user's active character's inventory.
"""
character_data = await self.rpg_cog.config.member(user).get_raw("active_character")
if not character_data:
return await self.rpg_cog.send_message(ctx, f"{user.mention}, you don't have an active character.")
inventory = character_data.get("inventory", {})
if item_name in inventory:
inventory[item_name] += quantity
else:
inventory[item_name] = quantity
await self.rpg_cog.config.member(user).set_raw("active_character", "inventory", value=inventory)
await self.rpg_cog.send_message(ctx, f"{quantity} {item_name}(s) added to your inventory!")
@inventory.command(name="remove")
async def remove_item(self, ctx, user: discord.Member, item_name, quantity=1):
"""
Removes an item from the user's active character's inventory.
"""
character_data = await self.rpg_cog.config.member(user).get_raw("active_character")
if not character_data:
return await self.rpg_cog.send_message(ctx, f"{user.mention}, you don't have an active character.")
inventory = character_data.get("inventory", {})
if item_name in inventory:
if inventory[item_name] >= quantity:
inventory[item_name] -= quantity
if inventory[item_name] == 0:
del inventory[item_name]
await self.rpg_cog.config.member(user).set_raw("active_character", "inventory", value=inventory)
await self.rpg_cog.send_message(ctx, f"{quantity} {item_name}(s) removed from your inventory!")
else:
await self.rpg_cog.send_message(ctx, f"You don't have enough {item_name}s.")
else:
await self.rpg_cog.send_message(ctx, f"You don't have any {item_name}s in your inventory.")
@inventory.command(name="bag")
async def get_inventory(self, user):
"""
Retrieves the inventory of the user's active character.
"""
character_data = await self.rpg_cog.config.member(user).get_raw("active_character")
if not character_data:
return None # Or handle the case where the user has no active character
return character_data.get("inventory", {})
@inventory.command(name="showbag")
async def display_inventory(self, ctx, user: discord.Member):
"""
Displays the user's inventory in a user-friendly format.
"""
inventory = await self.get_inventory(user)
if not inventory:
return await self.rpg_cog.send_message(ctx, f"{user.mention}, your inventory is empty!")
# Format the inventory for display (you can customize this)
inventory_str = "\n".join([f"{item}: {quantity}" for item, quantity in inventory.items()])
embed = discord.Embed(title=f"{user.name}'s Inventory", description=inventory_str)
await self.rpg_cog.send_message(ctx, embed=embed)

55
rpg/menu.py Normal file
View File

@@ -0,0 +1,55 @@
import discord
from .check import Check
class RPGMenu(discord.ui.View):
def __init__(self, rpg_cog):
super().__init__()
self.rpg_cog = rpg_cog
@discord.ui.button(label="Create Character", style=discord.ButtonStyle.primary, custom_id="create_character_button")
async def create_character_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_modal(CreateCharacterModal(self.rpg_cog))
@discord.ui.button(label="Attack", style=discord.ButtonStyle.red, custom_id="attack_button")
async def attack_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
# You'll need to implement the target selection logic here (e.g., using a dropdown or another interaction)
target = None # Placeholder for now
if target:
await self.rpg_cog.actions.attack(interaction, interaction.user, target)
else:
await interaction.response.send_message("You need to select a target to attack.", ephemeral=True)
@discord.ui.button(label="Heal", style=discord.ButtonStyle.green, custom_id="heal_button")
async def heal_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.rpg_cog.actions.heal(interaction, interaction.user)
@discord.ui.button(label="Stats", style=discord.ButtonStyle.blurple, custom_id="stats_button")
async def stats_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.rpg_cog.actions.display_stats(interaction, interaction.user)
@discord.ui.button(label="Inventory", style=discord.ButtonStyle.grey, custom_id="inventory_button")
async def inventory_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.rpg_cog.inventory.display_inventory(interaction, interaction.user)
class CreateCharacterModal(discord.ui.Modal):
def __init__(self, rpg_cog):
super().__init__(title="Create Character")
self.rpg_cog = rpg_cog
self.character_name = discord.ui.TextInput(
label="Enter your character's name:",
placeholder="e.g., BraveAdventurer",
required=True,
max_length=30
)
self.add_item(self.character_name)
async def on_submit(self, interaction: discord.Interaction):
character_name = self.character_name.value
#author = interaction.user
try:
await self.rpg_cog.actions.create_character(interaction, interaction.user, character_name)
except Exception as e:
await interaction.response.send_message(f"```An error occurred while creating your character: {e}```")
self.rpg_cog.log.error(f"Error in create_character: {e}")

187
rpg/rpg.py Normal file
View File

@@ -0,0 +1,187 @@
from atexit import register
import logging
import discord
from distutils import config
from redbot.core import commands, Config
from .check import Check
from .commands import RPGCommands
from .actions import RPGActions
from .shop import RPGShops
from .menu import RPGMenu
from .inventory import RPGInventory
class RPG(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.menu = RPGMenu(self)
self.commands = RPGCommands(self, bot)
self.actions = RPGActions(self)
self.shop = RPGShops(self)
self.inventory = RPGInventory(self)
self.log = logging.getLogger("red.rpg")
self.config = Config.get_conf(self, identifier=6857309412)
default_guild_settings = {
"characters": {
"default_stats": { # Nested under 'characters'
"Strength": 1,
"Defense": 1,
"Agility": 1,
"Magic": 1,
"Luck": 1,
"Health": 100,
"Mana": 50,
"Stamina": 50,
"Experience": 0,
"Gold": 0,
"Damage": 1,
"Recovery": 1,
"Resist": 1,
"Critical": 1,
"Speed": 1,
"Level": 1,
"Class": [],
"Skills": [],
"Inventory": [],
"Equipment": {},
"Quests": [],
"Guild": None,
"Location": None,
"Followers": None,
"Pets": None,
},
"default_statsmax": { # Nested under 'characters'
"Strength": 999,
"Defense": 999,
"Agility": 999,
"Magic": 999,
"Luck": 999,
"Health": 999,
"Mana": 999,
"Stamina": 999,
"Experience": 999999999,
"Gold": 999999999,
"Damage": 999,
"Recovery": 999,
"Resist": 999,
"Critical": 999,
"Speed": 999,
"Level": 999999999,
}
},
"classes": { # Definitions of available classes
"Warrior": {
"stats": {
"Strength": 5,
"Defense": 4,
"Agility": 3,
# ... other stats with appropriate values for a warrior
},
"description": "A brave and sturdy warrior, skilled in melee combat."
},
"Mage": {
"stats": {
"Strength": 2,
"Defense": 2,
"Magic": 5,
# ... other stats with appropriate values for a mage
},
"description": "A wise and powerful mage, capable of wielding arcane magic."
},
"Rogue": {
"stats": {
"Strength": 3,
"Defense": 3,
"Agility": 5,
# ... other stats with appropriate values for a rogue
},
"description": "A nimble and cunning rogue, adept at stealth and trickery."
}
# ... add more classes as needed
},
"active_character": {}, # Store the name of the currently active character for each member
}
default_user_settings = {
"active_character": None,
}
default_shop = {
"Items": [],
"Prices": [],
"Currency": "Gold",
"Currency_Symbol": "G",
"Currency_Plural": "Gold",
"Currency_Plural_Symbol": "G",
"Currency_Emoji": "💰",
}
default_quest = {
"Name": None,
"Description": None,
"Reward": None,
"Requirements": None,
"Progress": None,
"Status": None,
"Type": None,
"Repeat": None,
"Time": None,
"Location": None,
"Guild": None,
"Followers": None,
"Pets": None,
}
self.config.register_guild(**default_guild_settings)
self.config.register_user(**default_user_settings)
self.config.register_global(**default_shop)
self.config.register_global(**default_quest)
self.commands = RPGCommands(self, bot)
self.actions = RPGActions(self)
self.shop = RPGShops(self)
self.menu = RPGMenu(self)
self.inventory = RPGInventory(self)
async def register_guild(self, ctx):
await self.config.register_guild(ctx.guild, **default_guild_settings)
await self.send_message(ctx, "Guild registered for RPG system.")
async def register_user(self, ctx):
await self.config.register_user(ctx.author, **default_user_settings)
await self.send_message(ctx, "User registered for RPG system.")
async def register_shop(self, ctx):
await self.config.register_global(**default_shop)
await self.send_message(ctx, "Shop registered for RPG system.")
async def register_quest(self, ctx):
await self.config.register_global(**default_quest)
await self.send_message(ctx, "Quest registered for RPG system.")
async def unregister_guild(self, ctx):
await self.config.unregister_guild(ctx.guild)
await self.send_message(ctx, "Guild unregistered for RPG system.")
async def unregister_user(self, ctx):
await self.config.unregister_user(ctx.author)
await self.send_message(ctx, "User unregistered for RPG system.")
async def unregister_shop(self, ctx):
await self.config.unregister_global("Shop")
await self.send_message(ctx, "Shop unregistered for RPG system.")
async def unregister_quest(self, ctx):
await self.config.unregister_global("Quest")
await self.send_message(ctx, "Quest unregistered for RPG system.")
async def send_message(self, ctx, message, interaction, embed=None):
if embed:
await ctx.send(message, embed=embed)
elif interaction:
await interaction.response.send(message)
else:
await ctx.send(message)

176
rpg/shop.py Normal file
View File

@@ -0,0 +1,176 @@
from ast import alias
from enum import member
from locale import currency
import discord
from redbot.core import commands
from .inventory import RPGInventory
class RPGShops(commands.Cog):
def __init__(self, rpg_cog):
self.rpg_cog = rpg_cog
self.config = self.rpg_cog
default_guild = {
"shops": {},
"status": {
"active": bool,
"deactive": bool,
},
"currency": {
"name": str,
"symbol": str,
"emoji": str,
}
}
#self.config.register_guild(**default_guild_settings)
# -----------------------------------------------------------------------------------------
# --------------- SHOP GROUP COMMANDS -----------------------------------------------------
# -----------------------------------------------------------------------------------------
@commands.group(name="shop", alias=["sp"])
async def shop(self, ctx):
pass
# Comes from Base Shop Group Above
@shop.group(name="manager", alias=["mgr"])
async def manager(self, ctx):
pass
# Comes from Manager Group Above
@manager.group(name="set", alias=["st"])
async def set(self, ctx):
pass
# Comes From Set Group From Above
@set.group(name="status", alias=["sta"])
async def status(self, ctx):
pass
# Comes From Set Group From Above
@set.group(name="currency", alias=["cur"])
async def currency(self, ctx):
pass
# -----------------------------------------------------------------------------------------
# ------------------ SHOP BASE COMMANDS --------------------------------------------------
# -----------------------------------------------------------------------------------------
@shop.command(name="buy", alias=["by"]) # shop buy
async def buy(self, ctx, shop_name: str, item_name: str, quantity: int = 1):
"""
Buy an item from the shop.
"""
# Retrieve shop data
shops = await self.config.guild(ctx.guild).shops.all()
if shop_name not in shops:
return await ctx.send(f"Shop '{shop_name}' not found.")
shop_data = shops[shop_name]
items = shop_data.get("items", {}) # Assuming you store items in an 'items' dictionary within the shop data
if item_name not in items:
return await ctx.send(f"Item '{item_name}' not found in '{shop_name}'.")
item_data = items[item_name]
price = item_data.get("price")
stock = item_data.get("quantity")
# Check if the shop has enough stock
if stock is not None and stock < quantity:
return await ctx.send(f"Not enough '{item_name}' in stock. Only {stock} available.")
# Check if the user has enough currency
currency_name = await self.config.guild(ctx.guild).shops_currency_name.get()
user_balance = await self.rpg_cog.config.member(ctx.author).get_raw("gold") # Assuming gold is the currency
total_cost = price * quantity
if user_balance < total_cost:
return await ctx.send(f"You don't have enough {currency_name} to buy {quantity} {item_name}(s).")
# Deduct currency and add item to inventory
await self.rpg_cog.config.member(ctx.author).set_raw("gold", value=user_balance - total_cost)
await self.rpg_cog.inventory.add_item(ctx, ctx.author, item_name, quantity)
# Update shop inventory (if applicable)
if stock is not None:
shop_data["items"][item_name]["quantity"] -= quantity
await self.config.guild(ctx.guild).shops.set_raw(shop_name, value=shop_data)
await ctx.send(f"You bought {quantity} {item_name}(s) for {total_cost} {currency_name}!")
@shop.command(name="sell", alias=["sl"]) # shop sell
async def buy(self, ctx, item_name: str):
"""
Sell an item back to the shop.
"""
# ... (logic to handle the purchase and currency)
# Add the purchased item to the user's inventory
await self.inventory.remove_item(ctx, ctx.author, item_name)
@shop.command(name="give", alias=["gi"]) # shop give
async def give(self, ctx, item_name: str, target: member):
"""
Give an item to another player.
"""
# ... (logic to handle the transfer of items between players)
await self.inventory.remove_item(ctx, ctx.author, item_name)
await self.inventory.add_item(ctx, target, item_name)
@shop.command(name="list", alias=["ls"]) # shop list
async def list(self, ctx, shop_name: str):
"""
List the items available in a shop.
"""
# ... (logic to retrieve and display the items in the shop)
items = await self.rpg_cog.config.guild(ctx.guild).shops_items.get_raw(shop_name)
prices = await self.rpg_cog.config.guild(ctx.guild).shops_prices.get_raw(shop_name)
if items:
item_list = "\n".join([f"{item} - {price}" for item, price in zip(items, prices)])
await ctx.send(f"Items available in {shop_name}:\n{item_list}")
else:
await ctx.send(f"No items available in {shop_name}.")
# -----------------------------------------------------------------------------------------
# ------------------------- Manager Base Commands -----------------------------------------
# -----------------------------------------------------------------------------------------
@manager.command(name="create", alias=["cr"])
async def create_shop(self, ctx, shop_name: str, *, description: str):
await ctx.send(f"Shop '{shop_name}' created!")
@manager.command(name="delete", alias=["del"])
async def delete_shop(self, ctx, shop_name: str):
await ctx.send(f"Shop '{shop_name}' deleted!")
# -----------------------------------------------------------------------------------------
# --------------------------- SET BASE GROUP ----------------------------------------------
# -----------------------------------------------------------------------------------------
# --------------------------- STATUS BASE COMMANDS ----------------------------------------
# -----------------------------------------------------------------------------------------
@status.command(name="active", alias=["act"])
async def active_shop(self, ctx, shop_name: str):
await ctx.send(f"Shop '{shop_name}' activated!")
@status.command(name="deactive", alias=["deact"])
async def deactive_shop(self, ctx, shop_name: str):
await ctx.send(f"Shop '{shop_name}' deactivated!")
# -----------------------------------------------------------------------------------------
# --------------------------- CURRENCY BASE COMMANDS --------------------------------------
# -----------------------------------------------------------------------------------------
@currency.command(name="name", alias=["nm"]) # Use @currency.command
async def name_currency(self, ctx, currency_name: str):
await ctx.send(f"Currency name set to '{currency_name}'!")
@currency.command(name="symbol", alias=["sym"]) # Use @currency.command
async def symbol_currency(self, ctx, currency_symbol: str):
await ctx.send(f"Currency symbol set to '{currency_symbol}'!")
@currency.command(name="emoji", alias=["emo"]) # Use @currency.command
async def emoji_currency(self, ctx, currency_emoji: str):
await ctx.send(f"Currency emoji set to '{currency_emoji}'!")

0
servicereview/README.md Normal file
View File

View File

@@ -0,0 +1,4 @@
from .servicereview import ServiceReview
async def setup(bot):
await bot.add_cog(ServiceReview(bot))

15
servicereview/info.json Normal file
View File

@@ -0,0 +1,15 @@
{
"author": [ "unstableCogs" ],
"install_msg": "Thank you for installing the Service Review cog!",
"name": "ServiceReview",
"short": "A command for users to leave a service review.",
"description": "Allows users to submit a service review at any time, independently of any ticket system. Submissions are sent to a designated channel for staff.",
"tags": [
"review",
"service",
"feedback",
"utility"
],
"requirements": [ "rich" ],
"end_user_data_statement": "This cog persistently stores the user's ID and the content of their submitted review for record-keeping purposes."
}

View File

@@ -0,0 +1,116 @@
import discord
from redbot.core import commands, Config, app_commands
from typing import Optional
import datetime
# --- Modal for the Review Form ---
class ReviewModal(discord.ui.Modal, title="Service Review"):
service_type = discord.ui.TextInput(
label="Service Type",
placeholder="e.g., HPM, Staff, PM, Commission, etc."
)
rating = discord.ui.TextInput(
label="Rating (1-10)",
placeholder="Please enter a number from 1 to 10.",
max_length=2
)
review_text = discord.ui.TextInput(
label="Your Review",
style=discord.TextStyle.paragraph,
placeholder="Please provide details about your experience.",
max_length=1500
)
toxicity = discord.ui.TextInput(
label="Toxicity Level (ntox/stox)",
placeholder="ntox (non-toxic) or stox (semi-toxic)"
)
def __init__(self, cog: "ServiceReview"):
super().__init__()
self.cog = cog
async def on_submit(self, interaction: discord.Interaction):
guild = interaction.guild
if not guild:
# This should not happen due to guild_only decorator
return
channel_id = await self.cog.config.guild(guild).review_channel()
if not channel_id:
await interaction.response.send_message(
"The review channel has not been configured by an administrator.",
ephemeral=True
)
return
channel = guild.get_channel(channel_id)
if not isinstance(channel, discord.TextChannel):
await interaction.response.send_message(
"The configured review channel is invalid. Please contact an administrator.",
ephemeral=True
)
return
embed = discord.Embed(title="New Service Review", color=discord.Color.purple())
embed.set_author(name=f"{interaction.user.name} ({interaction.user.id})", icon_url=interaction.user.display_avatar.url)
embed.add_field(name="Service Type", value=self.service_type.value, inline=False)
embed.add_field(name="Rating", value=f"{self.rating.value}/10", inline=True)
embed.add_field(name="Toxicity", value=self.toxicity.value, inline=True)
embed.add_field(name="Review", value=self.review_text.value, inline=False)
embed.set_footer(text=f"User ID: {interaction.user.id}")
try:
review_message = await channel.send(embed=embed)
# **FIX:** Log the timestamp for the DataManager
async with self.cog.config.guild(guild).submitted_reviews() as reviews:
reviews[str(review_message.id)] = datetime.datetime.now(datetime.timezone.utc).isoformat()
await interaction.response.send_message("Thank you! Your review has been submitted successfully.", ephemeral=True)
except discord.Forbidden:
await interaction.response.send_message(
"I don't have permission to send messages in the review channel. Please contact an administrator.",
ephemeral=True
)
except discord.HTTPException as e:
await interaction.response.send_message(f"An error occurred while trying to send your review: {e}", ephemeral=True)
# --- Main Cog Class ---
class ServiceReview(commands.Cog):
"""A cog for users to leave service reviews for staff."""
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, identifier=1234567891, force_registration=True)
default_guild = {
"review_channel": None,
"submitted_reviews": {} # **FIX:** Added for DataManager logging
}
self.config.register_guild(**default_guild)
@app_commands.command(name="srev")
@app_commands.guild_only()
async def service_review(self, interaction: discord.Interaction):
"""Leave a review for a staff member or service."""
modal = ReviewModal(self)
await interaction.response.send_modal(modal)
@commands.group(aliases=["srset"]) # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def srevset(self, ctx: commands.Context):
"""Configure ServiceReview settings."""
pass
@srevset.command(name="channel")
async def set_review_channel(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel where service reviews will be sent."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).review_channel.set(channel.id)
await ctx.send(f"Service review channel has been set to {channel.mention}")
async def setup(bot):
await bot.add_cog(ServiceReview(bot))

4
staffmsg/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
from .staffmsg import StaffMsg
async def setup(bot):
await bot.add_cog(StaffMsg(bot))

17
staffmsg/info.json Normal file
View File

@@ -0,0 +1,17 @@
{
"author": [
"unstableCogs"
],
"install_msg": "Thank you for installing the Staff Messaging cog!",
"name": "StaffMsg",
"short": "A command for staff to send official DMs.",
"description": "Provides a permission-controlled command for staff to send direct messages to server members, with logging for accountability.",
"tags": [
"dm",
"messaging",
"staff",
"utility"
],
"requirements": [],
"end_user_data_statement": "This cog may store message content and user IDs in a log file or channel for moderation purposes."
}

188
staffmsg/staffmsg.py Normal file
View File

@@ -0,0 +1,188 @@
import discord
from redbot.core import commands, Config, app_commands
from typing import Optional
import datetime
# --- Modal for the Message Form ---
class MessageModal(discord.ui.Modal, title="Staff Message"):
message_content = discord.ui.TextInput(
label="Message to Send",
style=discord.TextStyle.paragraph,
placeholder="Type the official message you want to send to the user here.",
max_length=1800
)
def __init__(self, cog: "StaffMsg", target_user: discord.Member):
super().__init__()
self.cog = cog
self.target_user = target_user
async def on_submit(self, interaction: discord.Interaction):
guild = interaction.guild
if not guild:
return
# --- Send DM to User ---
embed_to_user = discord.Embed(
title=f"A Message from the Staff of {guild.name}",
description=self.message_content.value,
color=await self.cog.bot.get_embed_color(interaction.channel) if interaction.channel else discord.Color.blurple()
)
embed_to_user.set_footer(text="This is an official communication. Please do not reply to the bot.")
try:
await self.target_user.send(embed=embed_to_user)
except discord.Forbidden:
await interaction.response.send_message(
f"I could not send a DM to {self.target_user.mention}. They may have DMs disabled.",
ephemeral=True
)
return
except discord.HTTPException as e:
await interaction.response.send_message(f"An error occurred while sending the DM: {e}", ephemeral=True)
return
# --- Log the Message ---
log_channel_id = await self.cog.config.guild(guild).log_channel()
if log_channel_id:
log_channel = guild.get_channel(log_channel_id)
if isinstance(log_channel, discord.TextChannel):
log_embed = discord.Embed(
title="Staff DM Sent",
description=self.message_content.value,
color=discord.Color.blue()
)
log_embed.set_author(name=f"From: {interaction.user.name} ({interaction.user.id})", icon_url=interaction.user.display_avatar.url)
log_embed.add_field(name="To", value=f"{self.target_user.mention} ({self.target_user.id})")
try:
log_message = await log_channel.send(embed=log_embed)
async with self.cog.config.guild(guild).sent_dms() as dms:
dms[str(log_message.id)] = datetime.datetime.now(datetime.timezone.utc).isoformat()
except discord.Forbidden:
pass
await interaction.response.send_message(f"Your message has been successfully sent to {self.target_user.mention}.", ephemeral=True)
# --- Main Cog Class ---
class StaffMsg(commands.Cog):
"""A cog for staff to send official DMs to users."""
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, identifier=1234567892, force_registration=True)
default_guild = {
"log_channel": None,
"authorized_role": None,
"sent_dms": {} # For DataManager
}
self.config.register_guild(**default_guild)
async def cog_check(self, ctx: commands.Context) -> bool:
if not ctx.guild:
await ctx.send("This command can only be used in a server.", ephemeral=True)
return False
auth_role_id = await self.config.guild(ctx.guild).authorized_role()
if not auth_role_id:
await ctx.send("The authorized role for this command has not been set.", ephemeral=True)
return False
author = ctx.author
if not isinstance(author, discord.Member):
return False
if author.guild_permissions.administrator:
return True
auth_role = ctx.guild.get_role(auth_role_id)
if not auth_role or auth_role not in author.roles:
await ctx.send("You are not authorized to use this command.", ephemeral=True)
return False
return True
@commands.hybrid_command(name="smsg", aliases=["staff", "staffmsg"])
@app_commands.describe(user="The user to send a DM to.", message="(Optional) The message to send. Opens a form if left blank.")
@app_commands.guild_only()
async def staff_message(self, ctx: commands.Context, user: discord.Member, *, message: Optional[str] = None):
"""Send an official DM to a user. Opens a form if no message is provided."""
# This is a clever way to handle both slash and prefix commands.
# If the 'message' is None, it means it was likely a slash command
# or a prefix command with no text, so we open the modal.
if message is None:
if not ctx.interaction:
await ctx.send("Please provide a message to send.", ephemeral=True)
return
modal = MessageModal(self, user)
await ctx.interaction.response.send_modal(modal)
return
guild = ctx.guild
if not guild: # Should be caught by cog_check but for type safety
return
embed_to_user = discord.Embed(
title=f"A Message from the Staff of {guild.name}",
description=message,
color=await ctx.embed_color()
)
embed_to_user.set_footer(text="This is an official communication. Please do not reply to the bot.")
try:
await user.send(embed=embed_to_user)
except discord.Forbidden:
await ctx.send(f"I could not send a DM to {user.mention}. They may have DMs disabled.", ephemeral=True)
return
log_channel_id = await self.config.guild(guild).log_channel()
if log_channel_id:
log_channel = guild.get_channel(log_channel_id)
if isinstance(log_channel, discord.TextChannel):
log_embed = discord.Embed(
title="Staff DM Sent",
description=message,
color=discord.Color.blue()
)
log_embed.set_author(name=f"From: {ctx.author.name} ({ctx.author.id})", icon_url=ctx.author.display_avatar.url)
log_embed.add_field(name="To", value=f"{user.mention} ({user.id})")
try:
log_message = await log_channel.send(embed=log_embed)
async with self.config.guild(guild).sent_dms() as dms:
dms[str(log_message.id)] = datetime.datetime.now(datetime.timezone.utc).isoformat()
except discord.Forbidden:
pass
await ctx.send(f"Your message has been sent to {user.mention}.", ephemeral=True)
@commands.group(aliases=["smset"]) # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def staffmsgset(self, ctx: commands.Context):
"""Configure StaffMsg settings."""
pass
@staffmsgset.command(name="role")
async def set_auth_role(self, ctx: commands.Context, role: discord.Role):
"""Set the role authorized to use the staff message commands."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).authorized_role.set(role.id)
await ctx.send(f"Authorized role has been set to {role.mention}")
@staffmsgset.command(name="logchannel")
async def set_log_channel(self, ctx: commands.Context, channel: discord.TextChannel):
"""Set the channel where sent DMs will be logged."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).log_channel.set(channel.id)
await ctx.send(f"Log channel has been set to {channel.mention}")
async def setup(bot):
await bot.add_cog(StaffMsg(bot))

4
translator/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
from .translator import Translator
async def setup(bot):
await bot.add_cog(Translator(bot))

286
translator/commands.py Normal file
View File

@@ -0,0 +1,286 @@
# -*- coding: utf-8 -*-
import discord
import json
from typing import Optional
from redbot.core import commands, app_commands
from redbot.core.utils.chat_formatting import box, pagify
class CommandsMixin:
"""This class holds all the commands for the cog."""
@commands.hybrid_command(aliases=["ts"])
@app_commands.describe(
to_language="The language to translate to.",
text="The text to translate. For prefix commands, wrap multi-word text in quotes.",
from_language="[Optional] The language to translate from. Defaults to Common."
)
async def translate(self, ctx: commands.Context, to_language: str, text: str, from_language: Optional[str] = None):
"""Translates text from one language to another."""
from_lang_name = from_language if from_language else "common"
from_matches = await self._find_language(from_lang_name)
if not from_matches:
return await ctx.send(f"Could not find the 'from' language: `{from_lang_name}`")
if len(from_matches) > 1:
possible = [f"`{self.all_languages[k]['name']}` (`{k}`)" for k in from_matches]
return await ctx.send(f"Multiple 'from' languages found for `{from_lang_name}`. Please be more specific:\n" + ", ".join(possible))
from_lang_key = from_matches[0]
to_matches = await self._find_language(to_language)
if not to_matches:
return await ctx.send(f"Could not find the 'to' language: `{to_language}`")
if len(to_matches) > 1:
possible = [f"`{self.all_languages[k]['name']}` (`{k}`)" for k in to_matches]
return await ctx.send(f"Multiple 'to' languages found for `{to_language}`. Please be more specific:\n" + ", ".join(possible))
to_lang_key = to_matches[0]
from_lang_obj = self.all_languages[from_lang_key]
to_lang_obj = self.all_languages[to_lang_key]
try:
common_text = from_lang_obj['from_func'](text)
translated_text = to_lang_obj['to_func'](common_text)
except Exception as e:
await ctx.send(f"An error occurred during translation: `{e}`")
return
webhook = None
if ctx.guild and ctx.guild.me.guild_permissions.manage_webhooks:
for wh in await ctx.channel.webhooks():
if wh.name == "Translator Cog Webhook":
webhook = wh
break
if webhook is None:
webhook = await ctx.channel.create_webhook(name="Translator Cog Webhook")
if webhook:
if ctx.interaction:
await ctx.interaction.response.defer(ephemeral=True)
await webhook.send(content=translated_text, username=ctx.author.display_name, avatar_url=ctx.author.display_avatar.url)
await ctx.interaction.followup.send("Translation sent.", ephemeral=True)
else:
if ctx.channel.permissions_for(ctx.guild.me).manage_messages:
try:
await ctx.message.delete()
except discord.Forbidden:
pass
await webhook.send(content=translated_text, username=ctx.author.display_name, avatar_url=ctx.author.display_avatar.url)
else:
embed = discord.Embed(title=f"Translation to {to_lang_obj['name']}", color=await ctx.embed_color())
embed.add_field(name="Original Text", value=box(text), inline=False)
embed.add_field(name="Translated Text", value=box(translated_text), inline=False)
await ctx.send(embed=embed)
@commands.hybrid_command()
async def languages(self, ctx: commands.Context):
"""Lists all available languages."""
sorted_langs = sorted(self.all_languages.values(), key=lambda x: x['name'])
lang_list = [f"* `{lang['name']}`" for lang in sorted_langs]
output = "Available Languages:\n" + "\n".join(lang_list)
pages = [box(page) for page in pagify(output, page_length=1000)]
await ctx.send_interactive(pages, box_lang="md")
@commands.group(aliases=["px"], invoke_without_command=True)
async def proxy(self, ctx: commands.Context):
"""Toggles your translation proxy on or off."""
current_setting = await self.config.user(ctx.author).proxy_enabled()
new_setting = not current_setting
await self.config.user(ctx.author).proxy_enabled.set(new_setting)
status = "enabled" if new_setting else "disabled"
await ctx.send(f"Proxying is now `{status}`.")
@proxy.command(name="list")
async def proxy_list(self, ctx: commands.Context):
"""Shows your currently registered sonas."""
sonas = await self.config.user(ctx.author).sonas()
if not sonas:
return await ctx.send("You have no sonas registered.")
msg = "Your registered sonas:\n"
for name, data in sonas.items():
display_name = data.get("display_name", name)
lang_name = self.all_languages.get(data['language'], {}).get('name', 'Unknown Language')
if 'claws' in data:
start_claw, end_claw = data['claws']
elif 'brackets' in data: # Fallback for old data
start_claw, end_claw = data['brackets']
else:
continue
claw_info = f"Starts with `{start_claw}`" if not end_claw else f"`{start_claw}` and `{end_claw}`"
msg += f" - **{display_name}** (Internal Name: `{name}`): Translates to `{lang_name}`. Claws: {claw_info}\n"
for page in pagify(msg):
await ctx.send(page)
@proxy.command(name="add", aliases=["+"])
async def proxy_add(self, ctx: commands.Context, name: str, language: str, display_name: str, start_claw: str, end_claw: str = "", avatar: Optional[str] = None):
"""Registers a new sona with a name and avatar."""
matches = await self._find_language(language)
if not matches:
return await ctx.send(f"Language `{language}` not found.")
if len(matches) > 1:
possible = [f"`{self.all_languages[k]['name']}` (`{k}`)" for k in matches]
return await ctx.send(f"Multiple languages found for `{language}`. Please be more specific:\n" + ", ".join(possible))
lang_key = matches[0]
sona_key = name.lower()
avatar_url = avatar
if not avatar_url and ctx.message.attachments:
avatar_url = ctx.message.attachments[0].url
async with self.config.user(ctx.author).sonas() as sonas:
if sona_key in sonas:
return await ctx.send(f"A sona named `{name}` already exists.")
sonas[sona_key] = {
"display_name": display_name,
"avatar_url": avatar_url,
"language": lang_key,
"claws": [start_claw, end_claw]
}
await ctx.send(f"Sona `{name}` registered as `{display_name}` to translate to `{self.all_languages[lang_key]['name']}`.")
@proxy.command(name="remove", aliases=["-"])
async def proxy_remove(self, ctx: commands.Context, *, name: str):
"""Removes a sona."""
sona_key = name.lower()
async with self.config.user(ctx.author).sonas() as sonas:
if sona_key not in sonas:
return await ctx.send(f"No sona named `{name}` found.")
del sonas[sona_key]
await ctx.send(f"Sona `{name}` has been removed.")
@proxy.group()
async def sona(self, ctx: commands.Context):
"""Commands for managing a sona's appearance."""
pass
@proxy.group(name="auto")
async def proxy_auto(self, ctx: commands.Context):
"""Manage automatic translation in a channel."""
pass
@proxy_auto.command(name="set")
async def proxy_auto_set(self, ctx: commands.Context, sona_name: str):
"""Sets a sona to automatically translate your messages in this channel."""
sona_key = sona_name.lower()
sonas = await self.config.user(ctx.author).sonas()
if sona_key not in sonas:
return await ctx.send(f"No sona named `{sona_name}` found. Please register it first.")
async with self.config.channel(ctx.channel).autotranslate_users() as autotranslate_users:
autotranslate_users[str(ctx.author.id)] = sona_key
await ctx.send(f"Autotranslation enabled for you in this channel as **{sonas[sona_key]['display_name']}**.")
@proxy_auto.command(name="off")
async def proxy_auto_off(self, ctx: commands.Context):
"""Disables autotranslation for you in this channel."""
async with self.config.channel(ctx.channel).autotranslate_users() as autotranslate_users:
if str(ctx.author.id) in autotranslate_users:
del autotranslate_users[str(ctx.author.id)]
await ctx.send("Autotranslation has been disabled for you in this channel.")
else:
await ctx.send("You do not have autotranslation enabled in this channel.")
@sona.command(name="name")
async def sona_name(self, ctx: commands.Context, name: str, *, display_name: str):
"""Changes the display name of a sona."""
sona_key = name.lower()
async with self.config.user(ctx.author).sonas() as sonas:
if sona_key not in sonas:
return await ctx.send(f"No sona named `{name}` found.")
sonas[sona_key]["display_name"] = display_name
await ctx.send(f"Sona `{name}`'s display name has been changed to `{display_name}`.")
@sona.command(name="avatar")
async def sona_avatar(self, ctx: commands.Context, name: str, url: Optional[str] = None):
"""Changes the avatar of a sona.
You can either provide a direct image URL or upload an image with the command.
"""
sona_key = name.lower()
if not url and not ctx.message.attachments:
return await ctx.send("You must provide an image URL or upload an image.")
avatar_url = url
if ctx.message.attachments:
avatar_url = ctx.message.attachments[0].url
async with self.config.user(ctx.author).sonas() as sonas:
if sona_key not in sonas:
return await ctx.send(f"No sona named `{name}` found.")
sonas[sona_key]["avatar_url"] = avatar_url
await ctx.send(f"Sona `{name}`'s avatar has been updated.")
@commands.group(aliases=["tset"])
@commands.has_permissions(manage_guild=True)
async def translatorset(self, ctx: commands.Context):
"""Admin commands for the Translator cog."""
pass
@translatorset.group(name="language", aliases=["lang"])
async def translatorset_language(self, ctx: commands.Context):
"""Manage custom languages."""
pass
@translatorset_language.command(name="add", aliases=["+"])
async def translatorset_language_add(self, ctx: commands.Context, name: str, *, json_map: str):
"""Adds a new custom language."""
lang_key = name.lower()
if lang_key in self.all_languages:
return await ctx.send(f"A language with the key `{lang_key}` already exists.")
try:
lang_map = json.loads(json_map)
if not isinstance(lang_map, dict):
raise ValueError("JSON map must be an object/dictionary.")
except (json.JSONDecodeError, ValueError) as e:
return await ctx.send(f"Invalid JSON map provided: `{e}`")
new_lang_data = {'name': name.capitalize(), 'type': 'greedy', 'map': lang_map, 'is_custom': True}
async with self.config.languages() as languages:
languages[lang_key] = new_lang_data
await self._initialize_languages()
await ctx.send(f"Custom language `{name}` added successfully.")
@translatorset_language.command(name="remove", aliases=["-"])
async def translatorset_language_remove(self, ctx: commands.Context, name: str):
"""Removes a custom language."""
lang_key = name.lower()
current_data = await self.config.languages()
lang_obj = current_data.get(lang_key)
if not lang_obj or not lang_obj.get('is_custom', False):
return await ctx.send(f"No custom language named `{name}` found.")
async with self.config.languages() as languages:
if lang_key in languages:
del languages[lang_key]
await self._initialize_languages()
await ctx.send(f"Custom language `{name}` removed.")
@translatorset_language.command(name="listcustom")
async def translatorset_language_listcustom(self, ctx: commands.Context):
"""Lists all custom-added languages."""
custom_langs = [f"`{lang['name']}`" for lang in self.all_languages.values() if lang.get('is_custom')]
if not custom_langs:
return await ctx.send("There are no custom languages.")
await ctx.send("Custom Languages:\n" + ", ".join(custom_langs))
@translatorset_language.command(name="listbase")
async def translatorset_language_listbase(self, ctx: commands.Context):
"""Lists all base (built-in) languages."""
base_langs = [f"`{lang['name']}`" for lang in self.all_languages.values() if not lang.get('is_custom')]
await ctx.send("Base Languages:\n" + ", ".join(base_langs))

17
translator/info.json Normal file
View File

@@ -0,0 +1,17 @@
{
"author": [
"unstableCogs"
],
"install_msg": "Thank you for installing the Translator cog. Use the `/translate` command to get started.",
"name": "Translator",
"short": "Translates text into various fantasy and fun languages.",
"description": "A feature-rich translator cog ported from a web application. Supports numerous languages from Common to Valspiren, Sinary, and more. Includes a command to list all available languages.",
"tags": [
"translate",
"fun",
"roleplay",
"language"
],
"requirements": [],
"end_user_data_statement": "This cog does not store any end user data."
}

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,8 @@
MAP = {'a':'azg','b':'braz','c':'kraz','d':'dorg','e':'ezg','f':'fraz','g':'gor','h':'hath','i':'ix','j':'jraz','k':'kral','l':'laz','m':'maz','n':'naz','o':'oz','p':'praz','q':'qor','r':'raz','s':'saz','t':'taz','u':'uzg','v':'vraz','w':'waz','x':'xul','y':'yaz','z':'zaz'}
def get_language():
return {
'name': 'Abyssal',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'adriel','b':'baraqiel','c':'camael','d':'divinus','e':'elohim','f':'fanuel','g':'gloria','h':'hesed','i':'israfel','j':'jophiel','k':'kyrie','l':'lux','m':'michael','n':'netzach','o':'ophaniel','p':'peniel','q':'qadish','r':'raphael','s':'seraph','t':'tiferet','u':'uriel','v':'virtues','w':'wele\'el','x':'xathanael','y':'yesod','z':'zadkiel'}
def get_language():
return {
'name': 'Angelic',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,9 @@
MAP = {'a':'aqua','b':'blub','c':'\'cress','d':'drop','e':'eelee','f':'flow','g':'glur','h':'hydro','i':'ishi','j':'\'jyr','k':'\'kyr','l':'luu','m':'\'myr','n':'\'nyr','o':'oro','p':'ploop','q':'\'qyr','r':'\'ryp','s':'sh\'l','t':'tide','u':'\'urn','v':'\'vyr','w':'wash','x':'\'xyr','y':'\'yyr','z':'\'zyr'}
def get_language():
return {
'name': 'Aquan',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'abyss','b':'brine','c':'coral','d':'depth','e':'eel','f':'fin','g':'gurgle','h':'hydro','i':'ink','j':'jelly','k':'krill','l':'lagoon','m':'murk','n':'naut','o':'ocean','p':'pearl','q':'quatic','r':'reef','s':'salt','t':'tide','u':'urchin','v':'void','w':'wave','x':'xiph','y':'yacht','z':'zone'}
def get_language():
return {
'name': 'Aquatic',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'\'arr','b':'\'brach','c':'ch\'t','d':'\'drach','e':'\'err','f':'\'fune','g':'\'goss','h':'\'harr','i':'\'itt','j':'\'jarr','k':'klik\'','l':'\'lar','m':'\'marr','n':'\'narr','o':'\'orr','p':'\'parr','q':'\'qarr','r':'\'rarr','s':'skitter\'','t':'th\'k','u':'\'urr','v':'\'varr','w':'web\'','x':'\'xarr','y':'\'yarr','z':'\'zarr'}
def get_language():
return {
'name': 'Arachnid',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'\'aara','b':'\'bree','c':'chir\'','d':'\'dree','e':'eek','f':'\'flutter','g':'gree\'','h':'hrooa','i':'ii\'','j':'\'jakk','k':'kree\'','l':'\'liri','m':'\'meeka','n':'\'neer','o':'\'oroo','p':'pip\'','q':'\'qree','r':'\'reea','s':'\'skraw','t':'tweet\'','u':'\'urr','v':'\'vree','w':'\'warble','x':'\'xee','y':'\'yari','z':'\'zeer'}
def get_language():
return {
'name': 'Avian',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'\'ana','b':'\'bara','c':'\'cera','d':'\'dona','e':'\'elara','f':'\'fana','g':'\'gala','h':'\'hylia','i':'\'iana','j':'\'jana','k':'\'kana','l':'\'lora','m':'\'mara','n':'\'nara','o':'\'ora','p':'\'pera','q':'\'qana','r':'\'ria','s':'\'sera','t':'\'tara','u':'\'ura','v':'\'vara','w':'\'wana','x':'\'xara','y':'\'yana','z':'\'zara'}
def get_language():
return {
'name': 'Celestial',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
# This language is handled by its 'rule' type in the main cog.
# It doesn't need a map.
def get_language():
return {
'name': 'Common',
'type': 'rule'
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'auto','b':'bolt','c':'clank','d':'diode','e':'engine','f':'forge','g':'gear','h':'hydro','i':'iron','j':'joint','k':'kinetic','l':'link','m':'motor','n':'node','o':'optic','p':'piston','q':'quantum','r':'rivet','s':'servo','t':'titan','u':'unit','v':'volt','w':'whirr','x':'xenon','y':'yoke','z':'zinc'}
def get_language():
return {
'name': 'Construct',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'\'ayl','b':'\'baal','c':'\'cress','d':'\'drev','e':'\'eyl','f':'\'fane','g':'\'gyl','h':'hysh\'','i':'\'iyl','j':'\'jex','k':'\'krys','l':'\'lyl','m':'\'mal','n':'\'nyl','o':'\'oyl','p':'\'prax','q':'\'qyl','r':'\'ryl','s':'\'shayd','t':'\'trys','u':'\'uyl','v':'\'vyl','w':'\'wryl','x':'\'xyl','y':'\'yyl','z':'\'zyll'}
def get_language():
return {
'name': 'Devilish',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'ax','b':'baxis','c':'caex','d':'drak','e':'ess','f':'faex','g':'gix','h':'heth','i':'ir','j':'jyss','k':'kex','l':'lix','m':'maex','n':'nex','o':'oth','p':'pex','q':'qexis','r':'rax','s':'syth','t':'thrax','u':'ur','v':'vyx','w':'wess','x':'xis','y':'yth','z':'zix'}
def get_language():
return {
'name': 'Draconic',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'az','b':'bar','c':'krag','d':'dur','e':'ek','f':'fol','g':'grum','h':'hur','i':'in','j':'jor','k':'kaz','l':'lur','m':'mor','n':'nur','o':'ok','p':'por','q':'qur','r':'ruk','s':'son','t':'thor','u':'um','v':'val','w':'wor','x':'xor','z':'zul'}
def get_language():
return {
'name': 'Dwarvish',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'aer','b':'breeze','c':'cinder','d':'dust','e':'ember','f':'flow','g':'gust','h':'hail','i':'ignis','j':'jet','k':'kinetic','l':'lava','m':'mist','n':'nova','o':'ozone','p':'pyre','q':'quake','r':'rain','s':'stone','t':'terra','u':'umbra','v':'vapor','w':'wave','x':'xenon','y':'yon','z':'zephyr'}
def get_language():
return {
'name': 'Elemental',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
MAP = {'a':'ael','b':'\'eth','c':'cal','d':'dor','e':'elen','f':'fae','g':'\'gan','h':'h<EFBFBD>r','i':'ia','j':'yel','k':'\'ken','l':'lael','m':'mel','n':'n<EFBFBD>n','o':'oia','p':'\'pes','q':'qen','r':'rae','s':'sil','t':'t<EFBFBD>','u':'ui','v':'vae','w':'win','x':'\'xal','y':'yl','z':'z<EFBFBD>r'}
def get_language():
return {
'name': 'Elvish',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'meow','b':'brrt','c':'chrr','d':'drrt','e':'eek','f':'frrt','g':'grrowl','h':'hiss','i':'mii','j':'jrr','k':'krr','l':'lrr','m':'mrow','n':'nyah','o':'oww','p':'purr','q':'qrr','r':'rrr','s':'sss','t':'trill','u':'urr','v':'vrr','w':'wrr','x':'xrr','y':'yowl','z':'zzz'}
def get_language():
return {
'name': 'Feline',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'az\'ael','b':'ba\'al','c':'cre\'z','d':'dre\'th','e':'esh\'','f':'fiir\'','g':'gre\'th','h':'ha\'el','i':'i\'z','j':'je\'th','k':'krez\'','l':'le\'th','m':'morn\'','n':'ne\'th','o':'o\'z','p':'pre\'th','q':'qe\'th','r':'re\'th','s':'se\'th','t':'te\'th','u':'u\'z','v':'ve\'th','w':'we\'th','x':'xith\'','y':'ye\'th','z':'zael\''}
def get_language():
return {
'name': 'Fiendish',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'akk','b':'bink','c':'clank','d':'dink','e':'enk','f':'fizz','g':'giz','h':'hink','i':'ink','j':'jink','k':'kink','l':'link','m':'mink','n':'nink','o':'onk','p':'sprok','q':'qink','r':'rink','s':'sprock','t':'tink','u':'unk','v':'vink','w':'whirr','x':'xink','y':'yink','z':'zink'}
def get_language():
return {
'name': 'Gnomish',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'az','b':'bik','c':'clik','d':'dik','e':'ek','f':'fiz','g':'gib','h':'hik','i':'ik','j':'jik','k':'krik','l':'lik','m':'mik','n':'nik','o':'ok','p':'pik','q':'qik','r':'rik','s':'snik','t':'tik','u':'uk','v':'vik','w':'wik','x':'xik','y':'yik','z':'zik'}
def get_language():
return {
'name': 'Goblin',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'apple','b':'bramble','c':'crumpet','d':'dale','e':'elderberry','f':'fiddle','g':'garden','h':'hearth','i':'iris','j':'jam','k':'kettle','l':'lazy','m':'meadow','n':'nimble','o':'oats','p':'pudding','q':'quaint','r':'river','s':'sunny','t':'tater','u':'underhill','v':'vine','w':'willow','x':'extra','y':'yarn','z':'zesty'}
def get_language():
return {
'name': 'Half-Tongue',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'aloe','b':'bark','c':'clover','d':'dand','e':'elder','f':'fern','g':'groot','h':'herb','i':'ivy','j':'juni','k':'kelp','l':'leaf','m':'moss','n':'nettle','o':'oak','p':'petal','q':'quin','r':'root','s':'sprout','t':'thyme','u':'ursi','v':'vine','w':'willow','x':'xylem','y':'yarrow','z':'zinni'}
def get_language():
return {
'name': 'Herbilore',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'az\'','b':'\'baal','c':'\'krez','d':'\'drak','e':'ez\'','f':'\'fel','g':'\'gor','h':'\'hath','i':'iz\'','j':'\'jaz','k':'\'kraz','l':'\'laz','m':'\'mor','n':'\'naz','o':'oz\'','p':'\'paz','q':'\'qaz','r':'\'raz','s':'\'saz','t':'\'taz','u':'uz\'','v':'\'vaz','w':'\'waz','x':'\'xaz','y':'\'yaz','z':'\'zaz'}
def get_language():
return {
'name': 'Infernal',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,9 @@
MAP = {'a':'ka','b':'be','c':'chi','d':'de','e':'e','f':'fu','g':'ga','h':'hi','i':'i','j':'ji','k':'ki','l':'ru','m':'ma','n':'na','o':'o','p':'pe','q':'kyu','r':'re','s':'sa','t':'to','u':'u','v':'ve','w':'wa','x':'za','y':'ya','z':'ze'}
def get_language():
return {
'name': 'Kitsune',
'type': 'greedy',
'map': MAP,
'separator': ''
}

View File

@@ -0,0 +1,9 @@
MAP = {'a':'4','b':'8','c':'(','d':')','e':'3','f':'|=','g':'6','h':'#','i':'1','j':']','k':'|<','l':'1','m':'/\\/\\','n':'/\\/','o':'0','p':'|D','q':'(,)','r':'|2','s':'5','t':'7','u':'|_|','v':'\\/','w':'\\/\\/','x':'><','y':'`/','z':'2'}
def get_language():
return {
'name': 'Leet Speak',
'type': 'special',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'\'ax','b':'\'bax','c':'\'caz','d':'\'daz','e':'\'ex','f':'\'fax','g':'\'gaz','h':'h\'ss','i':'\'ix','j':'\'jax','k':'sk\'ex','l':'\'lax','m':'\'max','n':'\'nax','o':'\'ox','p':'\'pax','q':'\'qax','r':'\'rax','s':'s\'lith','t':'\'char','u':'\'ux','v':'\'vax','w':'\'wax','x':'\'xax','y':'\'yax','z':'\'zax'}
def get_language():
return {
'name': 'Lizardfolk',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'.-','b':'-...','c':'-.-.','d':'-..','e':'.','f':'..-.','g':'--.','h':'....','i':'..','j':'.---','k':'-.-','l':'.-..','m':'--','n':'-.','o':'---','p':'.--.','q':'--.-','r':'.-.','s':'...','t':'-','u':'..-','v':'...-','w':'.--','x':'-..-','y':'-.--','z':'--..','1':'.----','2':'..---','3':'...--','4':'....-','5':'.....','6':'-....','7':'--...','8':'---..','9':'----.','0':'-----',' ':'/'}
def get_language():
return {
'name': 'Morse Code',
'type': 'special',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'agaric','b':'bolete','c':'cap','d':'decay','e':'enoki','f':'fungi','g':'gill','h':'hyphae','i':'indigo','j':'jelly','k':'kombu','l':'lichen','m':'myco\'','n':'nidur','o':'oyster','p':'puff','q':'quorn','r':'rhizo','s':'spore\'','t':'thallus','u':'umbra','v':'velvet','w':'wart','x':'xero','y':'yeast','z':'zoospore'}
def get_language():
return {
'name': 'Myconid',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'ug','b':'blud','c':'crag','d':'dug','e':'eeg','f':'fug','g':'gron','h':'hug','i':'ig','j':'jug','k':'krug','l':'lug','m':'mush','n':'nug','o':'og','p':'pug','q':'qug','r':'rug','s':'slog','t':'thok','u':'urk','v':'vog','w':'wug','x':'xug','y':'yug','z':'zug'}
def get_language():
return {
'name': 'Ogrish',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'agh','b':'bug','c':'karg','d':'dur','e':'egh','f':'fug','g':'grol','h':'hosh','i':'izg','j':'jug','k':'krunk','l':'lug','m':'mog','n':'nog','o':'ogg','p':'pug','q':'qug','r':'ruk','s':'snaga','t':'tusk','u':'uruk','v':'vug','w':'warg','x':'xug','y':'yag','z':'zug'}
def get_language():
return {
'name': 'Orcish',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
# This language is handled by its 'rule' type in the main cog.
# It doesn't need a map.
def get_language():
return {
'name': 'Pig Latin',
'type': 'rule'
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'skree','b':'bite','c':'claw','d':'dark-thing','e':'eek','f':'filth','g':'gnaw','h':'hiss','i':'itch','j':'junk','k':'kill','l':'long-tail','m':'muck','n':'nest-thing','o':'rot-stink','p':'plague','q':'quick-quick','r':'rust','s':'skitter','t':'twitch','u':'under-thing','v':'vermin','w':'waste','x':'pox','y':'yes-yes','z':'zap-tail'}
def get_language():
return {
'name': 'Ratfolk',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'sk\'','b':'t\'k','c':'k\'ss','d':'d\'th','e':'e\'sk','f':'f\'t','g':'g\'th','h':'h\'k','i':'i\'s','j':'j\'t','k':'k\'t','l':'l\'k','m':'m\'k','n':'n\'t','o':'o\'s','p':'p\'k','q':'q\'t','r':'r\'k','s':'s\'k','t':'t\'s','u':'u\'s','v':'v\'t','w':'w\'k','x':'x\'s','y':'y\'k','z':'z\'t'}
def get_language():
return {
'name': 'Scorpion',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,10 @@
MAP = {'a':'a!','b':'7b','c':'c#','d':'d4','e':'3e','f':'f^','g':'g&','h':'h8','i':'(i','j':'j0','k':'_k','l':'l2','m':'=m','n':'n+','o':'5o','p':'-p','q':'q{','r':'}r','s':'[s','t':'t]','u':'|u','v':':v','w':'"w','x':'x<','y':'>y','z':'?z'}
def get_language():
return {
'name': 'Sinary',
'type': 'generic',
'map': MAP,
'chunk_size': 2,
'separator': ''
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'\'aura','b':'\'breth','c':'\'ciel','d':'\'dion','e':'\'ethys','f':'\'fey','g':'\'glyn','h':'\'hymn','i':'\'ia','j':'\'jora','k':'\'kye','l':'\'lume','m':'\'mana','n':'\'nima','o':'\'omni','p':'\'pria','q':'\'qia','r':'\'reth','s':'\'seren','t':'\'thyme','u':'\'umbra','v':'\'vym','w':'\'wisp','x':'\'xia','y':'\'yara','z':'\'zion'}
def get_language():
return {
'name': 'Spiritual',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'ah\'','b':'\'bel','c':'\'chae','d':'\'des','e':'\'esh','f':'\'fey','g':'\'gis','h':'hah\'','i':'\'ish','j':'\'jo','k':'\'ka','l':'\'lis','m':'\'mah','n':'\'nah','o':'oh\'','p':'\'pah','q':'\'qia','r':'\'rah','s':'\'sha','t':'\'thae','u':'uh\'','v':'\'vi','w':'\'wah','x':'\'xi','y':'\'yah','z':'\'zah'}
def get_language():
return {
'name': 'Succubus',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'ani','b':'bri','c':'cae','d':'dae','e':'eni','f':'fae','g':'gra','h':'hae','i':'ia','j':'jae','k':'kae','l':'lor','m':'mae','n':'nem','o':'olo','p':'pae','q':'qae','r':'rae','s':'sae','t':'tae','u':'uni','v':'vae','w':'wae','x':'xae','y':'yae','z':'zae'}
def get_language():
return {
'name': 'Sylvan',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'velk','b':'xund','c':'k\'yorl','d':'d\'ruth','e':'e\'trorn','f':'faer','g':'gol','h':'h\'chak','i':'i\'lith','j':'j\'lar','k':'k\'lar','l':'lil','m':'m\'lar','n':'nind','o':'olath','p':'p\'lar','q':'qu\'ellar','r':'ril','s':'sorn','t':'\'lar','u':'uss','v':'v\'lar','w':'wyl','x':'x\'lar','y':'y\'lar','z':'z\'ress'}
def get_language():
return {
'name': 'Undercommon',
'type': 'greedy',
'map': MAP
}

View File

@@ -0,0 +1,8 @@
# This language is handled by its 'rule' type in the main cog.
# It doesn't need a map.
def get_language():
return {
'name': 'UwU',
'type': 'rule'
}

View File

@@ -0,0 +1,10 @@
MAP = {'a':'ak','b':'ba','c':'ce','d':'di','e':'ek','f':'fo','g':'gu','h':'ha','i':'ik','j':'je','k':'ki','l':'lo','m':'mu','n':'na','o':'ok','p':'pe','q':'qi','r':'ro','s':'su','t':'ta','u':'uk','v':'ve','w':'wi','x':'xo','y':'yk','z':'zu'}
def get_language():
return {
'name': 'Valspiren',
'type': 'generic',
'map': MAP,
'chunk_size': 2,
'separator': ''
}

View File

@@ -0,0 +1,8 @@
MAP = {'a':'a\'th','b':'b\'zoth','c':'c\'thun','d':'d\'gol','e':'e\'th','f':'f\'thagn','g':'g\'noth','h':'h\'zoth','i':'i\'th','j':'j\'th','k':'k\'th','l':'l\'th','m':'m\'th','n':'n\'th','o':'o\'th','p':'p\'th','q':'qor\'','r':'r\'lyeh','s':'s\'th','t':'t\'th','u':'u\'th','v':'v\'lath','w':'w\'th','x':'x\'thul','y':'y\'th','z':'zy\'th'}
def get_language():
return {
'name': 'Voidtouched',
'type': 'greedy',
'map': MAP
}

196
translator/logic.py Normal file
View File

@@ -0,0 +1,196 @@
# -*- coding: utf-8 -*-
import re
import random
from redbot.core.utils.chat_formatting import box
def reverse_map(m): return {v: k for k, v in m.items()}
class TranslationLogicMixin:
"""This class holds all the translation logic for the cog."""
def _escape_regex(self, s):
return re.escape(s)
def _generic_translator(self, text, lang_map, char_separator):
# Regex to find custom emojis
emoji_regex = re.compile(r"<a?:\w+:\d+>")
# Find all emojis and store them
emojis = emoji_regex.findall(text)
# Replace emojis with a unique placeholder
placeholder = "||EMOJI||"
text_with_placeholders = emoji_regex.sub(placeholder, text)
# Translate the text with placeholders
word_separator = ' ' if char_separator == '' else ' '
words = text_with_placeholders.split(' ')
translated_words = []
emoji_counter = 0
for word in words:
if placeholder in word:
# If a word contains a placeholder, it might be part of the emoji code that got split.
# We simply re-insert the emoji from our list.
translated_words.append(emojis[emoji_counter])
emoji_counter += 1
else:
translated_word = char_separator.join([lang_map.get(char.lower(), char) for char in word])
translated_words.append(translated_word)
return word_separator.join(translated_words)
def _generic_decoder(self, text, reverse_map, chunk_size):
result = ""
text_no_space = text.replace(' ','')
for i in range(0, len(text_no_space), chunk_size):
chunk = text_no_space[i:i+chunk_size]
result += reverse_map.get(chunk, '?')
return result
def _greedy_decoder(self, text, reverse_map):
syllables = sorted(reverse_map.keys(), key=len, reverse=True)
regex = re.compile('|'.join(map(self._escape_regex, syllables)))
matches = regex.findall(text.replace(' ', ''))
return "".join([reverse_map.get(m, '?') for m in matches])
def _leet_decoder(self, text, reverse_map):
decoded_text = text
sorted_keys = sorted(reverse_map.keys(), key=len, reverse=True)
for key in sorted_keys:
decoded_text = decoded_text.replace(key, reverse_map[key])
return decoded_text
def _morse_decoder(self, text, reverse_map):
words = text.split(' ')
decoded_words = []
for word in words:
chars = word.split(' ')
decoded_words.append("".join([reverse_map.get(c, '?') for c in chars]))
return " ".join(decoded_words)
def _pig_latin_translator(self, text):
vowels = "aeiou"
translated_words = []
for word in text.split(' '):
if not word: continue
match = re.match(r"^([^a-zA-Z0-9]*)(.*?)([^a-zA-Z0-9]*)$", word)
leading_punct, clean_word, trailing_punct = match.groups()
if not clean_word:
translated_words.append(word)
continue
if clean_word and clean_word[0].lower() in vowels:
translated_word = clean_word + "way"
else:
first_vowel_index = -1
for i, char in enumerate(clean_word):
if char.lower() in vowels:
first_vowel_index = i
break
if first_vowel_index == -1:
translated_word = clean_word + "ay"
else:
translated_word = clean_word[first_vowel_index:] + clean_word[:first_vowel_index] + "ay"
translated_words.append(leading_punct + translated_word + trailing_punct)
return " ".join(translated_words)
def _pig_latin_decoder(self, text):
decoded_words = []
for word in text.split(' '):
if not word: continue
match = re.match(r"^([^a-zA-Z0-9]*)(.*?)([^a-zA-Z0-9]*)$", word)
leading_punct, clean_word, trailing_punct = match.groups()
if not clean_word:
decoded_words.append(word)
continue
original_word = ""
if clean_word.lower().endswith("way"):
original_word = clean_word[:-3]
elif clean_word.lower().endswith("ay"):
base_word = clean_word[:-2]
last_consonant_block_index = -1
for i in range(len(base_word) - 1, -1, -1):
if base_word[i].lower() not in "aeiou":
last_consonant_block_index = i
else:
break
if last_consonant_block_index != -1:
while last_consonant_block_index > 0 and base_word[last_consonant_block_index-1].lower() not in "aeiou":
last_consonant_block_index -= 1
consonants = base_word[last_consonant_block_index:]
stem = base_word[:last_consonant_block_index]
original_word = consonants + stem
else:
original_word = base_word
else:
original_word = clean_word
decoded_words.append(leading_punct + original_word + trailing_punct)
return " ".join(decoded_words)
def _uwu_translator(self, text):
text = text.lower()
text = text.replace('l', 'ww')
text = text.replace('r', 'w')
text = text.replace('na', 'nya').replace('ne', 'nye').replace('ni', 'nyi').replace('no', 'nyo').replace('nu', 'nyu')
text = text.replace('ove', 'uv')
words = text.split(' ')
uwu_words = []
for word in words:
if len(word) > 3 and random.random() < 0.3:
uwu_words.append(f"{word[0]}-{word}")
else:
uwu_words.append(word)
text = " ".join(uwu_words)
if random.random() < 0.5:
emoticons = [' uwu', ' owo', ' >w<', ' ^-^', ' ;;']
text += random.choice(emoticons)
return text
def _uwu_decoder(self, text):
emoticons = [' uwu', ' owo', ' >w<', ' ^-^', ' ;;']
for emo in emoticons:
if text.endswith(emo):
text = text[:-len(emo)]
text = re.sub(r'(\w)-(\w+)', r'\2', text)
text = text.replace('uv', 'ove')
text = text.replace('nyu', 'nu').replace('nyo', 'no').replace('nyi', 'ni').replace('nye', 'ne').replace('nya', 'na')
text = text.replace('ww', 'l')
text = text.replace('w', 'r')
return text
async def _find_language(self, query: str):
"""Finds languages by key or name, case-insensitively."""
query = query.lower()
exact_key_match = [key for key in self.all_languages if key.lower() == query]
if exact_key_match:
return exact_key_match
exact_name_match = [key for key, lang in self.all_languages.items() if lang['name'].lower() == query]
if exact_name_match:
return exact_name_match
partial_matches = [
key for key, lang in self.all_languages.items()
if query in key.lower() or query in lang['name'].lower()
]
return partial_matches
async def _auto_translate_to_common(self, text: str) -> list:
"""Helper to find all possible translations for a given text."""
possible_translations = []
for lang_key, lang_obj in self.all_languages.items():
if lang_key == 'common':
continue
try:
decoded_text = lang_obj['from_func'](text)
re_encoded_text = lang_obj['to_func'](decoded_text)
if re_encoded_text == text:
possible_translations.append(f"**As {lang_obj['name']}:**\n{box(decoded_text)}")
except Exception:
continue
return possible_translations

249
translator/translator.py Normal file
View File

@@ -0,0 +1,249 @@
# -*- coding: utf-8 -*-
import discord
import pkgutil
from redbot.core import commands, app_commands, Config
from redbot.core.utils.chat_formatting import box
from . import languages as lang_pkg
from .views import DismissView
from .logic import TranslationLogicMixin
from .commands import CommandsMixin
def reverse_map(m): return {v: k for k, v in m.items()}
class Translator(CommandsMixin, TranslationLogicMixin, commands.Cog):
"""A cog for translating text into various languages."""
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, identifier=8675309, force_registration=True)
self.config.register_global(languages={})
self.config.register_user(sonas={}, proxy_enabled=False)
self.config.register_channel(autotranslate_users={})
self.all_languages = {}
self.translate_to_common_context_menu = app_commands.ContextMenu(
name="Translate to Common",
callback=self.translate_to_common_context,
)
async def cog_load(self):
"""Load all languages from config and build the runtime objects."""
self.bot.tree.add_command(self.translate_to_common_context_menu)
await self._initialize_languages()
async def cog_unload(self):
"""Remove context menu on cog unload."""
self.bot.tree.remove_command(self.translate_to_common_context_menu.name, type=self.translate_to_common_context_menu.type)
def _load_base_languages_from_files(self):
"""Dynamically loads all base languages from the languages/ subfolder."""
base_languages_data = {}
for importer, modname, ispkg in pkgutil.iter_modules(lang_pkg.__path__, f"{lang_pkg.__name__}."):
if not ispkg:
try:
module = __import__(modname, fromlist=["get_language"])
if hasattr(module, "get_language"):
lang_data = module.get_language()
lang_key = modname.split('.')[-1]
base_languages_data[lang_key] = lang_data
except Exception as e:
print(f"Error loading language module {modname}: {e}")
return base_languages_data
def _build_runtime_languages(self, language_data):
"""Builds the final language dict with functions from stored data."""
runtime_langs = {}
for key, data in language_data.items():
lang_type = data.get("type", "greedy") # Default to greedy for custom
runtime_langs[key] = {"name": data["name"], "is_custom": data.get("is_custom", False), "type": lang_type}
if lang_type == "rule":
if key == "common":
runtime_langs[key]['to_func'] = lambda text: text
runtime_langs[key]['from_func'] = lambda text: text
elif key == "piglatin":
runtime_langs[key]['to_func'] = self._pig_latin_translator
runtime_langs[key]['from_func'] = self._pig_latin_decoder
elif key == "uwu":
runtime_langs[key]['to_func'] = self._uwu_translator
runtime_langs[key]['from_func'] = self._uwu_decoder
elif lang_type == "generic":
lang_map = data.get("map", {})
chunk_size = data.get("chunk_size", 2)
char_separator = data.get("separator", "")
word_separator = ' ' if char_separator == '' else ' '
runtime_langs[key]['to_func'] = lambda text, m=lang_map, s=char_separator: self._generic_translator(text, m, s)
runtime_langs[key]['from_func'] = lambda text, rm=reverse_map(lang_map), cs=chunk_size, ws=word_separator: " ".join([self._generic_decoder(word, rm, cs) for word in text.split(ws)])
elif lang_type == "special":
if key == "leet":
lang_map = data.get("map", {})
runtime_langs[key]['to_func'] = lambda text, m=lang_map: self._generic_translator(text, m, "")
runtime_langs[key]['from_func'] = lambda text, rm=reverse_map(lang_map): self._leet_decoder(text, rm)
elif key == "morse":
lang_map = data.get("map", {})
runtime_langs[key]['to_func'] = lambda text, m=lang_map: self._generic_translator(text, m, " ")
runtime_langs[key]['from_func'] = lambda text, rm=reverse_map(lang_map): self._morse_decoder(text, rm)
else: # Greedy is the default
lang_map = data.get("map", {})
char_separator = data.get("separator", " ")
word_separator = ' ' if char_separator == '' else ' '
runtime_langs[key]['to_func'] = lambda text, m=lang_map, s=char_separator: self._generic_translator(text, m, s)
runtime_langs[key]['from_func'] = lambda text, rm=reverse_map(lang_map), ws=word_separator: " ".join([self._greedy_decoder(word, rm) for word in text.split(ws)])
return runtime_langs
async def _initialize_languages(self):
"""Merge default and custom languages from config."""
base_languages_data = self._load_base_languages_from_files()
stored_languages_data = await self.config.languages()
if not stored_languages_data:
await self.config.languages.set(base_languages_data)
final_data = base_languages_data
else:
final_data = base_languages_data.copy()
for key, data in stored_languages_data.items():
if data.get("is_custom"):
final_data[key] = data
await self.config.languages.set(final_data)
self.all_languages = self._build_runtime_languages(final_data)
async def translate_to_common_context(self, interaction: discord.Interaction, message: discord.Message):
"""Translate a message to Common."""
await interaction.response.defer(ephemeral=True)
possible_translations = await self._auto_translate_to_common(message.content)
if not possible_translations:
await interaction.followup.send("Could not find a valid translation for this message.", ephemeral=True)
else:
await interaction.followup.send("\n\n".join(possible_translations), ephemeral=True)
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.author.bot or not message.guild:
return
prefix = (await self.bot.get_prefix(message))[0]
if message.content.startswith(prefix):
return
if message.reference and message.content.lower() == 'translate':
try:
replied_message = await message.channel.fetch_message(message.reference.message_id)
text_to_translate = replied_message.content
possible_translations = await self._auto_translate_to_common(text_to_translate)
if not possible_translations:
response_msg = "Could not find a valid translation for the replied message."
else:
response_msg = "\n\n".join(possible_translations)
view = DismissView(author=message.author)
sent_message = await message.reply(
response_msg,
view=view,
allowed_mentions=discord.AllowedMentions.none()
)
view.message = sent_message
if message.channel.permissions_for(message.guild.me).manage_messages:
await message.delete()
return
except Exception:
return
user_settings = await self.config.user(message.author).all()
if not user_settings['sonas']:
return
content = message.content
matched_sona = None
for sona_data in user_settings['sonas'].values():
if 'claws' in sona_data:
start_claw, end_claw = sona_data['claws']
elif 'brackets' in sona_data:
start_claw, end_claw = sona_data['brackets']
else:
continue
if not content.startswith(start_claw): continue
if end_claw and end_claw != "":
if not content.endswith(end_claw) or len(content) < len(start_claw) + len(end_claw):
continue
matched_sona = sona_data
break
if matched_sona:
if not user_settings['proxy_enabled']:
msg = (
f"{message.author.mention}, it looks like you tried to proxy as **{matched_sona['display_name']}**, "
f"but your proxy is turned off. You can re-enable it with the `{prefix}proxy` command."
)
try:
view = DismissView(author=message.author)
sent_message = await message.channel.send(msg, view=view, allowed_mentions=discord.AllowedMentions(users=True))
view.message = sent_message
except discord.Forbidden:
pass
return
if 'claws' in matched_sona:
start_claw, end_claw = matched_sona['claws']
else:
start_claw, end_claw = matched_sona['brackets']
text_to_translate = content[len(start_claw):-len(end_claw)] if end_claw else content[len(start_claw):]
lang_key = matched_sona['language']
else:
autotranslate_users = await self.config.channel(message.channel).autotranslate_users()
user_id_str = str(message.author.id)
if user_id_str not in autotranslate_users:
return
sona_key = autotranslate_users[user_id_str]
sonas = user_settings.get('sonas', {})
if sona_key not in sonas:
return
matched_sona = sonas[sona_key]
text_to_translate = content
lang_key = matched_sona['language']
to_lang_obj = self.all_languages.get(lang_key)
if not to_lang_obj: return
try:
translated_text = to_lang_obj['to_func'](text_to_translate)
except Exception:
return
webhook = None
if message.channel.permissions_for(message.guild.me).manage_webhooks:
webhooks = await message.channel.webhooks()
webhook = next((wh for wh in webhooks if wh.name == "Translator Cog Webhook"), None)
if webhook is None:
webhook = await message.channel.create_webhook(name="Translator Cog Webhook")
if webhook:
if message.channel.permissions_for(message.guild.me).manage_messages:
try:
await message.delete()
except discord.Forbidden:
pass
display_name = matched_sona.get("display_name", message.author.display_name)
avatar_url = matched_sona.get("avatar_url") or message.author.display_avatar.url
await webhook.send(
content=translated_text,
username=display_name,
avatar_url=avatar_url
)

28
translator/views.py Normal file
View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
import discord
class DismissView(discord.ui.View):
def __init__(self, author: discord.Member):
super().__init__(timeout=1800) # 30 minute timeout
self.author = author
self.message: discord.Message = None
async def interaction_check(self, interaction: discord.Interaction) -> bool:
if interaction.user.id != self.author.id:
await interaction.response.send_message("You are not authorized to dismiss this message.", ephemeral=True)
return False
return True
@discord.ui.button(label="Dismiss", style=discord.ButtonStyle.grey, emoji="??")
async def dismiss_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.message.delete()
self.stop()
async def on_timeout(self):
if self.message:
try:
await self.message.delete()
except (discord.NotFound, discord.Forbidden):
pass # Message was already deleted or permissions are missing
self.stop()

82
welcomer/README.md Normal file
View File

@@ -0,0 +1,82 @@
# Welcomer Cog - ver-1.0.0
A configurable cog to automatically welcome new users when they join your server.
# Features
- Fully Configurable: Set a custom welcome message and channel for each server.
- Enable/Disable: Easily toggle the welcomer on or off without losing your settings.
- Placeholder Support: Personalize your welcome message with user and server details.
- Easy Setup: A simple command group for admins to manage all settings.
- Permissions: All settings commands require `Manage Server` permissions to use.
# Commands
All configuration is handled through the `[p]welcomeset` command group.
[p]welcomeset channel <#channel>
Sets the channel where welcome messages will be sent.
Alias: chnl
Example: [p]welcomeset channel #welcome
[p]welcomeset message <message>
Sets the custom welcome message. See the "Placeholders" section below for available variables.
Alias: msg
Example: [p]welcomeset message Welcome {user.mention} to {server_name}! We're glad you're here.
[p]welcomeset toggle
Toggles the welcomer system on or off for the server.
Aliases: on, off
Example: [p]welcomeset toggle
[p]welcomeset settings
Displays the current settings for the welcomer in an embed.
Aliases: show, status
Example: [p]welcomeset settings
[p]welcomeset test
Sends a preview of the current welcome message to the channel where the command is run.
Example: [p]welcomeset test
[p]welcomeset reset
Resets all welcomer settings for the server to their default values.
Example: [p]welcomeset reset
Quick Setup Guide
Load the Cog:
[p]load welcomer
Set the Welcome Channel:
[p]welcomeset channel #your-welcome-channel
Set Your Custom Message:
[p]welcomeset message Welcome, {user.mention}! Enjoy your stay in {server_name}!
Enable the System:
[p]welcomeset toggle
The bot will now welcome new members in the channel you specified. You can use [p]welcomeset settings at any time to check your configuration.
Placeholders for the Welcome Message
You can use the following placeholders in your custom welcome message. They will be automatically replaced with the correct information when a new user joins.
{user}: The user object itself.
{user.mention}: Pings the new user (e.g., @UnstableKitsune).
{user_name}: The new user's name (e.g., UnstableKitsune).
{server_name}: The name of the server they joined.
For full documentation, please visit the [repository wiki](https://git.kitsunic.org/kitsunicWorks/unstable-cogs/wiki).

1
welcomer/__init__.py Normal file
View File

@@ -0,0 +1 @@
from .welcomer import setup

14
welcomer/info.json Normal file
View File

@@ -0,0 +1,14 @@
{
"author": [ "unstableCogs" ],
"install_msg": "Thank you for installing the Welcomer cog!",
"name": "Welcomer",
"short": "A simple cog to welcome new users.",
"description": "Greets new members in a designated channel with a customizable message. This cog is part of the Unified Bot Suite.",
"tags": [
"welcome",
"utility",
"greeting"
],
"requirements": [],
"end_user_data_statement": "This cog does not persistently store any end user data."
}

121
welcomer/welcomer.py Normal file
View File

@@ -0,0 +1,121 @@
import discord
from redbot.core import commands, Config
from redbot.core.bot import Red
from typing import Literal
class Welcomer(commands.Cog):
"""
A configurable cog to automatically welcome new users with multiple modes.
"""
def __init__(self, bot: Red):
self.bot = bot
self.config = Config.get_conf(self, identifier=1234567890, force_registration=True)
default_guild = {
"welcome_channel": None,
"welcome_message": "Welcome to the server, {user.mention}!",
"enabled": False,
"welcome_mode": "normal" # 'normal' or 'solstira'
}
self.config.register_guild(**default_guild)
@commands.Cog.listener()
async def on_member_join(self, member: discord.Member):
guild = member.guild
if not await self.config.guild(guild).enabled():
return
mode = await self.config.guild(guild).welcome_mode()
if mode == "solstira":
# Hardcoded Solstira welcome event
channel_id = 1409965732669948024
else: # Normal mode
channel_id = await self.config.guild(guild).welcome_channel()
if not channel_id:
return
channel = guild.get_channel(channel_id)
if not isinstance(channel, discord.TextChannel):
return
if not channel.permissions_for(guild.me).send_messages:
return
if mode == "solstira":
content = (
f"{member.mention}\n"
f"- `guide` <https://discord.com/channels/1409939326382651/140993936542124073>\n"
f"- <a:f_purpleflower:1409967049561524859> `roles` <@&1409937150>\n"
f"(<https://discord.com/channels/1409939326382651/140996735493797150>)\n"
f"- `psa` (<https://discord.com/channels/1409939326382651/140996779492440732>)"
)
embed = discord.Embed(description="--", color=0x8b9ed7)
try:
await channel.send(content, embed=embed)
except discord.HTTPException:
pass
else: # Normal mode
message_template = await self.config.guild(guild).welcome_message()
formatted_message = message_template.format(
user=member,
user_mention=member.mention,
user_name=member.name,
server_name=guild.name
)
try:
await channel.send(formatted_message)
except discord.HTTPException:
pass
@commands.group(aliases=["wset"]) # type: ignore
@commands.guild_only()
@commands.admin_or_permissions(manage_guild=True)
async def welcomeset(self, ctx: commands.Context):
"""Commands for configuring the welcome system."""
pass
@welcomeset.command(name="mode")
async def set_welcome_mode(self, ctx: commands.Context, mode: Literal["normal", "solstira"]):
"""Set the welcome mode for this server.
Modes:
- `normal`: A simple, configurable welcome message.
- `solstira`: The special, complex welcome event.
"""
if not ctx.guild:
return
await self.config.guild(ctx.guild).welcome_mode.set(mode.lower())
await ctx.send(f"Welcome mode has been set to **{mode.lower()}**.")
@welcomeset.command(name="channel")
async def set_welcome_channel(self, ctx: commands.Context, channel: discord.TextChannel):
"""(Normal Mode) Set the channel for welcome messages."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).welcome_channel.set(channel.id)
await ctx.send(f"Welcome channel set to {channel.mention}")
@welcomeset.command(name="message")
async def set_welcome_message(self, ctx: commands.Context, *, message: str):
"""(Normal Mode) Set the welcome message. Use placeholders like {user.mention}."""
if not ctx.guild:
return
await self.config.guild(ctx.guild).welcome_message.set(message)
await ctx.send("Welcome message updated.")
@welcomeset.command(name="toggle")
async def toggle_welcome(self, ctx: commands.Context):
"""Toggle the welcome system on or off."""
if not ctx.guild:
return
current_status = await self.config.guild(ctx.guild).enabled()
new_status = not current_status
await self.config.guild(ctx.guild).enabled.set(new_status)
status_text = "enabled" if new_status else "disabled"
await ctx.send(f"Welcome system has been {status_text}.")
async def setup(bot: Red):
await bot.add_cog(Welcomer(bot))