377 lines
11 KiB
C#
Raw Normal View History

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-10-19 14:20:39 +08:00
using Flandre.Framework.Common;
using Flandre.Framework.Routing;
using static asg_form.Controllers.InviteReferee;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Text;
using Azure.Identity;
using OpenAI.Chat;
using Azure.AI.OpenAI;
using Flandre.Core.Messaging;
using Flandre.Core.Common;
2024-08-03 20:40:34 +08:00
namespace asg_form
{
2024-10-19 14:20:39 +08:00
public static class runbot
{
public static Bot runbotr { get; set; }
}
2024-10-19 00:43:22 +08:00
[EventName("查询选手")]
2024-10-19 14:20:39 +08:00
public class qqbot:Plugin
2024-08-03 20:40:34 +08:00
{
2024-10-19 14:20:39 +08:00
[Command]
public string (string name)
2024-08-03 20:40:34 +08:00
{
2024-10-19 14:20:39 +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 14:20:39 +08:00
var roles = ctx.Roles.Include(a => a.form).Where(a => a.role_name.IndexOf(name) >= 0).ToList();
2024-10-19 00:43:22 +08:00
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 14:20:39 +08:00
return msg ;
}
catch
{
return "出现错误";
}
}
[Command]
public string ()
{
try
{
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")}";
}
return msg;
}
catch
{
return "出现错误";
}
}
[Command]
public string ()
{
try
{
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";
2024-08-03 20:40:34 +08:00
}
2024-10-19 14:20:39 +08:00
return msg;
}
catch
{
return "出现错误";
}
}
[Command]
public string (string name)
{
try
{
TestDbContext ctx = new TestDbContext();
List<form> teams = ctx.Forms.Include(a => a.role).Where(a => a.team_name.IndexOf(name) >= 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";
}
return msg;
}
catch
{
return "出现错误";
}
}
[Command]
public async Task<string> (MessageContext ctx)
{
try
{
using(TestDbContext testDb=new TestDbContext())
2024-08-03 20:40:34 +08:00
{
2024-10-19 14:20:39 +08:00
Random ran = new Random();
int n = ran.Next(100, 200);
2024-08-03 20:40:34 +08:00
2024-10-19 14:20:39 +08:00
if (!testDb.Qqusers.Any(a => a.qqid == ctx.UserId))
{
await testDb.Qqusers.AddAsync(new qquser { qqid = ctx.UserId, money = n });
}
else
{
var user=await testDb.Qqusers.FirstAsync(a=>a.qqid == ctx.UserId);
user.money += n;
}
await testDb.SaveChangesAsync();
return $"罗比很开心\r\n给你棒棒糖{n.ToString()}个";
2024-08-03 20:40:34 +08:00
}
2024-10-19 14:20:39 +08:00
}
catch
{
return "出现错误";
}
}
[Command]
public string ai(string msg)
{
try
{
AzureOpenAIClient azureClient = new(
new Uri("https://dashscope.aliyuncs.com/compatible-mode/v1"),
new System.ClientModel.ApiKeyCredential("sk-c6f37689f4014b5bbf5fd8b2e872d20b"));
ChatClient chatClient = azureClient.GetChatClient("qwen-turbo");
ChatCompletion completion = chatClient.CompleteChat(
[
// System messages represent instructions or other guidance about how the assistant should behave
new UserChatMessage("我们来玩角色扮演接下来你是一个没有父母但很喜欢姐姐的一个小男孩"),
new UserChatMessage(msg),
]);
return completion.Content[0].Text;
}
catch
{
return "出现错误";
}
}
[Command]
public string aimath(string msg)
{
try
{
AzureOpenAIClient azureClient = new(
new Uri("https://dashscope.aliyuncs.com/compatible-mode/v1"),
new System.ClientModel.ApiKeyCredential("sk-c6f37689f4014b5bbf5fd8b2e872d20b"));
ChatClient chatClient = azureClient.GetChatClient("qwen-math-plus");
ChatCompletion completion = chatClient.CompleteChat(
[
// System messages represent instructions or other guidance about how the assistant should behave
new UserChatMessage(msg),
]);
2024-08-03 20:40:34 +08:00
2024-10-19 14:20:39 +08:00
return completion.Content[0].Text;
}
catch
{
return "出现错误";
2024-08-03 20:40:34 +08:00
}
2024-10-19 14:20:39 +08:00
2024-10-19 00:43:22 +08:00
}
2024-08-03 20:40:34 +08:00
2024-10-19 14:20:39 +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-10-19 14:20:39 +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
// 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
// {
2024-10-19 14:20:39 +08:00
2024-10-19 00:43:22 +08:00
// }
// 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
}