<commit_before>from IRCMessage import IRCMessage
from IRCResponse import IRCResponse, ResponseType
from Function import Function
import FunctionData
import WebUtils

import re, datetime

class Instantiate(Function):
    Help = "lrr (<series>) - returns a link to the latest LRR video, or the latest of a series if you specify one"
    
    def GetResponse(self, message):
        if message.Type != 'PRIVMSG':
            return
        
        match = re.search('lrr|llr', message.Command, re.IGNORECASE)
        if not match:
            return
        
        if len(message.Parameters.strip()) > 0:
            feed = self.handleAliases(message.Parameters)
            lowerMap = dict(zip(map(lambda x:x.lower(),FunctionData.LRRChecker.iterkeys()),FunctionData.LRRChecker.iterkeys()))
            if feed.lower() in lowerMap:
                feedName = lowerMap[feed.lower()]
                feedLatest = FunctionData.LRRChecker[feedName]['lastTitle']
                feedLink = FunctionData.LRRChecker[feedName]['lastLink']
                
                response = 'Latest {0}: {1} | {2}'.format(feedName, feedLatest, feedLink)
                
                return IRCResponse(ResponseType.Say, response, message.ReplyTo)
                
            return IRCResponse(ResponseType.Say, "{0} is not one of the LRR series being monitored (leave a |tell for Tyranic-Moron if it's a new series or should be an alias!)".format(message.Parameters.strip()), message.ReplyTo)
        else:
            latestDate = datetime.datetime.utcnow() - datetime.timedelta(days=365*10)
            latestFeed = None
            latestTitle = None
            latestLink = None
            for feedName, feedDeets in FunctionData.LRRChecker.iteritems():
                if feedDeets['lastUpdate'] > latestDate:
                    latestDate = feedDeets['lastUpdate']
                    latestFeed = feedName
                    latestTitle = feedDeets['lastTitle']
                    latestLink = feedDeets['lastLink']
                    
            response = 'Latest {0}: {1} | {2}'.format(latestFeed, latestTitle, latestLink)
            return IRCResponse(ResponseType.Say, response, message.ReplyTo)

    def handleAliases(self, series):
        for feedName, feedDeets in FunctionData.LRRChecker.iteritems():
            if series.lower() in feedDeets['aliases']:
                return feedName
        return series

<commit_msg>Change LRR Help to a property to include the series in it<commit_after>from IRCMessage import IRCMessage
from IRCResponse import IRCResponse, ResponseType
from Function import Function
import FunctionData
import WebUtils

import re, datetime

class Instantiate(Function):
    @property
    def Help(self):
        return "lrr (<series>) - returns a link to the latest LRR video, or the latest of a series if you specify one; series are: {0}".format(", ".join(FunctionData.LRRChecker.keys())))
    
    def GetResponse(self, message):
        if message.Type != 'PRIVMSG':
            return
        
        match = re.search('lrr|llr', message.Command, re.IGNORECASE)
        if not match:
            return
        
        if len(message.Parameters.strip()) > 0:
            feed = self.handleAliases(message.Parameters)
            lowerMap = dict(zip(map(lambda x:x.lower(),FunctionData.LRRChecker.iterkeys()),FunctionData.LRRChecker.iterkeys()))
            if feed.lower() in lowerMap:
                feedName = lowerMap[feed.lower()]
                feedLatest = FunctionData.LRRChecker[feedName]['lastTitle']
                feedLink = FunctionData.LRRChecker[feedName]['lastLink']
                
                response = 'Latest {0}: {1} | {2}'.format(feedName, feedLatest, feedLink)
                
                return IRCResponse(ResponseType.Say, response, message.ReplyTo)
                
            return IRCResponse(ResponseType.Say, "{0} is not one of the LRR series being monitored (leave a |tell for Tyranic-Moron if it's a new series or should be an alias!)".format(message.Parameters.strip()), message.ReplyTo)
        else:
            latestDate = datetime.datetime.utcnow() - datetime.timedelta(days=365*10)
            latestFeed = None
            latestTitle = None
            latestLink = None
            for feedName, feedDeets in FunctionData.LRRChecker.iteritems():
                if feedDeets['lastUpdate'] > latestDate:
                    latestDate = feedDeets['lastUpdate']
                    latestFeed = feedName
                    latestTitle = feedDeets['lastTitle']
                    latestLink = feedDeets['lastLink']
                    
            response = 'Latest {0}: {1} | {2}'.format(latestFeed, latestTitle, latestLink)
            return IRCResponse(ResponseType.Say, response, message.ReplyTo)

    def handleAliases(self, series):
        for feedName, feedDeets in FunctionData.LRRChecker.iteritems():
            if series.lower() in feedDeets['aliases']:
                return feedName
        return series


{'fraction_non_alphanumeric': 0.09252045188936502, 'fraction_numerical': 0.005259057265290222, 'mean_word_length': 2.0971049457177324, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1304711', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1335, 'n_words': 354}