Skip to content

Commit

Permalink
Unpin redis and adapt plugins to work on other redis versions
Browse files Browse the repository at this point in the history
  • Loading branch information
em92 committed Oct 19, 2024
1 parent 8ed3ae6 commit 3c768c2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import datetime
import time
import re
import redis

LENGTH_REGEX = re.compile(r"(?P<number>[0-9]+) (?P<scale>seconds?|minutes?|hours?|days?|weeks?|months?|years?)")
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
Expand Down Expand Up @@ -239,7 +240,10 @@ def cmd_unban(self, player, msg, channel):
else:
db = self.db.pipeline()
for ban_id, score in bans:
db.zincrby(base_key, ban_id, -score)
if redis.VERSION < (3,):
db.zincrby(base_key, ban_id, -score)
else:
db.zincrby(base_key, -score, ban_id)
db.execute()
channel.reply("^6{}^7 has been unbanned.".format(name))

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
redis>=2.10, <3.0
redis
hiredis
requests
pyzmq<18; python_version < '3.9'
Expand Down
6 changes: 5 additions & 1 deletion silence.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import datetime
import time
import re
import redis

LENGTH_REGEX = re.compile(r"(?P<number>[0-9]+) (?P<scale>seconds?|minutes?|hours?|days?|weeks?|months?|years?)")
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
Expand Down Expand Up @@ -194,7 +195,10 @@ def cmd_unsilence(self, player, msg, channel):
else:
db = self.db.pipeline()
for silence_id, score in silences:
db.zincrby(base_key, silence_id, -score)
if redis.VERSION < (3,):
db.zincrby(base_key, silence_id, -score)
else:
db.zincrby(base_key, -score, silence_id)
db.execute()
if ident in self.silenced:
del self.silenced[ident]
Expand Down
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
sys.path.append(PATH + "/minqlx-plugin-tests/src/unittest/python")

from .test_balance import TestBalance
from .test_ban import TestBan

def suite():
r = unittest.TestSuite()
r.addTest(TestBalance())
r.addTest(TestBan())
return r


Expand Down
25 changes: 25 additions & 0 deletions tests/test_ban.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from minqlx_plugin_test import setup_plugin, connected_players, mocked_channel, fake_player, unstub, setup_cvars
import unittest

from ban import ban


class TestBan(unittest.TestCase):
def setUp(self):
setup_plugin()
connected_players()
setup_cvars({
"qlx_database": "redis",
})
self.plugin = ban()

def tearDown(self):
unstub()

def test_ban(self):
steam_id = 666
player = fake_player(steam_id, "Woodpecker")
channel = mocked_channel()
connected_players(player)
self.plugin.cmd_ban(None, ["!ban", "666", "10", "seconds"], channel)
raise NotImplementedError("Tests to check if ban actually executed")

0 comments on commit 3c768c2

Please sign in to comment.