修复重大bug

This commit is contained in:
杨毅 2024-10-19 23:09:48 +08:00
parent 4f637defde
commit 5b29ee73f3
3 changed files with 47 additions and 45 deletions

View File

@ -309,6 +309,9 @@ namespace asg_form.Controllers
} }
public IDBcontext()
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {

View File

@ -24,6 +24,7 @@ using Zack.EventBus;
Console.WriteLine("\n _____ _________ ________ \n / _ \\ / _____// _____/ \n / /_\\ \\ \\_____ \\/ \\ ___ \n/ | \\/ \\ \\_\\ \\\n\\____|__ /_______ /\\______ /\n \\/ \\/ \\/ \n__________ __ ___________ .___\n\\______ \\_____ ____ | | __\\_ _____/ ____ __| _/\n | | _/\\__ \\ _/ ___\\| |/ / | __)_ / \\ / __ | \n | | \\ / __ \\\\ \\___| < | \\ | \\/ /_/ | \n |______ /(____ /\\___ >__|_ \\/_______ /___| /\\____ | \n \\/ \\/ \\/ \\/ \\/ \\/ \\/ "); Console.WriteLine("\n _____ _________ ________ \n / _ \\ / _____// _____/ \n / /_\\ \\ \\_____ \\/ \\ ___ \n/ | \\/ \\ \\_\\ \\\n\\____|__ /_______ /\\______ /\n \\/ \\/ \\/ \n__________ __ ___________ .___\n\\______ \\_____ ____ | | __\\_ _____/ ____ __| _/\n | | _/\\__ \\ _/ ___\\| |/ / | __)_ / \\ / __ | \n | | \\ / __ \\\\ \\___| < | \\ | \\/ /_/ | \n |______ /(____ /\\___ >__|_ \\/_______ /___| /\\____ | \n \\/ \\/ \\/ \\/ \\/ \\/ \\/ ");
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -81,38 +82,6 @@ options.AddDefaultPolicy(builder => builder.WithOrigins(urls)
Task.Run(() =>
{
var builder1 = FlandreApp.CreateBuilder(new HostApplicationBuilderSettings
{
Args = args,
ContentRootPath = AppDomain.CurrentDomain.BaseDirectory
});
// 安装一个适配器,并添加在这里。
// builder.Adapters.Add(new YourAdapter());
builder1.Adapters.AddOneBot(builder.Configuration.GetSection("Adapters:OneBot"));
builder1.Plugins.Add<qqbot>();
var app1 = builder1.Build();
// 添加内置中间件。
// 这些中间件保证 Flandre 的正常运转。你也可以加入自己的中间件,并灵活调整其顺序。
app1.UseCommandSession();
// app.UseMiddleware(async (ctx, next) => { /* ... */ });
app1.UseCommandParser();
app1.UseCommandInvoker();
runbot.runbotr = app1.Bots.First();
app1.Run();
});
IServiceCollection services = builder.Services; IServiceCollection services = builder.Services;
@ -237,4 +206,39 @@ app.MapHub<room>("/room");
app.UseResponseCaching(); app.UseResponseCaching();
app.MapControllers(); app.MapControllers();
//新开一个线程,显示当前时间
new Thread(o =>
{
var builder1 = FlandreApp.CreateBuilder(new HostApplicationBuilderSettings
{
Args = args,
ContentRootPath = AppDomain.CurrentDomain.BaseDirectory
});
// 安装一个适配器,并添加在这里。
// builder.Adapters.Add(new YourAdapter());
builder1.Adapters.AddOneBot(builder1.Configuration.GetSection("Adapters:OneBot"));
builder1.Plugins.Add<qqbot>();
var app1 = builder1.Build();
// 添加内置中间件。
// 这些中间件保证 Flandre 的正常运转。你也可以加入自己的中间件,并灵活调整其顺序。
app1.UseCommandSession();
// app.UseMiddleware(async (ctx, next) => { /* ... */ });
app1.UseCommandParser();
app1.UseCommandInvoker();
app1.Run();
})
{ IsBackground = true }.Start();
app.Run(); app.Run();

View File

@ -45,15 +45,7 @@ namespace asg_form
public class qqbot:Plugin public class qqbot:Plugin
{ {
private readonly RoleManager<Role> roleManager;
private readonly UserManager<User> userManager;
public qqbot(
RoleManager<Role> roleManager, UserManager<User> userManager)
{
this.roleManager = roleManager;
this.userManager = userManager;
}
[Command] [Command]
public string (string name) public string (string name)
@ -245,10 +237,13 @@ namespace asg_form
{ {
try try
{ {
var user= await userManager.FindByNameAsync(username); using(IDBcontext db=new IDBcontext()) {
user.qqnumber = ctx.UserId; var auser=await db.users.FirstAsync(a => a.UserName == username);
await userManager.UpdateAsync(user); auser.qqnumber = ctx.UserId;
return $"绑定成功!\r\n姓名{user.chinaname}"; await db.SaveChangesAsync();
return $"绑定成功!\r\n姓名{auser.chinaname}";
}
} }
catch (Exception ex) catch (Exception ex)
{ {