from . import command, STOP_PROCESSING, CONTINUE_PROCESSING, RestartException
from .sed import Substitution
import inspect
import sys
import importlib
import os
import signal
import re

config = None

@command('wilco(?: (.+))?', pass_groups=True)
def wilco(bea, bot, update, groups):
    """ Wilco's vele namen. Aanpasbaar met sed-esque substitutie als argument. """
    expr, *_ = groups
    if expr is None:
        return update.message.reply_text(config['naam'])

    try:
        sub = Substitution(expr)
    except TypeError:
        return update.message.reply_text("Dat lijkt niet op een s///-substitutiepatroon.")

    config['naam'] = sub.do(config['naam'])
    return update.message.reply_text(config['naam'])

def init(bea, _config):
    global config
    config = _config
    return [wilco]
