232 lines
7.6 KiB
C#
232 lines
7.6 KiB
C#
using asg_form.Controllers;
|
||
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;
|
||
using Microsoft.AspNetCore.Connections;
|
||
using NPOI.SS.Formula.Functions;
|
||
using Onebot.Protocol;
|
||
using Onebot.Protocol.Models.Messages;
|
||
using Zack.EventBus;
|
||
|
||
namespace asg_form
|
||
{
|
||
[EventName("查询选手")]
|
||
public class qqbot:IIntegrationEventHandler
|
||
{
|
||
private IEventBus eventBus;
|
||
|
||
public qqbot(IEventBus eventBus)
|
||
{
|
||
this.eventBus = eventBus;
|
||
}
|
||
public Task Handle(string eventName, string eventData)
|
||
{
|
||
|
||
if (eventName == "查询选手")
|
||
{
|
||
try
|
||
{
|
||
TestDbContext ctx = new TestDbContext();
|
||
|
||
string msg = "";
|
||
var roles = ctx.Roles.Include(a => a.form).Where(a => a.role_name.IndexOf(eventData) >= 0).ToList();
|
||
foreach (var role in roles)
|
||
{
|
||
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";
|
||
}
|
||
eventBus.Publish("查询选手req",msg);
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
return Task.CompletedTask;
|
||
}
|
||
|
||
|
||
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;
|
||
}
|
||
|
||
private async void doAt1AM(object state)
|
||
{
|
||
//执行功能...
|
||
|
||
}
|
||
|
||
|
||
|
||
// 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
|
||
// {
|
||
|
||
// }
|
||
|
||
// });
|
||
|
||
|
||
// bot.MessageReceived
|
||
//.OfType<GroupMessageReceiver>()
|
||
//.Where(a => a.MessageChain.GetPlainMessage().StartsWith("查询选手 "))
|
||
// .Subscribe(async x =>
|
||
// {
|
||
|
||
|
||
|
||
// });
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// }
|
||
// catch
|
||
// {
|
||
|
||
// }
|
||
|
||
// }
|
||
|
||
|
||
}
|
||
}
|
||
|