Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def strike(self, channel, nick, count):
channel = channel.replace('#', '')
# cap at 19 messages
count = min(count, 19)
# get rid of 'the last !strike' too!
limit = count + 1
# don't delete anything beyond the past 18 hours
cutoff = datetime.datetime.utcnow() - datetime.timedelta(hours=18)
date_limit = storage.bson.objectid.ObjectId.from_datetime(cutoff)
query = dict(channel=channel, nick=nick, _id={'$gt': date_limit})
cursor = self.db.find(query).sort('_id', storage.pymongo.DESCENDING)
cursor = cursor.limit(limit)
ids_to_delete = [row['_id'] for row in cursor]
if ids_to_delete:
self.db.remove({'_id': {'$in': ids_to_delete}})
rows_deleted = max(len(ids_to_delete) - 1, 0)
return rows_deleted
def add(self, quote):
quote = quote.strip()
quote_id = self.db.insert_one(dict(library=self.lib, text=quote))
# see if the quote added is in the last IRC message logged
newest_first = [('_id', storage.pymongo.DESCENDING)]
last_message = self.db.database.logs.find_one(sort=newest_first)
if last_message and quote in last_message['message']:
self.db.update_one(
{'_id': quote_id}, {'$set': dict(log_id=last_message['_id'])}
)