]> jfr.im git - irc/rizon/acid.git/commitdiff
Squashed commit of the following:
authorAdam <redacted>
Sat, 21 Feb 2015 01:08:44 +0000 (20:08 -0500)
committerAdam <redacted>
Sat, 21 Feb 2015 01:08:44 +0000 (20:08 -0500)
commit 79adda15433e30bdbd3226c42af51e880f6d29f6
Author: Michiel <redacted>
Date:   Wed Jan 14 22:50:26 2015 +0100

    NameRegex now includes http links (for mibbit)

commit 4926cc5552a5c4d71968ac061e418365223891f5
Author: Michiel <redacted>
Date:   Wed Jan 14 17:22:11 2015 +0100

    Fixed error in controlRegex
    ClientName is now first word in version response

commit 70e844c02c72bbcbf9deab7a5b8c4fed4f8ac317
Author: Michiel <redacted>
Date:   Tue Jan 13 20:29:59 2015 +0100

    Updated control regex to remove colour codes

commit 68b814122806073e205cac47715cc70c209c5a38
Author: Michiel <redacted>
Date:   Tue Jan 13 20:18:20 2015 +0100

    Simplified compare fuction in ctcp.cvlist

commit 208ce67bb21ccce9fa41e511f6e2b228b67ee699
Author: Michiel <redacted>
Date:   Tue Jan 13 19:54:05 2015 +0100

    Added current client versions list as requested by Adam.

pyva/pyva/src/main/python/ctcp/ctcp.py

index 59be6837bbaa18b1cb25efc8bce41ca099a76630..5a310803979b21831ffc8b5afcf68d5b374e9825 100644 (file)
@@ -9,6 +9,7 @@ import istring
 from operator import itemgetter #for sort
 from collections import defaultdict
 import time
+import re
 
 from pyva import *
 import logging
@@ -327,6 +328,75 @@ class ctcp(AcidPlugin):
 
                Acidictive.privmsg(self.client, target, "END OF VLIST (%d results)" % count)
                return True
+       
+       # Version regex check link to see what it does:
+       # http://regexper.com/#%28%28%3F%3A\%28%3Fv%3F\d%2B\.[^\s]%2B\%29%3F%29|%28%3F%3AClient%3A\d%2B%3A\d%2B%29%29
+       versionRegex = re.compile("\(?v?(\d+\.[\d\.\-A-z]+)\)?|(Client:\d+:\d+)")
+       nameRegex = re.compile("([http://]*[\.\w+]+)")
+       # regex to strip control codes + colour codes from messages.
+       controlRegex = re.compile(u'([\u0000-\u0002\u0004-\u001F]|\u0003\d{1,2}(?:,\d{1,2}){0,1})')
+       
+       def cmd_ctcpCurrentVersionList(self, source, target, pieces):
+               hasLimit = False
+               showVersions = False
+               limit = 25
+               
+               for piece in pieces:
+                       if hasLimit == False:
+                               try:
+                                       limit = int(piece)
+                                       hasLimit = True
+                                       continue
+                               except ValueError:
+                                       limit = 25
+                       if showVersions == False and piece.lower() == "+versions":
+                               showVersions = True
+               
+               version_list = [];
+               
+               def compare(item1, item2):
+                       return item2['count'] - item1['count']
+
+               def select(list, key, value, newItem):
+                       for item in list:
+                               if item[key] == value:
+                                       return item
+                       else:
+                               list.append(newItem)
+                               return newItem
+
+               for user in User.getUsersC():
+                       try:
+                               cv = self.controlRegex.sub("", user['version'])
+                               clientVersion = self.versionRegex.search(cv)
+                               clientName = nameRegex.search(cv)
+                               try:
+                                       clientName = clientName.group(0)
+                               except:
+                                       continue
+                               item = select(version_list, 'name', clientName, { 'name': clientName, 'count': 0, 'versions': [] })
+                               item['count'] += 1
+                               if clientVersion.group(1) != None:
+                                       v = clientVersion.group(1)
+                                       version = select(item['versions'], 'version', v, { 'version': v, 'count': 0 })
+                                       version['count'] += 1
+                       except AttributeError:
+                               continue
+
+               version_list.sort(cmp=compare)
+               
+               counter = 0
+               
+               for item in version_list:
+                       Acidictive.privmsg(self.client, target, u"%s [%s %s]" % (item['name'], item['count'], 'time' if item['count'] == 1 else 'times'))
+                       if showVersions:
+                               item['versions'].sort(cmp=compare)
+                               for version in item['versions']:
+                                       Acidictive.privmsg(self.client, target, u"    %s [%s %s]" % (version['version'], version['count'], 'time' if version['count'] == 1 else 'times'))
+                       
+                       counter += 1
+                       if counter >= limit:
+                               return
 
 ## End Command hooks
 
@@ -363,4 +433,8 @@ class ctcp(AcidPlugin):
                         'permission': 'v',
                         'callback': self.cmd_ctcpVersionList,
                         'usage': "{top|search} [num|searchstring] - shows the top client version replies or searches them. Defaults to showing top"}),
+                       ('cvlist', {
+                        'permission': 'v',
+                        'callback': self.cmd_ctcpCurrentVersionList,
+                        'usage': "[limit] [+versions] - Shows the client types, and their version numbers (when +versions is provided as argument), currently online. Default limit is 25."}),
                )