<commit_before>"""
@date: 2021-02-06
@author: HelleDaryd
"""

from twisted.plugin import IPlugin
from zope.interface import implementer

from desertbot.message import IRCMessage
from desertbot.moduleinterface import IModule
from desertbot.modules.commandinterface import BotCommand
import re2 as re

WIKIPEDIA_URL_RE = re.compile(r"(?i)en\.wikipedia\.org/wiki/(?P<title>[^#\s]+)(?:#(?P<section>\S+))?")
@implementer(IPlugin, IModule)
class Wikipedia(BotCommand):
    def actions(self):
        return super(Wikipedia, self).actions() + [('urlfollow', 2, self.follow)]

    def help(self, query):
        return 'Automatic module that follows English Wikipedia URLs'

    def follow(self, _: IRCMessage, url: str) -> [str, None]:
        match = WIKIPEDIA_URL_RE.search(url)
        if not match:
            return

        title = match.group('title')
        section = match.group('section')

        response = self.bot.moduleHandler.runActionUntilValue("wikipedia", title, section)
        if response:
            return str(response), url
        return

wikipedia = Wikipedia()<commit_msg>Allow for mobile Wikipedia URLs<commit_after>"""
@date: 2021-02-06
@author: HelleDaryd
"""

from twisted.plugin import IPlugin
from zope.interface import implementer

from desertbot.message import IRCMessage
from desertbot.moduleinterface import IModule
from desertbot.modules.commandinterface import BotCommand
import re2 as re

WIKIPEDIA_URL_RE = re.compile(r"(?i)en\.(?:m.)?wikipedia\.org/wiki/(?P<title>[^#\s]+)(?:#(?P<section>\S+))?")
@implementer(IPlugin, IModule)
class Wikipedia(BotCommand):
    def actions(self):
        return super(Wikipedia, self).actions() + [('urlfollow', 2, self.follow)]

    def help(self, query):
        return 'Automatic module that follows English Wikipedia URLs'

    def follow(self, _: IRCMessage, url: str) -> [str, None]:
        match = WIKIPEDIA_URL_RE.search(url)
        if not match:
            return

        title = match.group('title')
        section = match.group('section')

        response = self.bot.moduleHandler.runActionUntilValue("wikipedia", title, section)
        if response:
            return str(response), url
        return

wikipedia = Wikipedia()
{'fraction_non_alphanumeric': 0.12719891745602166, 'fraction_numerical': 0.009021199819576003, 'mean_word_length': 3.679324894514768, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7235926', 'n_tokens_mistral': 698, 'n_tokens_neox': 659, 'n_words': 169}