chiark / gitweb /
Improve debug and chat notation for cmd messages
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 17 May 2009 10:46:28 +0000 (11:46 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 17 May 2009 10:46:28 +0000 (11:46 +0100)
yoweb-scrape

index 7db7afa..29af391 100755 (executable)
@@ -557,26 +557,30 @@ class ChatLogTracker:
                m = rm('(\\w+) abandoned a (\\S.*\\S) station\\.$')
                if m: oba('stopped'); return d("end")
 
-               def chat(what):
-                       who = m.group(1)
-                       try: pa = self._pl[who]
-                       except KeyError: return d('chat mystery')
-                       if pa.v is self._v:
-                               pa.last_chat_time = timestamp
-                               pa.last_chat_chan = what
-                               self.force_redisplay()
-                               return d('chat '+what)
-
-               def chat_metacmd(what):
+               def chat_core(speaker, chan):
+                       try: pa = self._pl[speaker]
+                       except KeyError: return 'mystery'
+                       if pa.v is not self._v: return 'elsewhere'
+                       pa.last_chat_time = timestamp
+                       pa.last_chat_chan = chan
+                       self.force_redisplay()
+                       return 'here'
+
+               def chat(chan):
+                       speaker = m.group(1)
+                       dm = chat_core(speaker, chan)
+                       return d('chat %s %s' % (chan, dm))
+
+               def chat_metacmd(chan):
                        (cmdr, metacmd) = m.groups()
                        metacmd = regexp.sub('\\s+', ' ', metacmd).strip()
                        m2 = regexp.match(
                                '/([ad]) (?:([A-Za-z ]+)\\s*:)?([A-Za-z ]+)$',
                                metacmd)
-                       if not m2: return chat(what)
+                       if not m2: return chat(chan)
 
                        (cmd, vn, targets) = m2.groups()
-                       dml = ['metachat', cmd]
+                       dml = ['cmd', chan, cmd]
 
                        if cmd == 'a': each = self._onboard_event
                        else: each = disembark
@@ -604,15 +608,15 @@ class ChatLogTracker:
                        else:
                                dml.append('unk-abbrev')
 
-                       if v is None:
-                               return d(' '.join(dml))
+                       if v is not None:
+                               targets = targets.strip().split(' ')
+                               dml.append(`len(targets)`)
+                               for target in targets:
+                                       each(v, timestamp, target.title(), how)
 
-                       targets = targets.strip().split(' ')
-                       dml.append(`len(targets)`)
-                       for target in targets:
-                               each(v, timestamp, target.title(), how)
-
-                       return d(' '.join(dml))
+                       dm = ' '.join(dml)
+                       chat_core(cmdr, 'cmd '+chan)
+                       return d(dm)
 
                m = rm('(\\w+) (?:issued an order|ordered everyone) "')
                if m: return ob1('general order');