示例#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}'
    )
示例#2
0
def mhca(instance: bot, message: trigger) -> None:
    """Expand a link to Miraheze Central Auth."""
    try:
        instance.say(
            f'https://meta.miraheze.org/wiki/Special:CentralAuth/{message.group(2).replace(" ", "_")}',
        )
    except AttributeError:
        instance.say('Syntax: .mhca example', message.sender)
示例#3
0
def addchan(instance: bot, message: trigger) -> None:
    """Reply to channel request message."""
    admins = ' '.join(map(str, instance.config.core.admin_accounts))
    if instance.config.responses.support_channel is not None:
        instance.say(
            f'Hey {admins}, {message.nick} would like to have me in their channel: {message.group(2)}',
            instance.config.responses.support_channel,
        )
        if message.sender != instance.config.responses.support_channel:
            instance.reply(
                f'Request sent! Action upon the request should be taken shortly. Thank you for using {instance.nick}!',
            )
示例#4
0
def high_priority_tasks_notification(instance: bot, message: trigger) -> None:  # noqa: U100
    """Send regular update on high priority tasks."""
    if instance.settings.phabricator.highpri_notify is True:
        info = get_host_and_api_or_query_key(
            instance.settings.phabricator.highpri_channel,
            instance.memory['phab']['jdcache'],
            [
                instance.settings.phabricator.api_token,
                instance.settings.phabricator.querykey,
            ],
        )
        result = phabapi.dophabsearch(
            info[0],
            info[1],
            info[2],
            session=instance.memory['shared']['session'],
            )
        if result:
            instance.say('Your weekly high priority task update:', instance.settings.phabricator.highpri_channel)
            for task in result:
                instance.say(task, instance.settings.phabricator.highpri_channel)
        else:
            instance.say(
                'High priority task update: Tasks exceeded limit or could not be found. Use ".highpri"',
                instance.settings.phabricator.highpri_channel,
            )
示例#5
0
def welcome_user(instance: bot, message: trigger) -> None:
    """Welcome users upon joining the channel."""
    if message.nick == instance.nick:
        return

    if message.sender not in instance.known_users_list:
        instance.known_users_list[message.sender] = []
    if message.account == '*' and message.nick not in instance.known_users_list[
            message.sender]:
        instance.known_users_list[message.sender].append(message.nick)
        welcome = send_welcome(message.nick, message.sender)
        if welcome is not None:
            instance.say(welcome)
    else:
        if (message.account and
                message.nick) not in instance.known_users_list[message.sender]:
            instance.known_users_list[message.sender].append(message.account)
            welcome = send_welcome(message.nick, message.sender)
            if welcome is not None:
                instance.say(welcome)

    save_known_users_list(instance.known_users_filename,
                          instance.known_users_list)
示例#6
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)
示例#7
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)
示例#8
0
def gj(instance: bot, message: trigger) -> None:
    """Tell the user that they are doing good work."""
    instance.say(f"You're doing good work, {message.group(2)}!")
示例#9
0
def ghuser(instance: bot, message: trigger) -> None:
    """Expand a link to github."""
    try:
        instance.say(f'https://github.com/{message.group(2)}')
    except TypeError:
        instance.say('Syntax: .github user', message.sender)
示例#10
0
def twlink(instance: bot, message: trigger) -> None:
    """Expand a link to Twitter."""
    try:
        instance.say(f'https://twitter.com/{message.group(2)}')
    except TypeError:
        instance.say('Syntax: .tw user', message.sender)
示例#11
0
def redditr(instance: bot, message: trigger) -> None:
    """Expand a link to reddit/r."""
    try:
        instance.say(f'https://reddit.com/r/{message.group(2)}')
    except TypeError:
        instance.say('Syntax: .subred example', message.sender)