Exemplo n.º 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')
Exemplo n.º 2
0
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)
Exemplo n.º 3
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)
Exemplo n.º 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,
        )
Exemplo n.º 5
0
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')
Exemplo n.º 6
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.º 7
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}!',
            )
Exemplo n.º 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'],
        ),
    )
Exemplo n.º 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,
            )
Exemplo n.º 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')
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 13
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.º 14
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)
Exemplo n.º 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')
Exemplo n.º 16
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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 20
0
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!')
Exemplo n.º 21
0
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})')
Exemplo n.º 22
0
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'
    )
Exemplo n.º 23
0
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.")
Exemplo n.º 24
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)}!")
Exemplo n.º 25
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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 29
0
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)