API#

Main bot class#

class walnut.bot.WalnutBot(config: Config)#

Main class handling the bot

config#

Bot configuration

discord#

Discord client

Type:

discord.Client

irc#

Discord client

Type:

pyrcb2.IRCBot

tree#

Discord command tree

Type:

discord.app_commands.CommandTree

irc_hooks#

List of hooks called with incoming IRC messages

Type:

list

discord_hooks#

List of hooks called with incoming Discord messages

Type:

list

add_discord_command(command: Command | ContextMenu | Group) None#

Adds a Discord command to the CommandTree

run() None#

Starts the bot and connects to Discord and IRC

Config classes#

See Configuration for more details on configuration options.

class walnut.config.Config(discord_token: str, irc_config: IRCConfig, relays: list[RelayConfig])#

Class storing main Walnut bot configuration

classmethod from_file(file: Path) Config#

Loads configuration from a TOML file

Parameters:

file – Path to a TOML configuration file

Returns:

Pre-set config class

Return type:

Config

Raises:

ValueError – Incorrect config values, missing config keys

class walnut.config.IRCConfig(server: str, port: int, ssl: bool, nickname: str, username: str, realname: str, password: str | None = None)#

Class storing IRC connection configuration

class walnut.config.RelayConfig(irc_channel: IStr, discord_channel_id: int, discord_webhook_url: str | None, colorize_irc_nicknames: bool = True, use_discord_nicknames: bool = True, use_discord_usernames_with_nicknames: bool = True, prevent_self_pinging: bool = True, enable_stickers: bool = True)#

Class storing Discord/IRC relay configuration

Default hooks#

See Extending for information on custom hooks.

class walnut.hooks.base.BaseHook#

Abstract base class for a Walnut IRC/Discord dual hook

abstract async handle_discord_message(message: Message) None#

Processes an incoming Discord message

abstract async handle_irc_message(message: Message) None#

Processes an incoming IRC message

abstract load(bot: WalnutBot) None#

Loads the relay into the bot

class walnut.hooks.relay.MessageRelay(irc_channel: str, discord_channel_id: int, discord_webhook_url: str | None = None)#

Discord/IRC message relay class

format_discord_user(user: User | Member, **kwargs) str#

Formats Discord user’s name for display on IRC

classmethod from_config(config: RelayConfig)#

Initializes a MessageRelay from a RelayConfig

async handle_discord_message(message: Message) None#

Handles and relays a Discord message

async handle_irc_message(message: Message) None#

Handles and relays an IRC message

load(bot: WalnutBot) None#

Loads the relay into the bot