添加QQBot功能并引入相关依赖
This commit is contained in:
		
							parent
							
								
									5b3e63bd8a
								
							
						
					
					
						commit
						2961bd5322
					
				@ -10,6 +10,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
 | 
					    <PackageReference Include="Ater.DeepSeek.Core" Version="1.1.6" />
 | 
				
			||||||
    <PackageReference Include="Auth0.ManagementApi" Version="7.38.0" />
 | 
					    <PackageReference Include="Auth0.ManagementApi" Version="7.38.0" />
 | 
				
			||||||
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.17" />
 | 
					    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.17" />
 | 
				
			||||||
    <PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="9.0.6" />
 | 
					    <PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="9.0.6" />
 | 
				
			||||||
@ -21,6 +22,7 @@
 | 
				
			|||||||
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 | 
					      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 | 
				
			||||||
    </PackageReference>
 | 
					    </PackageReference>
 | 
				
			||||||
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
 | 
					    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
 | 
				
			||||||
 | 
					    <PackageReference Include="Mliybs.QQBot" Version="0.7.2" />
 | 
				
			||||||
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
 | 
					    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
 | 
				
			||||||
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
 | 
					    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
 | 
				
			||||||
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.1" />
 | 
					    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.1" />
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										19
									
								
								AGSS/Models/Entities/PlayerModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								AGSS/Models/Entities/PlayerModel.cs
									
									
									
									
									
										Normal file
									
								
							@ -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;}
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -5,6 +5,7 @@ using AGSS.DbSet;
 | 
				
			|||||||
using AGSS.Models;
 | 
					using AGSS.Models;
 | 
				
			||||||
using AGSS.Models.Entities;
 | 
					using AGSS.Models.Entities;
 | 
				
			||||||
using AGSS.Models.Template;
 | 
					using AGSS.Models.Template;
 | 
				
			||||||
 | 
					using AGSS.QQBot;
 | 
				
			||||||
using AGSS.Services;
 | 
					using AGSS.Services;
 | 
				
			||||||
using AGSS.Utilities;
 | 
					using AGSS.Utilities;
 | 
				
			||||||
using asg_form;
 | 
					using asg_form;
 | 
				
			||||||
@ -31,7 +32,8 @@ builder.Services.AddCors(options =>
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 数据库配置(PGSQL)
 | 
					builder.Services.AddHostedService<QQBot>();
 | 
				
			||||||
 | 
					// 数据配置(PGSQL)
 | 
				
			||||||
builder.Services.AddDbContext<ApplicationDbContext>(opt =>
 | 
					builder.Services.AddDbContext<ApplicationDbContext>(opt =>
 | 
				
			||||||
    opt.UseNpgsql(builder.Configuration.GetConnectionString("DBContext")));
 | 
					    opt.UseNpgsql(builder.Configuration.GetConnectionString("DBContext")));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										78
									
								
								AGSS/QQBot/QQBot.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								AGSS/QQBot/QQBot.cs
									
									
									
									
									
										Normal file
									
								
							@ -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}");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					           
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					               
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user