#$ neutron_plugin 01
import popen2
import re
ASPELL = "/usr/bin/aspell -a"
def handler_aspell(type, source, parameters):
parameters = parameters.lstrip().rstrip()
splitdata = parameters.split()
aspell = ASPELL
reply = ""
if len(splitdata) > 1:
lang = parameters.lower()
if re.match(r"\w\w ", lang):
parameters = parameters[3:].lstrip()
aspell += " --lang=" + lang
stdout, stdin = popen2.popen2(aspell)
stdin.write(parameters.encode('iso-8859-15'))
stdin.close()
r = stdout.readline()
for r in stdout.readlines():
r = r.decode('iso-8859-15')
if r == "*\n":
reply += "* Word correctly spelled.\n"
elif r.startswith("& "):
if r.count(": "):
reply += "* Let me suggest " + r[r.find(": ")+2:].strip()
reply += ".\n"
else:
reply += r
if not reply:
reply = "Unknown error"
smsg(type, source, reply.rstrip())
register_command_handler(handler_aspell, 'aspell', 0, 'Check the spelling',
'aspell [lang]', ['aspell fr bonjour'])