Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
2fd0ca2c64 | |||
2961bd5322 | |||
5b3e63bd8a | |||
f9d4b179c7 | |||
9a0bba59b5 |
@ -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" />
|
||||||
|
96
AGSS/Controllers/Admin/AdminPlayerControllers.cs
Normal file
96
AGSS/Controllers/Admin/AdminPlayerControllers.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using AGSS.Models.Entities;
|
||||||
|
using AGSS.Models.Template;
|
||||||
|
using AGSS.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AGSS.Controllers.Admin;
|
||||||
|
|
||||||
|
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
|
[Route("api/v1/[controller]")]
|
||||||
|
public class AdminPlayerControllers:ControllerBase
|
||||||
|
{
|
||||||
|
private readonly RoleManager<RoleModel> _roleManager;
|
||||||
|
|
||||||
|
|
||||||
|
private readonly UserManager<UserModel> _userManager; // Assuming UserModel is the type of user
|
||||||
|
|
||||||
|
private readonly PlayerService _playerService;
|
||||||
|
public AdminPlayerControllers(RoleManager<RoleModel> roleManager, UserManager<UserModel> userManager, PlayerService playerService)
|
||||||
|
{
|
||||||
|
_roleManager = roleManager;
|
||||||
|
_userManager = userManager;
|
||||||
|
_playerService = playerService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpDelete]
|
||||||
|
public async Task<IActionResult> DelPlayer(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
await _playerService.DelectPlayerAsync(id);
|
||||||
|
return Ok(new ReturnTemplate(200,"删除成功!",""));
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
return Ok(new ReturnTemplate(500, "出现了错误", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> NewPlayer(PlayerModel player)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
await _playerService.CreatePlayerAsync(player);
|
||||||
|
return Ok(new ReturnTemplate(200, "你已经新建了player", player));
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
return Ok(new ReturnTemplate(500, "出现了错误", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
[HttpGet("Page")]
|
||||||
|
public async Task<IActionResult> GetPlayers([FromQuery] int pageNumber, [FromQuery] int pageSize)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var pagedResult = await _playerService.GetPlayersAsync(pageNumber, pageSize);
|
||||||
|
return Ok(new ReturnTemplate(200, "成功获取玩家列表", pagedResult));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
return Ok(new ReturnTemplate(500, "出现了错误", new PagedResult<PlayerModel>()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> UpdatePlayer([FromBody]PlayerModel player)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await _playerService.UpdatePlayerAsync(player);
|
||||||
|
return Ok(new ReturnTemplate(500, "更新成功",""));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
return Ok(new ReturnTemplate(500, "出现了错误",""));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -10,6 +10,7 @@ namespace AGSS.DbSet
|
|||||||
public override DbSet<RoleModel> Roles { get; set; }
|
public override DbSet<RoleModel> Roles { get; set; }
|
||||||
public DbSet<DictItem> DictItems { get; set; }
|
public DbSet<DictItem> DictItems { get; set; }
|
||||||
public DbSet<MenuModel> Menus { get; set; }
|
public DbSet<MenuModel> Menus { get; set; }
|
||||||
|
public DbSet<PlayerModel> Players { get; set; }
|
||||||
|
|
||||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||||
: base(options)
|
: base(options)
|
||||||
|
10
AGSS/Models/Entities/PagedResult.cs
Normal file
10
AGSS/Models/Entities/PagedResult.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace AGSS.Models.Entities
|
||||||
|
{
|
||||||
|
public class PagedResult<T>
|
||||||
|
{
|
||||||
|
public int TotalItems { get; set; }
|
||||||
|
public int PageNumber { get; set; }
|
||||||
|
public int PageSize { get; set; }
|
||||||
|
public List<T> Items { get; set; } = new List<T>();
|
||||||
|
}
|
||||||
|
}
|
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}");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
57
AGSS/Services/PlayerService.cs
Normal file
57
AGSS/Services/PlayerService.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
using AGSS.DbSet;
|
||||||
|
using AGSS.Models.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace AGSS.Services;
|
||||||
|
|
||||||
|
public class PlayerService
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly ApplicationDbContext _context;
|
||||||
|
|
||||||
|
public PlayerService(ApplicationDbContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> CreatePlayerAsync(PlayerModel player)
|
||||||
|
{
|
||||||
|
var result= await _context.Players.AddAsync(new PlayerModel()
|
||||||
|
{
|
||||||
|
Name = player.Name,
|
||||||
|
Asset = player.Asset,
|
||||||
|
Description = player.Description,
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public async Task<bool> UpdatePlayerAsync(PlayerModel player)
|
||||||
|
{
|
||||||
|
var result = await _context.Players.FirstAsync(a => a.Uuid == player.Uuid);
|
||||||
|
result.Name = player.Name;
|
||||||
|
result.Asset = player.Asset;
|
||||||
|
result.Description = player.Description;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public async Task<bool> DelectPlayerAsync(string PlayerId)
|
||||||
|
{
|
||||||
|
var result = await _context.Players.FirstAsync(a => a.Uuid == PlayerId);
|
||||||
|
_context.Remove(result);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public async Task<PagedResult<PlayerModel>> GetPlayersAsync(int pageNumber, int pageSize)
|
||||||
|
{
|
||||||
|
var totalItems = await _context.Players.CountAsync();
|
||||||
|
var skip = (pageNumber - 1) * pageSize;
|
||||||
|
var players = await _context.Players.Skip(skip).Take(pageSize).ToListAsync();
|
||||||
|
return new PagedResult<PlayerModel>
|
||||||
|
{
|
||||||
|
TotalItems = totalItems,
|
||||||
|
PageNumber = pageNumber,
|
||||||
|
PageSize = pageSize,
|
||||||
|
Items = players
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
41
qodana.yaml
Normal file
41
qodana.yaml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#-------------------------------------------------------------------------------#
|
||||||
|
# Qodana analysis is configured by qodana.yaml file #
|
||||||
|
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
|
||||||
|
#-------------------------------------------------------------------------------#
|
||||||
|
version: "1.0"
|
||||||
|
|
||||||
|
#Specify IDE code to run analysis without container (Applied in CI/CD pipeline)
|
||||||
|
ide: QDNET
|
||||||
|
|
||||||
|
#Specify inspection profile for code analysis
|
||||||
|
profile:
|
||||||
|
name: qodana.starter
|
||||||
|
|
||||||
|
#Enable inspections
|
||||||
|
#include:
|
||||||
|
# - name: <SomeEnabledInspectionId>
|
||||||
|
|
||||||
|
#Disable inspections
|
||||||
|
#exclude:
|
||||||
|
# - name: <SomeDisabledInspectionId>
|
||||||
|
# paths:
|
||||||
|
# - <path/where/not/run/inspection>
|
||||||
|
|
||||||
|
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
|
||||||
|
#bootstrap: sh ./prepare-qodana.sh
|
||||||
|
|
||||||
|
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
|
||||||
|
#plugins:
|
||||||
|
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
|
||||||
|
|
||||||
|
# Quality gate. Will fail the CI/CD pipeline if any condition is not met
|
||||||
|
# severityThresholds - configures maximum thresholds for different problem severities
|
||||||
|
# testCoverageThresholds - configures minimum code coverage on a whole project and newly added code
|
||||||
|
# Code Coverage is available in Ultimate and Ultimate Plus plans
|
||||||
|
#failureConditions:
|
||||||
|
# severityThresholds:
|
||||||
|
# any: 15
|
||||||
|
# critical: 5
|
||||||
|
# testCoverageThresholds:
|
||||||
|
# fresh: 70
|
||||||
|
# total: 50
|
Loading…
x
Reference in New Issue
Block a user