Update to freenode's new capability mechanism
[people/stefanha/gpxebot.git] / cmds.py
diff --git a/cmds.py b/cmds.py
index b3d57e0..82defdf 100644 (file)
--- a/cmds.py
+++ b/cmds.py
@@ -88,24 +88,28 @@ def errcode_command(who, _, replyto, words):
 commands['errcode'] = errcode_command
 commands['error'] = errcode_command
 
-PCI_ID_RE = re.compile(r'([0-9a-fA-F]{4}):([0-9a-fA-F]{4})')
-
 def lspci_command(who, _, replyto, words):
     '''Look up driver for PCI ID (lspci 10ec:8139)'''
-    if len(words) != 2:
+    ids = []
+    if len(words) == 2:
+        ids = words[1].split(':')
+    elif len(words) == 3:
+        ids = words[1:3]
+    if len(ids) != 2:
         return 'PRIVMSG', (replyto, 'Invalid arguments')
 
-    m = PCI_ID_RE.match(words[1])
-    if not m:
+    try:
+        vendor_id, device_id = [int(s, 16) for s in ids]
+    except ValueError:
         return 'PRIVMSG', (replyto, 'Invalid arguments')
-    pci_id = '%s,%s' % tuple(s.lower() for s in m.groups())
+    pci_id = '%04x,%04x' % (vendor_id, device_id)
 
     try:
         for line in open(config.NICFILE):
-            line = line.strip()
+            line = line.rstrip('\r\n')
             if not line or line.startswith('#'):
                 continue
-            fields = line.split()
+            fields = line.split('\t')
 
             if fields[0] == 'family':
                 driver = fields[1].split('/')[-1]