11
11
import zipfile , os , re
12
12
import psycopg2 .extras
13
13
14
- __version__ = "0.9 .0"
14
+ __version__ = "0.10 .0"
15
15
16
16
class MCPBot (BotBase ):
17
17
def __init__ (self , configfile = None , nspass = None , backupcfg = False ):
@@ -400,8 +400,12 @@ def getHistory(self, bot, sender, dest, cmd, args):
400
400
member_type = 'field'
401
401
if cmd ['command' ] == 'mh' : member_type = 'method'
402
402
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 )
405
409
406
410
407
411
def findKey (self , bot , sender , dest , cmd , args ):
@@ -465,9 +469,9 @@ def listMembers(self, bot, sender, dest, cmd, args):
465
469
def setLocked (self , bot , sender , dest , cmd , args ):
466
470
member_type = None
467
471
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'
471
475
if member_type :
472
476
val , status = self .db .setMemberLock (member_type , is_lock , cmd ['command' ], sender , args )
473
477
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):
749
753
for i , entry in enumerate (val ):
750
754
msg = "[{mc_version_code}, {status} {time_stamp}] {irc_nick}: {old_mcp_name} §B=>§N {new_mcp_name}" .format (** entry )
751
755
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 )
753
757
754
758
if i < limit :
755
759
self .sendOutput (dest , msg )
@@ -766,6 +770,41 @@ def sendHistoryResults(self, member_type, sender, dest, val, status, limit):
766
770
# self.reply("[%s, %s] %s: %s -> %s" % (row['mcpversion'], row['timestamp'], row['nick'], row['oldname'], row['newname']))
767
771
768
772
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
+
769
808
def sendClassResults (self , sender , dest , val , status , limit = 0 , summary = False ):
770
809
if status :
771
810
self .sendNotice (sender .nick , str (type (status )) + ' : ' + str (status ))
@@ -979,6 +1018,10 @@ def isValid24HourTimeStr(timestr):
979
1018
return True
980
1019
981
1020
1021
+ def isSrgName (name ):
1022
+ return name .startswith ('field_' ) or name .startswith ('func_' ) or name .startswith ('p_' )
1023
+
1024
+
982
1025
def sorted_nicely ( l , reverse = False ):
983
1026
""" Sort the given iterable in the way that humans expect."""
984
1027
convert = lambda text : int (text ) if text .isdigit () else text
0 commit comments