2024-10-19 00:43:22 +08:00
|
|
|
|
using asg_form.Controllers;
|
2024-08-03 20:40:34 +08:00
|
|
|
|
using Mirai.Net.Data.Messages.Concretes;
|
|
|
|
|
using Mirai.Net.Data.Messages;
|
|
|
|
|
using Mirai.Net.Data.Messages.Receivers;
|
|
|
|
|
using Mirai.Net.Sessions;
|
|
|
|
|
using Mirai.Net.Sessions.Http.Managers;
|
|
|
|
|
using System.Reactive.Linq;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Mirai.Net.Data.Events.Concretes.Bot;
|
|
|
|
|
using static asg_form.Controllers.schedule;
|
|
|
|
|
using NPOI.OpenXmlFormats.Spreadsheet;
|
|
|
|
|
using Manganese.Array;
|
|
|
|
|
using static NPOI.HSSF.Util.HSSFColor;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using Masuit.Tools.Hardware;
|
|
|
|
|
using Masuit.Tools.Win32;
|
|
|
|
|
using Masuit.Tools;
|
2024-10-02 17:53:16 +08:00
|
|
|
|
using Microsoft.AspNetCore.Connections;
|
|
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
|
using Onebot.Protocol;
|
|
|
|
|
using Onebot.Protocol.Models.Messages;
|
2024-10-19 00:43:22 +08:00
|
|
|
|
using Zack.EventBus;
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
|
|
|
|
namespace asg_form
|
|
|
|
|
{
|
2024-10-19 00:43:22 +08:00
|
|
|
|
[EventName("查询选手")]
|
|
|
|
|
public class qqbot:IIntegrationEventHandler
|
2024-08-03 20:40:34 +08:00
|
|
|
|
{
|
2024-10-19 00:43:22 +08:00
|
|
|
|
private IEventBus eventBus;
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
public qqbot(IEventBus eventBus)
|
2024-08-03 20:40:34 +08:00
|
|
|
|
{
|
2024-10-19 00:43:22 +08:00
|
|
|
|
this.eventBus = eventBus;
|
2024-08-03 20:40:34 +08:00
|
|
|
|
}
|
2024-10-19 00:43:22 +08:00
|
|
|
|
public Task Handle(string eventName, string eventData)
|
2024-08-03 20:40:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
if (eventName == "查询选手")
|
2024-08-03 20:40:34 +08:00
|
|
|
|
{
|
2024-10-19 00:43:22 +08:00
|
|
|
|
try
|
2024-08-03 20:40:34 +08:00
|
|
|
|
{
|
2024-10-19 00:43:22 +08:00
|
|
|
|
TestDbContext ctx = new TestDbContext();
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
|
|
|
|
string msg = "";
|
2024-10-19 00:43:22 +08:00
|
|
|
|
var roles = ctx.Roles.Include(a => a.form).Where(a => a.role_name.IndexOf(eventData) >= 0).ToList();
|
|
|
|
|
foreach (var role in roles)
|
2024-08-03 20:40:34 +08:00
|
|
|
|
{
|
2024-10-19 00:43:22 +08:00
|
|
|
|
msg = $"{msg}\r\n姓名:{role.role_name}\r\n第五人格ID:{role.role_id}\r\n选手id:{role.Id}\r\n阵营:{role.role_lin}\r\n属于队伍:{role.form.team_name}\r\n";
|
2024-08-03 20:40:34 +08:00
|
|
|
|
}
|
2024-10-19 00:43:22 +08:00
|
|
|
|
eventBus.Publish("查询选手req",msg);
|
2024-08-03 20:40:34 +08:00
|
|
|
|
}
|
2024-10-19 00:43:22 +08:00
|
|
|
|
catch
|
2024-08-03 20:40:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2024-10-19 00:43:22 +08:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
public static bool isToday(DateTime dt)
|
|
|
|
|
{
|
|
|
|
|
DateTime today = DateTime.Today;
|
|
|
|
|
DateTime tempToday = new DateTime(dt.Year, dt.Month, dt.Day);
|
|
|
|
|
if (today == tempToday)
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
private async void doAt1AM(object state)
|
|
|
|
|
{
|
|
|
|
|
//执行功能...
|
|
|
|
|
|
|
|
|
|
}
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
// protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
|
|
// {
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
// var client = new OnebotClient(ConnectionFactory.FromWebsocket("localhost", 7890, "WHO_S_YOUR_DADDY"));
|
|
|
|
|
// await client.SendPrivateMessageAsync("10000", new Message()
|
|
|
|
|
// {
|
|
|
|
|
// MessageSegment.Text("hello")
|
|
|
|
|
// });
|
|
|
|
|
// client.
|
|
|
|
|
|
|
|
|
|
// bot.EventReceived
|
|
|
|
|
// .OfType<DroppedEvent>()
|
|
|
|
|
// .Subscribe(async receiver =>
|
|
|
|
|
// {
|
|
|
|
|
// await Task.Delay(10000);
|
|
|
|
|
// await ExecuteAsync(stoppingToken);
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// bot.MessageReceived
|
|
|
|
|
// .OfType<GroupMessageReceiver>()
|
|
|
|
|
// .Subscribe(async x =>
|
|
|
|
|
// {
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// if (x.MessageChain.GetPlainMessage() == "近期赛程")
|
|
|
|
|
// {
|
|
|
|
|
// TestDbContext testDb = new TestDbContext();
|
|
|
|
|
// int q = testDb.team_Games.Count();
|
|
|
|
|
// var a = testDb.team_Games.Where(a => a.opentime >= DateTime.Now).Take(7);
|
|
|
|
|
// string msg = "";
|
|
|
|
|
// foreach (var b in a)
|
|
|
|
|
// {
|
|
|
|
|
// msg = $"{msg}\r\n{b.team1_name} VS {b.team2_name}\r\n时间:{b.opentime.ToString("f")}";
|
|
|
|
|
// }
|
|
|
|
|
// await MessageManager.SendGroupMessageAsync(x.GroupId, msg);
|
|
|
|
|
// }
|
|
|
|
|
// if (x.MessageChain.GetPlainMessage() == "后端状态")
|
|
|
|
|
// {
|
|
|
|
|
// string msg = $"CPU占用:{SystemInfo.CpuLoad.ToString("f2")}\r\n内存占用:{SystemInfo.MemoryAvailable.ToString("f2")}\r\n部署系统:{Windows.GetOsVersion()}";
|
|
|
|
|
|
|
|
|
|
// await MessageManager.SendGroupMessageAsync(x.GroupId, msg);
|
|
|
|
|
// }
|
|
|
|
|
// if (x.MessageChain.GetPlainMessage() == "参赛队伍")
|
|
|
|
|
// {
|
|
|
|
|
// TestDbContext testDb = new TestDbContext();
|
|
|
|
|
// var team = testDb.Forms.Select(a => a.team_name);
|
|
|
|
|
// string msg = "";
|
|
|
|
|
// foreach (var t in team)
|
|
|
|
|
// {
|
|
|
|
|
// msg = $"{msg} {t}";
|
|
|
|
|
// }
|
|
|
|
|
// await MessageManager.SendGroupMessageAsync(x.GroupId, $"在所有比赛中有以下队伍参赛:\r\n{string.Join(" , ",team)}");
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// if (x.MessageChain.GetPlainMessage() == "查询冠军")
|
|
|
|
|
// {
|
|
|
|
|
// TestDbContext ctx = new TestDbContext();
|
|
|
|
|
|
|
|
|
|
// var teams = ctx.Champions.Include(a=>a.events).Include(a=>a.form.role).Select(a => new {a.form,a.events,a.msg}).ToList();
|
|
|
|
|
// string msg = "";
|
|
|
|
|
// foreach (var t in teams)
|
|
|
|
|
// {
|
|
|
|
|
// string role = "";
|
|
|
|
|
|
|
|
|
|
// foreach (var t2 in t.form.role)
|
|
|
|
|
// {
|
|
|
|
|
// role = $"{role} {t2.role_name}";
|
|
|
|
|
// }
|
|
|
|
|
// msg = $"{msg}\r\n队伍名称:{t.form.team_name}\r\n队员:{role}\r\n属于:{t.events.name}\r\n简介:{t.msg}\r\n";
|
|
|
|
|
// }
|
|
|
|
|
// await MessageManager.SendGroupMessageAsync(x.GroupId, $"拥有以下冠军:{msg}");
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// catch(Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// await MessageManager.SendGroupMessageAsync(x.GroupId, $"错误:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// bot.MessageReceived
|
|
|
|
|
// .OfType<GroupMessageReceiver>()
|
|
|
|
|
// .Where(a=>a.MessageChain.GetPlainMessage().StartsWith("查询战队 "))
|
|
|
|
|
// .Subscribe(async x =>
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
// TestDbContext ctx = new TestDbContext();
|
|
|
|
|
|
|
|
|
|
// string result = x.MessageChain.GetPlainMessage().Substring(5); // 截取从'o'之后的字符串
|
|
|
|
|
// Console.WriteLine(result);
|
|
|
|
|
// List<form> teams = ctx.Forms.Include(a => a.role).Where(a => a.team_name.IndexOf(result) >= 0).ToList();
|
|
|
|
|
// string msg = "";
|
|
|
|
|
// foreach (var t in teams)
|
|
|
|
|
// {
|
|
|
|
|
// string role = "";
|
|
|
|
|
// foreach (var t2 in t.role)
|
|
|
|
|
// {
|
|
|
|
|
// role = $"{role} {t2.role_name}";
|
|
|
|
|
// }
|
|
|
|
|
// msg = $"{msg}\r\n队伍名称:{t.team_name}\r\n队员:{role}\r\n";
|
|
|
|
|
// }
|
|
|
|
|
// await MessageManager.SendGroupMessageAsync(x.GroupId, msg);
|
|
|
|
|
// }
|
|
|
|
|
// catch
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
// }
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
// });
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
// bot.MessageReceived
|
|
|
|
|
//.OfType<GroupMessageReceiver>()
|
|
|
|
|
//.Where(a => a.MessageChain.GetPlainMessage().StartsWith("查询选手 "))
|
|
|
|
|
// .Subscribe(async x =>
|
|
|
|
|
// {
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
// });
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
// }
|
|
|
|
|
// catch
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
// }
|
2024-08-03 20:40:34 +08:00
|
|
|
|
|
2024-10-19 00:43:22 +08:00
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-08-03 20:40:34 +08:00
|
|
|
|
}
|
|
|
|
|
|