comparison orpg/chat/commands.py @ 71:449a8900f9ac ornery-dev

Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author sirebral
date Thu, 20 Aug 2009 03:00:39 -0500
parents 4385a7d0efd1
children eb1b275699c4
comparison
equal deleted inserted replaced
70:52a5fa913008 71:449a8900f9ac
12 import time 12 import time
13 import orpg.orpg_version 13 import orpg.orpg_version
14 import orpg.orpg_windows 14 import orpg.orpg_windows
15 import traceback 15 import traceback
16 16
17 from orpg.tools.orpg_log import logger
18 from orpg.tools.decorators import debugging
19
17 ##-------------------------------------------------------------- 20 ##--------------------------------------------------------------
18 ## dynamically loading module for extended developer commands 21 ## dynamically loading module for extended developer commands
19 ## allows developers to work on new chat commands without 22 ## allows developers to work on new chat commands without
20 ## integrating them directly into the ORPG code allowing 23 ## integrating them directly into the ORPG code allowing
21 ## updating of their code without merging changes 24 ## updating of their code without merging changes
34 37
35 # Initialization subroutine. 38 # Initialization subroutine.
36 # 39 #
37 # !self : instance of self 40 # !self : instance of self
38 # !chat : instance of the chat window to write to 41 # !chat : instance of the chat window to write to
42 @debugging
39 def __init__(self,chat): 43 def __init__(self,chat):
40 self.post = chat.Post 44 self.post = chat.Post
41 self.colorize = chat.colorize 45 self.colorize = chat.colorize
42 self.session = chat.session 46 self.session = chat.session
43 #self.send = chat.session.send 47 #self.send = chat.session.send
54 # This subroutine will take a text string and attempt to match to a series 58 # This subroutine will take a text string and attempt to match to a series
55 # of implemented emotions. 59 # of implemented emotions.
56 # 60 #
57 # !self : instance of self 61 # !self : instance of self
58 # !text : string of text matching an implemented emotion 62 # !text : string of text matching an implemented emotion
63 @debugging
59 def addcommand(self, cmd, function, helpmsg): 64 def addcommand(self, cmd, function, helpmsg):
60 if not self.cmdlist.has_key(cmd) and not self.shortcmdlist.has_key(cmd): 65 if not self.cmdlist.has_key(cmd) and not self.shortcmdlist.has_key(cmd):
61 self.cmdlist[cmd] = {} 66 self.cmdlist[cmd] = {}
62 self.cmdlist[cmd]['function'] = function 67 self.cmdlist[cmd]['function'] = function
63 self.cmdlist[cmd]['help'] = helpmsg 68 self.cmdlist[cmd]['help'] = helpmsg
64 #print 'Command Added: ' + cmd 69 #print 'Command Added: ' + cmd
65 70
71 @debugging
66 def addshortcmd(self, shortcmd, longcmd): 72 def addshortcmd(self, shortcmd, longcmd):
67 if not self.shortcmdlist.has_key(shortcmd) and not self.cmdlist.has_key(shortcmd): 73 if not self.shortcmdlist.has_key(shortcmd) and not self.cmdlist.has_key(shortcmd):
68 self.shortcmdlist[shortcmd] = longcmd 74 self.shortcmdlist[shortcmd] = longcmd
69 75
76 @debugging
70 def removecmd(self, cmd): 77 def removecmd(self, cmd):
71 if self.cmdlist.has_key(cmd): 78 if self.cmdlist.has_key(cmd):
72 del self.cmdlist[cmd] 79 del self.cmdlist[cmd]
73 elif self.shortcmdlist.has_key(cmd): 80 elif self.shortcmdlist.has_key(cmd):
74 del self.shortcmdlist[cmd] 81 del self.shortcmdlist[cmd]
75 82
76 #print 'Command Removed: ' + cmd 83 #print 'Command Removed: ' + cmd
77 84
78 85
86 @debugging
79 def defaultcmds(self): 87 def defaultcmds(self):
80 self.addcommand('/help', self.on_help, '- Displays this help message') 88 self.addcommand('/help', self.on_help, '- Displays this help message')
81 self.addcommand('/version', self.on_version, ' - Displays current version of OpenRPG.') 89 self.addcommand('/version', self.on_version, ' - Displays current version of OpenRPG.')
82 self.addcommand('/me', self.chat.emote_message, ' - Alias for **yourname does something.**') 90 self.addcommand('/me', self.chat.emote_message, ' - Alias for **yourname does something.**')
83 self.addcommand('/ignore', self.on_ignore, '[player_id,player_id,... | ignored_ip,ignored_ip,... | list] - Toggle ignore for user associated with that player ID. Using the IP will remove only not toggle.') 91 self.addcommand('/ignore', self.on_ignore, '[player_id,player_id,... | ignored_ip,ignored_ip,... | list] - Toggle ignore for user associated with that player ID. Using the IP will remove only not toggle.')
103 self.addcommand('/description', self.on_description, 'message - Creates a block of text, used for room descriptions and such') 111 self.addcommand('/description', self.on_description, 'message - Creates a block of text, used for room descriptions and such')
104 self.addcommand('/sound', self.on_sound, 'Sound_URL - Plays a sound for all clients in the room.') 112 self.addcommand('/sound', self.on_sound, 'Sound_URL - Plays a sound for all clients in the room.')
105 self.addcommand('/purge', self.on_purge, 'This will clear the entire chat window') 113 self.addcommand('/purge', self.on_purge, 'This will clear the entire chat window')
106 self.addcommand('/advfilter', self.on_filter, 'This will toggle the Advanced Filter') 114 self.addcommand('/advfilter', self.on_filter, 'This will toggle the Advanced Filter')
107 115
116 @debugging
108 def defaultcmdalias(self): 117 def defaultcmdalias(self):
109 self.addshortcmd('/?', '/help') 118 self.addshortcmd('/?', '/help')
110 self.addshortcmd('/he', '/me') 119 self.addshortcmd('/he', '/me')
111 self.addshortcmd('/she', '/me') 120 self.addshortcmd('/she', '/me')
112 self.addshortcmd('/i', '/ignore') 121 self.addshortcmd('/i', '/ignore')
117 self.addshortcmd('/d', '/description') 126 self.addshortcmd('/d', '/description')
118 127
119 #This is just an example or a differant way the shorcmd can be used 128 #This is just an example or a differant way the shorcmd can be used
120 self.addshortcmd('/sleep', '/me falls asleep') 129 self.addshortcmd('/sleep', '/me falls asleep')
121 130
122 131 @debugging
123 def docmd(self,text): 132 def docmd(self,text):
124 cmdsearch = string.split(text,None,1) 133 cmdsearch = string.split(text,None,1)
125 cmd = string.lower(cmdsearch[0]) 134 cmd = string.lower(cmdsearch[0])
126 start = len(cmd) 135 start = len(cmd)
127 end = len(text) 136 end = len(text)
133 self.docmd(self.shortcmdlist[cmd] + " " + cmdargs) 142 self.docmd(self.shortcmdlist[cmd] + " " + cmdargs)
134 else: 143 else:
135 msg = "Sorry I don't know what %s is!" % (cmd) 144 msg = "Sorry I don't know what %s is!" % (cmd)
136 self.chat.InfoPost(msg) 145 self.chat.InfoPost(msg)
137 146
147 @debugging
138 def on_filter(self, cmdargs): 148 def on_filter(self, cmdargs):
139 #print self.chat.advancedFilter 149 #print self.chat.advancedFilter
140 test = not self.chat.advancedFilter 150 test = not self.chat.advancedFilter
141 #print test 151 #print test
142 152
157 if self.chat.advancedFilter: 167 if self.chat.advancedFilter:
158 self.chat.InfoPost("Advanced Filtering has been turned On") 168 self.chat.InfoPost("Advanced Filtering has been turned On")
159 else: 169 else:
160 self.chat.InfoPost("Advanced Filtering has been turned Off") 170 self.chat.InfoPost("Advanced Filtering has been turned Off")
161 171
172 @debugging
162 def on_purge(self, cmdargs): 173 def on_purge(self, cmdargs):
163 self.chat.PurgeChat() 174 self.chat.PurgeChat()
164 self.chat.InfoPost('Chat Buffer has been Purged!') 175 self.chat.InfoPost('Chat Buffer has been Purged!')
165 176
177 @debugging
166 def on_sound(self, cmdargs): 178 def on_sound(self, cmdargs):
167 if len(cmdargs) < 8: 179 if len(cmdargs) < 8:
168 self.chat.InfoPost("You must provide a URL for the file name, it does not work for just local sound files") 180 self.chat.InfoPost("You must provide a URL for the file name, it does not work for just local sound files")
169 return 181 return
170 args = string.split(cmdargs, None, -1) 182 args = string.split(cmdargs, None, -1)
194 elif group_id == '0': 206 elif group_id == '0':
195 self.chat.InfoPost("You cannot send sound files to the lobby!") 207 self.chat.InfoPost("You cannot send sound files to the lobby!")
196 else: 208 else:
197 self.chat.InfoPost("Something dun fuckered up Frank!") 209 self.chat.InfoPost("Something dun fuckered up Frank!")
198 210
211 @debugging
199 def on_version(self, cmdargs=""): 212 def on_version(self, cmdargs=""):
200 self.chat.InfoPost("Version is OpenRPG " + self.chat.version) 213 self.chat.InfoPost("Version is OpenRPG " + self.chat.version)
201 214
215 @debugging
202 def on_load(self, cmdargs): 216 def on_load(self, cmdargs):
203 args = string.split(cmdargs,None,-1) 217 args = string.split(cmdargs,None,-1)
204 try: 218 try:
205 self.settings.setup_ini(args[0]) 219 self.settings.setup_ini(args[0])
206 self.settings.reload_settings(self.chat) 220 self.settings.reload_settings(self.chat)
207 self.chat.InfoPost("Settings Loaded from file " + args[0] ) 221 self.chat.InfoPost("Settings Loaded from file " + args[0] )
208 except Exception,e: 222 except Exception,e:
209 print e 223 print e
210 self.chat.InfoPost("ERROR Loading settings") 224 self.chat.InfoPost("ERROR Loading settings")
211 225
226 @debugging
212 def on_font(self, cmdargs): 227 def on_font(self, cmdargs):
213 try: 228 try:
214 fontsettings = self.chat.set_default_font(fontname=cmdargs, fontsize=None) 229 fontsettings = self.chat.set_default_font(fontname=cmdargs, fontsize=None)
215 except: 230 except:
216 self.chat.InfoPost("ERROR setting default font") 231 self.chat.InfoPost("ERROR setting default font")
217 232
233 @debugging
218 def on_fontsize(self, cmdargs): 234 def on_fontsize(self, cmdargs):
219 args = string.split(cmdargs,None,-1) 235 args = string.split(cmdargs,None,-1)
220 try: 236 try:
221 fontsettings = self.chat.set_default_font(fontname=None, fontsize=int(args[0])) 237 fontsettings = self.chat.set_default_font(fontname=None, fontsize=int(args[0]))
222 except Exception, e: 238 except Exception, e:
223 print e 239 print e
224 self.chat.InfoPost("ERROR setting default font size") 240 self.chat.InfoPost("ERROR setting default font size")
225 241
242 @debugging
226 def on_close(self, cmdargs): 243 def on_close(self, cmdargs):
227 try: 244 try:
228 chatpanel = self.chat 245 chatpanel = self.chat
229 if (chatpanel.sendtarget == "all"): 246 if (chatpanel.sendtarget == "all"):
230 chatpanel.InfoPost("Error: cannot close public chat tab.") 247 chatpanel.InfoPost("Error: cannot close public chat tab.")
232 chatpanel.chat_timer.Stop() 249 chatpanel.chat_timer.Stop()
233 chatpanel.parent.onCloseTab(0) 250 chatpanel.parent.onCloseTab(0)
234 except: 251 except:
235 self.chat.InfoPost("Error: cannot close private chat tab.") 252 self.chat.InfoPost("Error: cannot close private chat tab.")
236 253
254 @debugging
237 def on_time(self, cmdargs): 255 def on_time(self, cmdargs):
238 local_time = time.localtime() 256 local_time = time.localtime()
239 gmt_time = time.gmtime() 257 gmt_time = time.gmtime()
240 format_string = "%A %b %d, %Y %I:%M:%S%p" 258 format_string = "%A %b %d, %Y %I:%M:%S%p"
241 self.chat.InfoPost("<br />Local: " + time.strftime(format_string)+\ 259 self.chat.InfoPost("<br />Local: " + time.strftime(format_string)+\
242 "<br />GMT: "+time.strftime(format_string,gmt_time)) 260 "<br />GMT: "+time.strftime(format_string,gmt_time))
243 261
262 @debugging
244 def on_dieroller(self, cmdargs): 263 def on_dieroller(self, cmdargs):
245 args = string.split(cmdargs,None,-1) 264 args = string.split(cmdargs,None,-1)
246 rm = self.chat.DiceManager 265 rm = self.chat.DiceManager
247 try: 266 try:
248 rm.setRoller(args[0]) 267 rm.setRoller(args[0])
251 except Exception, e: 270 except Exception, e:
252 print e 271 print e
253 self.chat.InfoPost("Available die rollers: " + str(rm.listRollers())) 272 self.chat.InfoPost("Available die rollers: " + str(rm.listRollers()))
254 self.chat.InfoPost("You are using the <b>\"" + rm.getRoller() + "\"</b> die roller.") 273 self.chat.InfoPost("You are using the <b>\"" + rm.getRoller() + "\"</b> die roller.")
255 274
275 @debugging
256 def on_ping(self, cmdargs): 276 def on_ping(self, cmdargs):
257 ct = time.clock() 277 ct = time.clock()
258 msg = "<ping player='"+self.session.id+"' time='"+str(ct)+"' />" 278 msg = "<ping player='"+self.session.id+"' time='"+str(ct)+"' />"
259 self.session.outbox.put(msg) 279 self.session.outbox.put(msg)
260 280
281 @debugging
261 def on_log(self,cmdargs): 282 def on_log(self,cmdargs):
262 args = string.split(cmdargs,None,-1) 283 args = string.split(cmdargs,None,-1)
263 logfile = self.settings.get_setting( 'GameLogPrefix' ) 284 logfile = self.settings.get_setting( 'GameLogPrefix' )
264 285
265 if len( args ) == 0: 286 if len( args ) == 0:
287 self.chat.SystemPost('You must also specify a filename with the <em>/log to</em> command.' ) 308 self.chat.SystemPost('You must also specify a filename with the <em>/log to</em> command.' )
288 self.postLoggingState() 309 self.postLoggingState()
289 else: 310 else:
290 self.chat.InfoPost("Unknown logging command, use 'on' or 'off'" ) 311 self.chat.InfoPost("Unknown logging command, use 'on' or 'off'" )
291 312
313 @debugging
292 def postLoggingState( self ): 314 def postLoggingState( self ):
293 logfile = self.settings.get_setting( 'GameLogPrefix' ) 315 logfile = self.settings.get_setting( 'GameLogPrefix' )
294 try: 316 try:
295 if logfile[0] != ANTI_LOG_CHAR: 317 if logfile[0] != ANTI_LOG_CHAR:
296 comment = 'is' 318 comment = 'is'
303 325
304 # This subroutine will set the players netork status. 326 # This subroutine will set the players netork status.
305 # 327 #
306 #!self : instance of self 328 #!self : instance of self
307 329
330 @debugging
308 def on_name(self, cmdargs): 331 def on_name(self, cmdargs):
309 #only 20 chars no more! :) 332 #only 20 chars no more! :)
310 if cmdargs == "": 333 if cmdargs == "":
311 self.chat.InfoPost("**Incorrect syntax for name.") 334 self.chat.InfoPost("**Incorrect syntax for name.")
312 else: 335 else:
317 # def on_status - end 340 # def on_status - end
318 341
319 # This subroutine will set the players netork status. 342 # This subroutine will set the players netork status.
320 # 343 #
321 # !self : instance of self 344 # !self : instance of self
345 @debugging
322 def on_status(self, cmdargs): 346 def on_status(self, cmdargs):
323 if cmdargs == "": 347 if cmdargs == "":
324 self.chat.InfoPost("Incorrect synatx for status.") 348 self.chat.InfoPost("Incorrect synatx for status.")
325 else: 349 else:
326 #only 20 chars no more! :) 350 #only 20 chars no more! :)
327 txt = cmdargs[:20] 351 txt = cmdargs[:20]
328 self.session.set_text_status(str(txt)) 352 self.session.set_text_status(str(txt))
329 # def on_status - end 353 # def on_status - end
330 354
355 @debugging
331 def on_set(self, cmdargs): 356 def on_set(self, cmdargs):
332 args = string.split(cmdargs,None,-1) 357 args = string.split(cmdargs,None,-1)
333 keys = self.settings.get_setting_keys() 358 keys = self.settings.get_setting_keys()
334 #print keys 359 #print keys
335 if len(args) == 0: 360 if len(args) == 0:
360 385
361 # This subroutine will display the correct usage of the different emotions. 386 # This subroutine will display the correct usage of the different emotions.
362 # 387 #
363 #!self : instance of self 388 #!self : instance of self
364 389
390 @debugging
365 def on_help(self, cmdargs=""): 391 def on_help(self, cmdargs=""):
366 cmds = self.cmdlist.keys() 392 cmds = self.cmdlist.keys()
367 cmds.sort() 393 cmds.sort()
368 shortcmds = self.shortcmdlist.keys() 394 shortcmds = self.shortcmdlist.keys()
369 shortcmds.sort() 395 shortcmds.sort()
382 408
383 # This subroutine will either show the list of currently ignored users 409 # This subroutine will either show the list of currently ignored users
384 # !self : instance of self 410 # !self : instance of self
385 # !text : string that is comprised of a list of users to toggle the ignore flag 411 # !text : string that is comprised of a list of users to toggle the ignore flag
386 412
413 @debugging
387 def on_ignore(self, cmdargs): 414 def on_ignore(self, cmdargs):
388 args = string.split(cmdargs,None,-1) 415 args = string.split(cmdargs,None,-1)
389 (ignore_list, ignore_name) = self.session.get_ignore_list() 416 (ignore_list, ignore_name) = self.session.get_ignore_list()
390 ignore_output = self.colorize(self.chat.syscolor,"<br /><u>Player IDs Currently being Ignored:</u><br />") 417 ignore_output = self.colorize(self.chat.syscolor,"<br /><u>Player IDs Currently being Ignored:</u><br />")
391 if cmdargs == "": 418 if cmdargs == "":
408 self.chat.InfoPost("Player " + name + " with ID:" + id + " now being ignored") 435 self.chat.InfoPost("Player " + name + " with ID:" + id + " now being ignored")
409 except: 436 except:
410 self.chat.InfoPost(m + " was ignored because it is an invalid player ID") 437 self.chat.InfoPost(m + " was ignored because it is an invalid player ID")
411 traceback.print_exc() 438 traceback.print_exc()
412 439
440 @debugging
413 def on_role(self, cmdargs): 441 def on_role(self, cmdargs):
414 if cmdargs == "": 442 if cmdargs == "":
415 self.session.display_roles() 443 self.session.display_roles()
416 return 444 return
417 delim = cmdargs.find("=") 445 delim = cmdargs.find("=")
439 # 467 #
440 # !self : instance of self 468 # !self : instance of self
441 # !text : string that is comprised of a list of users and the message to 469 # !text : string that is comprised of a list of users and the message to
442 #whisper. 470 #whisper.
443 471
472 @debugging
444 def on_whisper(self, cmdargs): 473 def on_whisper(self, cmdargs):
445 delim = cmdargs.find("=") 474 delim = cmdargs.find("=")
446 475
447 if delim < 0: 476 if delim < 0:
448 if self.previous_whisper: 477 if self.previous_whisper:
457 self.chat.whisper_to_players(mesg,player_ids) 486 self.chat.whisper_to_players(mesg,player_ids)
458 487
459 #--------------------------------------------------------- 488 #---------------------------------------------------------
460 # [START] Digitalxero Multi Whisper Group 1/1/05 489 # [START] Digitalxero Multi Whisper Group 1/1/05
461 #--------------------------------------------------------- 490 #---------------------------------------------------------
491 @debugging
462 def on_groupwhisper(self, cmdargs): 492 def on_groupwhisper(self, cmdargs):
463 args = string.split(cmdargs,None,-1) 493 args = string.split(cmdargs,None,-1)
464 delim = cmdargs.find("=") 494 delim = cmdargs.find("=")
465 495
466 if delim > 0: 496 if delim > 0:
517 547
518 #--------------------------------------------------------- 548 #---------------------------------------------------------
519 # [END] Digitalxero Multi Whisper Group 1/1/05 549 # [END] Digitalxero Multi Whisper Group 1/1/05
520 #--------------------------------------------------------- 550 #---------------------------------------------------------
521 551
552 @debugging
522 def on_gmwhisper(self, cmdargs): 553 def on_gmwhisper(self, cmdargs):
523 if cmdargs == "": 554 if cmdargs == "":
524 self.chat.InfoPost("**Incorrect syntax for GM Whisper.") 555 self.chat.InfoPost("**Incorrect syntax for GM Whisper.")
525 else: 556 else:
526 the_gms = self.chat.get_gms() 557 the_gms = self.chat.get_gms()
532 gmstring += each_gm 563 gmstring += each_gm
533 self.on_whisper(gmstring + "=" + cmdargs) 564 self.on_whisper(gmstring + "=" + cmdargs)
534 else: 565 else:
535 self.chat.InfoPost("**No GMs to Whisper to.") 566 self.chat.InfoPost("**No GMs to Whisper to.")
536 567
568 @debugging
537 def on_moderate(self, cmdargs): 569 def on_moderate(self, cmdargs):
538 if cmdargs != "": 570 if cmdargs != "":
539 pos = cmdargs.find("=") 571 pos = cmdargs.find("=")
540 if (pos < 0): 572 if (pos < 0):
541 plist = "" 573 plist = ""
569 else: 601 else:
570 msg = "<moderate action='list' from='"+self.session.id+"' />" 602 msg = "<moderate action='list' from='"+self.session.id+"' />"
571 self.session.outbox.put(msg) 603 self.session.outbox.put(msg)
572 self.session.update() 604 self.session.update()
573 605
606 @debugging
574 def on_update(self, cmdargs): 607 def on_update(self, cmdargs):
575 self.chat.InfoPost("This command is no longer valid") 608 self.chat.InfoPost("This command is no longer valid")
576 609
610 @debugging
577 def on_description(self, cmdargs): 611 def on_description(self, cmdargs):
578 if len(cmdargs) <= 0: 612 if len(cmdargs) <= 0:
579 self.chat.InfoPost("**No description text to display." + str(delim)) 613 self.chat.InfoPost("**No description text to display." + str(delim))
580 return 614 return
581 mesg = "<table bgcolor='#c0c0c0' border='3' cellpadding='5' cellspacing='0' width='100%'><tr><td><font color='#000000'>" 615 mesg = "<table bgcolor='#c0c0c0' border='3' cellpadding='5' cellspacing='0' width='100%'><tr><td><font color='#000000'>"
582 mesg += string.strip(cmdargs) 616 mesg += string.strip(cmdargs)
583 mesg += "</font></td></tr></table>" 617 mesg += "</font></td></tr></table>"
584 self.chat.Post(mesg) 618 self.chat.Post(mesg)
585 self.chat.send_chat_message(mesg) 619 self.chat.send_chat_message(mesg)
586 620
621 @debugging
587 def invoke_tab(self, cmdargs): 622 def invoke_tab(self, cmdargs):
588 ######START mDuo13's Tab Initiator######## 623 ######START mDuo13's Tab Initiator########
589 try: 624 try:
590 int(cmdargs) 625 int(cmdargs)
591 playerid = cmdargs.strip() 626 playerid = cmdargs.strip()
607 nidx = self.chat.parent.get_tab_index(displaypanel) 642 nidx = self.chat.parent.get_tab_index(displaypanel)
608 self.chat.parent.newMsg(nidx) 643 self.chat.parent.newMsg(nidx)
609 return 644 return
610 #######END mDuo13's Tab Initiator######### 645 #######END mDuo13's Tab Initiator#########
611 646
647 @debugging
612 def on_remote_admin(self, cmdargs): 648 def on_remote_admin(self, cmdargs):
613 args = string.split(cmdargs,None,-1) 649 args = string.split(cmdargs,None,-1)
614 #handles remote administration commands 650 #handles remote administration commands
615 try: 651 try:
616 pass_state = 0 652 pass_state = 0