nxy/bot/plugins/linux.py

61 lines
2.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
import random
import irc3
import feedparser
from docopt import Dict as DocOptDict
from irc3.plugins.command import command
from irc3.utils import IrcString
from . import Plugin
2017-07-07 00:11:20 +00:00
from ..utils import re_generator
2017-07-04 13:22:20 +00:00
GNU_LINUX = """I'd Just Like To Interject For A Moment. What you're referring
to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it,
GNU plus Linux. Linux is not an operating system unto itself, but rather
another free component of a fully functioning GNU system made useful by the
GNU corelibs, shell utilities and vital system components comprising a full
OS as defined by POSIX."""
2017-05-30 11:51:45 +00:00
class Linux(Plugin):
KERNEL_FEED = 'https://www.kernel.org/feeds/kdist.xml'
2017-07-07 00:11:20 +00:00
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(debian|ubuntu|apt|dpkg).*')
def debillian(self, target: str):
2017-07-04 13:22:20 +00:00
"""Annoying RE trigger for debian with variable count of E."""
if random.randint(0, 3) is 0:
2017-07-07 00:11:20 +00:00
self.bot.privmsg(target, re_generator())
2017-06-01 15:38:34 +00:00
2017-07-07 00:11:20 +00:00
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(?<!gnu[/+])linux(?! kernel).*')
def linux(self, target: str):
2017-07-04 13:22:20 +00:00
"""Super annoying, useless 'Stallman is mad' trigger."""
if random.randint(0, 12) is 0:
self.bot.privmsg(target, GNU_LINUX)
@command
def kernel(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Get Linux kernel releases.
%%kernel
"""
2017-05-30 11:51:45 +00:00
feed = feedparser.parse(self.KERNEL_FEED)
2017-07-04 13:22:20 +00:00
# Cancel if no feed or entries
2017-07-04 16:47:23 +00:00
if not feed or not feed.get('entries'):
2017-07-07 00:11:20 +00:00
self.log.error('Error fetching kernel.org releases feed')
2017-07-04 13:22:20 +00:00
return
# Make list of releases
releases = []
for e in feed['entries']:
version, branch = e['title'].split(': ')
2017-07-04 13:22:20 +00:00
if '(EOL)' in e['description']:
2017-07-07 00:11:20 +00:00
branch = '{}, \x1DEOL\x0F'.format(branch)
2017-07-04 13:22:20 +00:00
2017-07-07 00:11:20 +00:00
releases.append('\x02{}\x0F ({})'.format(version, branch))
2017-07-04 13:22:20 +00:00
2017-07-07 00:11:20 +00:00
return '\x02[Kernel]\x0F {}'.format(', '.join(releases))