Info and Info Reactor

Info

class mcdreforged.info_reactor.info.Info(source: InfoSource, raw_content: str)[source]

An Info instance contains the parsed result from the server or from the console

id: int

A monotonously increasing unique id

hour: int | None

Time information from the parsed text - hour

min: int | None

Time information from the parsed text - minute

sec: int | None

Time information from the parsed text - second

raw_content: str

Very raw unparsed content from the server stdout.

It’s also the content to be echoed to the stdout

content: str | None

The parsed message text

If the text is sent by a player it will be what the player said. Otherwise it will be the content that removes stuffs like timestamp or thread name

source: InfoSource

A int (actually InfoSource, a subclass of int) representing the the type of the info

For info from the server, its value is 0

For info from the console, its value is 1

See InfoSource for all possible values

logging_level: str | None

The logging level of the server’s stdout, such as "INFO" or "WARN"

property player: str | None

The name of the player

If it’s not sent by a player the value will be None

property is_from_console: bool

If the source of the info is InfoSource.CONSOLE (1), i.e. from the console

property is_from_server: bool

If the source of the info is InfoSource.SERVER (0), i.e. from the server

property is_player: bool

If the source is from a player in the server

property is_user: bool

If the source is from a user, i.e. if the source is from the console or from a player in the server

get_server() ServerInterface[source]

Return the server interface instance

get_command_source() InfoCommandSource | None[source]

Extract a command source object from this object:

  • ConsoleCommandSource if this info is from console

  • PlayerCommandSource if this info is from a player in the server

Returns:

The command source instance, or None if it can’t extract a command source

to_command_source() InfoCommandSource[source]

The same to method get_command_source(), but it raises a IllegalCallError if it can’t extract a command source

Raises:

IllegalCallError – if a command source cannot be extracted from this object

should_send_to_server() bool[source]

Representing if MCDR should send the content to the standard input stream of the server if this info is input from the console

cancel_send_to_server() None[source]

Prevent this info from being sent to the standard input stream of the server

class mcdreforged.info_reactor.info.InfoSource(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: int, Enum

Sources where an Info object comes from

SERVER = 0

From the standard output stream of the server

CONSOLE = 1

From input from console

Info Reactor

class mcdreforged.info_reactor.abstract_info_reactor.AbstractInfoReactor(mcdr_server: MCDReforgedServer)[source]

The abstract base class for info reactors

mcdr_server: MCDReforgedServer

The MCDR server object

abstract react(info: Info)[source]

React to an Info object

It will be invoked on the task executor thread

Parameters:

info – The info to be reacted to

on_server_start()[source]

Gets invoked when the server starts

on_server_stop()[source]

Gets invoked when the server stops

Info Filter

class mcdreforged.info_reactor.info_filter.InfoFilter[source]
abstract filter_server_info(info: Info) bool[source]

Filter an info object from the server output, check if it should be discarded

If the server info object is discarded, it will not be echoed to the console output, and will not be processed by any of the remaining MCDR logic

Do not affect innocent info objects; that is, do not discard those info that contains important messages (e.g. server start / stop), or MCDR might not work correctly

This function is invoked right after an Info object is parsed from server output

Parameters:

info – The info object, which is parsed from server output, to check

Returns:

True: do nothing; False: discard the info object