comparison plugins/xxnote.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 c54768cffbd4
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 # !openrpg : instance of the the base openrpg control
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 = 'Quick Notes'
14 self.author = 'Dj Gilcrease'
15 self.help = "This plugin lets you take quick notes on a subject"
16 self.notes = {}
17
18
19 def plugin_enabled(self):
20 self.notes = self.plugindb.GetDict("xxnote", "notes", {})
21
22 self.plugin_addcommand('/newnote', self.on_newnote, '{Subject} - Will create a new note subject')
23 self.plugin_addcommand('/appendnote', self.on_appendnote, '{Subject}={Note} - Will append a note to {Subject}')
24 self.plugin_addcommand('/delnote', self.on_delnote, '{Subject}={Note_id}|all - Will delete {Note_id} from {Subject} or will delete the subject compleatly')
25 self.plugin_addcommand('/editnote', self.on_editnote, '{Subject}={Note_id} {Note} - Will replace {Note_id} with {Note} for {Subject}')
26 self.plugin_addcommand('/clearnotes', self.on_clearnotes, '- Will clear all of your notes')
27 self.plugin_addcommand('/listnotes', self.on_listnotes, '- Will list all of the note subjects you have')
28 self.plugin_addcommand('/viewnote', self.on_viewnote, '{Subject} - Will display the notes you have for {Subject}')
29 self.plugin_addcommand('/notetonode', self.on_notetonode, '{Subject} - Will create a text node containing your notes for {Subject}')
30 self.plugin_addcommand('/notehelp', self.on_notehelp, '- Will Display the help for each command of this plugin!')
31
32
33 def plugin_disabled(self):
34 self.plugin_removecmd('/newnote')
35 self.plugin_removecmd('/appendnote')
36 self.plugin_removecmd('/editnote')
37 self.plugin_removecmd('/delnote')
38 self.plugin_removecmd('/listnotes')
39 self.plugin_removecmd('/viewnote')
40 self.plugin_removecmd('/notetonode')
41 self.plugin_removecmd('/notehelp')
42 self.plugin_removecmd('/clearnotes')
43
44 def on_newnote(self, cmdargs):
45 if len(cmdargs) == 0:
46 self.on_notehelp('')
47 return
48
49 subject = cmdargs
50 if not self.notes.has_key(subject):
51 self.notes[subject] = []
52 self.plugindb.SetDict("xxnote", "notes", self.notes)
53 self.chat.InfoPost("Created new note for " + subject)
54 else:
55 self.chat.InfoPost("You already have a note with the subject " + subject)
56
57 def on_appendnote(self, cmdargs):
58 args = cmdargs.split("=",-1)
59 if len(args) < 2:
60 self.on_notehelp('')
61 return
62
63 subject = args[0]
64 note = args[1]
65 if not self.notes.has_key(subject):
66 self.notes[subject] = []
67 self.notes[subject].append(note)
68 self.plugindb.SetDict("xxnote", "notes", self.notes)
69 self.chat.InfoPost("Created new note for " + subject)
70 else:
71 self.notes[subject].append(note)
72 self.plugindb.SetDict("xxnote", "notes", self.notes)
73 self.chat.InfoPost("Appended <i>" + note + "</i> to <b>" + subject + "</b>")
74
75 self.on_viewnote(subject)
76
77 def on_editnote(self, cmdargs):
78 args = cmdargs.split("=",-1)
79 if len(args) < 2:
80 self.on_notehelp('')
81 return
82
83 s = args[1].find(" ")
84 subject = args[0]
85 note_id = int(args[1][:s])
86 note = args[1][s:]
87 if not self.notes.has_key(subject):
88 self.notes[subject] = []
89 self.notes[subject].append(note)
90 self.plugindb.SetDict("xxnote", "notes", self.notes)
91 self.chat.InfoPost("Created new note for " + subject)
92 else:
93 self.notes[subject][note_id] = note
94 self.plugindb.SetDict("xxnote", "notes", self.notes)
95 self.chat.InfoPost("Edited <i>" + str(note_id) + ': ' + note + "</i> to <b>" + subject + "</b>")
96
97 self.on_viewnote(subject)
98
99 def on_delnote(self, cmdargs):
100 args = cmdargs.split("=",-1)
101 if len(args) < 2:
102 self.on_notehelp('')
103 return
104
105 subject = args[0]
106 noteid = args[1]
107
108 if noteid == 'all':
109 del self.notes[subject]
110 self.plugindb.SetDict("xxnote", "notes", self.notes)
111 self.chat.InfoPost("Removed subject " + subject)
112 else:
113 del self.notes[subject][int(noteid)]
114 self.plugindb.SetDict("xxnote", "notes", self.notes)
115 self.chat.InfoPost("Removed note " + noteid + " from subject " + subject)
116 self.on_viewnote(subject)
117
118 def on_clearnotes(self, cmdargs):
119 self.notes = {}
120 self.plugindb.SetDict("xxnote", "notes", self.notes)
121 self.chat.InfoPost("Cleared all of your notes")
122
123 def on_listnotes(self, cmdargs):
124 if len(self.notes) == 0:
125 self.chat.InfoPost("You have no notes at this time, use /newnote to create one")
126 return
127 self.chat.InfoPost("The subjects you have notes on are:")
128 for subject in self.notes.keys():
129 self.chat.InfoPost("** " + subject)
130
131 def on_viewnote(self, cmdargs):
132 if len(cmdargs) == 0:
133 self.on_notehelp('')
134 return
135
136 subject = cmdargs
137 if self.notes.has_key(subject):
138 msg = '<table bgcolor="#cccccc"><tr><td colspan="2"><b><font color="#000000">Notes for '
139 msg += subject
140 msg += ':</font></b></td></tr><tr><td width="10">ID</td><td>Note Text</td></tr>'
141 noteid = 0
142 for n in self.notes[subject]:
143 msg += '<tr><td width="10"><font color="#000000">'
144 msg += str(noteid)
145 msg += '</font></td>'
146 msg += '<td><font color="#000000">'
147 msg += n
148 msg += '</font></td></tr>'
149 noteid += 1
150
151 msg += '</table>'
152 self.chat.InfoPost(msg)
153 else:
154 self.chat.InfoPost("You have no notes for " + subject)
155
156 def on_notetonode(self, cmdargs):
157 if len(cmdargs) == 0:
158 self.on_notehelp('')
159 return
160
161 subject = cmdargs
162 if self.notes.has_key(subject):
163 node = '<nodehandler class="textctrl_handler" icon="note" module="forms" name="'
164 node += subject
165 node += '" version="1.0"><text multiline="1" send_button="1">'
166 for note in self.notes[subject]:
167 node += note + "\n"
168 node += '</text></nodehandler>'
169 self.gametree.insert_xml(node)
170 else:
171 self.chat.InfoPost("You have no notes for " + subject)
172
173 def on_notehelp(self, cmdargs):
174 self.chat.InfoPost('/newnote ' + self.cmdlist['/newnote']['help'])
175 self.chat.InfoPost('/appendnote ' + self.cmdlist['/appendnote']['help'])
176 self.chat.InfoPost('/delnote ' + self.cmdlist['/delnote']['help'])
177 self.chat.InfoPost('/listnotes ' + self.cmdlist['/listnotes']['help'])
178 self.chat.InfoPost('/clearnotes ' + self.cmdlist['/clearnotes']['help'])
179 self.chat.InfoPost('/notetonode ' + self.cmdlist['/notetonode']['help'])
180 self.chat.InfoPost('/viewnote ' + self.cmdlist['/viewnote']['help'])