diff --git a/asg_form.sln b/asg_form.sln index 5e0c515..bc1bca9 100644 --- a/asg_form.sln +++ b/asg_form.sln @@ -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 diff --git a/asg_form/Dockerfile b/asg_form/Dockerfile index d625d7a..d598be4 100644 --- a/asg_form/Dockerfile +++ b/asg_form/Dockerfile @@ -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"] \ No newline at end of file +#基于 `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"] \ No newline at end of file diff --git a/asg_form/Program.cs b/asg_form/Program.cs index 1147cb5..23b551b 100644 --- a/asg_form/Program.cs +++ b/asg_form/Program.cs @@ -84,7 +84,7 @@ services.AddDbContext(opt => string connStr = @"Host=localhost;Port=2345;Database=asg;Username=postgres;Password=luolan12323;"; opt.UseNpgsql(connStr); }); -services.AddHostedService(); +//services.AddHostedService(); services.AddDataProtection(); @@ -191,9 +191,7 @@ app.UseStaticFiles(new StaticFileOptions FileProvider = new PhysicalFileProvider(fileUpload5), RequestPath = "/excel" }); - app.UseAuthentication(); - app.UseAuthorization(); app.MapHub("/room"); diff --git a/asg_form/asg_form.csproj b/asg_form/asg_form.csproj index 076f8b5..8acaf42 100644 --- a/asg_form/asg_form.csproj +++ b/asg_form/asg_form.csproj @@ -29,6 +29,8 @@ + + @@ -55,6 +57,7 @@ + @@ -71,4 +74,10 @@ + + + PreserveNewest + + + diff --git a/asg_form/qqbot.cs b/asg_form/qqbot.cs index 6ea0b29..76b7f0b 100644 --- a/asg_form/qqbot.cs +++ b/asg_form/qqbot.cs @@ -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() .Subscribe(async receiver => { @@ -256,3 +258,4 @@ namespace asg_form } } +*/ \ No newline at end of file diff --git a/qqbot/Dbset.cs b/qqbot/Dbset.cs new file mode 100644 index 0000000..4c06695 --- /dev/null +++ b/qqbot/Dbset.cs @@ -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 + { + public void Configure(EntityTypeBuilder 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 + { + public void Configure(EntityTypeBuilder 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; } + /// + /// 解说的名字,用逗号隔开!!!!!!! + /// + public string commentary { get; set; } + /// + /// 裁判的名字 + /// + public string referee { get; set; } + /// + /// bilibili录屏路径 + /// + 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 Roles { get; set; } + public DbSet team_Games { get; set; } + + //public DbSet 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); + } + + } + + + + + +} \ No newline at end of file diff --git a/qqbot/ExamplePlugin.cs b/qqbot/ExamplePlugin.cs new file mode 100644 index 0000000..52b051c --- /dev/null +++ b/qqbot/ExamplePlugin.cs @@ -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 + { + /// + /// 每次收到消息时触发。 + /// + public override async Task OnMessageReceivedAsync(MessageContext ctx) + { + // 如果消息文本为 "Hello!", + if (ctx.Message.GetText() == "Hello!") + { + // 则发送一条 "World!" 消息作为回复。 + await ctx.Bot.SendMessageAsync(ctx.Message, "World!"); + } + } + + /// + /// 定义一条指令。
+ /// 向机器人发送 "example {num}" 时触发,其中 num 为一个合法的 double 值。 + ///
+ /// + /// + /// 定义一个参数。框架会自动识别参数的类型,并解析用户传入的文本。 + /// + /// + /// + /// 指令方法需要返回机器人的回复消息。 + /// + /// + /// + /// 发送:example 1.28
+ /// 回复:1.28 的二次方为 1.6384。 + ///
+ [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 "出现错误"; + } + + } + } +} \ No newline at end of file diff --git a/qqbot/Program.cs b/qqbot/Program.cs new file mode 100644 index 0000000..bb2ef59 --- /dev/null +++ b/qqbot/Program.cs @@ -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(); + +var app = builder.Build(); +// 添加内置中间件。 +// 这些中间件保证 Flandre 的正常运转。你也可以加入自己的中间件,并灵活调整其顺序。 +app.UseCommandSession(); +// app.UseMiddleware(async (ctx, next) => { /* ... */ }); +app.UseCommandParser(); +app.UseCommandInvoker(); + +app.Run(); \ No newline at end of file diff --git a/qqbot/appsettings.Development.json b/qqbot/appsettings.Development.json new file mode 100644 index 0000000..1248ed7 --- /dev/null +++ b/qqbot/appsettings.Development.json @@ -0,0 +1,7 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug" + } + } +} \ No newline at end of file diff --git a/qqbot/appsettings.json b/qqbot/appsettings.json new file mode 100644 index 0000000..09f2485 --- /dev/null +++ b/qqbot/appsettings.json @@ -0,0 +1,17 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information" + } + }, + "Adapters": { + "OneBot": { + "Bots": [ + { + "Protocol": "WebSocket", + "Endpoint": "ws://127.0.0.1:8080" + } + ] + } + } +} \ No newline at end of file diff --git a/qqbot/qqbot.csproj b/qqbot/qqbot.csproj new file mode 100644 index 0000000..1c293e9 --- /dev/null +++ b/qqbot/qqbot.csproj @@ -0,0 +1,23 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + + + +