Events/join

From Werewolf Wiki
Jump to navigation Jump to search

The join event is called in the !join and !fjoin commands, and is fired before the bot processes the join. The event can control the flow from the join functions, and can bypass the regular join logic with custom logic.

Event callback

def on_join(event: Event, cli: IRCClient, var: module, nick: str, chan: str, rest: str, forced: bool) -> None
  • Default action is to join the user(s) to the game if the command was executed in the main channel and no game is running, otherwise will join the user(s) to deadchat if the command is executed while a game is running. The default action can be prevented so that no built-in join logic is run. In this case, it is the responsibility of the callback to perform all necessary logic.
  • event: The event object
  • cli: The IRC instance
  • var: Reference to the src.settings module
  • nick: Nick that executed the !join or !fjoin. Note: in !fjoin, the nicks to join are in rest, nick itself is not joined
  • chan: Channel the command was executed in
  • rest: Parameters given to the command as a single string. In !join, this may be the gamemode to vote for. In !fjoin, this is the list of players to join.
  • forced: True if this is an !fjoin, False if this is a regular !join.

Event data

{
    "join_player": func(cli: IRCClient, player: str, chan: str, who: str=None, forced: bool=False, *, sanity: bool=True) -> bool,
    "join_deadchat": func(cli: IRCClient, *all_nicks: tuple(str)) -> None,
    "vote_gamemode": func(cli: IRCClient, nick: str, chan: str, gamemode: str, doreply: bool) -> None
}

The event data is initialized to the functions join_player, join_deadchat, and vote_gamemode in wolfgame.py, respectively. These can be called in order to make use of the bot's default logic when preventing the default logic in the join command itself, or can be overridden with custom functions so that the default join logic calls the event's functions instead of the built-in ones. The join_player function should return True if the player was successfully joined, and False otherwise. Its sanity keyword argument is a special case for the maelstrom game mode which if False bypasses checks that prevent players from joining mid-game. If you wish to set this to False, you are responsible for assigning that player to a role; see the maelstrom code for an example of how to do this.