Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord Backups with Webhooks #34

Merged
merged 22 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Models/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ static Settings()
/// </summary>
public string? DataLocation { get; set; }

/// <summary>
/// Discord WebHook URL for backups.
/// </summary>
public string? DiscordWebhookURL { get; set; }

/// <summary>
/// Discord WebHook backups toggle state.
/// </summary>
public bool DiscordWebhookEnabled { get; set; }

/// <summary>
/// Automatically copy newly detected save codes as you play.
/// </summary>
Expand Down
12 changes: 8 additions & 4 deletions Models/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ internal class Entry
public DateTime Timestamp;
public string Content;

[JsonProperty("pc")]
public int PlayerCount;
public string? Players;

public string[]? RTerrors;
public string? RType;
public ToNRoundType RT;
public ToNRoundResult RResult;

[JsonIgnore] public History? Parent;
[JsonIgnore] public bool Fresh;
[JsonIgnore] public int Length => Content.Length;

Expand All @@ -58,7 +62,7 @@ public override string ToString()
if (Settings.Get.SaveRoundInfo && Settings.Get.ShowWinLose)
{
sb.Append('[');
sb.Append(RResult == ToNRoundResult.R ? ' ' : RResult.ToString());
sb.Append(RResult);
sb.Append("] ");
}

Expand All @@ -73,11 +77,11 @@ public override string ToString()
return sb.ToString();
}

public string GetTooltip(bool showPlayers, bool showTerrors)
public string GetTooltip(bool showPlayers, bool showTerrors, bool showNote = true)
{
StringBuilder sb = new StringBuilder();
sb.Append(Timestamp.ToString("F"));
if (!string.IsNullOrEmpty(Note))
if (!string.IsNullOrEmpty(Note) && showNote)
{
sb.AppendLine();
sb.AppendLine();
Expand All @@ -89,7 +93,7 @@ public string GetTooltip(bool showPlayers, bool showTerrors)
sb.AppendLine();
sb.AppendLine();

sb.AppendLine("Round info: " + (RResult == ToNRoundResult.W ? "Survived" : "Died"));
// sb.AppendLine("Round info: " + (RResult == ToNRoundResult.W ? "Survived" : "Died"));

if (!string.IsNullOrEmpty(RType))
sb.AppendLine("Round type: " + RType);
Expand Down
9 changes: 9 additions & 0 deletions Models/History.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Newtonsoft.Json;
using System.Globalization;

using LogContext = ToNSaveManager.Utils.LogWatcher.LogContext;

namespace ToNSaveManager.Models
{
internal class History : IComparable<History>
Expand All @@ -10,6 +12,8 @@ internal class History : IComparable<History>
public DateTime Timestamp = DateTime.MinValue;
public bool IsCustom = false;

public string? DisplayName = string.Empty;

[JsonConstructor]
private History() { }

Expand All @@ -27,6 +31,11 @@ public History(string name, DateTime timestamp)
IsCustom = true;
}

public void SetLogContext(LogContext context)
{
DisplayName = context.DisplayName;
}

public void SetLogKey(string logKey)
{
if (IsCustom) return;
Expand Down
39 changes: 36 additions & 3 deletions Models/ToNIndex.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using Newtonsoft.Json;

namespace ToNSaveManager.Models
{
Expand Down Expand Up @@ -93,6 +93,9 @@ public string GetNames(string separator = ", ")
"RUN" , "走れ!", // The meatball man
"8 Pages" , "8ページ",

// Events
"Cold Night" , "冷たい夜", // Winterfest

// Beyond's favorite
"Custom" , "カスタム", // IGNORE SAVES FOR THIS ONE
};
Expand All @@ -115,13 +118,40 @@ static ToNRoundType GetRoundType(string raw)
raw = raw.Replace(' ', '_').Replace("8", "Eight");
return Enum.TryParse(typeof(ToNRoundType), raw, out object? result) && result != null ? (ToNRoundType)result : ToNRoundType.Unknown;
}

internal static uint GetRoundColorFromType(ToNRoundType RoundType) => RoundTypeColors.ContainsKey(RoundType) ? RoundTypeColors[RoundType] : 16721714;

internal static readonly Dictionary<ToNRoundType, uint> RoundTypeColors = new Dictionary<ToNRoundType, uint>()
{
{ ToNRoundType.Unknown, 16721714 },
{ ToNRoundType.Classic, 0xFFFFFF },
{ ToNRoundType.Fog, 0x808486 },
{ ToNRoundType.Punished, 0xFFF800 },
{ ToNRoundType.Sabotage, 0x3BF37D },
{ ToNRoundType.Cracked, 0xFF00D3 },
{ ToNRoundType.Bloodbath, 0xF51313 },

{ ToNRoundType.Midnight, 0xE23232 },
{ ToNRoundType.Alternate, 0xF1F1F1 },

{ ToNRoundType.Mystic_Moon, 0xB0DEF9 },
{ ToNRoundType.Twilight, 0xF8A900 },
{ ToNRoundType.Blood_Moon, 0xF51313 },
{ ToNRoundType.Solstice, 0x3BF3B3 },

{ ToNRoundType.RUN, 0xC15E3D },
{ ToNRoundType.Eight_Pages, 0xFFFFFF },
{ ToNRoundType.Custom, 0x000000 }, // Ignored

{ ToNRoundType.Cold_Night, 0xA37BE4 },
};
}

public enum ToNRoundResult
{
R, // Respawn
W, // Win
L, // Lose
D, // Leaving
}

public enum ToNRoundType
Expand All @@ -140,7 +170,10 @@ public enum ToNRoundType
Mystic_Moon, Blood_Moon, Twilight, Solstice,

// Special // Replace 8 with Eight
RUN, Eight_Pages, Custom
RUN, Eight_Pages, Custom,

// Events
Cold_Night
}

