Skip to content

Commit 1e980e0

Browse files
committed
Update to pymongo 4.x, fix last and termdates plugins
1 parent ae61a36 commit 1e980e0

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
install_requires=[
1717
'click>=6.2,<7.0',
1818
'straight.plugin==1.4.0-post-1',
19-
'pymongo>=3.6.0,<4',
19+
'pymongo>=4.0.1',
2020
'requests>=2.9.1,<3.0.0',
2121
'lxml>=2.3.5',
2222
'aiogoogle>=0.1.13',

src/csbot/plugins/last.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def _schedule_update(self, e, query, update):
106106

107107
@Plugin.hook('last.update')
108108
def _apply_update(self, e):
109-
self.db.remove(e['query'])
110-
self.db.insert(e['update'])
109+
self.db.replace_one(e['query'], e['update'], upsert=True)
111110

112111
@Plugin.command('seen', help=('seen nick [type]: show the last thing'
113112
' said by a nick in this channel, optionally'

src/csbot/plugins/termdates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,16 @@ def termdates_set(self, e):
196196
# Save to the database. As we don't touch the _id attribute in this
197197
# method, this will cause `save` to override the previously-loaded
198198
# entry (if there is one).
199-
self.db_terms.save(self.terms)
200-
self.db_weeks.save(self.weeks)
199+
if '_id' in self.terms:
200+
self.db_terms.replace_one({'_id': self.terms['_id']}, self.terms, upsert=True)
201+
else:
202+
res = self.db_terms.insert_one(self.terms)
203+
self.terms['_id'] = res.inserted_id
204+
if '_id' in self.weeks:
205+
self.db_weeks.replace_one({'_id': self.weeks['_id']}, self.weeks, upsert=True)
206+
else:
207+
res = self.db_weeks.insert_one(self.weeks)
208+
self.weeks['_id'] = res.inserted_id
201209

202210
# Finally, we're initialised!
203211
self.initialised = True

0 commit comments

Comments
 (0)