Exemple #1
0
def check_phab_cache(instance: bot, message: trigger) -> None:  # noqa: U100
    """Validate the cache matches the copy on disk."""
    result = jp.validatecache(instance.settings.phabricator.datafile, instance.memory['phab']['jdcache'])
    if result:
        instance.reply('Cache is correct.')
    else:
        instance.reply('Cache does not match on-disk copy')
def setup(instance: bot) -> None:
    """Do required setup for this module."""
    instance.known_users_filename = os.path.join(
        instance.config.core.homedir,
        f'{instance.nick}-{instance.config.core.host}.known_users.db',
    )
    instance.known_users_list = load_known_users_list(
        instance.known_users_filename)
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)
Exemple #4
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,
        )
def miraheze_gethelp(instance: bot, message: trigger) -> None:
    """Reply to help requests."""
    if message.sender == '#miraheze':
        instance.reply(
            'Pinging dmehus, Reception123, RhinosF1, Southparkfan, Universal_Omega and Voidwalker,'
            'who might be able to help you. Other users in this channel also see this and may be able to assist you.'
        )
    else:
        instance.reply(
            'If you need Miraheze releated help, please join #miraheze')
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}'
    )
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}!',
            )
Exemple #8
0
def phabtask2(instance: bot, message: trigger) -> None:
    """Get a Miraheze phabricator link to a the task number you provide."""
    task_id = str(message.match.group(0))[1:]
    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'],
        ),
    )
Exemple #9
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,
            )
Exemple #10
0
def forcehighpri(instance: bot, message: trigger) -> None:
    """Send full list of high priority tasks."""
    info = get_host_and_api_or_query_key(
        message.sender,
        instance.memory['phab']['jdcache'],
        [
            instance.settings.phabricator.api_token,
            instance.settings.phabricator.querykey,
        ],
    )
    result = phabapi.dophabsearch(
        info[0],
        info[1],
        info[2],
        limit=False,
        session=instance.memory['shared']['session'],
        )
    if result:
        for task in result:
            instance.reply(task)
    else:
        instance.reply('No tasks have high priority that I can see')
Exemple #11
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)
Exemple #12
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)
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)
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)
Exemple #15
0
def reset_phab_cache(instance: bot, message: trigger) -> None:  # noqa: U100
    """Reset the cache of the channel management data file."""
    instance.reply('Refreshing Cache...')
    instance.memory['phab']['jdcache'] = jp.createdict(instance.settings.phabricator.datafile)
    instance.reply('Cache refreshed')
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)
Exemple #17
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)
Exemple #18
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)
Exemple #19
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)
def miraheze_discord(instance: bot, message: trigger) -> None:  # noqa: U100
    """Display discord information for Miraheze."""
    instance.reply(
        'You can join discord by going to, https://miraheze.org/discord!')
def botversion(instance: bot, message: trigger) -> None:  # noqa: U100
    """List the current version of the bot."""
    instance.reply(
        f'The current version of this bot is {VERSION} ({SHORTVERSION})')
def githubsource(instance: bot, message: trigger) -> None:  # noqa: U100
    """Give the link to MirahezeBot's Github."""
    instance.reply(
        'My code can be found here: https://github.com/MirahezeBots/MirahezeBots'
    )
def cancel(instance: bot, message: trigger) -> None:
    """Cancel reminder."""
    admins = ' '.join(map(str, instance.config.core.admin_accounts))
    instance.reply(f"Pinging {admins} to cancel {message.nicks}'s reminder.")
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)}!")
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)
Exemple #26
0
def setup(instance: bot) -> None:
    """Create the config section & memory."""
    instance.config.define_section('phabricator', PhabricatorSection)
    instance.memory['phab'] = SopelMemory()
    instance.memory['phab']['jdcache'] = jp.createdict(instance.settings.phabricator.datafile)
Exemple #27
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)
Exemple #28
0
def setup(instance: bot) -> None:
    """Create the resources that can be accessed via sopel shared."""
    instance.memory['shared'] = SopelMemory()
    instance.memory['shared']['session'] = Session()
def miraheze(instance: bot, message: trigger) -> None:
    """Tells you about Miraheze and where to learn more."""
    if message.sender == '#miraheze':
        instance.reply(MIRAHEZE_ABOUT_MIRAHEZE_CHANNEL)
    else:
        instance.reply(MIRAHEZE_ABOUT_OTHER_CHANNELS)