Spaces:
Sleeping

File size: 2,536 Bytes
11af6bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 11 14:23:48 2025

@author: sma
"""

import re

def parse_log_file(log_content: str):
    """
    Parses a CS 1.6 log file and extracts admin actions and chat messages.
    Returns a dictionary with admin names as keys.
    """
    log_lines = log_content.splitlines()
    admin_actions = {}

    # Regex patterns for admin actions
    action_patterns = {
        "kicked": r'"([^<]+)<\d+><STEAM_[^>]+><[^>]*>" kick',
        "banned": r'"([^<]+)<\d+><STEAM_[^>]+><[^>]*>" banned',
        "slapped": r'"([^<]+)<\d+><STEAM_[^>]+><[^>]*>" slap with',
        "slayed": r'"([^<]+)<\d+><STEAM_[^>]+><[^>]*>" slay',
        "transfers": r'"([^<]+)<\d+><STEAM_[^>]+><[^>]*>" transfer',
        "renamed" : r'\[crx_nonamechange\.amxx\]\s+(.*?)\s+changed',
    }

    # Regex for admin chat
    admin_chat_pattern = r'\[adminchat\.amxx\] Chat: "([^"]+)<\d+><[^>]+><>" tsay "(.*)"'

    for line in log_lines:
        found = False
        for action, pattern in action_patterns.items():
            match = re.search(pattern, line)
            if match:
                admin = match.group(1).strip()
                if admin not in admin_actions:
                    admin_actions[admin] = {a: 0 for a in list(action_patterns.keys()) + ["whitechat"]}
                admin_actions[admin][action] += 1
                found = True
                break

        if not found:
            chat_match = re.search(admin_chat_pattern, line)
            if chat_match:
                admin = chat_match.group(1).strip()
                message = chat_match.group(2).strip()
                if admin not in admin_actions:
                    admin_actions[admin] = {a: 0 for a in list(action_patterns.keys()) + ["whitechat"]}
                if "message" not in admin_actions[admin]:
                    admin_actions[admin]["message"] = []
                admin_actions[admin]["whitechat"] += 1
                admin_actions[admin]["message"].append(message)

    return admin_actions


# ---------------- TEST MAIN --------------------------------------------------
if __name__ == "__main__":
    from pathlib import Path
    import pprint

    # Pfad zur Logdatei anpassen
    log_path = Path("L20250908.log")

    if log_path.exists():
        with log_path.open("r", encoding="utf-8", errors="ignore") as f:
            log_content = f.read()

        result = parse_log_file(log_content)
        pprint.pprint(result)
    else:
        print(f"File not found: {log_path}")