Skip to content

Commit fd73ad5

Browse files
committed
added DiscordTimestamp example and updated readme
1 parent 9217ffe commit fd73ad5

15 files changed

Lines changed: 2854 additions & 20 deletions

HuntroxGames/DiscordWebhookUnity/Example/DiscordTS.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Linq;
3+
using HuntroxGames.Utils;
4+
using HuntroxGames.Utils.DiscordWebhook;
5+
using TMPro;
6+
using UnityEngine;
7+
8+
namespace HuntroxGames.Examples
9+
{
10+
public class DiscordTSExample : MonoBehaviour
11+
{
12+
[Header("Webhook Settings")]
13+
[SerializeField] private string webhookName = "DTS Bot";
14+
[SerializeField] private string webhookAvatarUrl = "";
15+
[SerializeField] private string webhookUrl = "";
16+
17+
[Header("UI References")]
18+
[SerializeField] private TMP_Dropdown tsTypeDropdown;
19+
[SerializeField] private TMP_InputField textInput;
20+
21+
private void Start()
22+
{
23+
//clear all options in tsTypeDropdown
24+
tsTypeDropdown.ClearOptions();
25+
//create options for all DiscordTimestampFormat enum values
26+
tsTypeDropdown.AddOptions(Enum.GetNames(typeof(DiscordTimestampFormat)).ToList());
27+
tsTypeDropdown.value = 0;
28+
tsTypeDropdown.RefreshShownValue();
29+
}
30+
public void SendWebhook()
31+
{
32+
var content = textInput.text;
33+
var tsType = (DiscordTimestampFormat)tsTypeDropdown.value;
34+
var timestamp = Utils.Utils.DateToDiscordTimestamp(DateTime.Now, tsType);
35+
var webhook = new Webhook
36+
{
37+
username = webhookName,
38+
avatar_url = webhookAvatarUrl
39+
};
40+
webhook.SetContent($"{content} {timestamp}");
41+
webhook.SendWebhook(webhookUrl);
42+
43+
}
44+
}
45+
}

HuntroxGames/DiscordWebhookUnity/Example/DiscordTS/DiscordTSExample.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)