Happenings¶
This module contains a parser of NationStates’ Happenings, with the strong intention of being both complete and convenient.
This page describes how happenings are parsed and processed; to subscribe to the
happening feeds use the World methods happenings()
and new_happenings()
.
Examples¶
Greet every nation that moves to a new region:
async for happening in \
aionationstates.world.new_happenings(filters=['move']):
if type(happening) is aionationstates.happenings.Move:
region_name = await happening.new_region.name()
nation_name = await happening.agent.name()
print(f'Welcome to {region_name}, {nation_name}!')
Detect regional currency adoption:
region_name = 'the pacific'
regional_currency = 'Denarius'
async for happening in aionationstates.world.new_happenings(
filters=['change'], regions=[region_name]):
if type(happening) is aionationstates.happenings.SettingsChange:
if happening.changes.get('currency') == regional_currency:
nation_name = await happening.agent.name()
print(f'{nation_name} has adopted {regional_currency}!')
Detect embassies built and closed:
async for happening in \
aionationstates.world.new_happenings(filters=['embassy']):
region_names = await asyncio.gather(*[
region.name() for region in happening.regions])
if type(happening) is aionationstates.happenings.EmbassyEstablishment:
print('{} ❤️ {}'.format(*region_names))
elif type(happening) is aionationstates.happenings.EmbassyCancellation:
print('{} 💔 {}'.format(*region_names))
Design considerations¶
Parsing happenings can serve a variety of use-cases. You may want to maintain an
endorsement graph for your region, which would require very specific handling of
a handful of happening types (notably Endorsement
,
EndorsementWithdrawal
, Move
, and CTE
) or you might be
after graphing game activity over time, and thus need to process a broad
spectrum of happenings very generically. This module seeks to accomodate both
the precise and broad use-cases.
Base classes¶
Starting with the cold hard truth–
-
class
UnrecognizedHappening
¶ A happening that wasn’t recognized by the system.
Most likely cause of this is the futility of this measly effort against the inescapable and ever-growing chaos of our Universe.
Not necessarily an error in the parsing system, rather an indicator of its incompleteness.
Note that all the other classes in the happenings module inherit from this class, so all the attributes listed below are present on them as well.
-
timestamp
¶ Time of the happening.
- Type
naive UTC
datetime.datetime
-
Now let’s look at how this module functions when it works as intended, shall we?
On the most basic level, all happenings divide into two groups:
-
class
Action
¶ Bases:
aionationstates.happenings.UnrecognizedHappening
A direct action taken by a player.
-
class
Consequence
¶ Bases:
aionationstates.happenings.UnrecognizedHappening
A result of previous actions.
The rest of data classes in this module inherit from the classes above.
Additionally, there are generalizable characteristics some happenings share, that can’t be separated well into categories:
-
class
Regional
¶ Bases:
aionationstates.happenings.UnrecognizedHappening
An event taking place in a single region.
-
class
Affecting
¶ Bases:
aionationstates.happenings.UnrecognizedHappening
An event passively involving a player.
Base classes unifying a set of caracteristics like these can be seen throughout the rest of the module.
Categories of happenings¶
Embassies¶
-
class
Embassy
¶ Bases:
aionationstates.happenings.UnrecognizedHappening
Base class for any event related to an embassy between two regions.
-
class
EmbassyEstablishment
¶ Bases:
aionationstates.happenings.Consequence
,aionationstates.happenings.Embassy
An embassy being established between two regions.
-
class
EmbassyCancellation
¶ Bases:
aionationstates.happenings.Consequence
,aionationstates.happenings.Embassy
Embassy being cancelled between two regions.
-
class
EmbassyOrder
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.RegionalAdministrative
,aionationstates.happenings.Embassy
Base class for any action affecting an embassy.
-
class
EmbassyConstructionRequest
¶ Bases:
aionationstates.happenings.EmbassyOrder
A nation proposing construction of embassies between two regions.
-
class
EmbassyConstructionConfirmation
¶ Bases:
aionationstates.happenings.EmbassyOrder
A nation accepting a request to construct embassies between two regions.
-
class
EmbassyConstructionRequestWithdrawal
¶ Bases:
aionationstates.happenings.EmbassyOrder
A nation withdrawing a request to construct embassies between two regions.
-
class
EmbassyConstructionAbortion
¶ Bases:
aionationstates.happenings.EmbassyOrder
A nation aborting construction of embassies between two regions.
-
class
EmbassyClosureOrder
¶ Bases:
aionationstates.happenings.EmbassyOrder
A nation ordering closure of embassies between two regions.
Administration of a region¶
-
class
RegionalAdministrative
¶ Bases:
aionationstates.happenings.Regional
Base class for any action taken by regional administration, or a change thereof.
-
class
DelegateChange
¶ Bases:
aionationstates.happenings.Consequence
,aionationstates.happenings.RegionalAdministrative
A region changing World Assembly Delegates.
Note that NationStates spreads this out to three distinct happening formats:
delegates changing;
a nation taking the free delegate position; and
a delegate being removed, leaving the position empty.
As I believe this to be superfluous, this class represents all three. In case either the old of new delegate is missing, the corresponding attribute will be set to None.
-
class
OfficerAppointment
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.Affecting
,aionationstates.happenings.RegionalAdministrative
A nation appointing a Regional Officer.
Authority of the new officer.
- Type
-
class
OfficerDismissal
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.Affecting
,aionationstates.happenings.RegionalAdministrative
A nation dismissing a Regional Officer.
-
class
DelegateModification
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.RegionalAdministrative
A founder modifying the authority of the World Assembly Delegate.
- Type
- Type
-
class
OfficerModification
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.Affecting
,aionationstates.happenings.RegionalAdministrative
A founder or Delegate modifying one of the Regional Officers.
- Type
- Type
-
class
PollCreation
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.RegionalAdministrative
A nation creating a new regional poll.
Note that the poll id is inaccessible from the happening, so the created poll can’t be linked directly. The best you can do is request the current poll of the region from the happening.
-
class
PollDeletion
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.RegionalAdministrative
A nation deleting the regional poll.
Z-Day¶
-
class
Zombie
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.Affecting
Base class for any Z-Day strike.
-
class
ZombieCure
¶ Bases:
aionationstates.happenings.Zombie
A nation curing another nation during Z-Day.
-
class
ZombieKill
¶ Bases:
aionationstates.happenings.Zombie
A nation cleansing another nation during Z-Day.
-
class
ZombieInfect
¶ Bases:
aionationstates.happenings.Zombie
A nation infecting another nation during Z-Day.
-
class
ZombieBorderControlActivation
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.RegionalAdministrative
A nation activating regional border control during Z-Day.
-
class
ZombieBorderControlDeactivation
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.RegionalAdministrative
A nation removing regional border control during Z-Day.
World Assembly¶
-
class
WorldAssembly
¶ Bases:
aionationstates.happenings.UnrecognizedHappening
Base class for any event related to the World Assembly.
-
class
WorldAssemblyApplication
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.WorldAssembly
A nation applying to join the World Assembly.
-
class
WorldAssemblyAdmission
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.WorldAssembly
A nation being admitted to the World Assembly.
This is an
Action
, not aConsequence
, as WA admissions are a direct result of following an emailed link.
-
class
WorldAssemblyResignation
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.WorldAssembly
A nation resigning from World Assembly.
The rest¶
-
class
Move
¶ Bases:
aionationstates.happenings.Action
A nation moving regions.
-
class
Founding
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.Regional
A nation being founded.
-
class
Refounding
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.Regional
A nation being refounded.
-
class
CTE
¶ Bases:
aionationstates.happenings.Consequence
,aionationstates.happenings.Affecting
,aionationstates.happenings.Regional
A nation ceasing to exist.
-
class
Legislation
¶ Bases:
aionationstates.happenings.Action
A nation answering an issue.
-
class
FlagChange
¶ Bases:
aionationstates.happenings.Action
A nation altering its flag.
-
class
SettingsChange
¶ Bases:
aionationstates.happenings.Action
A nation modifying its customizeable fields.
-
changes
¶ A mapping of field names (such as “currency”, “motto”, etc.) to their new values.
- Type
dict with keys and values of str
-
-
class
DispatchPublication
¶ Bases:
aionationstates.happenings.Action
A dispatch being published.
In case you’re wondering, deleting a dispatch doesn’t produce a happening.
-
dispatch
¶ - Type
-
-
class
CategoryChange
¶ Bases:
aionationstates.happenings.Consequence
,aionationstates.happenings.Affecting
A nation being reclassified to a different WA Category.
-
class
BannerCreation
¶ Bases:
aionationstates.happenings.Action
A nation creating a custom banner.
-
class
MessageLodgement
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.Regional
A nation lodging a message on a regional message board.
-
class
Endorsement
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.Affecting
A nation endorsing another nation.
-
class
EndorsementWithdrawal
¶ Bases:
aionationstates.happenings.Action
,aionationstates.happenings.Affecting
A nation withdrawing its endorsement of another nation.