2025-01-27 20:32:23 +08:00

219 lines
6.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Flandre.Core.Common;
using Flandre.Core.Messaging.Segments;
using Flandre.Core.Messaging;
using Manganese.Text;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using NLog;
using RestSharp;
using System.Diagnostics;
using static asg_form.Controllers.InviteReferee;
using Newtonsoft.Json;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace asg_form.Controllers
{
[ApiController]
public class WebsiteScreenshot
{
public static async Task<byte[]> CaptureWebsiteAsync(string url)
{
string apiKey = "XFQEXfIxBHqIhT9jKLDNYxRVD8U";
string apiUrl = $"https://api.thumbalizr.com/?url={url}&width=1024&height=768&api_key={apiKey}";
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(apiUrl);
if (response.IsSuccessStatusCode)
{
byte[] imageBytes = await response.Content.ReadAsByteArrayAsync();
return imageBytes;
}
else
{
throw new Exception("Failed to capture screenshot.");
}
}
}
}
public class webhook : ControllerBase
{
private readonly Logger logger = LogManager.GetCurrentClassLogger();
/// <summary>
/// 获取所有video
/// </summary>
/// <returns></returns>
[Route("api/v1/biliup/")]
[HttpPost]
public async Task<ActionResult<List<string>>> get_video([FromBody] Rootobject rootobject)
{
logger.Warn("bilibili webhook" + rootobject.EventType);
if (rootobject.EventType == "FileClosed")
{
logger.Warn(rootobject.EventType);
Random random = new Random();
string[] strings = { "upload", "--copyright 1", "--dolby 0", "--hires 0", $"--title {rootobject.EventData.Title}-直播回放{random.Next(1, 99)}", "--tag 第五人格,第五人格ASG赛事", @$"{AppDomain.CurrentDomain.BaseDirectory}video\{rootobject.EventData.RelativePath}" };
StartProcess("biliup.exe", strings);
return Ok("ok");
}
else
{
return Ok("ok");
}
}
public class azurereq
{
public Message message { get; set; }
public DateTime createdDate { get; set; }
}
public class Message
{
public string text { get; set; }
}
[Route("api/v1/Codepush/")]
[HttpPost]
public async Task<object> Codepush([FromBody] azurereq date)
{
try
{
var message = new MessageBuilder().Text($"后端推送了新的代码库\r\n详细信息{date.message.text}");
try
{
var image = await WebsiteScreenshot.CaptureWebsiteAsync("https://dev.azure.com/luolan/ASG/_git/asg_backend/commits");
message.Image(image);
}
catch
{
}
message.Build();
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "931217544", null, message, "931217544");
}
catch
{
}
return "ok";
}
[Route("api/v1/issueadd/")]
[HttpPost]
public async Task<object> issueadd([FromBody] azurereq date)
{
try
{
var message = new MessageBuilder().Text($"后端有新bug被提交请及时解决\r\n详细信息{date.message.text}").Build();
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "931217544", null, message, "931217544");
}
catch
{
var message = new MessageBuilder().Text($"后端有新bug被提交请及时解决\r\n详细信息{date}").Build();
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "931217544", null, message, "931217544");
}
return "ok";
}
public class biliup
{
public int copyright { get; set; }
public string source { get; set; }
public int tid { get; set; }
public string cover { get; set; }
public string title { get; set; }
public int desc_format_id { get; set; }
public string desc { get; set; }
public string dynamic { get; set; }
public bool open_subtitle { get; set; }
public string tag { get; set; }
public int interactive { get; set; }
public int dolby { get; set; }
public bool up_selection_reply { get; set; }
public bool up_close_reply { get; set; }
public bool up_close_danmu { get; set; }
public string video_path { get; set; }
public string cover_path { get; set; }
}
public bool StartProcess(string runFilePath, params string[] args)
{
string s = "";
foreach (string arg in args)
{
s = s + arg + " ";
}
s = s.Trim();
Process process = new Process();//创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo(runFilePath, s); // 括号里是(程序名,参数)
process.StartInfo = startInfo;
process.Start();
return true;
}
public class Rootobject
{
public string EventType { get; set; }
public DateTime EventTimestamp { get; set; }
public string EventId { get; set; }
public Eventdata EventData { get; set; }
}
public class Eventdata
{
public string RelativePath { get; set; }
public int FileSize { get; set; }
public float Duration { get; set; }
public DateTime FileOpenTime { get; set; }
public DateTime FileCloseTime { get; set; }
public string SessionId { get; set; }
public int RoomId { get; set; }
public int ShortId { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string AreaNameParent { get; set; }
public string AreaNameChild { get; set; }
public bool Recording { get; set; }
public bool Streaming { get; set; }
public bool DanmakuConnected { get; set; }
}
}
}