Skip to content

Commit 3623363

Browse files
committed
Introduce pre-commit with some built-in rules
1 parent a538a67 commit 3623363

16 files changed

Lines changed: 139 additions & 111 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

.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-

balance.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def handle_round_countdown(self, *args, **kwargs):
8282
def f():
8383
self.execute_suggestion()
8484
f()
85-
85+
8686
self.in_countdown = True
8787

8888
def handle_round_start(self, *args, **kwargs):
@@ -100,7 +100,7 @@ def f():
100100
if len(players["red"] + players["blue"]) % 2 != 0:
101101
self.msg("Teams were ^6NOT^7 balanced due to the total number of players being an odd number.")
102102
return
103-
103+
104104
players = dict([(p.steam_id, gt) for p in players["red"] + players["blue"]])
105105
self.add_request(players, self.callback_balance, minqlx.CHAT_CHANNEL)
106106
f()
@@ -166,7 +166,7 @@ def fetch_ratings(self, players, request_id):
166166
last_status = res.status_code
167167
if res.status_code != requests.codes.ok:
168168
continue
169-
169+
170170
js = res.json()
171171
if "players" not in js:
172172
last_status = -1
@@ -181,14 +181,14 @@ def fetch_ratings(self, players, request_id):
181181
with self.ratings_lock:
182182
if sid not in self.ratings:
183183
self.ratings[sid] = {}
184-
184+
185185
for gt in p:
186186
p[gt]["time"] = t
187187
p[gt]["local"] = False
188188
self.ratings[sid][gt] = p[gt]
189189
if self.ratings[sid][gt]["elo"] == 0 and self.ratings[sid][gt]["games"] == 0:
190190
self.ratings[sid][gt]["elo"] = DEFAULT_RATING
191-
191+
192192
if sid in players and gt == players[sid]:
193193
# The API gave us the game type we wanted, so we remove it.
194194
del players[sid]
@@ -304,13 +304,13 @@ def callback_getrating(self, players, channel, gametype):
304304
name = player.name
305305
else:
306306
name = sid
307-
307+
308308
channel.reply("{} has a rating of ^6{}^7 in {}.".format(name, self.ratings[sid][gametype]["elo"], gametype.upper()))
309309

310310
def cmd_setrating(self, player, msg, channel):
311311
if len(msg) < 3:
312312
return minqlx.RET_USAGE
313-
313+
314314
try:
315315
sid = int(msg[1])
316316
target_player = None
@@ -323,7 +323,7 @@ def cmd_setrating(self, player, msg, channel):
323323
except minqlx.NonexistentPlayerError:
324324
player.tell("Invalid client ID. Use either a client ID or a SteamID64.")
325325
return minqlx.RET_STOP_ALL
326-
326+
327327
try:
328328
rating = int(msg[2])
329329
except ValueError:
@@ -334,7 +334,7 @@ def cmd_setrating(self, player, msg, channel):
334334
name = target_player.name
335335
else:
336336
name = sid
337-
337+
338338
gt = self.game.type_short
339339
self.db[RATING_KEY.format(sid, gt)] = rating
340340

@@ -350,7 +350,7 @@ def cmd_setrating(self, player, msg, channel):
350350
def cmd_remrating(self, player, msg, channel):
351351
if len(msg) < 2:
352352
return minqlx.RET_USAGE
353-
353+
354354
try:
355355
sid = int(msg[1])
356356
target_player = None
@@ -363,12 +363,12 @@ def cmd_remrating(self, player, msg, channel):
363363
except minqlx.NonexistentPlayerError:
364364
player.tell("Invalid client ID. Use either a client ID or a SteamID64.")
365365
return minqlx.RET_STOP_ALL
366-
366+
367367
if target_player:
368368
name = target_player.name
369369
else:
370370
name = sid
371-
371+
372372
gt = self.game.type_short
373373
del self.db[RATING_KEY.format(sid, gt)]
374374

@@ -389,7 +389,7 @@ def cmd_balance(self, player, msg, channel):
389389
if len(teams["red"] + teams["blue"]) % 2 != 0:
390390
player.tell("The total number of players should be an even number.")
391391
return minqlx.RET_STOP_ALL
392-
392+
393393
players = dict([(p.steam_id, gt) for p in teams["red"] + teams["blue"]])
394394
self.add_request(players, self.callback_balance, minqlx.CHAT_CHANNEL)
395395

@@ -453,12 +453,12 @@ def cmd_teams(self, player, msg, channel):
453453
if gt not in SUPPORTED_GAMETYPES:
454454
player.tell("This game mode is not supported by the balance plugin.")
455455
return minqlx.RET_STOP_ALL
456-
456+
457457
teams = self.teams()
458458
if len(teams["red"]) != len(teams["blue"]):
459459
player.tell("Both teams should have the same number of players.")
460460
return minqlx.RET_STOP_ALL
461-
461+
462462
teams = dict([(p.steam_id, gt) for p in teams["red"] + teams["blue"]])
463463
self.add_request(teams, self.callback_teams, channel)
464464

@@ -514,7 +514,7 @@ def cmd_agree(self, player, msg, channel):
514514
"""After the bot suggests a switch, players in question can use this to agree to the switch."""
515515
if self.suggested_pair and not all(self.suggested_agree):
516516
p1, p2 = self.suggested_pair
517-
517+
518518
if p1 == player:
519519
self.suggested_agree[0] = True
520520
elif p2 == player:
@@ -534,7 +534,7 @@ def cmd_ratings(self, player, msg, channel):
534534
if gt not in EXT_SUPPORTED_GAMETYPES:
535535
player.tell("This game mode is not supported by the balance plugin.")
536536
return minqlx.RET_STOP_ALL
537-
537+
538538
players = dict([(p.steam_id, gt) for p in self.players()])
539539
self.add_request(players, self.callback_ratings, channel)
540540

@@ -612,9 +612,9 @@ def execute_suggestion(self):
612612
p2.update()
613613
except minqlx.NonexistentPlayerError:
614614
return
615-
615+
616616
if p1.team != "spectator" and p2.team != "spectator":
617617
self.switch(self.suggested_pair[0], self.suggested_pair[1])
618-
618+
619619
self.suggested_pair = None
620620
self.suggested_agree = [False, False]

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)