1111import zipfile , os , re
1212import psycopg2 .extras
1313
14- __version__ = "0.9 .0"
14+ __version__ = "0.10 .0"
1515
1616class MCPBot (BotBase ):
1717 def __init__ (self , configfile = None , nspass = None , backupcfg = False ):
@@ -400,8 +400,12 @@ def getHistory(self, bot, sender, dest, cmd, args):
400400 member_type = 'field'
401401 if cmd ['command' ] == 'mh' : member_type = 'method'
402402 if cmd ['command' ] == 'ph' : member_type = 'method_param'
403- val , status = self .db .getHistory (member_type , args )
404- self .sendHistoryResults (member_type , sender , dest , val , status , limit = self .moreCount if not sender .dccSocket else self .moreCountDcc )
403+ if isSrgName (args [0 ]) or is_integer (args [0 ]) or member_type == 'method_param' :
404+ val , status = self .db .getHistory (member_type , args )
405+ self .sendHistoryResults (member_type , sender , dest , val , status , limit = self .moreCount if not sender .dccSocket else self .moreCountDcc )
406+ else :
407+ val , status = self .db .searchHistory (member_type , args )
408+ self .sendSearchHistoryResults (member_type , sender , dest , val , args [0 ], status , limit = self .moreCount if not sender .dccSocket else self .moreCountDcc )
405409
406410
407411 def findKey (self , bot , sender , dest , cmd , args ):
@@ -465,9 +469,9 @@ def listMembers(self, bot, sender, dest, cmd, args):
465469 def setLocked (self , bot , sender , dest , cmd , args ):
466470 member_type = None
467471 is_lock = cmd ['command' ][0 ] == 'l'
468- if cmd ['command' ].find ('f' ) > - 1 or args [0 ].beginswith ('field_' ): member_type = 'field'
469- elif cmd ['command' ].find ('m' ) > - 1 or args [0 ].beginswith ('func_' ): member_type = 'method'
470- elif cmd ['command' ].find ('p' ) > - 1 or args [0 ].beginswith ('p_' ): member_type = 'method_param'
472+ if cmd ['command' ].find ('f' ) > - 1 or args [0 ].startswith ('field_' ): member_type = 'field'
473+ elif cmd ['command' ].find ('m' ) > - 1 or args [0 ].startswith ('func_' ): member_type = 'method'
474+ elif cmd ['command' ].find ('p' ) > - 1 or args [0 ].startswith ('p_' ): member_type = 'method_param'
471475 if member_type :
472476 val , status = self .db .setMemberLock (member_type , is_lock , cmd ['command' ], sender , args )
473477 self .sendSetLockResults (member_type , sender , dest , val , status , args [0 ], is_lock )
@@ -749,7 +753,7 @@ def sendHistoryResults(self, member_type, sender, dest, val, status, limit):
749753 for i , entry in enumerate (val ):
750754 msg = "[{mc_version_code}, {status} {time_stamp}] {irc_nick}: {old_mcp_name} §B=>§N {new_mcp_name}" .format (** entry )
751755 if entry ['undo_irc_nick' ]:
752- msg = msg + ' §RUndone {undo_time_stamp}: {undo_irc_nick}' .format (** entry )
756+ msg = msg + ' §B§ RUndone {undo_time_stamp}: {undo_irc_nick}' .format (** entry )
753757
754758 if i < limit :
755759 self .sendOutput (dest , msg )
@@ -766,6 +770,41 @@ def sendHistoryResults(self, member_type, sender, dest, val, status, limit):
766770 # self.reply("[%s, %s] %s: %s -> %s" % (row['mcpversion'], row['timestamp'], row['nick'], row['oldname'], row['newname']))
767771
768772
773+ def sendSearchHistoryResults (self , member_type , sender , dest , val , search , status , limit ):
774+ if member_type == 'method_param' :
775+ member_type_disp = 'Method Param'
776+ else :
777+ member_type_disp = member_type [0 ].upper () + member_type [1 :]
778+
779+ if status :
780+ self .sendNotice (sender .nick , "§B" + str (type (status )) + ' : ' + str (status ))
781+ return
782+
783+ if len (val ) == 0 :
784+ self .sendOutput (dest , "§BNo results found." )
785+ return
786+
787+ toQueue = []
788+ self .sendOutput (dest , "===§B " + member_type_disp + " History: " + search + " §N===" .format (** val [0 ]))
789+
790+ for i , entry in enumerate (val ):
791+ msg = "[{mc_version_code} {class_srg_name}.{srg_name}, {status} {time_stamp}] {irc_nick}: {old_mcp_name} §B=>§N {new_mcp_name}" .format (** entry )
792+ if entry ['undo_irc_nick' ]:
793+ msg = msg + ' §B§RUndone {undo_time_stamp}: {undo_irc_nick}' .format (** entry )
794+
795+ if i < limit :
796+ self .sendOutput (dest , msg )
797+ else :
798+ toQueue .append (msg )
799+
800+ if len (toQueue ) > 0 :
801+ self .sendOutput (dest , "§B+ §N%(count)d§B more. Please use %(cmd_char)smore to see %(more)d queued entries." %
802+ {'count' : len (toQueue ), 'cmd_char' : self .cmdChar , 'more' : min (self .moreCount if not sender .dccSocket else self .moreCountDcc , len (toQueue ))})
803+ sender .clearMsgQueue ()
804+ for msg in toQueue :
805+ sender .addToMsgQueue (msg )
806+
807+
769808 def sendClassResults (self , sender , dest , val , status , limit = 0 , summary = False ):
770809 if status :
771810 self .sendNotice (sender .nick , str (type (status )) + ' : ' + str (status ))
@@ -979,6 +1018,10 @@ def isValid24HourTimeStr(timestr):
9791018 return True
9801019
9811020
1021+ def isSrgName (name ):
1022+ return name .startswith ('field_' ) or name .startswith ('func_' ) or name .startswith ('p_' )
1023+
1024+
9821025def sorted_nicely ( l , reverse = False ):
9831026 """ Sort the given iterable in the way that humans expect."""
9841027 convert = lambda text : int (text ) if text .isdigit () else text
0 commit comments