import html import itertools import random import string def _text(ctx): return (ctx.args or (ctx.reply.text if ctx.reply and ctx.reply.text else '') or (ctx.reply.caption if ctx.reply and ctx.reply.caption else '') or '').strip() def _items(text: str): return [x.strip() for x in text.replace('\n', ',').split(',') if x.strip()] def setup(registry): async def coin_cmd(ctx): await ctx.respond(f'🪙 Moneda\n\n{random.choice(["Cara 😄", "Cruz 😵"])}') async def dice_cmd(ctx): sides = 6 if ctx.args.strip().isdigit(): sides = max(2, min(1000, int(ctx.args.strip()))) await ctx.respond(f'🎲 Dado\n\nSalió: {random.randint(1, sides)} de {sides}') async def rand_cmd(ctx): parts = ctx.args.split() if len(parts) == 2 and all(p.lstrip('-').isdigit() for p in parts): a, b = map(int, parts) else: a, b = 1, 100 if a > b: a, b = b, a await ctx.respond(f'🎰 Número aleatorio\n\n{random.randint(a, b)}') async def choose_cmd(ctx): text = _text(ctx) items = _items(text) if len(items) < 2: await ctx.respond('⚠️ Pon varias opciones separadas por comas.') return await ctx.respond(f'🎯 Elegido\n\n{html.escape(random.choice(items))}') async def pick_cmd(ctx): await choose_cmd(ctx) async def sample_cmd(ctx): text = _text(ctx) if not text: await ctx.respond('⚠️ Usa .samplex 2 | a,b,c,d') return if ' | ' not in text: await ctx.respond('⚠️ Usa .samplex 2 | a,b,c,d') return n_raw, items_raw = [p.strip() for p in text.split(' | ', 1)] if not n_raw.isdigit(): await ctx.respond('⚠️ El primer valor debe ser un número.') return items = _items(items_raw) n = max(1, min(len(items), int(n_raw))) out = random.sample(items, n) await ctx.respond('🧺 Muestra aleatoria\n\n' + '\n'.join(f'• {html.escape(x)}' for x in out)) async def shuffle_cmd(ctx): items = _items(_text(ctx)) if len(items) < 2: await ctx.respond('⚠️ Pon varias opciones separadas por comas.') return random.shuffle(items) await ctx.respond('🔀 Opciones mezcladas\n\n' + '\n'.join(f'{i+1}. {html.escape(x)}' for i, x in enumerate(items))) async def eightball_cmd(ctx): answers = [ 'Sí, totalmente 😎', 'No 😬', 'Tal vez 🤔', 'Tiene buena pinta ✨', 'Mejor espera ⏳', 'Hazlo 💥', 'No lo haría 🚫', 'Todo apunta a que sí ✅', 'Difícil saberlo 🌫️', 'Se viene algo bueno 🔥' ] q = _text(ctx) or 'Pregunta misteriosa' await ctx.respond(f'🎱 8 Ball\n\n❓ {html.escape(q)}\n💬 {random.choice(answers)}') async def mock_cmd(ctx): text = _text(ctx) if not text: await ctx.respond('⚠️ Pásame un texto.') return out = ''.join(ch.upper() if i % 2 else ch.lower() for i, ch in enumerate(text)) await ctx.respond(f'🫠 Mock\n\n{html.escape(out)}') async def clapify_cmd(ctx): text = _text(ctx) if not text: await ctx.respond('⚠️ Pásame un texto.') return await ctx.respond(f'👏 Clapify\n\n{html.escape(" 👏 ".join(text.split()))}') async def spaceify_cmd(ctx): text = _text(ctx) if not text: await ctx.respond('⚠️ Pásame un texto.') return await ctx.respond(f'🌌 Spaceify\n\n{html.escape(" ".join(list(text)))}') async def reversewords_cmd(ctx): text = _text(ctx) if not text: await ctx.respond('⚠️ Pásame un texto.') return out = ' '.join(reversed(text.split())) await ctx.respond(f'🔁 Palabras invertidas\n\n{html.escape(out)}') async def scramble_cmd(ctx): text = _text(ctx) if not text: await ctx.respond('⚠️ Pásame un texto.') return chars = list(text) random.shuffle(chars) await ctx.respond(f'🧩 Texto mezclado\n\n{html.escape("".join(chars))}') async def rcase_cmd(ctx): text = _text(ctx) if not text: await ctx.respond('⚠️ Pásame un texto.') return out = ''.join(random.choice([c.lower(), c.upper()]) for c in text) await ctx.respond(f'🎨 Random case\n\n{html.escape(out)}') async def linepick_cmd(ctx): text = _text(ctx) lines = [x for x in text.splitlines() if x.strip()] if len(lines) < 2: await ctx.respond('⚠️ Necesito varias líneas.') return await ctx.respond(f'📌 Línea elegida\n\n{html.escape(random.choice(lines))}') async def lorem_cmd(ctx): words = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'nunc', 'vitae', 'urna', 'magna'] n = 20 if ctx.args.strip().isdigit(): n = max(5, min(200, int(ctx.args.strip()))) out = ' '.join(random.choice(words) for _ in range(n)) await ctx.respond(f'📝 Lorem aleatorio\n\n{out}') async def nickname_cmd(ctx): starts = ['Neo', 'Dark', 'Ultra', 'Mega', 'Ghost', 'Pixel', 'Crypto', 'Turbo', 'Luna', 'Solar'] ends = ['Fox', 'Byte', 'Storm', 'Nova', 'Wave', 'Wolf', 'Cat', 'Pulse', 'Code', 'Flame'] await ctx.respond(f'🪪 Nick aleatorio\n\n{random.choice(starts)}{random.choice(ends)}{random.randint(1,99)}') async def teamup_cmd(ctx): items = _items(_text(ctx)) if len(items) < 2: await ctx.respond('⚠️ Pon varios nombres separados por comas.') return random.shuffle(items) pairs = [items[i:i+2] for i in range(0, len(items), 2)] out = [] for i, pair in enumerate(pairs, 1): out.append(f'Equipo {i}: ' + ' + '.join(html.escape(x) for x in pair)) await ctx.respond('👥 Equipos\n\n' + '\n'.join(out)) async def pairs_cmd(ctx): await teamup_cmd(ctx) async def draw_cmd(ctx): items = _items(_text(ctx)) if not items: await ctx.respond('⚠️ Pon opciones separadas por comas.') return random.shuffle(items) out = '\n'.join(f'{i+1}. {html.escape(x)}' for i, x in enumerate(items)) await ctx.respond('🏆 Sorteo / ranking aleatorio\n\n' + out) async def decide_cmd(ctx): await ctx.respond(f'🤖 Decisión rápida\n\n{random.choice(["Sí", "No", "Hazlo", "Pasa", "Espera un poco", "Ve con todo"])} {random.choice(["🔥", "😅", "✨", "🚀", "🤝", "🧠"])} ') async def yesno_cmd(ctx): await ctx.respond(f'✅❌ Respuesta\n\n{random.choice(["Sí", "No"])}') registry.add('coin', coin_cmd, 'Lanza una moneda.', usage='.coin', category='Aleatorio') registry.add('dicex', dice_cmd, 'Lanza un dado de N caras.', usage='.dicex 20', category='Aleatorio') registry.add('rand', rand_cmd, 'Número aleatorio entre A y B.', usage='.rand 1 100', category='Aleatorio') registry.add('choose', choose_cmd, 'Elige una opción.', usage='.choose rojo, azul, verde', category='Aleatorio') registry.add('pick', pick_cmd, 'Alias de choose.', usage='.pick pizza, sushi', category='Aleatorio') registry.add('samplex', sample_cmd, 'Toma una muestra aleatoria.', usage='.samplex 2 | a,b,c,d', category='Aleatorio') registry.add('shufflex', shuffle_cmd, 'Mezcla opciones.', usage='.shufflex a,b,c,d', category='Aleatorio') registry.add('eightball', eightball_cmd, 'Responde como una bola mágica.', usage='.eightball me irá bien?', category='Aleatorio') registry.add('mock', mock_cmd, 'Alterna mayúsculas y minúsculas.', usage='.mock hola', category='Aleatorio') registry.add('clapify', clapify_cmd, 'Añade aplausos entre palabras.', usage='.clapify esto está duro', category='Aleatorio') registry.add('spaceify', spaceify_cmd, 'Separa letras con espacios.', usage='.spaceify hola', category='Aleatorio') registry.add('reversewords', reversewords_cmd, 'Invierte el orden de palabras.', usage='.reversewords hola mundo', category='Aleatorio') registry.add('scramble', scramble_cmd, 'Mezcla caracteres del texto.', usage='.scramble hola', category='Aleatorio') registry.add('rcase', rcase_cmd, 'Pone letras en may/min aleatorias.', usage='.rcase hola', category='Aleatorio') registry.add('linepick', linepick_cmd, 'Elige una línea al azar.', usage='.linepick', category='Aleatorio') registry.add('loremx', lorem_cmd, 'Genera lorem aleatorio.', usage='.loremx 30', category='Aleatorio') registry.add('nickname', nickname_cmd, 'Genera un nick aleatorio.', usage='.nickname', category='Aleatorio') registry.add('teamup', teamup_cmd, 'Forma equipos aleatorios.', usage='.teamup ana, luis, marta, pepe', category='Aleatorio') registry.add('pairsx', pairs_cmd, 'Alias de teamup.', usage='.pairsx ana, luis, marta, pepe', category='Aleatorio') registry.add('draw', draw_cmd, 'Hace un sorteo/orden aleatorio.', usage='.draw ana, luis, marta', category='Aleatorio') registry.add('decide', decide_cmd, 'Te suelta una decisión rápida.', usage='.decide', category='Aleatorio') registry.add('yesno', yesno_cmd, 'Responde sí o no.', usage='.yesno', category='Aleatorio')