public void CallYoutubeComment(YoutubeLiveChatCallbackBody body) { InsertEventLog($"[{DateTimeExtensions.TimestampToDateTime(body.PublishTime).AddHours(8):yyyy-MM-dd HH:mm:ss}] Vtuber [{body.VtuberName}] 在 {body.LiveAuthorName} 的直播间发表了评论 {body.Message}"); foreach (var vtuberBot in Bots) { var groups = vtuberBot.GetGroupsAsync().GetAwaiter().GetResult(); if (groups == null) { continue; } foreach (var groupInfo in groups) { var config = Config.DefaultConfig.GroupConfigs.FirstOrDefault(v => v.GroupId == groupInfo.GroupId) ?.PublishConfigs.FirstOrDefault(v => v.VtuberName == body.VtuberName); if (config == null || !config.YoutubeComment || LiveList.ContainsKey(body.VtuberName)) { continue; } try { vtuberBot.GetSendingService().SendGroupMessageAsync(groupInfo.GroupId, $"Vtuber {body.VtuberName} 于 {DateTimeExtensions.TimestampToDateTime(body.PublishTime).AddHours(8):yyyy-MM-dd HH:mm:ss} 在 {body.LiveAuthorName} 的直播间发表了评论\r\n" + $"评论内容: {body.Message}\r\n" + $"直播地址: {body.LiveLink}") .GetAwaiter().GetResult(); } catch (Exception ex) { LogHelper.Error("Cannot send message.", true, ex); } } } }
public async Task CallYoutubeCommentedAsync(VtuberEntity commentAuthor, VtuberEntity liveAuthor, YoutubeLiveChat comment) { using (var client = HttpClientExtensions.CreateClient()) { var body = new YoutubeLiveChatCallbackBody() { VtuberName = commentAuthor.OriginalName, LiveAuthorName = liveAuthor.OriginalName, LiveLink = "https://www.youtube.com/watch?v=" + comment.VideoId, Message = comment.DisplayMessage, PublishTime = comment.PublishTime.ToTimestamp(), Sign = Sign }; await client.PostJsonAsync(Url + "youtube/live/vtuberCommented", body); } }