From 2961bd53226f8205ca7fac541419c3b9cb385618 Mon Sep 17 00:00:00 2001 From: luolan Date: Thu, 21 Aug 2025 16:59:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0QQBot=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E5=BC=95=E5=85=A5=E7=9B=B8=E5=85=B3=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGSS/AGSS.csproj | 2 + AGSS/Models/Entities/PlayerModel.cs | 19 +++++++ AGSS/Program.cs | 4 +- AGSS/QQBot/QQBot.cs | 78 +++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 AGSS/Models/Entities/PlayerModel.cs create mode 100644 AGSS/QQBot/QQBot.cs diff --git a/AGSS/AGSS.csproj b/AGSS/AGSS.csproj index 345d158..d5a4a8a 100644 --- a/AGSS/AGSS.csproj +++ b/AGSS/AGSS.csproj @@ -10,6 +10,7 @@ + @@ -21,6 +22,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/AGSS/Models/Entities/PlayerModel.cs b/AGSS/Models/Entities/PlayerModel.cs new file mode 100644 index 0000000..e03c4f3 --- /dev/null +++ b/AGSS/Models/Entities/PlayerModel.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; + +namespace AGSS.Models.Entities; + +public class PlayerModel +{ + [Key] + [MaxLength(150)] + public string Uuid { get; set; } = string.Empty; + + [MaxLength(10)] + public required string Name { get; set;} + [MaxLength(1300)] + public required string Description { get; set;} + [MaxLength(150)] + public required string Asset { get; set;} + + +} \ No newline at end of file diff --git a/AGSS/Program.cs b/AGSS/Program.cs index d4ca93b..549efc8 100644 --- a/AGSS/Program.cs +++ b/AGSS/Program.cs @@ -5,6 +5,7 @@ using AGSS.DbSet; using AGSS.Models; using AGSS.Models.Entities; using AGSS.Models.Template; +using AGSS.QQBot; using AGSS.Services; using AGSS.Utilities; using asg_form; @@ -31,7 +32,8 @@ builder.Services.AddCors(options => }); -// 数据库配置(PGSQL) +builder.Services.AddHostedService(); +// 数据配置(PGSQL) builder.Services.AddDbContext(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("DBContext"))); diff --git a/AGSS/QQBot/QQBot.cs b/AGSS/QQBot/QQBot.cs new file mode 100644 index 0000000..9f28f67 --- /dev/null +++ b/AGSS/QQBot/QQBot.cs @@ -0,0 +1,78 @@ + + +using System.Text.Json; +using DeepSeek.Core; +using DeepSeek.Core.Models; +using Mliybs.QQBot.Bots.WebSocket; + +namespace AGSS.QQBot +{ + public class QQBot:BackgroundService + { + + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + + try + { + + string id = "102802431"; + string secret = "VTRPNLJHFEDCBA98888888889ABCDEFH"; + + + using var bot = new WebSocketBot(id, secret); // 此处的id与secret为外部填入的参数 + +// 该方法会返回ReadyEvent对象,只要没有抛出异常就视为连接成功 +// 方法参数填入需要订阅的事件,默认不填表示订阅私信与群聊事件(不包括频道私信) +// 使用位或运算订阅多个事件,如WebSocketIntent.GroupAndC2cEvent | WebSocketIntent.PublicGuildMessages + await bot.ConnectAsync(); + + bot.MessageReceived.Subscribe(async x => + { + if (x.Content == " test") + { + + } + else + { + // Create an instance using the apiKey + var client = new DeepSeekClient("sk-e18c1c1fb9c94888a4e59328436640b6"); + +// Construct the request body + var request = new ChatRequest + { + Messages = [ + Message.NewUserMessage(x.Content) + ], + // Specify the model + Model = Constant.Model.ChatModel + }; + + var chatResponse = await client.ChatAsync(request, new CancellationToken()); + if (chatResponse is null) + { + Console.WriteLine(client.ErrorMsg); + } + await x.ReplyAsync(chatResponse?.Choices.First().Message?.Content); + } + Console.WriteLine(x.Content); + // 回复消息 + }); + + bot.KeepRunning(); // 如果当前线程为主线程请调用该方法或Console.ReadLine()卡住线程 + + + } + catch (Exception e) + { + Console.WriteLine($"启动失败了{e}"); + } + + + + + + } + } + } \ No newline at end of file