mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 14:14:37 +01:00
Added fortune command and some more tests.
This commit is contained in:
parent
56117a0662
commit
ad8159751f
@ -52,16 +52,22 @@ import utils
|
|||||||
def configure(onStart, afterConnect, advanced):
|
def configure(onStart, afterConnect, advanced):
|
||||||
from questions import expect, anything, something, yn
|
from questions import expect, anything, something, yn
|
||||||
onStart.append('load Unix')
|
onStart.append('load Unix')
|
||||||
cmdLine = utils.findBinaryInPath('aspell')
|
spellCmd = utils.findBinaryInPath('aspell')
|
||||||
if not cmdLine:
|
if not spellCmd:
|
||||||
cmdLine = utils.findBinaryInPath('ispell')
|
cmdLine = utils.findBinaryInPath('ispell')
|
||||||
if not cmdLine:
|
if not spellCmd:
|
||||||
print 'NOTE: I couldn\'t find aspell or ispell in your path,'
|
print 'NOTE: I couldn\'t find aspell or ispell in your path,'
|
||||||
print 'so that function of this module will not work. You may'
|
print 'so that function of this module will not work. You may'
|
||||||
print 'choose to install it later, and then the module will'
|
print 'choose to install it later. To re-enable this command then, '
|
||||||
print 'automatically work, as long as it is in the path of the'
|
print 'remove the "disable spell" line from your configuration file.'
|
||||||
print 'user that supybot runs under.'
|
onStart.append('disable spell')
|
||||||
print
|
fortuneCmd = utils.findBinaryInPath('fortune')
|
||||||
|
if not fortuneCmd:
|
||||||
|
print 'NOTE: I couldn\'t find fortune in your path, so that function '
|
||||||
|
print 'of this module will not work. You may choose to install it '
|
||||||
|
print 'later. To re-enable this command then, remove the '
|
||||||
|
print '"disable fortune" command from your configuration file.'
|
||||||
|
onStart.append('disable fortune')
|
||||||
|
|
||||||
print 'The "progstats" command can reveal potentially sensitive'
|
print 'The "progstats" command can reveal potentially sensitive'
|
||||||
print 'information about your machine. Here\'s an example of its output:'
|
print 'information about your machine. Here\'s an example of its output:'
|
||||||
@ -86,17 +92,17 @@ class Unix(callbacks.Privmsg):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
# Initialize a file descriptor for the spell module.
|
# Initialize a file descriptor for the spell module.
|
||||||
cmdLine = utils.findBinaryInPath('aspell')
|
spellCmd = utils.findBinaryInPath('aspell')
|
||||||
if not cmdLine:
|
if not spellCmd:
|
||||||
cmdLine = utils.findBinaryInPath('ispell')
|
spellCmd = utils.findBinaryInPath('ispell')
|
||||||
(self._spellRead, self._spellWrite) = popen2.popen4(cmdLine + ' -a', 0)
|
(self._spellRead, self._spellWrite) = popen2.popen4([spellCmd, '-a'],0)
|
||||||
# Ignore the banner
|
self._spellRead.readline() # Ignore the banner.
|
||||||
self._spellRead.readline()
|
self.fortuneCmd = utils.findBinaryInPath('fortune')
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
# close the filehandles
|
# close the filehandles
|
||||||
for h in (self._spellRead, self._spellWrite):
|
for h in (self._spellRead, self._spellWrite):
|
||||||
h.close()
|
h.close()
|
||||||
|
|
||||||
def errno(self, irc, msg, args):
|
def errno(self, irc, msg, args):
|
||||||
"""<error number or code>
|
"""<error number or code>
|
||||||
@ -179,6 +185,17 @@ class Unix(callbacks.Privmsg):
|
|||||||
resp = 'Something unexpected was seen in the [ai]spell output.'
|
resp = 'Something unexpected was seen in the [ai]spell output.'
|
||||||
irc.reply(msg, resp)
|
irc.reply(msg, resp)
|
||||||
|
|
||||||
|
def fortune(self, irc, msg, args):
|
||||||
|
"""takes no arguments
|
||||||
|
|
||||||
|
Returns a fortune from the *nix fortune program.
|
||||||
|
"""
|
||||||
|
(r, w) = popen2.popen4('%s -s' % self.fortuneCmd)
|
||||||
|
s = r.read()
|
||||||
|
w.close()
|
||||||
|
r.close()
|
||||||
|
irc.reply(msg, ' '.join(s.split()))
|
||||||
|
|
||||||
|
|
||||||
Class = Unix
|
Class = Unix
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
@ -33,7 +33,6 @@ from test import *
|
|||||||
|
|
||||||
class UnixTestCase(PluginTestCase):
|
class UnixTestCase(PluginTestCase):
|
||||||
plugins = ('Unix',)
|
plugins = ('Unix',)
|
||||||
|
|
||||||
def testSpell(self):
|
def testSpell(self):
|
||||||
self.assertRegexp('spell Strike', 'correctly')
|
self.assertRegexp('spell Strike', 'correctly')
|
||||||
self.assertRegexp('spell asdlkfjasdlfkjsdalfkjasdflkasjdflskdfjlsd',
|
self.assertRegexp('spell asdlkfjasdlfkjsdalfkjasdflkasjdflskdfjlsd',
|
||||||
@ -41,4 +40,19 @@ class UnixTestCase(PluginTestCase):
|
|||||||
self.assertNotError('spell Strizzike')
|
self.assertNotError('spell Strizzike')
|
||||||
self.assertError('spell foo bar baz')
|
self.assertError('spell foo bar baz')
|
||||||
|
|
||||||
|
def testErrno(self):
|
||||||
|
self.assertRegexp('errno 12', '^ENOMEM')
|
||||||
|
self.assertRegexp('errno ENOMEM', '#12')
|
||||||
|
|
||||||
|
def testProgstats(self):
|
||||||
|
self.assertNotError('progstats')
|
||||||
|
|
||||||
|
def testCrypt(self):
|
||||||
|
self.assertNotError('crypt jemfinch')
|
||||||
|
|
||||||
|
def testFortune(self):
|
||||||
|
self.assertNotError('fortune')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user