Exemplo n.º 1
0
def add_known_user(instance: bot, message: trigger) -> None:
    """Add user to known users list."""
    username = message.group(3)
    if message.group(4):
        channel = message.group(4)
    elif message.sender[0] == '#':
        channel = message.sender
    else:
        channel = DEFAULT_CHANNEL

    if not USERNAME_RE.match(username):
        instance.reply(f'Invalid username: {username}')
        return

    if not CHANNEL_RE.match(channel):
        instance.reply(f'Invalid channel name: {channel}')
        return

    if channel not in instance.known_users_list:
        instance.known_users_list[channel] = []

    if username in instance.known_users_list[channel]:
        instance.say(
            f'{username} is already added to known users list of channel {channel}'
        )
        return

    instance.known_users_list[channel].append(username)
    save_known_users_list(instance.known_users_filename,
                          instance.known_users_list)
    instance.say(
        f'Okay, {username} is now added to known users list of channel {channel}'
    )
Exemplo n.º 2
0
def hotchoc(instance: bot, message: trigger) -> None:
    """Make me give the specified nick a hot chocolate."""
    if message.group(2) is None:
        instance.reply('To whom should I give this hot chocolate?')
    else:
        instance.action(
            f'gives {message.group(2)} a warm, velvety salted caramel hot chocolate with cream and marhsmellows.',
            message.sender,
        )
Exemplo n.º 3
0
def mhwiki(instance: bot, message: trigger) -> None:
    """Expand a link to Miraheze wikis."""
    try:
        options = message.group(2).split(' ', 1)
        if len(options) == 1:
            instance.say(
                f'https://meta.miraheze.org/wiki/{options[0].replace(" ", "_")}',
            )
        elif len(options) == 2:
            wiki = options[0]
            page = options[1].replace(' ', '_')
            instance.say(f'https://{wiki}.miraheze.org/wiki/{page}')
    except AttributeError:
        instance.say('Syntax: .mh wiki page', message.sender)
Exemplo n.º 4
0
def phabtask(instance: bot, message: trigger) -> None:
    """Get information on a phabricator task."""
    try:
        if message.group(2).startswith('T'):
            task_id = message.group(2).split('T')[1]
        else:
            task_id = message.group(2)
        info = get_host_and_api_or_query_key(
            message.sender,
            instance.memory['phab']['jdcache'],
            [
                instance.settings.phabricator.api_token,
                instance.settings.phabricator.querykey,
            ],
        )
        instance.reply(
            phabapi.gettaskinfo(
                info[0],
                info[1],
                task=task_id,
                session=instance.memory['shared']['session']),
            )
    except AttributeError:
        instance.say('Syntax: .task (task ID with or without T)', message.sender)
Exemplo n.º 5
0
def coffee(instance: bot, message: trigger) -> None:
    """Make me give the specified nick a coffee."""
    if message.group(2) is None:
        instance.reply('To whom should I give this cup of coffee?')
    else:
        instance.action(f'gives {message.group(2)} a nice warm cup of coffee.', message.sender)
Exemplo n.º 6
0
def present(instance: bot, message: trigger) -> None:
    """Make me give the specified nick a present."""
    if message.group(2) is None:
        instance.reply('To whom should I give this present?')
    else:
        instance.action(f'gives {message.group(2)} a present.', message.sender)
Exemplo n.º 7
0
def burger(instance: bot, message: trigger) -> None:
    """Make me give the specified nick a burger."""
    if message.group(2) is None:
        instance.reply('To whom should I give this cheeseburger?')
    else:
        instance.action(f'gives {message.group(2)} a freshly cooked cheeseburger.', message.sender)
Exemplo n.º 8
0
def hug(instance: bot, message: trigger) -> None:
    """Make me give the specified nick a hug."""
    if message.group(2) is None:
        instance.reply('To whom should I give this hug?')
    else:
        instance.action(f'gives {message.group(2)} a great big bear hug.', message.sender)