From 1e980e08f98c0f6cec1fd8878f059dcf5e11bf14 Mon Sep 17 00:00:00 2001 From: Alan Briolat Date: Wed, 16 Feb 2022 09:53:19 +0000 Subject: [PATCH] Update to pymongo 4.x, fix `last` and `termdates` plugins --- setup.py | 2 +- src/csbot/plugins/last.py | 3 +-- src/csbot/plugins/termdates.py | 12 ++++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 954f38df..2c2826f2 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ install_requires=[ 'click>=6.2,<7.0', 'straight.plugin==1.4.0-post-1', - 'pymongo>=3.6.0,<4', + 'pymongo>=4.0.1', 'requests>=2.9.1,<3.0.0', 'lxml>=2.3.5', 'aiogoogle>=0.1.13', diff --git a/src/csbot/plugins/last.py b/src/csbot/plugins/last.py index 56f1cbd5..fbba774f 100644 --- a/src/csbot/plugins/last.py +++ b/src/csbot/plugins/last.py @@ -106,8 +106,7 @@ def _schedule_update(self, e, query, update): @Plugin.hook('last.update') def _apply_update(self, e): - self.db.remove(e['query']) - self.db.insert(e['update']) + self.db.replace_one(e['query'], e['update'], upsert=True) @Plugin.command('seen', help=('seen nick [type]: show the last thing' ' said by a nick in this channel, optionally' diff --git a/src/csbot/plugins/termdates.py b/src/csbot/plugins/termdates.py index a9dd869b..948adaa5 100644 --- a/src/csbot/plugins/termdates.py +++ b/src/csbot/plugins/termdates.py @@ -196,8 +196,16 @@ def termdates_set(self, e): # Save to the database. As we don't touch the _id attribute in this # method, this will cause `save` to override the previously-loaded # entry (if there is one). - self.db_terms.save(self.terms) - self.db_weeks.save(self.weeks) + if '_id' in self.terms: + self.db_terms.replace_one({'_id': self.terms['_id']}, self.terms, upsert=True) + else: + res = self.db_terms.insert_one(self.terms) + self.terms['_id'] = res.inserted_id + if '_id' in self.weeks: + self.db_weeks.replace_one({'_id': self.weeks['_id']}, self.weeks, upsert=True) + else: + res = self.db_weeks.insert_one(self.weeks) + self.weeks['_id'] = res.inserted_id # Finally, we're initialised! self.initialised = True