Skip to content

Commit

Permalink
Merge pull request #265 from nwesterhausen/nw-doc-update
Browse files Browse the repository at this point in the history
docs: update docs
  • Loading branch information
nwesterhausen authored May 30, 2024
2 parents 092e3e4 + 8e314cd commit 6d6f291
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 43 deletions.
1 change: 1 addition & 0 deletions docs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A plugin to connect your Valheim server to Discord.
- Server startup (server starting, loading the world)
- Server started (world loaded, ready to join)
- Server shutting down (server stopping)
- New day starts on server
- Player join
- Player leave
- Player shouting
Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

A full changelog of changes, dating all the way back to the first release.

## Version upcoming

Features

- Server New Day event and message
- `%DAY_NUMBER%` variable replacement

## Version 2.2.0

Features
Expand Down
9 changes: 9 additions & 0 deletions docs/config/messages.events.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ In the event messages, anywhere in the message you can use the string vars `%EVE
| `%EVENT_MSG%` | The appropriate start/end message for the event | Event start/stop message |
:::

::: tip Available Dynamic Variables

| Variable | Replaced with.. | Can be used in.. |
| ------------------- | ----------------------------------------------------------------------------------------- | ------------------- |
| `%VAR1%` - `VAR10%` | Custom variable value (defined in [Custom Variables](/config/variables.html) config file) | Any messages |
| `%PUBLICIP%` | Server's public IP (according to the server) | Any server messages |
| `%DAY_NUMBER%` | Current day number on server | Any messages |
:::

:::details Random Messages
All of the message options support having multiple messages defined in a semicolon (`;`) separated list. If you have multiple messages defined for these settings, one gets chosen at random when DiscordConnector decides to send the corresponding message.

Expand Down
9 changes: 6 additions & 3 deletions docs/config/messages.leaderboards.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Messages.LeaderBoards

::: details Available Custom Variables
These are defined in the [Custom Variables](/config/variables.html) config file.
::: tip Available Dynamic Variables

`%VAR1%`, `%VAR2%`, `%VAR3%`, `%VAR4%`, `%VAR5%`, `%VAR6%`, `%VAR7%`, `%VAR8%`, `%VAR9%`, `%VAR10%`
| Variable | Replaced with.. | Can be used in.. |
| ------------------- | ----------------------------------------------------------------------------------------- | ------------------- |
| `%VAR1%` - `VAR10%` | Custom variable value (defined in [Custom Variables](/config/variables.html) config file) | Any messages |
| `%PUBLICIP%` | Server's public IP (according to the server) | Any server messages |
| `%DAY_NUMBER%` | Current day number on server | Any messages |
:::

## Leader Board Heading for Top N Players
Expand Down
9 changes: 9 additions & 0 deletions docs/config/messages.player.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
| `%POS%` | Player's coordinate position | Player join/leave/shout/ping/death messages. |
:::

::: tip Available Dynamic Variables

| Variable | Replaced with.. | Can be used in.. |
| ------------------- | ----------------------------------------------------------------------------------------- | ------------------- |
| `%VAR1%` - `VAR10%` | Custom variable value (defined in [Custom Variables](/config/variables.html) config file) | Any messages |
| `%PUBLICIP%` | Server's public IP (according to the server) | Any server messages |
| `%DAY_NUMBER%` | Current day number on server | Any messages |
:::

:::details Random Messages
All of the message options support having multiple messages defined in a semicolon (`;`) separated list. If you have multiple messages defined for these settings, one gets chosen at random when DiscordConnector decides to send the corresponding message.

Expand Down
9 changes: 9 additions & 0 deletions docs/config/messages.playerfirsts.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
| `%POS%` | Player's coordinate position | Player join/leave/shout/ping/death messages. |
:::

::: tip Available Dynamic Variables

| Variable | Replaced with.. | Can be used in.. |
| ------------------- | ----------------------------------------------------------------------------------------- | ------------------- |
| `%VAR1%` - `VAR10%` | Custom variable value (defined in [Custom Variables](/config/variables.html) config file) | Any messages |
| `%PUBLICIP%` | Server's public IP (according to the server) | Any server messages |
| `%DAY_NUMBER%` | Current day number on server | Any messages |
:::

:::details Random Messages
All of the message options support having multiple messages defined in a semicolon (`;`) separated list. If you have multiple messages defined for these settings, one gets chosen at random when DiscordConnector decides to send the corresponding message.

Expand Down
11 changes: 7 additions & 4 deletions docs/config/messages.server.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Messages.Server

::: tip Available Predefined Variables (Server)
| Variable | Replaced with.. | Can be used in.. |
| ------------ | ---------------------------------------------------------------------- | ------------------- |
| `%PUBLICIP%` | Server's public IP (obtained from [ifconfig.me](https://ifconfig.me/)) | Any server messages |
::: tip Available Dynamic Variables

| Variable | Replaced with.. | Can be used in.. |
| ------------------- | ----------------------------------------------------------------------------------------- | ------------------- |
| `%VAR1%` - `VAR10%` | Custom variable value (defined in [Custom Variables](/config/variables.html) config file) | Any messages |
| `%PUBLICIP%` | Server's public IP (according to the server) | Any server messages |
| `%DAY_NUMBER%` | Current day number on server | Any messages |
:::

## Server Launch Message
Expand Down
64 changes: 58 additions & 6 deletions src/DiscordApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static void SendMessage(Webhook.Event ev, string message, UnityEngine.Vec
{
if (Plugin.StaticConfig.DiscordEmbedsEnabled)
{
SendMessageWithFields(ev, message, new List<Tuple<string, string>> {
SendMessageWithFields(ev, message, [
Tuple.Create("Coordinates",MessageTransformer.FormatVector3AsPos(pos))
});
]);
}
else
{
Expand All @@ -36,7 +36,7 @@ public static void SendMessage(Webhook.Event ev, string message, UnityEngine.Vec
public static void SendMessage(Webhook.Event ev, string message)
{
// A simple string message
var payload = new DiscordSimpleWebhook
DiscordSimpleWebhook payload = new()
{
content = message
};
Expand Down Expand Up @@ -73,7 +73,7 @@ public static void SendMessageWithFields(Webhook.Event ev, string content = null
if (fields != null)
{
// Convert the fields into JSON Strings
List<string> fieldStrings = new List<string>();
List<string> fieldStrings = [];
foreach (Tuple<string, string> t in fields)
{
try
Expand All @@ -92,7 +92,7 @@ public static void SendMessageWithFields(Webhook.Event ev, string content = null

if (fieldStrings.Count > 0)
{
// Put the field JSON strings into our payload object
// Put the field JSON strings into our payload object
// Fields go under embed as array
payloadString += "\"embeds\":[{\"fields\":[";
payloadString += string.Join(",", fieldStrings.ToArray());
Expand All @@ -113,7 +113,7 @@ public static void SendMessageWithFields(Webhook.Event ev, string content = null
payloadString += $"\"content\":\"{content}\"";
}

// Finish the payload JSON
// Finish the payload JSON
payloadString += "}";

// Use our pre-existing method to send serialized JSON to discord
Expand Down Expand Up @@ -246,25 +246,77 @@ private static void SendSerializedJson(string serializedJson)
}
}

/// <summary>
/// Simple webhook object is used for messages that contain only a simple string.
/// </summary>
internal class DiscordSimpleWebhook
{
/// <summary>
/// The message content to send to Discord. This is considered simple because it is not a series of embeds/fields.
///
/// This works best for simple messages, and is used for most messages sent by the plugin.
///
/// E.g. "Player joined the game", "Player left the game", etc.
/// </summary>
public string content { get; set; }
}

/// <summary>
/// Complex webhook object is used for messages that contain more than just a simple string.
/// </summary>
internal class DiscordComplexWebhook
{
/// <summary>
/// Message content to send to Discord. This is considered complex because it contains multiple embeds/fields.
///
/// This is used for POS embeds, and the leaderboards.
/// </summary>
public DiscordEmbed embeds { get; set; }
}

/// <summary>
/// A complex Discord message, containing more than just a simple string.
///
/// See https://discord.com/developers/docs/resources/channel#embed-object
/// </summary>
internal class DiscordEmbed
{

#nullable enable
/// <summary>
/// The title of the message.
/// </summary>
public string? title { get; set; }
/// <summary>
/// The description of the message.
/// </summary>
public string? description { get; set; }
/// <summary>
/// A list of fields to include in the message.
///
/// For leaderboards, each leaderboard that is included is a field.
/// </summary>
public List<DiscordField>? fields { get; set; }
#nullable restore
}

/// <summary>
/// A field for a Discord message, which allows for fancy formatting.
///
/// See https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
/// </summary>
internal class DiscordField
{
/// <summary>
/// Name of the field.
///
/// These are just titled embedded values, where the name is the title. The value is a content string.
/// </summary>
public string name { get; set; }
/// <summary>
/// The string content of the field.
///
/// For example, the leaderboards are a list with `\n` as a separator, so they appear as an ordered list in Discord.
/// </summary>
public string value { get; set; }
}
Loading

0 comments on commit 6d6f291

Please sign in to comment.