-
Notifications
You must be signed in to change notification settings - Fork 30
/
permaban.py
75 lines (54 loc) · 3.12 KB
/
permaban.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Created by Thomas Jones on 19/06/2017 - thomas@tomtecsolutions.com
# permaban.py, a plugin for minqlx to thoroughly perma-ban players.
# This plugin is released to everyone, for any purpose. It comes with no warranty, no guarantee it works, it's released AS IS.
# You can modify everything, except for lines 1-4 and the !tomtec_versions code. They're there to indicate I whacked this together originally. Please make it better :D
import minqlx
class permaban(minqlx.Plugin):
def __init__(self):
self.add_hook("player_connect", self.handle_player_connect, priority=minqlx.PRI_HIGH)
self.add_command("permaban", self.cmd_permaban, 5, usage="<id>/<steam_id>")
self.add_command("tomtec_versions", self.cmd_showversion)
self.plugin_version = "1.5"
def cmd_permaban(self, player, msg, channel):
if len(msg) < 2:
return minqlx.RET_USAGE
try:
ident = int(msg[1])
target_player = None
if 0 <= ident < 64:
steam_id = self.player(int(msg[1])).steam_id
player_name = self.player(int(msg[1])).name
else:
player_name = ident
steam_id = ident
except ValueError:
channel.reply("Invalid ID. Use either a client ID or a SteamID64.")
return
except minqlx.NonexistentPlayerError:
channel.reply("Invalid client ID. Use either a client ID or a SteamID64.")
return
self.db.set("minqlx:players:{}:permabanned".format(steam_id), "1")
if self.player(steam_id):
self.kick(self.player(steam_id), "You have been permanently banned.")
channel.reply("{}^7 has been permanently banned.".format(player_name))
def handle_player_connect(self, player):
is_banned_id = self.is_banned(player)
if is_banned_id:
if (is_banned_id == player.steam_id):
return "Your account is permabanned.\n"
else:
self.db.set("minqlx:players:{}:permabanned".format(is_banned_id), "1") # make sure every single associated account is banned
self.db.set("minqlx:players:{}:permabanned".format(player.steam_id), "1") # make sure the new account is banned
return "Your associated accounts are permabanned.\n"
def is_banned(self, player):
ip_list = list(self.db.smembers("minqlx:players:{}:ips".format(player.steam_id)))
ip_list.append(player.ip)
if self.db.get("minqlx:players:{}:permabanned".format(player.steam_id)) == "1":
return player.steam_id
for ip in ip_list:
for steam_id in list(self.db.smembers("minqlx:ips:{}".format(ip))):
if self.db.get("minqlx:players:{}:permabanned".format(steam_id)) == "1":
return steam_id
return False
def cmd_showversion(self, player, msg, channel):
channel.reply("^4permaban.py^7 - version {}, created by Thomas Jones on 19/06/2017.".format(self.plugin_version))