~m4v/scratbot-plugins/spaces

« back to all changes in this revision

Viewing changes to plugin.py

  • Committer: Elián Hanisch
  • Date: 2010-01-16 21:15:56 UTC
  • Revision ID: lambdae2@gmail.com-20100116211556-wlhd7cwawl9pveo5
--any option for the search function, for find facts matching any word and
not all

Show diffs side-by-side

added added

removed removed

Lines of Context:
1163
1163
        logInfo(irc, msg, 'search channel: $channel msg: $msg')
1164
1164
 
1165
1165
        channel = formatChannel(msg.args[0])
1166
 
        if '--all-channels' in text: # ugly but good for now
1167
 
            text = text.replace('--all-channels', '')
 
1166
        if ' --all-channels' in text: # ugly but good for now
 
1167
            text = text.replace(' --all-channels', '')
1168
1168
            tableList = self.db.getTables(all=self.registryValue('sqlite.table.fact'))
1169
1169
        elif channel:
1170
1170
            tableList = self.db.getTables(inChannel=channel)
1172
1172
            tableList = self.db.getTables(all=self.registryValue('sqlite.table.fact'))
1173
1173
        facts = []
1174
1174
        #log.debug('Factos.search() tables=%s' % (tableList, ))
 
1175
        matchall = True
 
1176
        if ' --any' in text:
 
1177
            matchall = False
 
1178
            text = text.replace(' --any', '')
1175
1179
 
1176
1180
        def setFact(values, table):
1177
1181
            fact = Fact()
1181
1185
 
1182
1186
        keywords = text.split()
1183
1187
        for table in tableList:
1184
 
            facts.extend([ setFact(v, table) for v in self.db.search(keywords, table=table) ])
 
1188
            facts.extend([ setFact(v, table) for v in self.db.search(keywords, table=table,
 
1189
                matchall=matchall) ])
1185
1190
        # remove disabled
1186
1191
        facts = [ f for f in facts if not f.isDisabled() ]
1187
1192
        facts.sort()