mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-21 21:54:36 +00:00
Noi
ddcde10e09
All existing VB code was 'translated' to C# as closely as possible, with minor changes and additional notes. Currently untested and likely broken. Further commits will go toward making overall improvements until this version replaces the currently existing code.
64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace BirthdayBot.Data
|
|
{
|
|
/// <summary>
|
|
/// Holds information regarding the previous updating information done on a guild including success/error information.
|
|
/// </summary>
|
|
class OperationStatus
|
|
{
|
|
private readonly Dictionary<OperationType, string> _log = new Dictionary<OperationType, string>();
|
|
|
|
public DateTimeOffset Timestamp { get; }
|
|
|
|
public OperationStatus (params (OperationType, string)[] statuses)
|
|
{
|
|
Timestamp = DateTimeOffset.UtcNow;
|
|
foreach (var status in statuses)
|
|
{
|
|
_log[status.Item1] = status.Item2;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prepares known information in a displayable format.
|
|
/// </summary>
|
|
public string GetDiagStrings()
|
|
{
|
|
var report = new StringBuilder();
|
|
foreach (OperationType otype in Enum.GetValues(typeof(OperationType)))
|
|
{
|
|
var prefix = $"`{Enum.GetName(typeof(OperationType), otype)}`: ";
|
|
|
|
string info = null;
|
|
|
|
if (!_log.TryGetValue(otype, out info))
|
|
{
|
|
report.AppendLine(prefix + "No data");
|
|
continue;
|
|
}
|
|
|
|
if (info == null)
|
|
{
|
|
report.AppendLine(prefix + "Success");
|
|
}
|
|
else
|
|
{
|
|
report.AppendLine(prefix + info);
|
|
}
|
|
}
|
|
return report.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Specifies the type of operation logged. These enum values are publicly displayed in the specified order.
|
|
/// </summary>
|
|
public enum OperationType
|
|
{
|
|
UpdateBirthdayRoleMembership,
|
|
SendBirthdayAnnouncementMessage
|
|
}
|
|
}
|
|
}
|