Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from enum import Enum, auto
- users = {}
- storedUsers = {}
- ROUND_TIME = 4*60 + 26
- def main():
- lastGame = []
- lastLines = []
- while True:
- users.clear()
- lines = getLogLines()
- if lines == lastLines:
- continue
- lastLines = lines
- game = getGame(lines)
- if(game == lastGame):
- continue
- lastGame = game
- badActions = getBadActions(game)
- if len(badActions) == 0:
- print("-"*10 + "[Expired]" + "-"*10)
- continue
- for i in range(10):
- print()
- for action in removeDuplicates(badActions):
- print(action)
- time.sleep(30)
- def getUser(name):
- if name in users.keys():
- return users[name]
- user = User(name)
- users[name] = user
- return user
- def getLogLines():
- lines = open(
- "C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive\csgo\output.log", encoding="utf8").readlines()
- result = []
- for line in lines:
- result.append(line.strip())
- return result
- def getGame(lines):
- if "--------------------------------------" not in lines:
- return []
- lines.reverse()
- end = lines.index("--------------------------------------")
- start = lines.index("--------------------------------------", end+2)
- lines = lines[start:end:-1]
- return lines
- def getBadActions(lines):
- users = {}
- flag = []
- for line in lines:
- if not line.startswith("["):
- continue
- if not line[1].isnumeric():
- continue
- time = getTime(line)
- timeLeft = ROUND_TIME - time
- atype = getActionType(line)
- name = getPlayerName(atype, line)
- role = getPlayerRole(atype, line)
- user = getUser(name)
- user.role = role
- if atype == ActionType.DAMAGE or atype == ActionType.KILL:
- id = getPlayerID(line)
- user.id = id
- key = " damaged " if atype == ActionType.DAMAGE else " killed "
- dName = getTargetName(line, key)
- weapon = getWeapon(line)
- dId = getTargetID(line)
- dRole = Role[line[line.index("(", line.index("(", line.index(
- dName) + len(dName))+1)+1: line.index(")", line.index(")", line.index(dName) + len(dName))+1)].upper()]
- damaged = getUser(dName)
- damaged.role = dRole
- damaged.id = dId
- if damaged not in user.damaged:
- user.damaged.append(damaged)
- rLine = user.name + " ("+user.role.value + ")"+key + damaged.name + \
- " ("+damaged.role.value + ") with " + weapon
- if timeLeft < 60 * 2:
- rLine = "(AFTER 2) " + rLine
- if role == Role.INNOCENT and damaged.role == Role.TRAITOR:
- if (len(damaged.damaged) == 0):
- flag.append("[NOSHOT] " + rLine)
- if role != Role.TRAITOR:
- if time < 10 and user not in damaged.damaged:
- flag.append("[EARLY (00:0"+str(time % 60)+")] " + rLine)
- if "BAD ACTION" in line:
- flag.append("[BAD] " + rLine)
- return flag
- def removeDuplicates(lines):
- result = []
- lastline = ""
- amo = 0
- for line in lines:
- if line == lastline:
- amo += 1
- continue
- if amo >= 1:
- result.append(lastline+" x"+str(amo+1))
- else:
- result.append(lastline)
- amo = 0
- lastline = line
- if amo >= 1:
- result.append(line+" x"+str(amo+1))
- else:
- result.append(line)
- return result
- def getActionType(line):
- atype = ActionType.DAMAGE
- if "killed" in line:
- atype = ActionType.KILL
- elif "identified body of" in line:
- atype = ActionType.IDENTIFY
- elif "purchased an item from the shop" in line:
- atype = ActionType.BUY_ITEM
- elif "pressed the button" in line:
- atype = ActionType.BUTTON
- elif "was tased by" in line:
- atype = ActionType.TASER
- return atype
- def getWeapon(line):
- return line[line.index("with ")+len("with "):line.index("]", line.index("]")+1)].replace("weapon_", "").upper()
- def getTime(line):
- return int(line[1:line.index(":")]) * 60 + \
- int(line[line.index(":")+1:line.index("]")])
- def getPlayerRole(action, line):
- if action == ActionType.IDENTIFY:
- role = Role[line[line.index("(")+1: line.index(")")].upper()]
- else:
- role = Role[line[line.index(
- "(", line.index("(") + 1)+1: line.index(")", line.index(")")+1)].upper()]
- return role
- def getPlayerID(line):
- return line[line.index("(")+1:line.index(") (")]
- def getTargetID(line):
- return line[line.index("(", line.index("(", line.index("(")+1)+1)+1: line.index(")", line.index(")", line.index(")")+1)+1)]
- def getPlayerName(action, line):
- if action == ActionType.IDENTIFY:
- name = line[line.index("->")+3:line.index(" (")]
- else:
- name = line[line.index("[", 1)+1:line.index(" (")]
- return name
- def getTargetName(line, key):
- return line[line.index(key) + len(key):line.index(
- "(STEAM_", line.index("(STEAM_")+1) - 1]
- def printNames(players):
- for i in range(len(players)):
- print(players[i].name, end=", ")
- print("")
- class Role(Enum):
- TRAITOR = "T"
- INNOCENT = "I"
- DETECTIVE = "D"
- UNKNOWN = "U"
- class User:
- def __init__(self, name):
- self.name = name
- self.actions = {}
- self.damaged = []
- self.role = Role.UNKNOWN
- self.id = ""
- class ActionType(Enum):
- DAMAGE = auto()
- KILL = auto()
- BUY_ITEM = auto()
- BUTTON = auto()
- IDENTIFY = auto()
- TASER = auto()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement