mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-03 01:39:23 +01:00
Rewrote dict command.
This commit is contained in:
parent
c99f68894a
commit
fa53cf34d5
@ -35,9 +35,10 @@ Various commands that depend on Twisted <http://www.twistedmatrix.com/>.
|
|||||||
|
|
||||||
from baseplugin import *
|
from baseplugin import *
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
from twisted.protocols import dict
|
from twisted.protocols import dict
|
||||||
|
|
||||||
import debug
|
|
||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
@ -58,16 +59,26 @@ class TwistedCommands(callbacks.Privmsg):
|
|||||||
irc.error(msg, failure.getErrorMessage())
|
irc.error(msg, failure.getErrorMessage())
|
||||||
return errback
|
return errback
|
||||||
|
|
||||||
|
dictnumberre = re.compile('^\d+:\s*(.*)$')
|
||||||
def dictCallback(self, irc, msg, word):
|
def dictCallback(self, irc, msg, word):
|
||||||
def formatDictResults(definitions):
|
def formatDictResults(definitions):
|
||||||
L = []
|
defs = []
|
||||||
for definition in definitions:
|
for definition in definitions:
|
||||||
L.append(' '.join(definition.text))
|
definition.text.pop(0)
|
||||||
if not L:
|
lines = map(str.strip, map(str, definition.text))
|
||||||
|
L = []
|
||||||
|
for line in lines:
|
||||||
|
m = self.dictnumberre.match(line)
|
||||||
|
if m:
|
||||||
|
defs.append(' '.join(L))
|
||||||
|
L = []
|
||||||
|
L.append(m.group(1))
|
||||||
|
else:
|
||||||
|
L.append(line)
|
||||||
|
if not defs:
|
||||||
irc.reply(msg, '%s appears to have no definition.' % word)
|
irc.reply(msg, '%s appears to have no definition.' % word)
|
||||||
return
|
return
|
||||||
s = ircutils.privmsgPayload(L, ', or ', 400).encode('utf-8')
|
s = ircutils.privmsgPayload(defs, ', or ', 400).encode('utf-8')
|
||||||
s = ' '.join(s.split()) # Normalize whitespace.
|
|
||||||
irc.reply(msg, s)
|
irc.reply(msg, s)
|
||||||
return formatDictResults
|
return formatDictResults
|
||||||
|
|
||||||
@ -82,6 +93,10 @@ class TwistedCommands(callbacks.Privmsg):
|
|||||||
deferred.addErrback(self.defaultErrback(irc, msg))
|
deferred.addErrback(self.defaultErrback(irc, msg))
|
||||||
|
|
||||||
|
|
||||||
|
class TwistedRegexp(callbacks.PrivmsgRegexp):
|
||||||
|
def dccrecv(self, irc, msg, match):
|
||||||
|
r""
|
||||||
|
|
||||||
|
|
||||||
Class = TwistedCommands
|
Class = TwistedCommands
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user