2024-10-19 14:20:39 +08:00

377 lines
11 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 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;
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;
namespace asg_form
{
public static class runbot
{
public static Bot runbotr { get; set; }
}
[EventName("查询选手")]
public class qqbot:Plugin
{
[Command]
public string (string name)
{
try
{
TestDbContext ctx = new TestDbContext();
string msg = "";
var roles = ctx.Roles.Include(a => a.form).Where(a => a.role_name.IndexOf(name) >= 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";
}
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";
}
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())
{
Random ran = new Random();
int n = ran.Next(100, 200);
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()}个";
}
}
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),
]);
return completion.Content[0].Text;
}
catch
{
return "出现错误";
}
}
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
// {
// }
// 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
// {
// }
// }
}
}