internal class ToNIndex
Expand Down
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
- `Auto Clipboard Copy` Automatically copy new save codes to clipboard.
- `Collect Player Names` Save codes will show players that were in the instance.
- `XSOverlay Popup` XSOverlay notifications when new save codes are detected.
- `Play Audio` Play a notification audio when a new save is detected.
- `Play Sound` Play a notification audio when a new save is detected.
- Double Click to select a custom audio file. (Only '.wav' files)
- Right Click to reset audio file back to 'default.wav'
- `Colorful Objectives` Items in the 'Objectives' window will show colors that correspond to those of the items in the game.
- `Auto Discord Backup` Uses a [discord webhook](##how-to-properly-configure-automatic-discord-backup-using-webhooks) to automatically upload a backup of your new codes to a discord channel as you play.
- `Check For Updates` When clicked, it will check this github repo for new releases, and prompt you to try an automatic update.
<details><summary>Preview Image</summary><p> <img src="Resources/settings.png" > </p></details>

Expand All @@ -41,6 +42,7 @@
- ### Save Codes (Right Panel)
* `Add to` Lets you save or favorite this code to a separated custom collection with a name of your choice.
* `Edit Note` You can attach a note to this save code, so you can recognize it better.
* `Backup` Forces a backup upload to Discord if **Auto Discord Backup** is configured on settings.
* `Delete` Deletes just this save code from the database.

### Objectives Window
Expand Down Expand Up @@ -71,6 +73,26 @@
> <p> <img src="Resources/logging.png" height="420px" > </p>
> </details>

> ## How to properly configure Automatic Discord Backup using Webhooks?
> You can set a Discord webhook url to automatically upload your codes to a discord channel.
>
> - Just go to your preferred channel on your discord server.
> - Click **Edit Channel** and then go to **Integrations**.
> - Add a webhook integration to this channel. *You can give it a name and a profile picture*.
> - Copy the webhook url.
> - Open settings on the Save Manager app.
> - Enable `Auto Discord Backup`, you will see a text input popup.
> - Paste your webhook url in the text field.
> - Click **save**.
>
> NOTE: If you want to test this functionality, you can right click on a save entry then click **Backup**. If everything is right, save will be uploaded to the discord channel.
> <details>
> <summary><b>Show Discord Screenshots</b></summary>
> <p> <img src="Resources/Webhook/screenshot_0.png" height="auto" > </p>
> <p> <img src="Resources/Webhook/screenshot_1.png" width="682px" > </p>
> <p> <img src="Resources/Webhook/screenshot_2.png" width="512px" > </p>
> </details>

> ## Why is the .exe so big? >100MB
> The exe is bundled with the .NET runtime that it's required to run the program. Using a command line argument for dotnet publishing: `--self-contained true -p:PublishSingleFile=true` <br>
> This adds size to the file, but ensures that the program runs independently without relying on a previous .NET installation.
Expand All @@ -87,8 +109,14 @@
> We are allowed to read these files since it does not modify or alter the game in any way.
> **This is not a mod or a cheat.**

> ### Please do <u>NOT</u> message Beyond about suggestions or problems with this tool.
> You can report problems or suggestions under the [Issues](https://github.com/ChrisFeline/ToNSaveManager/issues) tab on this repo. Alternatively see contact information below.

# 📫 Contact:
> **Discord:** [@Kittenji](https://discord.gg/HGk2RQX)<br>
> **VRChat:** [Kittenji](https://vrchat.com/home/user/usr_7ac745b8-e50e-4c9c-95e5-8e7e3bcde682)
> ## Say hi if you see me playing [Terrors of Nowhere](https://vrchat.com/home/world/wrld_a61cdabe-1218-4287-9ffc-2a4d1414e5bd)!
> <p> <img src="Resources/loop.gif" alt="Preview" title="AAAAAA!"> </p>
> <p> <img src="Resources/loop.gif" alt="Preview" title="AAAAAA!"> </p>

# ❤️ Support:
> If you want to support the development of this tool you can [Buy Me A Coffee ♥](https://ko-fi.com/kittenji) on ko-fi.
Binary file added Resources/Webhook/screenshot_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Webhook/screenshot_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Webhook/screenshot_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Resources/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/support_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions ToNSaveManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,19 @@
<Folder Include="Properties\DataSources\" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
Loading
Loading