A Discord webhook that the server can post messages to. The class is also the registry of the webhooks: Webhook:add stores a webhook under an ID, and Webhook:get, Webhook:all and Webhook:get_type look the stored ones up. Every webhook lists the types of messages it accepts, so that a message of some type can be posted to all of the webhooks that want it. Flux creates the webhooks listed in the settings of the server and posts log messages to them with Log:to_discord.

Summary

Methods

Adds a webhook to the list of registered webhooks.
all()server
Returns all of the registered webhooks.
get(id)server
Returns the registered webhook with the specified ID.
Returns the registered webhooks that accept messages of the specified type.
Creates a new Discord webhook.
Checks whether this webhook accepts messages of the specified type.
Checks whether a webhook with the specified ID is registered.
Posts a message to the Discord webhook.

Methods

Webhook:add(id, webhook)

server packages/flow/lib/classes/sv_webhook.lua:53

Adds a webhook to the list of registered webhooks.

Webhook:add(id, Webhook.new(data.id, data.key, data.types))

Parameters

  • id String ID to store the webhook under
  • webhook Webhook/Function optional, defaults to nil webhook or a function that returns one, a blank webhook is created if omitted

Returns

  • Webhook the stored webhook

Returns all of the registered webhooks.

Returns

  • Map webhooks by ID

Returns the registered webhook with the specified ID. Also available as Webhook#find and Webhook#find_by_id.

Parameters

  • id String

Returns

  • Webhook the webhook, or nil if there is no such webhook

Webhook:get_type(message_type)

server packages/flow/lib/classes/sv_webhook.lua:82

Returns the registered webhooks that accept messages of the specified type.

Parameters

  • message_type String message type

Returns

  • List<Webhook>

Webhook:init(id, key, types)

server packages/flow/lib/classes/sv_webhook.lua:22

Creates a new Discord webhook.

Parameters

  • id String optional, defaults to '' ID of the Discord webhook
  • key String optional, defaults to '' token of the Discord webhook
  • types List<String> optional, defaults to {} types of messages the webhook accepts, 'all' for any type

Webhook:is_type(message_type)

server packages/flow/lib/classes/sv_webhook.lua:105

Checks whether this webhook accepts messages of the specified type.

Parameters

  • message_type String message type

Returns

  • Boolean

Webhook:present(id)

server packages/flow/lib/classes/sv_webhook.lua:98

Checks whether a webhook with the specified ID is registered. Also available as Webhook#exists and Webhook#exist.

Parameters

  • id String

Returns

  • Boolean

Webhook:push(message, data)

server packages/flow/lib/classes/sv_webhook.lua:32

Posts a message to the Discord webhook.

Parameters

  • message String
  • data Map optional, defaults to {} optional username, avatar_url and tts fields of the message

Defined in