-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathvotemanager.py
84 lines (64 loc) · 3.47 KB
/
votemanager.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
76
77
78
79
80
81
82
83
84
# Created by Thomas Jones on 19/01/2016 - thomas@tomtecsolutions.com
# votemanager.py - a minqlx plugin to permit privileged players to vote normally initially, then vote a second time to force the vote either way.
# 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
"""
This plugin works best when the player isn't a QLDS mod/admin, otherwise it can only be
used to give the impression that a QLDS mod/admin voted.
You can also protect players with permission level >= LEVEL from getting kickvoted
by setting: qlx_protectedPerm "LEVEL"
"""
import minqlx
class votemanager(minqlx.Plugin):
def __init__(self):
self.add_hook("vote_called", self.handle_vote_called)
self.add_hook("vote_started", self.handle_vote_started)
self.add_hook("vote", self.handle_vote)
self.add_hook("vote_ended", self.handle_vote_ended)
self.add_command("tomtec_versions", self.cmd_showversion)
self.set_cvar_once("qlx_protectedPerm", "1")
self.has_voted = []
self.plugin_version = "1.4"
def handle_vote_started(self, player, vote, args):
self.has_voted = []
def handle_vote_called(self, caller, vote, args):
if vote.lower() in ["clientkick", "kick"]:
try:
guy = self.player(int(args)) if vote.lower() == "clientkick" else self.find_player(args.lower())[0]
except:
return minqlx.RET_STOP_ALL
perm = self.db.get_permission(guy)
if perm >= self.get_cvar("qlx_protectedPerm", int):
caller.tell("{}^7 has permission level ^4{}^7 and will not be kicked.".format(guy.name, perm))
return minqlx.RET_STOP_ALL
self.has_voted.append(caller)
def handle_vote(self, player, yes):
if not self.is_vote_active():
return
if player in self.has_voted:
ident = player.steam_id
if (player.privileges != None or self.db.has_permission(ident, 3)):
minqlx.force_vote(yes)
if yes:
word = "passed"
else:
word = "vetoed"
self.msg("{}^7 {} the vote.".format(player.name, word))
return minqlx.RET_STOP_ALL
self.has_voted.append(player)
if (player.privileges != None):
# at least give the impression that the QLDS admin/mod voted normally.
if yes:
yes_votes = int(minqlx.get_configstring(10))
yes_votes += 1
minqlx.set_configstring(10, str(yes_votes))
else:
no_votes = int(minqlx.get_configstring(11))
no_votes += 1
minqlx.set_configstring(11, str(no_votes))
return minqlx.RET_STOP_ALL
#self.msg("self.has_voted == {}".format(str(self.has_voted))) # was used to make sure we stored player objects properly.
def handle_vote_ended(self, votes, vote, args, passed):
self.has_voted = []
def cmd_showversion(self, player, msg, channel):
channel.reply("^4votemanager.py^7 - version {}, created by Thomas Jones on 19/01/2016.".format(self.plugin_version))