Skip to content

Commit

Permalink
Add DiscordService
Browse files Browse the repository at this point in the history
  • Loading branch information
jim60105 committed Dec 11, 2023
1 parent 15062d8 commit aeaf6f8
Show file tree
Hide file tree
Showing 8 changed files with 2,171 additions and 2,118 deletions.
35 changes: 1 addition & 34 deletions Helper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Discord;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;

namespace YoutubeLiveChatToDiscord;

Expand Down Expand Up @@ -36,38 +35,6 @@ where File.Exists(path)
return YtdlPath;
}

/// <summary>
/// 把.NET Core logger對應到Discord內建的logger上面
/// </summary>
/// <param name="arg"></param>
/// <returns></returns>
internal static Task DiscordWebhookClient_Log(LogMessage arg)
=> Task.Run(() =>
{
switch (arg.Severity)
{
case LogSeverity.Critical:
_logger.LogCritical("{message}", arg);
break;
case LogSeverity.Error:
_logger.LogError("{message}", arg);
break;
case LogSeverity.Warning:
_logger.LogWarning("{message}", arg);
break;
case LogSeverity.Info:
_logger.LogInformation("{message}", arg);
break;
case LogSeverity.Verbose:
_logger.LogTrace("{message}", arg);
break;
case LogSeverity.Debug:
default:
_logger.LogDebug("{message}", arg);
break;
}
});

/// <summary>
/// 處理Youtube的圖片url,取得原始尺寸圖片
/// </summary>
Expand Down
7 changes: 5 additions & 2 deletions Json/SourceGenerationContext.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using YoutubeLiveChatToDiscord.Models;
using static YoutubeLiveChatToDiscord.Models.Info;

// Must read:
// https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation?pivots=dotnet-8-0
[JsonSerializable(typeof(Info))]
[JsonSerializable(typeof(Chat))]
[JsonSourceGenerationOptions(WriteIndented = true, AllowTrailingCommas = true, ReadCommentHandling = JsonCommentHandling.Skip)]
[JsonSerializable(typeof(Info.info))]
[JsonSerializable(typeof(Chat.chat))]
[JsonSerializable(typeof(Info.Thumbnail), TypeInfoPropertyName = "InfoThumbnail")]
[JsonSerializable(typeof(Chat.Thumbnail), TypeInfoPropertyName = "ChatThumbnail")]
internal partial class SourceGenerationContext : JsonSerializerContext { }
547 changes: 148 additions & 399 deletions LiveChatMonitorWorker.cs

Large diffs are not rendered by default.

Loading

0 comments on commit aeaf6f8

Please sign in to comment.