Skip to content

Instantly share code, notes, and snippets.

@cstewart90
Last active February 4, 2017 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cstewart90/abd37c94fb9a87600173 to your computer and use it in GitHub Desktop.
Save cstewart90/abd37c94fb9a87600173 to your computer and use it in GitHub Desktop.
from enum import Enum
class VoteFlags(Enum):
map = 1
map_restart = 2
nextmap = 4
gametype = 8
kick = 16 # Also clientkick
timelimit = 32
fraglimit = 64
shuffle = 128
teamsize = 256
cointoss = 512 # Also random
loadouts = 1024
endgame_voting = 2048
ammo = 4096
timers = 8192
weaprespawn = 16382
@classmethod
def disabled_votes(cls, value):
return [x.name for x in cls if value & x.value == x.value]
@classmethod
def add_type(cls, current_value, type):
type = VoteFlags[type]
if current_value & type.value == 0:
return current_value + type.value
else:
return current_value
print(VoteFlags.disabled_votes(23)) # Returns ['map', 'map_restart', 'nextmap', 'kick']
try:
print(VoteFlags.add_type(19, "amm")) # Raises KeyError.
except KeyError:
print("type is not valid.")
print(VoteFlags.add_type(1, "kick")) # Returns 17
print(VoteFlags.add_type(0, "ammo")) # Returns 4096
print(VoteFlags.add_type(29816, "kick")) # Returns 29816 because kick is already disabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment