Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/random-discord-text-formatter/1.0.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Random Discord Formatter

Minimal Python helper that takes text from an Espanso form, randomly applies Discord markdown (bold, italic, underline, strikethrough, code, spoiler, and combos) plus random case flipping, then prints the result to stdout so Espanso can paste it.

## What it does

- Prompts via Espanso form (multiline text field).
- Splits the input on whitespace (keeps spaces intact).
- Randomly flips the case of each letter (~50% chance).
- Wraps each word in one random Discord style.
- Prints the result to stdout.

Because formatting is applied per whole word and spaces stay between the markers, Discord parses it correctly (no stray asterisks).

## Usage

1. Type `:randytext`.
2. Espanso shows a form with a multiline text field.
3. Enter your text and submit (Submit button or Ctrl+Enter).
4. The formatted result is pasted.

## Requirements

- Python 3

## Files

- `random_discord_text_formatter.py` — the script
- `package.yml` — Espanso match + form definition
- `_manifest.yml` — package metadata

## Notes

- Formatting styles: bold, italic, bold italic, underline, bold underline, italic underline, strikethrough, bold strikethrough, italic strikethrough, inline code, spoiler.
- Case flipping only affects letters.
- Empty form submission produces no output.
- The script path in `package.yml` uses `%CONFIG%` so it resolves correctly after package installation.
7 changes: 7 additions & 0 deletions packages/random-discord-text-formatter/1.0.0/_manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: "random-discord-text-formatter"
title: "Random Discord Text Formatter"
description: "Random Discord markdown formatting and case flipping via a minimal Python/Espanso prompt. Perfect for chaotic but valid Discord messages. Use :randytext to trigger it."
homepage: "https://github.com/kreezxil/hub/"
version: 1.0.0
author: Kreezxil
tags: [ "discord", "markdown", "formatting", "python", "fun", "text" ]
19 changes: 19 additions & 0 deletions packages/random-discord-text-formatter/1.0.0/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
matches:
- trigger: ":randytext"
replace: "{{output}}"
vars:
- name: form1
type: form
params:
layout: |
Text to format:
[[text]]
fields:
text:
multiline: true
- name: output
type: script
params:
args:
- python3
- "%CONFIG%/match/packages/random-discord-text-formatter/random_discord_text_formatter.py"
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
"""
Random Discord Formatter for Espanso
Reads text from the Espanso form (via ESPANSO_FORM1_TEXT),
applies random Discord markdown + case flipping, and prints the result.
"""

import os
import random
import re
import sys

FORMATTERS = [
lambda s: f"**{s}**", # bold
lambda s: f"*{s}*", # italic
lambda s: f"***{s}***", # bold italic
lambda s: f"__{s}__", # underline
lambda s: f"**__{s}__**", # bold underline
lambda s: f"*__{s}__*", # italic underline
lambda s: f"~~{s}~~", # strikethrough
lambda s: f"**~~{s}~~**", # bold strikethrough
lambda s: f"*~~{s}~~*", # italic strikethrough
lambda s: f"`{s}`", # inline code
lambda s: f"||{s}||", # spoiler
]

def random_case_word(word: str) -> str:
"""Randomly flip case of each letter (~50% chance)."""
return "".join(
c.swapcase() if c.isalpha() and random.random() < 0.5 else c
for c in word
)

def apply_random_discord(text: str) -> str:
"""
Split on whitespace (preserve spaces), randomly case-flip letters,
then wrap each word in one Discord style.
"""
if not text or not text.strip():
return ""
parts = re.split(r"(\s+)", text)
result = []
for part in parts:
if not part or part.isspace():
result.append(part)
continue
word = random_case_word(part)
formatter = random.choice(FORMATTERS)
result.append(formatter(word))
Comment on lines +47 to +49
return "".join(result)

def main() -> None:
# Form field "text" is exposed as ESPANSO_FORM1_TEXT
raw = os.environ.get("ESPANSO_FORM1_TEXT", "").strip()
if not raw:
# Empty form → nothing to expand
sys.exit(0)
print(apply_random_discord(raw), flush=True)

if __name__ == "__main__":
main()
Loading