Skip to content
Open
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
38 changes: 36 additions & 2 deletions CustomRPC/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,12 @@ private bool SetPresence()
settings.button1URL = settings.button1URL.Trim();
settings.button2URL = settings.button2URL.Trim();

string settingsWithCountdown = Countdownify(settings.details);

var rp = new RichPresence()
{
Type = (ActivityType)settings.type,
Details = settings.details,
Details = settingsWithCountdown,
State = settings.state,
Party = new Party()
{
Expand Down Expand Up @@ -817,7 +819,8 @@ string Proxify(string key)
return Regex.Replace(key, @"//((cdn)|(media))\.discordapp\.((com)|(net))/", "//customrp.xyz/proxy/");

return key;
};
}
;

try
{
Expand Down Expand Up @@ -1705,5 +1708,36 @@ private void Update(object sender, EventArgs e)
Utils.SaveSettings();
SetPresence();
}

/// <summary>
/// Replace {countdown: dd/mm/yyyy} with number of days until that day
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
private string Countdownify(string input)
{
string[] split = input.Split('{', '}');
string output = "";

foreach (var s in split)
{
if (s.StartsWith("countdown: ") && s.Length == 21)
{
string date = s.Substring(11, 10);

DateTime dateTime = DateTime.ParseExact(date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
int daysUntilDate = dateTime.Subtract(DateTime.Now).Days;
int daysLeft = Math.Max(daysUntilDate, 0); // If we pass the day we don't want to go negative

output += daysLeft;
}
else
{
output += s;
}
}

return output;
}
}
}