Files
overub/modules/text/__init__.py
2025-12-21 17:12:32 +01:00

124 lines
3.7 KiB
Python

from core.module import Module
class TextModule(Module):
name = "text"
version = "0.1.0"
description = "Text manipulation commands"
async def on_load(self) -> None:
builder = self.commands
@builder.command(
name="upper",
description="Convert text to uppercase",
category="text",
usage=".upper <text>",
example=".upper hello",
)
async def upper_cmd(event, args):
text = " ".join(args)
await event.reply(text.upper() if text else "")
@builder.command(
name="lower",
description="Convert text to lowercase",
category="text",
usage=".lower <text>",
example=".lower HELLO",
)
async def lower_cmd(event, args):
text = " ".join(args)
await event.reply(text.lower() if text else "")
@builder.command(
name="bold",
description="Wrap text in bold markdown",
category="text",
usage=".bold <text>",
)
async def bold_cmd(event, args):
text = " ".join(args)
await event.reply(f"**{text}**" if text else "")
@builder.command(
name="italic",
description="Wrap text in italic markdown",
category="text",
usage=".italic <text>",
)
async def italic_cmd(event, args):
text = " ".join(args)
await event.reply(f"_{text}_" if text else "")
@builder.command(
name="reverse",
description="Reverse text",
category="text",
usage=".reverse <text>",
)
async def reverse_cmd(event, args):
text = " ".join(args)
await event.reply(text[::-1] if text else "")
@builder.command(
name="encode",
description="Base64 encode text",
category="text",
usage=".encode <text>",
)
async def encode_cmd(event, args):
import base64
text = " ".join(args)
if not text:
await event.reply("")
return
encoded = base64.b64encode(text.encode("utf-8")).decode("utf-8")
await event.reply(encoded)
@builder.command(
name="decode",
description="Base64 decode text",
category="text",
usage=".decode <text>",
)
async def decode_cmd(event, args):
import base64
text = " ".join(args)
if not text:
await event.reply("")
return
try:
decoded = base64.b64decode(text.encode("utf-8")).decode("utf-8")
except Exception:
await event.reply("Invalid base64")
return
await event.reply(decoded)
@builder.command(
name="count",
description="Count characters and words",
category="text",
usage=".count <text>",
)
async def count_cmd(event, args):
text = " ".join(args)
if not text:
await event.reply("Chars: 0 Words: 0")
return
words = len(text.split())
chars = len(text)
await event.reply(f"Chars: {chars} Words: {words}")
@builder.command(
name="fancy",
description="Simple spaced text",
category="text",
usage=".fancy <text>",
)
async def fancy_cmd(event, args):
text = " ".join(args)
await event.reply(" ".join(text) if text else "")