nerimity-sdk-contrib 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ .env
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ site/
9
+ .pytest_cache/
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.4
2
+ Name: nerimity-sdk-contrib
3
+ Version: 0.1.0
4
+ Summary: Ready-made plugins for nerimity-sdk bots
5
+ License: MIT
6
+ Keywords: bot,nerimity,plugins,sdk
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: nerimity-sdk>=0.2.5
9
+ Description-Content-Type: text/markdown
10
+
11
+ # nerimity-sdk-contrib
12
+
13
+ Ready-made plugins for [nerimity-sdk](https://pypi.org/project/nerimity-sdk/) bots.
14
+
15
+ ```bash
16
+ pip install nerimity-sdk-contrib
17
+ ```
18
+
19
+ ## Plugins
20
+
21
+ | Plugin | Description |
22
+ |---|---|
23
+ | `WelcomePlugin` | Greets new members with a configurable message |
24
+ | `AutoModPlugin` | Deletes messages matching a word/regex list |
25
+ | `StarboardPlugin` | Reposts highly-reacted messages to a starboard channel |
26
+ | `LoggingPlugin` | Logs joins, leaves, deletes, and edits to a channel |
27
+
28
+ ## Usage
29
+
30
+ ```python
31
+ from nerimity_sdk_contrib import WelcomePlugin, AutoModPlugin, StarboardPlugin, LoggingPlugin
32
+
33
+ await bot.plugins.load(WelcomePlugin(channel_id="123"))
34
+ await bot.plugins.load(AutoModPlugin(blocked=["badword"], log_channel_id="456"))
35
+ await bot.plugins.load(StarboardPlugin(channel_id="789", threshold=3))
36
+ await bot.plugins.load(LoggingPlugin(channel_id="000"))
37
+ ```
38
+
39
+ ## Adding a new plugin
40
+
41
+ 1. Create `nerimity_sdk_contrib/your_plugin.py` with a class inheriting `PluginBase`
42
+ 2. Import and re-export it in `__init__.py`
43
+ 3. Add it to the table above and to the [plugin marketplace docs](https://joddabodscripts.github.io/Nerimity-SDK/plugins/)
@@ -0,0 +1,33 @@
1
+ # nerimity-sdk-contrib
2
+
3
+ Ready-made plugins for [nerimity-sdk](https://pypi.org/project/nerimity-sdk/) bots.
4
+
5
+ ```bash
6
+ pip install nerimity-sdk-contrib
7
+ ```
8
+
9
+ ## Plugins
10
+
11
+ | Plugin | Description |
12
+ |---|---|
13
+ | `WelcomePlugin` | Greets new members with a configurable message |
14
+ | `AutoModPlugin` | Deletes messages matching a word/regex list |
15
+ | `StarboardPlugin` | Reposts highly-reacted messages to a starboard channel |
16
+ | `LoggingPlugin` | Logs joins, leaves, deletes, and edits to a channel |
17
+
18
+ ## Usage
19
+
20
+ ```python
21
+ from nerimity_sdk_contrib import WelcomePlugin, AutoModPlugin, StarboardPlugin, LoggingPlugin
22
+
23
+ await bot.plugins.load(WelcomePlugin(channel_id="123"))
24
+ await bot.plugins.load(AutoModPlugin(blocked=["badword"], log_channel_id="456"))
25
+ await bot.plugins.load(StarboardPlugin(channel_id="789", threshold=3))
26
+ await bot.plugins.load(LoggingPlugin(channel_id="000"))
27
+ ```
28
+
29
+ ## Adding a new plugin
30
+
31
+ 1. Create `nerimity_sdk_contrib/your_plugin.py` with a class inheriting `PluginBase`
32
+ 2. Import and re-export it in `__init__.py`
33
+ 3. Add it to the table above and to the [plugin marketplace docs](https://joddabodscripts.github.io/Nerimity-SDK/plugins/)
@@ -0,0 +1,35 @@
1
+ """
2
+ nerimity-sdk-contrib
3
+ ====================
4
+ Ready-made plugins for nerimity-sdk bots.
5
+
6
+ Usage::
7
+
8
+ pip install nerimity-sdk-contrib
9
+
10
+ from nerimity_sdk_contrib import WelcomePlugin, AutoModPlugin, StarboardPlugin, LoggingPlugin
11
+
12
+ await bot.plugins.load(WelcomePlugin(channel_id="123"))
13
+ await bot.plugins.load(AutoModPlugin(blocked=["badword"]))
14
+ await bot.plugins.load(StarboardPlugin(channel_id="456", threshold=3))
15
+ await bot.plugins.load(LoggingPlugin(channel_id="789"))
16
+
17
+ Adding a new plugin
18
+ -------------------
19
+ 1. Create nerimity_sdk_contrib/your_plugin.py with a class inheriting PluginBase
20
+ 2. Import and re-export it here
21
+ 3. Add it to the docs/plugins.md marketplace table
22
+ """
23
+ from nerimity_sdk_contrib.welcome import WelcomePlugin
24
+ from nerimity_sdk_contrib.automod import AutoModPlugin
25
+ from nerimity_sdk_contrib.starboard import StarboardPlugin
26
+ from nerimity_sdk_contrib.server_logging import LoggingPlugin
27
+
28
+ __version__ = "0.1.0"
29
+
30
+ __all__ = [
31
+ "WelcomePlugin",
32
+ "AutoModPlugin",
33
+ "StarboardPlugin",
34
+ "LoggingPlugin",
35
+ ]
@@ -0,0 +1,37 @@
1
+ import re
2
+ from nerimity_sdk.plugins.manager import PluginBase, listener
3
+ from nerimity_sdk.utils.mentions import mention
4
+
5
+
6
+ class AutoModPlugin(PluginBase):
7
+ """Deletes messages containing blocked words or regex patterns.
8
+
9
+ Usage::
10
+
11
+ await bot.plugins.load(AutoModPlugin(
12
+ blocked=["badword", r"\\bspam+\\b"],
13
+ log_channel_id="123", # optional
14
+ ))
15
+ """
16
+ name = "automod"
17
+
18
+ def __init__(self, blocked: list[str],
19
+ log_channel_id: str | None = None) -> None:
20
+ super().__init__()
21
+ self._pattern = re.compile("|".join(blocked), re.IGNORECASE)
22
+ self.log_channel_id = log_channel_id
23
+
24
+ @listener("message:created")
25
+ async def on_message(self, event) -> None:
26
+ from nerimity_sdk.events.payloads import MessageCreatedEvent
27
+ if not isinstance(event, MessageCreatedEvent):
28
+ return
29
+ msg = event.message
30
+ if not self._pattern.search(msg.content or ""):
31
+ return
32
+ await self.bot.rest.delete_message(msg.channel_id, msg.id)
33
+ if self.log_channel_id:
34
+ await self.bot.rest.create_message(
35
+ self.log_channel_id,
36
+ f"🚫 Deleted message from {mention(msg.created_by.id)}: ||{msg.content}||"
37
+ )
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "nerimity-sdk-contrib"
7
+ version = "0.1.0"
8
+ description = "Ready-made plugins for nerimity-sdk bots"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "MIT" }
12
+ keywords = ["nerimity", "bot", "sdk", "plugins"]
13
+ dependencies = ["nerimity-sdk>=0.2.5"]
14
+
15
+ [tool.hatch.build.targets.wheel]
16
+ packages = ["nerimity_sdk_contrib"]
@@ -0,0 +1,46 @@
1
+ from nerimity_sdk.plugins.manager import PluginBase, listener
2
+ from nerimity_sdk.utils.mentions import mention
3
+
4
+
5
+ class LoggingPlugin(PluginBase):
6
+ """Logs server events to a channel: joins, leaves, deletes, edits.
7
+
8
+ Usage::
9
+
10
+ await bot.plugins.load(LoggingPlugin(channel_id="123"))
11
+ """
12
+ name = "logging"
13
+
14
+ def __init__(self, channel_id: str) -> None:
15
+ super().__init__()
16
+ self.channel_id = channel_id
17
+
18
+ async def _log(self, text: str) -> None:
19
+ await self.bot.rest.create_message(self.channel_id, text)
20
+
21
+ @listener("server:member_joined")
22
+ async def on_join(self, event) -> None:
23
+ from nerimity_sdk.events.payloads import MemberJoinedEvent
24
+ if isinstance(event, MemberJoinedEvent):
25
+ await self._log(f"➡️ {mention(event.member.user.id)} joined")
26
+
27
+ @listener("server:member_left")
28
+ async def on_leave(self, event) -> None:
29
+ from nerimity_sdk.events.payloads import MemberLeftEvent
30
+ if isinstance(event, MemberLeftEvent):
31
+ await self._log(f"⬅️ <user {event.user_id}> left")
32
+
33
+ @listener("message:deleted")
34
+ async def on_delete(self, event) -> None:
35
+ from nerimity_sdk.events.payloads import MessageDeletedEvent
36
+ if isinstance(event, MessageDeletedEvent):
37
+ msg = self.bot.cache.messages.get(event.message_id)
38
+ content = f"||{msg.content}||" if msg else f"(id: {event.message_id})"
39
+ await self._log(f"🗑️ Message deleted in <#{event.channel_id}>: {content}")
40
+
41
+ @listener("message:updated")
42
+ async def on_edit(self, event) -> None:
43
+ from nerimity_sdk.events.payloads import MessageUpdatedEvent
44
+ if isinstance(event, MessageUpdatedEvent):
45
+ new = event.updated.get("content", "")
46
+ await self._log(f"✏️ Message edited in <#{event.channel_id}>: {new}")
@@ -0,0 +1,42 @@
1
+ from nerimity_sdk.plugins.manager import PluginBase, listener
2
+ from nerimity_sdk.utils.mentions import mention
3
+
4
+
5
+ class StarboardPlugin(PluginBase):
6
+ """Reposts highly-reacted messages to a starboard channel.
7
+
8
+ Usage::
9
+
10
+ await bot.plugins.load(StarboardPlugin(
11
+ channel_id="123",
12
+ emoji="⭐",
13
+ threshold=3,
14
+ ))
15
+ """
16
+ name = "starboard"
17
+
18
+ def __init__(self, channel_id: str, emoji: str = "⭐",
19
+ threshold: int = 3) -> None:
20
+ super().__init__()
21
+ self.channel_id = channel_id
22
+ self.emoji = emoji
23
+ self.threshold = threshold
24
+ self._posted: set[str] = set()
25
+
26
+ @listener("message:reaction_added")
27
+ async def on_reaction(self, event) -> None:
28
+ from nerimity_sdk.events.payloads import ReactionAddedEvent
29
+ if not isinstance(event, ReactionAddedEvent):
30
+ return
31
+ if event.name != self.emoji or event.count < self.threshold:
32
+ return
33
+ if event.message_id in self._posted:
34
+ return
35
+ self._posted.add(event.message_id)
36
+ msg = self.bot.cache.messages.get(event.message_id)
37
+ content = msg.content if msg else f"(message {event.message_id})"
38
+ author = mention(msg.created_by.id) if msg else "unknown"
39
+ await self.bot.rest.create_message(
40
+ self.channel_id,
41
+ f"{self.emoji} **{event.count}** | {author}\n{content}"
42
+ )
@@ -0,0 +1,35 @@
1
+ from nerimity_sdk.plugins.manager import PluginBase, listener
2
+ from nerimity_sdk.utils.mentions import mention
3
+
4
+
5
+ class WelcomePlugin(PluginBase):
6
+ """Sends a welcome message when a member joins.
7
+
8
+ Usage::
9
+
10
+ await bot.plugins.load(WelcomePlugin(
11
+ channel_id="123",
12
+ message="👋 Welcome {mention} to the server!",
13
+ ))
14
+
15
+ Template variables: {mention}, {username}, {tag}
16
+ """
17
+ name = "welcome"
18
+
19
+ def __init__(self, channel_id: str,
20
+ message: str = "👋 Welcome {mention}!") -> None:
21
+ super().__init__()
22
+ self.channel_id = channel_id
23
+ self.message_template = message
24
+
25
+ @listener("server:member_joined")
26
+ async def on_join(self, event) -> None:
27
+ from nerimity_sdk.events.payloads import MemberJoinedEvent
28
+ if not isinstance(event, MemberJoinedEvent):
29
+ return
30
+ user = event.member.user
31
+ text = (self.message_template
32
+ .replace("{mention}", mention(user.id))
33
+ .replace("{username}", user.username)
34
+ .replace("{tag}", user.tag))
35
+ await self.bot.rest.create_message(self.channel_id, text)