Skip to content

Commit dd99e58

Browse files
authored
Merge branch 'MinoMino:master' into master
2 parents 0272389 + 7713adc commit dd99e58

19 files changed

Lines changed: 252 additions & 104 deletions

.github/workflows/pre-commit.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "master"
7+
push:
8+
branches:
9+
- "master"
10+
11+
jobs:
12+
pre-commit:
13+
runs-on: ubuntu-22.04
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-python@v2
17+
- name: Get python version
18+
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
19+
- uses: actions/cache@v1
20+
with:
21+
path: ~/.cache/pre-commit
22+
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
23+
- name: Install pre-commit
24+
run: pip install pre-commit
25+
- name: Run pre-commit
26+
run: pre-commit run --all-files --show-diff-on-failure --color=always
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Tests (PyPA packages)
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
branches:
9+
- "master"
10+
11+
jobs:
12+
test:
13+
strategy:
14+
matrix:
15+
include:
16+
- python-version: "3.12"
17+
os: "ubuntu-22.04"
18+
- python-version: "3.11"
19+
os: "ubuntu-22.04"
20+
- python-version: "3.10"
21+
os: "ubuntu-22.04"
22+
- python-version: "3.9"
23+
os: "ubuntu-22.04"
24+
- python-version: "3.8"
25+
os: "ubuntu-22.04"
26+
- python-version: "3.7"
27+
os: "ubuntu-22.04"
28+
- python-version: "3.6"
29+
os: "ubuntu-20.04"
30+
- python-version: "3.5"
31+
os: "ubuntu-20.04"
32+
33+
runs-on: ${{ matrix.os }}
34+
env:
35+
GET_PIP_PATH_PREFIX: ${{ contains(fromJSON('["3.7", "3.6", "3.5"]'), matrix.python-version) && format('pip/{0}/', matrix.python-version) || '' }}
36+
steps:
37+
- uses: actions/checkout@v3
38+
with:
39+
submodules: 'true'
40+
- name: Include ppa repository
41+
run: sudo add-apt-repository ppa:deadsnakes/ppa
42+
43+
- name: Set up Python ${{ matrix.python-version }}
44+
run: |
45+
sudo apt-get install python${{ matrix.python-version }}-dev
46+
sudo update-alternatives --install /usr/bin/python3 python3 `which python${{ matrix.python-version }}` 1
47+
sudo update-alternatives --install /usr/bin/python3-config python3-config `which python${{ matrix.python-version }}-config` 1
48+
49+
- name: Install disutils package
50+
if: contains(fromJSON('["3.5"]'), matrix.python-version) == false
51+
run: sudo apt-get install python${{ matrix.python-version }}-distutils
52+
53+
- name: Download get-pip.py
54+
run: curl https://bootstrap.pypa.io/${{ env.GET_PIP_PATH_PREFIX }}get-pip.py -o get-pip.py
55+
56+
- name: Install pip
57+
run: python3 get-pip.py
58+
59+
# TODO: try to remove this after unpining redis
60+
- name: Install setuptools
61+
if: contains(fromJSON('["3.12"]'), matrix.python-version)
62+
run: python3 get-pip.py "setuptools"
63+
64+
- name: Install requirements
65+
run: python3 -m pip install -r requirements.txt
66+
67+
- name: Install requirements for testing
68+
run: python3 -m pip install mockito
69+
70+
- name: Run tests
71+
run: python3 -m unittest tests

.github/workflows/test-ubuntu.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Tests (Ubuntu packages)
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
branches:
9+
- "master"
10+
11+
jobs:
12+
test:
13+
strategy:
14+
matrix:
15+
os: ["ubuntu-24.04", "ubuntu-22.04", "ubuntu-20.04"]
16+
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
submodules: 'true'
22+
- name: Set up Python
23+
run: sudo apt-get install python3
24+
- name: Install requirements
25+
run: sudo apt-get install python3-redis python3-hiredis python3-requests python3-zmq
26+
- name: Install requirements for testing (from PyPA)
27+
if: matrix.os == 'ubuntu-20.04'
28+
run: python3 -m pip install mockito
29+
- name: Install requirements for testing (from Ubuntu packages)
30+
if: matrix.os != 'ubuntu-20.04'
31+
run: sudo apt-get install python3-mockito
32+
- name: Run tests
33+
run: python3 -m unittest tests

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,4 +672,3 @@ may consider it more useful to permit linking proprietary applications with
672672
the library. If this is what you want to do, use the GNU Lesser General
673673
Public License instead of this License. But first, please read
674674
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
675-

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,21 @@ and thus not have the client download them automatically.
9898
- `qlx_workshopReferences`: A comma-separated list of workshop IDs for items you want to force the client to download.
9999
Use this for custom resources, such as sounds packs and whatnot.
100100

