机器人支持
This commit is contained in:
parent
453bffed77
commit
607afae3c6
@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "解决方案项", "解决
|
||||
main.md = main.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "qqbot", "qqbot\qqbot.csproj", "{48194663-D4E2-40CE-9ED0-9A7459ABA9AD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -22,6 +24,10 @@ Global
|
||||
{6BBCCC2C-1B0A-4456-B9E5-B0EF2B156D8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6BBCCC2C-1B0A-4456-B9E5-B0EF2B156D8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6BBCCC2C-1B0A-4456-B9E5-B0EF2B156D8B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{48194663-D4E2-40CE-9ED0-9A7459ABA9AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{48194663-D4E2-40CE-9ED0-9A7459ABA9AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48194663-D4E2-40CE-9ED0-9A7459ABA9AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{48194663-D4E2-40CE-9ED0-9A7459ABA9AD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1,30 +1,16 @@
|
||||
# 请参阅 https://aka.ms/customizecontainer 以了解如何自定义调试容器,以及 Visual Studio 如何使用此 Dockerfile 生成映像以更快地进行调试。
|
||||
|
||||
# 此阶段用于在快速模式(默认为调试配置)下从 VS 运行时
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
|
||||
# 此阶段用于生成服务项目
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["/asg_form.csproj", "/"]
|
||||
RUN dotnet restore "./root/asg1/asg_backend/asg_form/asg_form.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/root/asg1/asg_backend/asg_form"
|
||||
RUN dotnet build "./root/asg1/asg_backend/asg_form/asg_form.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
# 此阶段用于发布要复制到最终阶段的服务项目
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./root/asg1/asg_backend/asg_form/asg_form.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# 此阶段在生产中使用,或在常规模式下从 VS 运行时使用(在不使用调试配置时为默认值)
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "ASG后端.dll"]
|
||||
#基于 `microsoft/dotnet:1.0.0-core` 来构建我们的镜像
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||
|
||||
#拷贝项目publish文件夹中的所有文件到 docker容器中的publish文件夹中
|
||||
COPY . /publish
|
||||
|
||||
#设置工作目录为 `/publish` 文件夹,即容器启动默认的文件夹
|
||||
WORKDIR /publish
|
||||
|
||||
#设置Docker容器对外暴露8003端口
|
||||
EXPOSE 5000
|
||||
|
||||
#使用`dotnet testmvc.dll`来运行应用程序
|
||||
|
||||
CMD ["dotnet", "ASG后端.dll", "--server.urls", "http://*:5000"]
|
@ -84,7 +84,7 @@ services.AddDbContext<IDBcontext>(opt =>
|
||||
string connStr = @"Host=localhost;Port=2345;Database=asg;Username=postgres;Password=luolan12323;";
|
||||
opt.UseNpgsql(connStr);
|
||||
});
|
||||
services.AddHostedService<qqbot>();
|
||||
//services.AddHostedService<qqbot>();
|
||||
|
||||
|
||||
services.AddDataProtection();
|
||||
@ -191,9 +191,7 @@ app.UseStaticFiles(new StaticFileOptions
|
||||
FileProvider = new PhysicalFileProvider(fileUpload5),
|
||||
RequestPath = "/excel"
|
||||
});
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapHub<room>("/room");
|
||||
|
@ -29,6 +29,8 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ChatGPT.Net" Version="2.0.0" />
|
||||
<PackageReference Include="EntityFrameworkCore.DataEncryption" Version="5.0.0" />
|
||||
<PackageReference Include="Flandre.Core" Version="1.0.0-rc.4" />
|
||||
<PackageReference Include="Flandre.Framework" Version="1.0.0-rc.11" />
|
||||
<PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.16" />
|
||||
<PackageReference Include="ini-parser" Version="2.5.2" />
|
||||
<PackageReference Include="MailKit" Version="4.3.0" />
|
||||
@ -55,6 +57,7 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NLog" Version="5.2.4" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
|
||||
<PackageReference Include="Onebot.Protocol" Version="2.0.143" />
|
||||
|
||||
|
||||
<PackageReference Include="Panda.SimpleExcel" Version="1.3.2" />
|
||||
@ -71,4 +74,10 @@
|
||||
<ContainerPort Include="8081" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Dockerfile">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,4 +1,4 @@
|
||||
using asg_form.Controllers;
|
||||
/*using asg_form.Controllers;
|
||||
using Mirai.Net.Data.Messages.Concretes;
|
||||
using Mirai.Net.Data.Messages;
|
||||
using Mirai.Net.Data.Messages.Receivers;
|
||||
@ -16,6 +16,10 @@ 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;
|
||||
|
||||
namespace asg_form
|
||||
{
|
||||
@ -87,19 +91,17 @@ namespace asg_form
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
//定时任务
|
||||
{
|
||||
//定时任务
|
||||
setTaskAtFixedTime();
|
||||
var bot = new MiraiBot
|
||||
{
|
||||
Address = "localhost:8080",
|
||||
QQ = "197649191",
|
||||
VerifyKey = "1234567890"
|
||||
};
|
||||
var client = new OnebotClient(ConnectionFactory.FromWebsocket("localhost", 7890, "WHO_S_YOUR_DADDY"));
|
||||
await client.SendPrivateMessageAsync("10000", new Message()
|
||||
{
|
||||
MessageSegment.Text("hello")
|
||||
});
|
||||
client.
|
||||
|
||||
await bot.LaunchAsync();
|
||||
|
||||
bot.EventReceived
|
||||
bot.EventReceived
|
||||
.OfType<DroppedEvent>()
|
||||
.Subscribe(async receiver =>
|
||||
{
|
||||
@ -256,3 +258,4 @@ namespace asg_form
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
107
qqbot/Dbset.cs
Normal file
107
qqbot/Dbset.cs
Normal file
@ -0,0 +1,107 @@
|
||||
|
||||
//using asg_form.Controllers.Budget;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace asg_form.Controllers
|
||||
{
|
||||
|
||||
class schgameConfig : IEntityTypeConfiguration<team_game>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<team_game> builder)
|
||||
{
|
||||
builder.ToTable("F_game");
|
||||
builder.Property(e => e.team1_name).IsRequired();
|
||||
builder.Property(e => e.team1_piaoshu).IsRequired();
|
||||
builder.Property(e => e.team2_name).IsRequired();
|
||||
builder.Property(e => e.team2_piaoshu).IsRequired();
|
||||
builder.Property(e => e.opentime).IsRequired();
|
||||
|
||||
}
|
||||
}
|
||||
class RoleConfig : IEntityTypeConfiguration<role>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<role> builder)
|
||||
{
|
||||
builder.ToTable("F_role");
|
||||
builder.Property(e => e.role_id).IsRequired();
|
||||
builder.Property(e => e.role_lin).IsRequired();
|
||||
builder.Property(e => e.role_name).IsRequired();
|
||||
|
||||
}
|
||||
}
|
||||
public class role
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
|
||||
public string role_id { get; set; } = "无";
|
||||
public string role_name { get; set; } = "无";//阵容
|
||||
public string? Game_Name { get; set; } = "未知";
|
||||
public string role_lin { get; set; }
|
||||
public string? Id_Card { get; set; } = "未知";
|
||||
public string? Common_Roles { get; set; } = "未知";
|
||||
public string? Phone_Number { get; set; } = "未知";
|
||||
public string? Id_Card_Name { get; set; } = "未知";
|
||||
public int? Historical_Ranks { get; set; } = 0;
|
||||
}
|
||||
|
||||
public class team_game
|
||||
{
|
||||
public long id { get; set; }
|
||||
|
||||
public string team1_name { get; set; }
|
||||
public int team1_piaoshu { get; set; }
|
||||
public string team2_name { get; set; }
|
||||
public int team2_piaoshu { get; set; }
|
||||
public DateTime opentime { get; set; }
|
||||
/// <summary>
|
||||
/// 解说的名字,用逗号隔开!!!!!!!
|
||||
/// </summary>
|
||||
public string commentary { get; set; }
|
||||
/// <summary>
|
||||
/// 裁判的名字
|
||||
/// </summary>
|
||||
public string referee { get; set; }
|
||||
/// <summary>
|
||||
/// bilibili录屏路径
|
||||
/// </summary>
|
||||
public Uri? bilibiliuri { get; set; }
|
||||
public string? winteam { get; set; }
|
||||
public string? tag { get; set; }
|
||||
public string? belong { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class TestDbContext : DbContext
|
||||
{
|
||||
|
||||
|
||||
public DbSet<role> Roles { get; set; }
|
||||
public DbSet<team_game> team_Games { get; set; }
|
||||
|
||||
//public DbSet<BgDB> budgetDetails { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
string connStr = @"Host=localhost;Port=2345;Database=asg;Username=postgres;Password=luolan12323;";
|
||||
optionsBuilder.UseNpgsql(connStr);
|
||||
|
||||
}
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
63
qqbot/ExamplePlugin.cs
Normal file
63
qqbot/ExamplePlugin.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using asg_form.Controllers;
|
||||
using Flandre.Core.Common;
|
||||
using Flandre.Core.Messaging;
|
||||
using Flandre.Framework.Common;
|
||||
using Flandre.Framework.Routing;
|
||||
|
||||
namespace qqbot
|
||||
{
|
||||
public sealed class ExamplePlugin : Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// 每次收到消息时触发。
|
||||
/// </summary>
|
||||
public override async Task OnMessageReceivedAsync(MessageContext ctx)
|
||||
{
|
||||
// 如果消息文本为 "Hello!",
|
||||
if (ctx.Message.GetText() == "Hello!")
|
||||
{
|
||||
// 则发送一条 "World!" 消息作为回复。
|
||||
await ctx.Bot.SendMessageAsync(ctx.Message, "World!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定义一条指令。<br/>
|
||||
/// 向机器人发送 "example {num}" 时触发,其中 num 为一个合法的 double 值。
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="num">
|
||||
/// 定义一个参数。框架会自动识别参数的类型,并解析用户传入的文本。
|
||||
/// </param>
|
||||
///
|
||||
/// <returns>
|
||||
/// 指令方法需要返回机器人的回复消息。
|
||||
/// </returns>
|
||||
///
|
||||
/// <example>
|
||||
/// 发送:example 1.28 <br/>
|
||||
/// 回复:1.28 的二次方为 1.6384。
|
||||
/// </example>
|
||||
[Command]
|
||||
public string 查询选手(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
TestDbContext ctx = new TestDbContext();
|
||||
|
||||
string msg = "";
|
||||
var roles = ctx.Roles.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";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "出现错误";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
25
qqbot/Program.cs
Normal file
25
qqbot/Program.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Flandre.Adapters.OneBot.Extensions;
|
||||
using Flandre.Framework;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using qqbot;
|
||||
|
||||
var builder = FlandreApp.CreateBuilder(new HostApplicationBuilderSettings
|
||||
{
|
||||
Args = args,
|
||||
ContentRootPath = AppDomain.CurrentDomain.BaseDirectory
|
||||
});
|
||||
|
||||
// 安装一个适配器,并添加在这里。
|
||||
// builder.Adapters.Add(new YourAdapter());
|
||||
builder.Adapters.AddOneBot(builder.Configuration.GetSection("Adapters:OneBot"));
|
||||
builder.Plugins.Add<ExamplePlugin>();
|
||||
|
||||
var app = builder.Build();
|
||||
// 添加内置中间件。
|
||||
// 这些中间件保证 Flandre 的正常运转。你也可以加入自己的中间件,并灵活调整其顺序。
|
||||
app.UseCommandSession();
|
||||
// app.UseMiddleware(async (ctx, next) => { /* ... */ });
|
||||
app.UseCommandParser();
|
||||
app.UseCommandInvoker();
|
||||
|
||||
app.Run();
|
7
qqbot/appsettings.Development.json
Normal file
7
qqbot/appsettings.Development.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug"
|
||||
}
|
||||
}
|
||||
}
|
17
qqbot/appsettings.json
Normal file
17
qqbot/appsettings.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information"
|
||||
}
|
||||
},
|
||||
"Adapters": {
|
||||
"OneBot": {
|
||||
"Bots": [
|
||||
{
|
||||
"Protocol": "WebSocket",
|
||||
"Endpoint": "ws://127.0.0.1:8080"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
23
qqbot/qqbot.csproj
Normal file
23
qqbot/qqbot.csproj
Normal file
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Flandre.Adapters.OneBot.Extensions" Version="2.0.0-rc.3" />
|
||||
<PackageReference Include="Flandre.Core" Version="1.0.0-rc.4" />
|
||||
<PackageReference Include="Flandre.Framework" Version="1.0.0-rc.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- 自动复制配置文件至输出目录 -->
|
||||
<Content Include="**\*.json" Exclude="bin\**\*;obj\**\*" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user