182 lines
5.5 KiB
C#
Raw Normal View History

2024-11-03 00:08:34 +08:00
using Flandre.Core.Common;
using Flandre.Core.Messaging.Segments;
using Flandre.Core.Messaging;
using Manganese.Text;
2024-08-03 20:40:34 +08:00
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using NLog;
using RestSharp;
using System.Diagnostics;
2024-11-03 00:08:34 +08:00
using static asg_form.Controllers.InviteReferee;
2024-11-03 00:38:59 +08:00
using Newtonsoft.Json;
2024-11-03 00:44:03 +08:00
using static System.Runtime.InteropServices.JavaScript.JSType;
2024-08-03 20:40:34 +08:00
namespace asg_form.Controllers
{
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();
2024-11-03 01:10:52 +08:00
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}" };
2024-08-03 20:40:34 +08:00
StartProcess("biliup.exe", strings);
return Ok("ok");
}
else
{
return Ok("ok");
}
2024-11-03 00:08:34 +08:00
}
2024-11-03 01:10:52 +08:00
public class azurereq
{
public Message message { get; set; }
public DateTime createdDate { get; set; }
}
public class Message
{
public string text { get; set; }
}
2024-11-03 00:08:34 +08:00
[Route("api/v1/Codepush/")]
[HttpPost]
2024-11-03 01:10:52 +08:00
public async Task<object> Codepush([FromBody] azurereq date)
2024-11-03 00:08:34 +08:00
{
2024-11-03 01:10:52 +08:00
try
{
var message = new MessageBuilder().Text($"后端推送了新的代码库\r\n详细信息{date.message.text}").Build();
2024-11-03 00:08:34 +08:00
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "931217544", null, message, "931217544");
}
2024-11-03 01:10:52 +08:00
catch
{
2024-11-03 00:08:34 +08:00
}
return "ok";
}
[Route("api/v1/issueadd/")]
[HttpPost]
2024-11-03 01:10:52 +08:00
public async Task<object> issueadd([FromBody] azurereq date)
2024-11-03 00:08:34 +08:00
{
try
{
2024-11-03 01:10:52 +08:00
2024-11-03 00:17:19 +08:00
var message = new MessageBuilder().Text($"后端有新bug被提交请及时解决\r\n详细信息{date.message.text}").Build();
2024-11-03 00:08:34 +08:00
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "931217544", null, message, "931217544");
2024-08-03 20:40:34 +08:00
2024-11-03 00:08:34 +08:00
}
catch
{
2024-11-03 01:10:52 +08:00
var message = new MessageBuilder().Text($"后端有新bug被提交请及时解决\r\n详细信息{date}").Build();
2024-11-03 00:44:03 +08:00
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "931217544", null, message, "931217544");
2024-08-03 20:40:34 +08:00
2024-11-03 00:08:34 +08:00
}
return "ok";
2024-08-03 20:40:34 +08:00
}
2024-11-03 01:12:42 +08:00
2024-11-03 01:16:02 +08:00
2024-11-03 01:18:51 +08:00
2024-11-03 01:22:46 +08:00
2024-08-03 20:40:34 +08:00
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; }
}
}
}