# Path: cardinal/decorators.py
# def command(triggers):
#     if isinstance(triggers, str):
#         triggers = [triggers]
# 
#     if not isinstance(triggers, list):
#         raise TypeError("Command must be a trigger string or list of triggers")
# 
#     def wrap(f):
#         f.commands = triggers
#         return f
# 
#     return wrap
# 
# def help(lines):
#     # For backwards compatibility
#     if isinstance(lines, str):
#         lines = [lines]
# 
#     if not isinstance(lines, list):
#         raise TypeError("Help must be a help string or list of help strings")
# 
#     def wrap(f):
#         # Create help list or prepend to it
#         if not hasattr(f, 'help'):
#             f.help = lines
#         else:
#             f.help = lines + f.help
# 
#         return f
# 
#     return wrap


import random
import re
from cardinal.decorators import command, help


def parse_roll(arg):
    # some people might separate with commas
    arg = arg.rstrip(',')

    # regex intentionally does not match negatives
    if match := re.match(r'^(\d+)d(\d+)$', arg):
        num_dice = int(match.group(1))
        sides = int(match.group(2))
    elif match := re.match(r'^d?(\d+)$', arg):
        num_dice = 1
        sides = int(match.group(1))
    else:
        return []

    # Ignore 1-sided dice, or large dice
    if sides < 2 or sides > 120:
        return []

    # Don't let people exhaust memory
    if num_dice > 10:
        num_dice = 10

    return [sides] * num_dice


class RandomPlugin:
    @command('roll')
    @help("Roll dice")

# Path: cardinal/decorators.py
# def command(triggers):
#     if isinstance(triggers, str):
#         triggers = [triggers]
# 
#     if not isinstance(triggers, list):
#         raise TypeError("Command must be a trigger string or list of triggers")
# 
#     def wrap(f):
#         f.commands = triggers
#         return f
# 
#     return wrap
# 
# def help(lines):
#     # For backwards compatibility
#     if isinstance(lines, str):
#         lines = [lines]
# 
#     if not isinstance(lines, list):
#         raise TypeError("Help must be a help string or list of help strings")
# 
#     def wrap(f):
#         # Create help list or prepend to it
#         if not hasattr(f, 'help'):
#             f.help = lines
#         else:
#             f.help = lines + f.help
# 
#         return f
# 
#     return wrap


# Path: plugins/random/plugin.py
import random
import re
from cardinal.decorators import command, help



def parse_roll(arg):
    # some people might separate with commas
    arg = arg.rstrip(',')

    # regex intentionally does not match negatives
    if match := re.match(r'^(\d+)d(\d+)$', arg):
        num_dice = int(match.group(1))
        sides = int(match.group(2))
    elif match := re.match(r'^d?(\d+)$', arg):
        num_dice = 1
        sides = int(match.group(1))
    else:
        return []

    # Ignore 1-sided dice, or large dice
    if sides < 2 or sides > 120:
        return []

    # Don't let people exhaust memory
    if num_dice > 10:
        num_dice = 10

    return [sides] * num_dice


class RandomPlugin:
    @command('roll')
    @help("Roll dice")

    @help("Syntax: .roll #d# (e.g. .roll 2d6)")