|
20 | 20 | import datetime |
21 | 21 | import time |
22 | 22 | import re |
| 23 | +import redis |
23 | 24 |
|
24 | 25 | LENGTH_REGEX = re.compile(r"(?P<number>[0-9]+) (?P<scale>seconds?|minutes?|hours?|days?|weeks?|months?|years?)") |
25 | 26 | TIME_FORMAT = "%Y-%m-%d %H:%M:%S" |
@@ -199,7 +200,11 @@ def cmd_ban(self, player, msg, channel): |
199 | 200 | base_key = PLAYER_KEY.format(ident) + ":bans" |
200 | 201 | ban_id = self.db.zcard(base_key) |
201 | 202 | db = self.db.pipeline() |
202 | | - db.zadd(base_key, time.time() + td.total_seconds(), ban_id) |
| 203 | + ban_time = time.time() + td.total_seconds() |
| 204 | + if redis.VERSION < (3,): |
| 205 | + db.zadd(base_key, ban_time, ban_id) |
| 206 | + else: |
| 207 | + db.zadd(base_key, {ban_id: ban_time}) |
203 | 208 | ban = {"expires": expires, "reason": reason, "issued": now, "issued_by": player.steam_id} |
204 | 209 | db.hmset(base_key + ":{}".format(ban_id), ban) |
205 | 210 | db.execute() |
@@ -239,7 +244,10 @@ def cmd_unban(self, player, msg, channel): |
239 | 244 | else: |
240 | 245 | db = self.db.pipeline() |
241 | 246 | for ban_id, score in bans: |
242 | | - db.zincrby(base_key, ban_id, -score) |
| 247 | + if redis.VERSION < (3,): |
| 248 | + db.zincrby(base_key, ban_id, -score) |
| 249 | + else: |
| 250 | + db.zincrby(base_key, -score, ban_id) |
243 | 251 | db.execute() |
244 | 252 | channel.reply("^6{}^7 has been unbanned.".format(name)) |
245 | 253 |
|
|
0 commit comments