~m4v/scratbot-plugins/spaces

« back to all changes in this revision

Viewing changes to plugin.py

  • Committer: Elián Hanisch
  • Date: 2010-01-16 17:17:38 UTC
  • mfrom: (142.4.47 Factos-history)
  • Revision ID: lambdae2@gmail.com-20100116171738-bonpipqpkzl1ly3z
merge with history refactoring branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
tableFact = objects.Table(objects.tblFactStruct, tableConf.fact(), tableIndex='name')
42
42
# base table for record edits
43
43
tableHist = objects.Table(objects.tblHistStruct, tableConf.history())
 
44
tableHistRedo = objects.Table(objects.tblHistStruct, tableConf.history() + '_redo')
44
45
# table for user hostmasks
45
46
tableUser = objects.databases.Table(objects.tblUserStruct, tableConf.users(), tableIndex='user_id')
46
47
 
589
590
 
590
591
# Database config
591
592
filename = conf.supybot.directories.data.dirize(conf.supybot.plugins.Factos.sqlite.database())
592
 
SqliteDB = lambda file: objects.SqliteDB(file, tableFact, tableHist, tableUser)
 
593
SqliteDB = lambda file: objects.SqliteDB(file, tableFact, tableHist, tableHistRedo, tableUser)
593
594
factosDatabase = plugins.DB(filename, {'sqlite':SqliteDB})
594
595
 
595
596
class Factos(callbacks.Plugin):
722
723
            except ValueError:
723
724
                irc.error('Bad history id')
724
725
                return
725
 
            hist = self.db.getHist(equal=fact.name, channel=fact.channel)
 
726
            redo = ''
 
727
            if id > 0:
 
728
                # redo history
 
729
                redo = True
 
730
                hist = self.db.getHist(equal=fact.name, channel=fact.channel, table=tableHistRedo)
 
731
                id -= 1
 
732
            else:
 
733
                hist = self.db.getHist(equal=fact.name, channel=fact.channel)
 
734
                hist = list(hist)  
 
735
                hist.reverse()
726
736
            try:
727
737
                hist = hist[id]
728
738
            except IndexError:
729
 
                irc.reply('No history.')
 
739
                irc.reply('Sin historial.')
730
740
                return
731
 
            irc.reply('Revisión Nº%s | \'%s:%s\'' % (hist['history_id'], hist['name'], hist['data']))
 
741
            irc.reply('Revisión %sNº%s | \'%s:%s\'' % (redo and '(deshecha) ', hist['history_id'], hist['name'], hist['data']))
732
742
        elif 'fullhistory' in self.options:
733
743
            hist_list = self.db.getHist(equal=fact.name, channel=fact.channel)
734
744
            if hist_list:
1296
1306
        logInfo(irc, msg, 'undo channel: $channel msg: $msg')
1297
1307
 
1298
1308
        fact.pull(channel)
1299
 
        hist = self.db.getHist(equal=fact.name, channel=fact.channel)
1300
 
        if hist and hist[-1]['history_id'] > 0:
1301
 
            redo_id = int(hist[0]['history_id'])
1302
 
            if redo_id > 0:
1303
 
                redo_id = -1
1304
 
            else:
1305
 
                redo_id -= 1
1306
 
            self.db.updateHist(fact.getHist(), hist[-1]['history_id'], redo_id)
1307
 
            fact.upFromHist(hist[-1])
 
1309
        hist = self.db.getHist(equal=fact.name, channel=fact.channel, limit=1)
 
1310
        if hist:
 
1311
            undo_hist = hist[0]
 
1312
            self.db.updateHist(fact.getHist(), undo_hist['history_id'], channel=fact.channel)
 
1313
            fact.upFromHist(undo_hist)
1308
1314
            fact.push()
1309
1315
            irc.edited(fact)
1310
1316
        else:
1321
1327
        logInfo(irc, msg, 'redo channel: $channel msg: $msg')
1322
1328
 
1323
1329
        fact.pull(channel)
1324
 
        hist = self.db.getHist(equal=fact.name, channel=fact.channel)
1325
 
        if hist and hist[0]['history_id'] < 0:
1326
 
            undo_id = int(hist[-1]['history_id'])
1327
 
            if undo_id >  0:
1328
 
                undo_id += 1
1329
 
            else:
1330
 
                undo_id = 1
1331
 
            self.db.updateHist(fact.getHist(), hist[0]['history_id'], undo_id)
1332
 
            fact.upFromHist(hist[0])
 
1330
        hist = self.db.getHist(equal=fact.name, channel=fact.channel, table=tableHistRedo, limit=1)
 
1331
        if hist:
 
1332
            redo_hist = hist[0]
 
1333
            self.db.updateHist(fact.getHist(), redo_hist['history_id'], undo=False,
 
1334
                    channel=fact.channel)
 
1335
            fact.upFromHist(redo_hist)
1333
1336
            fact.push()
1334
1337
            irc.edited(fact)
1335
1338
        else: