From c9431d0c86fdfad6458297bea99a29802ad6c2fa Mon Sep 17 00:00:00 2001 From: Unstable Kitsune Date: Thu, 11 Sep 2025 17:15:29 -0400 Subject: [PATCH 1/2] feat: Add /workorder.9tkd to .gitignore Includes .vs/ and pyproject.toml to prevent tracking unintended files Fixes license typo in README.md from GPU-3.0 to GPL-3.0 --- .gitignore | 5 +++++ README.md | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 36b13f1..a33a735 100644 --- a/.gitignore +++ b/.gitignore @@ -174,3 +174,8 @@ cython_debug/ # PyPI configuration file .pypirc +/workorder.9tkd + +.vs/ + +pyproject.toml diff --git a/README.md b/README.md index 469cd80..0e1774c 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ As this is my main focus, All the support is welcomed & extremely appreicated! I - [Cog-Creators](https://github.com/Cog-Creators) --- ## License -This repository and is cogs are protected under the GPU-3.0 License. -For Further information visit [GPC-30 License](https://git.kitsunic.org/kitsunicWorks/unstable-cogs/src/branch/main/LICENSE) +This repository and is cogs are protected under the GPL-3.0 License. +For Further information visit [GPL-30 License](https://git.kitsunic.org/kitsunicWorks/unstable-cogs/src/branch/main/LICENSE) Copyright (C) 2025-present kitsunicWorks unstable-cog \ No newline at end of file From 5b9c27fcad3b51a314978a27ad4f542053abb359 Mon Sep 17 00:00:00 2001 From: Unstable Kitsune Date: Thu, 11 Sep 2025 17:16:29 -0400 Subject: [PATCH 2/2] feat: add kBump database bridge cog Integrates MongoDB connection to kBump services for Red bot, enabling data reading and interaction. Adds command to check server bump status with detailed embed output. --- kbump/__init__.py | 4 ++ kbump/info.json | 8 ++++ kbump/kbump.py | 104 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 kbump/__init__.py create mode 100644 kbump/info.json create mode 100644 kbump/kbump.py diff --git a/kbump/__init__.py b/kbump/__init__.py new file mode 100644 index 0000000..f843dc1 --- /dev/null +++ b/kbump/__init__.py @@ -0,0 +1,4 @@ +from .kbump import kBump + +async def setup(bot): + await bot.add_cog(kBump(bot)) \ No newline at end of file diff --git a/kbump/info.json b/kbump/info.json new file mode 100644 index 0000000..dffa14f --- /dev/null +++ b/kbump/info.json @@ -0,0 +1,8 @@ +{ + "author": ["kitsunicWorks"], + "name": "kBump", + "short": "A bridge to the kBump database.", + "description": "Allows this Red bot to read and interact with data from the separate kBump services.", + "requirements": ["pymongo"], + "tags": ["utility", "database", "bridge"] +} \ No newline at end of file diff --git a/kbump/kbump.py b/kbump/kbump.py new file mode 100644 index 0000000..e8a7454 --- /dev/null +++ b/kbump/kbump.py @@ -0,0 +1,104 @@ +import discord +import pymongo +from redbot.core import checks, commands +from redbot.core.bot import Red + +class kBump(commands.Cog): + """ + A bridge to the kBump MongoDB database. + """ + + def __init__(self, bot: Red): + self.bot = bot + self.client = None + self.servers_collection = None + # Create a background task to connect to the DB after the bot is ready + self.db_init_task = self.bot.loop.create_task(self.initialize_db()) + + async def initialize_db(self): + """Initializes the database connection.""" + await self.bot.wait_until_ready() + try: + # Retrieve the secure URI we set with the '[p]set api' command + uri = (await self.bot.get_shared_api_tokens("mongodb")).get("uri") + if not uri: + print("[kBump] MongoDB URI not set! Use '[p]set api mongodb uri ...' to set it.") + return + self.client = pymongo.MongoClient(uri) + # Connect to the same database and collection as your other bot + db = self.client["BytesBump"] + self.servers_collection = db["servers"] + print("[kBump] Successfully connected to the BytesBump MongoDB.") + except pymongo.errors.PyMongoError as e: + print(f"[kBump] PyMongo error connecting to BytesBump MongoDB: {e}") + return + except Exception as e: + print(f"[kBump] General error connecting to BytesBump MongoDB: {e}") + +def cog_unload(self): + """Close the client connection when the cog is unloaded.""" + if self.client: + try: + self.client.close() + print("[kBump] Closed connection to the BytesBump MongoDB.") + except Exception as e: + print(f"[kBump] Error closing connection to the BytesBump MongoDB: {e}") + # Cancel the background task + self.db_init_task.cancel() + +@commands.command() +@commands.guild_only() +@checks.mod_or_permissions(manage_guild=True) +async def bumpstatus(self, ctx: commands.Context, guild: discord.Guild = None): + """ + Checks the kBump setup status for a server. + If no server is provided, it checks the current server. + """ + try: + if not self.servers_collection: + await ctx.send("Database connection is not available. Please check the console logs.") + return + if not self.servers_collection: + await ctx.send("The kBump database connection is not yet initialized. Please wait for the initialization task to complete.") + return + target_guild = guild or ctx.guild + server_data = self.servers_collection.find_one({"_id": target_guild.id}) + if not server_data: + await ctx.send(f"No kBump data found for the server: `{target_guild.name}`.") + return + # Rest of the code remains the same + except pymongo.errors.PyMongoError as e: + print(f"[kBump] PyMongo error getting kBump data for server: {e}") + await ctx.send(f"Error getting kBump data for the server: `{target_guild.name}`. Please check the console logs for more information.") + return + except Exception as e: + print(f"[kBump] General error getting kBump data for server: {e}") + await ctx.send(f"Error getting kBump data for the server: `{target_guild.name}`. Please check the console logs for more information.") + return + + embed_color = discord.Color(server_data.get('color', 0x2F3136)) + embed = discord.Embed( + title=f"kBump Status for {target_guild.name}", + color=embed_color + ) + embed.set_thumbnail(url=target_guild.icon.url if target_guild.icon else None) + + description = server_data.get('description', 'Not set.') + embed.add_field(name="📝 Description", value=f"```{description[:1000]}```", inline=False) + + custom_tags = server_data.get('tags', 'Not set.') + embed.add_field(name="🏷️ Custom Tags", value=custom_tags, inline=False) + + discovery_tags = server_data.get('discovery_tags') + if discovery_tags: + embed.add_field(name="🌐 Official Discovery Tags", value=discovery_tags, inline=False) + + vanity = server_data.get('vanity_code') + if vanity: + embed.add_field(name="🔗 Vanity URL", value=f"`discord.gg/{vanity}`", inline=True) + + invite = server_data.get('invite_code') + if invite: + embed.add_field(name="✉️ Invite Code", value=f"`{invite}`", inline=True) + + await ctx.send(embed=embed) \ No newline at end of file