Skip to content

Commit feef4eb

Browse files
committed
add functionality to search for old member names in the history
1 parent c55d16f commit feef4eb

File tree

2 files changed

+72
-7
lines changed

2 files changed

+72
-7
lines changed

Database.py

+22
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,28 @@ def getHistory(self, table, args):
176176
return self.execute(sqlrequest, {'member': args[0]})
177177

178178

179+
def searchHistory(self, table, args):
180+
sqlrequest1 = "SELECT *, 'Committed' as status FROM mcp.%s " % (table + "_history_vw")
181+
sqlrequest2 = "SELECT *, 'Staged' as status FROM mcp.%s " % ('staged_' + table + "_vw")
182+
183+
sqlrequest1 += 'where (old_mcp_name = %(member)s or new_mcp_name = %(member)s) '
184+
sqlrequest2 += 'where (old_mcp_name = %(member)s or new_mcp_name = %(member)s) '
185+
186+
splitted = args[0].split('.')
187+
if len(splitted) > 1:
188+
clazz = splitted[0]
189+
member = splitted[1]
190+
sqlrequest1 += 'and class_srg_name = %(clazz)s'
191+
sqlrequest2 += 'and class_srg_name = %(clazz)s'
192+
else:
193+
clazz = None
194+
member = args[0]
195+
196+
sqlrequest = 'select * from (%s union %s) hist order by srg_name, time_stamp desc' % (sqlrequest1, sqlrequest2)
197+
198+
return self.execute(sqlrequest, {'clazz': clazz, 'member': member})
199+
200+
179201
def getClass(self, args):
180202
sqlrequest = "SELECT * FROM mcp.class_vw "
181203

MCPBot.py

+50-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import zipfile, os, re
1212
import psycopg2.extras
1313

14-
__version__ = "0.9.0"
14+
__version__ = "0.10.0"
1515

1616
class 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 + ' §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+
9821025
def 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

Comments
 (0)