kagtcprlib.handlers

Module handlers contains some example handlers which might be added to Client instances.

Classes

BaseHandler Abstract base class for handlers.
RotatingFileLoggingHandler(log_directory, …) A handler which logs all the lines received to a file.
class kagtcprlib.handlers.BaseHandler[source]

Bases: abc.ABC

Abstract base class for handlers. Handlers are added to `Client`s and respond to lines of text received from KAG.

handle(client_nickname, timestamp, line)[source]

Handles a line of text received from KAG. If the handler returns a string it will be sent over the connection.

Parameters:
  • timestamp (str) – The timestamp of the line
  • line (str) – The line received from kag
class kagtcprlib.handlers.PlayerCountHandler[source]

Bases: kagtcprlib.handlers.BaseHandler

Keeps a count of the number of players on a server by looking for lines like: Joan of Arc (Eluded) is now spectating Joan of Arc (Eluded) has joined Red Team Player Eluded left the game (players left 0)

handle(client_nickname, timestamp, content)[source]

Handles a line of text received from KAG. If the handler returns a string it will be sent over the connection.

Parameters:
  • timestamp (str) – The timestamp of the line
  • line (str) – The line received from kag
class kagtcprlib.handlers.RotatingFileLoggingHandler(log_directory, file_name)[source]

Bases: kagtcprlib.handlers.BaseHandler

A handler which logs all the lines received to a file. Uses RotatingFileHandler internally.

Parameters:
  • log_directory (str) – Path to the directory to place log files in
  • file_name (str) – The name of the log file
handle(client_nickname, timestamp, line)[source]

Handles a line of text received from KAG. If the handler returns a string it will be sent over the connection.

Parameters:
  • timestamp (str) – The timestamp of the line
  • line (str) – The line received from kag