plugins/aspell_plugin.py
changeset 14 5b5eaf194467
child 16 7a3843e91aa2
equal deleted inserted replaced
13:d3207cb5a777 14:5b5eaf194467
       
     1 #$ neutron_plugin 01
       
     2 
       
     3 import popen2
       
     4 import re
       
     5 
       
     6 ASPELL = "/usr/bin/aspell -a"
       
     7 
       
     8 def handler_aspell(type, source, parameters):
       
     9     parameters = parameters.lstrip().rstrip()
       
    10     splitdata = parameters.split()
       
    11     aspell = ASPELL
       
    12     reply = ""
       
    13 
       
    14     if len(splitdata) > 1:
       
    15         lang = parameters.lower()
       
    16         if re.match(r"\w\w ", lang):
       
    17             parameters = parameters[3:].lstrip()
       
    18             aspell += " --lang=" + lang
       
    19 
       
    20     stdout, stdin = popen2.popen2(aspell)
       
    21 
       
    22     stdin.write(parameters)
       
    23     stdin.close()
       
    24 
       
    25     r = stdout.readline()
       
    26     for r in stdout.readlines():
       
    27         if r == "*\n":
       
    28             reply += "* Word correctly spelled.\n"
       
    29         elif r.startswith("& "):
       
    30             if r.count(": "):
       
    31                 reply += "* Let me suggest " + r[r.find(": ")+2:].strip()
       
    32                 reply += ".\n"
       
    33             else:
       
    34                 reply += r
       
    35 
       
    36     if not reply:
       
    37         reply = "Unknown error"
       
    38 
       
    39     smsg(type, source, reply.rstrip())
       
    40 
       
    41 register_command_handler(handler_aspell, 'aspell', 0, 'Check the spelling',
       
    42 			 'aspell [lang]', ['aspell fr bonjour'])