Skip to content

Instantly share code, notes, and snippets.

@brandonsturgeon
Created November 11, 2016 21:09
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 brandonsturgeon/40ee5d1d0322881d319ebfe949a1ef4c to your computer and use it in GitHub Desktop.
Save brandonsturgeon/40ee5d1d0322881d319ebfe949a1ef4c to your computer and use it in GitHub Desktop.
module LineHelper
CHAT_REGEX = /^\[\d\d:\d\d:\d\d\] (?:\(TEAM\))?(.*): (.*)\r/
KILL_REGEX = /^\[\d\d:\d\d:\d\d\] (.*) killed (.*) using (.*)\r/
KILLED_BY_REGEX = /^\[\d\d:\d\d:\d\d\] (.*) was killed by (.*)\r/
ENT_REGEX = /^\[\d\d:\d\d:\d\d\] (.*)<(.*)> spawned(?:\/gave himself)? (?:vehicle|model|sent|ragdoll|swep) (.*)\r/
TOOL_REGEX = /^\[\d\d:\d\d:\d\d\] (.*)<(.*)> used the tool (\w*) on (.*)\r/
CONNECTION_REGEX = /^\[\d\d:\d\d:\d\d\] Client \"(.*)\" connected.\r/
SUICIDE_REGEX = /^\[\d\d:\d\d:\d\d\] (.*) suicided!\r/
KICK_REGEX = /^\[\d\d:\d\d:\d\d\] (.*) kicked (.*) \((.*)\)\r/
BAN_REGEX = /^\[\d\d:\d\d:\d\d\] (.*) banned (.*) (?:for (\d* (?:minutes|hours|days)|permanently))(?: (.*))?\r/
def self.identify_line(line)
case line
when CHAT_REGEX
type = 'chat'
data = { player: $1, message: $2 }
{type: type, data: data}
when KILL_REGEX
type = 'kill'
data = { player: $1, victim: $2, weapon: $3 }
{type: type, data: data}
when KILLED_BY_REGEX
type = 'killed_by'
data = { player: $1, killer: $2 }
{type: type, data: data}
when ENT_REGEX
type = 'ent_spawned'
data = { player: $1, ent: $3 }
{type: type, data: data}
when TOOL_REGEX
type = 'tool_used'
data = { player: $1, tool_name: $3, target: $4 }
{type: type, data: data}
when CONNECTION_REGEX
type = 'connection'
data = { player: $1 }
{type: type, data: data}
when SUICIDE_REGEX
type = 'suicide'
data = { player: $1 }
{type: type, data: data}
when KICK_REGEX
type = 'kick'
data = { player: $1, victim: $2, reason: $3 || '' }
{type: type, data: data}
when BAN_REGEX
type = 'ban'
data = { player: $1, victim: $2, length: $3, reason: $4 || ''}
{type: type, data: data}
else
{}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment