from operator import itemgetter #for sort
from collections import defaultdict
import time
+import re
from pyva import *
import logging
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
'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."}),
)