comparison plugins/xxspell.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children 15488fe94f52
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 import os
2 import orpg.pluginhandler
3
4 class Plugin(orpg.pluginhandler.PluginHandler):
5 # Initialization subroutine.
6 #
7 # !self : instance of self
8 # !chat : instance of the chat window to write to
9 def __init__(self, plugindb, parent):
10 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
11
12 # The Following code should be edited to contain the proper information
13 self.name = 'Spelling Checker (aka Autoreplace)'
14 self.author = 'Woody, mDuo13'
15 self.help = "This plugin automatically replaces certain keys with other ones wheneve\nr"
16 self.help += "it sees them. You can edit this plugin to change what it replaces. This one\n"
17 self.help += "even corrects other people's spelling."
18 self.checklist = {}
19
20 def plugin_enabled(self):
21 #This is where you set any variables that need to be initalized when your plugin starts
22 #You can add new /commands like
23 self.plugin_addcommand("/spell", self.on_spell, "[add {bad_word} {new_word} | list | remove {bad_word}] - This function allows you to add words to be auto replaced when they are sent or recived. If you want either word to have a space in it you will need to use the _ (underscore) as a space, it will be replaced with a space before it is added to the check list")
24 self.checklist = self.plugindb.GetDict("xxspell", "checklist", {})
25
26 def plugin_disabled(self):
27 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin
28 #such as closing windows created by the plugin
29 self.plugin_removecmd('/spell')
30
31 def replace(self, text):
32 for a in self.checklist.keys():
33 text = text.replace(a, self.checklist[a])
34 return text
35
36 def plugin_incoming_msg(self, text, type, name, player):
37 text = self.replace(text)
38 return text, type, name
39
40 def pre_parse(self, text):
41 text = self.replace(text)
42 return text
43
44 def on_spell(self, cmdargs):
45 args = cmdargs.split(None,-1)
46 if len(args) == 0:
47 args = [' ']
48 if args[0] == 'list':
49 self.chat.InfoPost(self.make_list())
50 elif args[0] == 'remove':
51 args = self.create_spaces(args)
52 if self.checklist.has_key(args[1]):
53 del self.checklist[args[1]]
54 self.plugindb.SetDict("xxspell", "checklist", self.checklist)
55 self.chat.InfoPost("%s removed from the check list" % args[1])
56 else:
57 self.chat.InfoPost("%s was not in the check list" % args[1])
58 elif args[0] == 'add':
59 args = self.create_spaces(args)
60 self.checklist[args[1]] = args[2]
61 self.plugindb.SetDict("xxspell", "checklist", self.checklist)
62 self.chat.InfoPost("%s will now be replaced by %s" % (args[1], args[2]))
63 else:
64 helptxt = "Spelling Command Help:<br />"
65 helptxt += "<b>/spell add bad_word new_word</b> - Here it is important to remember that any spaces in your bad or new words needs to be type as _ (an underscore).<br />"
66 helptxt += "<b>/spell remove bad_word</b> - Here it is important to remember that any spaces in your bad word needs to be type as _ (an underscore).<br />"
67 helptxt += "<b>/spell list</b> - This will list all of the bad words you are checking for, along with thier replacements.<br />"
68 self.chat.InfoPost(helptxt)
69
70
71 def create_spaces(self, list):
72 i = 0
73 for n in list:
74 list[i] = n.replace("_"," ")
75 i += 1
76 return list
77
78 def make_list(self):
79 keychain = self.checklist.keys()
80 lister = ""
81 for key in keychain:
82 lister += "<b>" + key.replace("<","&lt;").replace(">","&gt;") + "</b> :: <b>" + self.checklist[key].replace("<","&lt;").replace(">","&gt;") + "</b><br />"
83 if len(keychain)==0:
84 return "No variables!"
85 else:
86 return lister