101+
## Develop
102+
103+
To install requirements for unit testing:
104+
105+
```
106+
git submodule init
107+
git submodule update --recursive
108+
python3 -m pip install mockito
109+
```
110+
111+
To run unit tests, use following commands:
112+
113+
```
114+
python3 -m unittest tests
115+
```
116+
101117
## Contribute
102-
If you create pull requests, please try to not deviate from the coding style of the plugins (e.g. don't use camelCase variable names and stuff like that), and please create the PR against the develop branch of the repository.
118+
If you create pull requests, please try to not deviate from the coding style of the plugins (e.g. don't use camelCase variable names and stuff like that), and please create the PR against the master branch of the repository.

ban.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(self):
4949
# List of players playing that could potentially be considered leavers.
5050
self.players_start = []
5151
self.pending_warnings = {}
52-
52+
5353
def handle_player_connect(self, player):
5454
status = self.leave_status(player.steam_id)
5555
# Check if a player has been banned for leaving, if we're doing that.
@@ -58,7 +58,7 @@ def handle_player_connect(self, player):
5858
# Check if player needs to be warned.
5959
elif status and status[0] == "warn":
6060
self.pending_warnings[player.steam_id] = status[1]
61-
61+
6262
# Check if a player has been banned manually.
6363
banned = self.is_banned(player.steam_id)
6464
if banned:
@@ -156,7 +156,7 @@ def cmd_ban(self, player, msg, channel):
156156
except minqlx.NonexistentPlayerError:
157157
channel.reply("Invalid client ID. Use either a client ID or a SteamID64.")
158158
return
159-
159+
160160
if target_player:
161161
name = target_player.name
162162
else:
@@ -171,14 +171,14 @@ def cmd_ban(self, player, msg, channel):
171171
reason = " ".join(msg[4:])
172172
else:
173173
reason = ""
174-
174+
175175
r = LENGTH_REGEX.match(" ".join(msg[2:4]).lower())
176176
if r:
177177
number = float(r.group("number"))
178178
if number <= 0: return
179179
scale = r.group("scale").rstrip("s")
180180
td = None
181-
181+
182182
if scale == "second":
183183
td = datetime.timedelta(seconds=number)
184184
elif scale == "minute":
@@ -193,7 +193,7 @@ def cmd_ban(self, player, msg, channel):
193193
td = datetime.timedelta(days=number * 30)
194194
elif scale == "year":
195195
td = datetime.timedelta(weeks=number * 52)
196-
196+
197197
now = datetime.datetime.now().strftime(TIME_FORMAT)
198198
expires = (datetime.datetime.now() + td).strftime(TIME_FORMAT)
199199
base_key = PLAYER_KEY.format(ident) + ":bans"
@@ -203,7 +203,7 @@ def cmd_ban(self, player, msg, channel):
203203
ban = {"expires": expires, "reason": reason, "issued": now, "issued_by": player.steam_id}
204204
db.hmset(base_key + ":{}".format(ban_id), ban)
205205
db.execute()
206-
206+
207207
try:
208208
self.kick(ident, "has been banned until ^6{}^7: {}".format(expires, reason))
209209
except ValueError:
@@ -226,7 +226,7 @@ def cmd_unban(self, player, msg, channel):
226226
except minqlx.NonexistentPlayerError:
227227
channel.reply("Invalid client ID. Use either a client ID or a SteamID64.")
228228
return
229-
229+
230230
if target_player:
231231
name = target_player.name
232232
else:
@@ -260,7 +260,7 @@ def cmd_checkban(self, player, msg, channel):
260260
except minqlx.NonexistentPlayerError:
261261
channel.reply("Invalid client ID. Use either a client ID or a SteamID64.")
262262
return
263-
263+
264264
if target_player:
265265
name = target_player.name
266266
else:
@@ -280,7 +280,7 @@ def cmd_checkban(self, player, msg, channel):
280280
if status and status[0] == "ban":
281281
channel.reply("^6{} ^7is banned for having left too many games.".format(name))
282282
return
283-
283+
284284
channel.reply("^6{} ^7is not banned.".format(name))
285285

286286
def cmd_forgive(self, player, msg, channel):
@@ -300,7 +300,7 @@ def cmd_forgive(self, player, msg, channel):
300300
except minqlx.NonexistentPlayerError:
301301
channel.reply("Invalid client ID. Use either a client ID or a SteamID64.")
302302
return
303-
303+
304304
if target_player:
305305
name = target_player.name
306306
else:
@@ -310,12 +310,12 @@ def cmd_forgive(self, player, msg, channel):
310310
if base_key not in self.db:
311311
channel.reply("I do not know ^6{}^7.".format(name))
312312
return
313-
313+
314314
try:
315315
leaves = int(self.db[base_key + ":games_left"])
316316
except KeyError:
317317
leaves = 0
318-
318+
319319
if leaves <= 0:
320320
channel.reply("^6{}^7's leaves are already at ^6{}^7.".format(name, leaves))
321321
return
@@ -353,7 +353,7 @@ def is_banned(self, steam_id):
353353
expires = datetime.datetime.strptime(longest_ban["expires"], TIME_FORMAT)
354354
if (expires - datetime.datetime.now()).total_seconds() > 0:
355355
return expires, longest_ban["reason"]
356-
356+
357357
return None
358358

359359
def leave_status(self, steam_id):
@@ -368,7 +368,7 @@ def leave_status(self, steam_id):
368368
left = self.db[PLAYER_KEY.format(steam_id) + ":games_left"]
369369
except KeyError:
370370
return None
371-
371+
372372
completed = int(completed)
373373
left = int(left)
374374

@@ -386,7 +386,7 @@ def leave_status(self, steam_id):
386386
ratio = (completed + (min_games_completed - total)) / min_games_completed
387387
else:
388388
ratio = completed / total
389-
389+
390390
if ratio <= warn_threshold and (ratio > ban_threshold or total < min_games_completed):
391391
action = "warn"
392392
elif ratio <= ban_threshold and total >= min_games_completed:

clan.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def handle_set_configstring(self, index, value):
4747
def cmd_clan(self, player, msg, channel):
4848
index = 529 + player.id
4949
tag_key = _tag_key.format(player.steam_id)
50-
50+
5151
if len(msg) < 2:
5252
if tag_key in self.db:
5353
del self.db[tag_key]
@@ -64,7 +64,7 @@ def cmd_clan(self, player, msg, channel):
6464
if len(self.clean_text(msg[1])) > 5:
6565
player.tell("The clan tag can only be at most 5 characters long, excluding colors.")
6666
return minqlx.RET_STOP_EVENT
67-
67+
6868
# If the player already has a clan, we need to edit the current
6969
# configstring. We can't just append cn and xcn.
7070
tag = self.clean_tag(msg[1])
@@ -83,4 +83,3 @@ def sub_func(match):
8383
return match.group(1)
8484

8585
return _re_remove_excessive_colors.sub(sub_func, tag)
86-

docs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def cmd_gencmd(self, players, msg, channel):
4949
"below. A level **2** player can execute level **2**, **1** and **0** commands, and so on.\n"
5050
"\n\n"
5151
)
52-
52+
5353
for perm in sorted(cmds.keys()):
5454
out += "* Permission level **{}**\n\n".format(perm)
5555
for cmd in sorted(cmds[perm], key=lambda x: x.plugin.__class__.__name__):
@@ -62,7 +62,7 @@ def cmd_gencmd(self, players, msg, channel):
6262
out += "`{}`, ".format(name_alias)
6363
out = out[:-2] + ")"
6464
out += " from *{}*\n\n".format(cmd.plugin.__class__.__name__)
65-
65+
6666
# Docstring.
6767
if cmd.handler.__doc__:
6868
out += " {}\n\n".format(cmd.handler.__doc__)
@@ -71,7 +71,7 @@ def cmd_gencmd(self, players, msg, channel):
7171
if cmd.usage:
7272
out += " *Usage*: `{} {}`\n\n" \
7373
.format(name, cmd.usage)
74-
74+
7575
out += "*Automatically generated by [minqlx {} (with plugins {})](https://github.com/MinoMino/minqlx)*" \
7676
.format(minqlx.__version__, minqlx.__plugins_version__)
7777

0 commit comments

Comments
 (0)