This commit is contained in:
杨毅 2024-10-20 13:51:44 +08:00
parent 5b29ee73f3
commit 0c04933135
5 changed files with 79 additions and 7 deletions

View File

@ -1,4 +1,7 @@
using Manganese.Text; using Flandre.Core.Common;
using Flandre.Core.Messaging.Segments;
using Flandre.Core.Messaging;
using Manganese.Text;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -6,6 +9,7 @@ using Microsoft.EntityFrameworkCore;
using Mirai.Net.Sessions.Http.Managers; using Mirai.Net.Sessions.Http.Managers;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Security.Claims; using System.Security.Claims;
using static asg_form.Controllers.InviteReferee;
namespace asg_form.Controllers namespace asg_form.Controllers
{ {
@ -71,7 +75,10 @@ namespace asg_form.Controllers
await userManager.UpdateAsync(user); await userManager.UpdateAsync(user);
try try
{ {
await MessageManager.SendGroupMessageAsync("870248618", $"解说:\r\n{chinaname}\r\n选择了比赛:\r\n{teamgame.team1_name} VS {teamgame.team2_name}"); var message = new MessageBuilder().Add(new AtSegment(user.qqnumber??"2667210109")).Text($"解说:\r\n{chinaname}\r\n选择了比赛:\r\n{teamgame.team1_name} VS {teamgame.team2_name}").Build();
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "925510646", null, message, "925510646");
} }
catch catch
{ {
@ -132,6 +139,17 @@ namespace asg_form.Controllers
} }
teamgame.commentary = JsonConvert.SerializeObject(com); teamgame.commentary = JsonConvert.SerializeObject(com);
await testDb.SaveChangesAsync(); await testDb.SaveChangesAsync();
try
{
var message = new MessageBuilder().Add(new AtSegment(user.qqnumber ?? "2667210109")).Text($"解说:\r\n{chinaname}\r\n取消了比赛:\r\n{teamgame.team1_name} VS {teamgame.team2_name}").Build();
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "925510646", null, message, "925510646");
}
catch
{
}
return "成功"; return "成功";
} }
return BadRequest(new error_mb { code = 400, message = $"你是{user.officium},你不是解说,无法操作" }); return BadRequest(new error_mb { code = 400, message = $"你是{user.officium},你不是解说,无法操作" });

View File

@ -266,11 +266,11 @@ namespace asg_form.Controllers
var isadmin = await userManager.IsInRoleAsync(user, "admin"); var isadmin = await userManager.IsInRoleAsync(user, "admin");
List<string> roles = (List<string>)await userManager.GetRolesAsync(user); List<string> roles = (List<string>)await userManager.GetRolesAsync(user);
if (showbase64) { if (showbase64) {
return new post_user { id = id.ToInt64(), money = user.Integral, Base64 = user.UserBase64, name = user.UserName, chinaname = user.chinaname, email = user.Email, isadmin = isadmin, Roles = roles, officium = user.officium }; return new post_user { id = id.ToInt64(), money = user.Integral, Base64 = user.UserBase64, name = user.UserName, chinaname = user.chinaname, email = user.Email, isadmin = isadmin, Roles = roles, officium = user.officium ,qqnumber=user.qqnumber};
} }
else else
{ {
return new post_user { id = id.ToInt64(), money = user.Integral, name = user.UserName, chinaname = user.chinaname, email = user.Email, isadmin = isadmin, Roles = roles, officium = user.officium }; return new post_user { id = id.ToInt64(), money = user.Integral, name = user.UserName, chinaname = user.chinaname, email = user.Email, isadmin = isadmin, Roles = roles, officium = user.officium, qqnumber = user.qqnumber };
} }
@ -287,7 +287,7 @@ namespace asg_form.Controllers
public bool isadmin { get; set; } public bool isadmin { get; set; }
public string? officium { get; set; } public string? officium { get; set; }
public long? money { get; set; } public long? money { get; set; }
public string? qqnumber { get; set; }
public List<string>? Roles { get; set; } public List<string>? Roles { get; set; }
} }

View File

@ -0,0 +1,54 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Security.Claims;
namespace asg_form.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class qqbotr : ControllerBase
{
private readonly RoleManager<Role> roleManager;
private readonly UserManager<User> userManager;
public qqbotr(
RoleManager<Role> roleManager, UserManager<User> userManager)
{
this.roleManager = roleManager;
this.userManager = userManager;
}
/// <summary>
/// 设置qq号
/// </summary>
/// <param name="qqnumber"></param>
/// <returns></returns>
[HttpPost]
[Authorize]
public async Task<ActionResult<int>> qqnumber(string qqnumber)
{
string id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
var user = await userManager.FindByIdAsync(id);
user.qqnumber= qqnumber;
var r = await userManager.UpdateAsync(user);
return Ok("修改成功");
}
}
}

View File

@ -234,6 +234,7 @@ new Thread(o =>
// app.UseMiddleware(async (ctx, next) => { /* ... */ }); // app.UseMiddleware(async (ctx, next) => { /* ... */ });
app1.UseCommandParser(); app1.UseCommandParser();
app1.UseCommandInvoker(); app1.UseCommandInvoker();
runbot.runbotr = app1.Bots.First();
app1.Run(); app1.Run();

View File

@ -279,8 +279,7 @@ namespace asg_form
try try
{ {
var message = new List<MessagesItem>(); var message = new List<MessagesItem>();
message.Add(new MessagesItem { role = "user", content = "我们来玩角色扮演接下来你是一个没有父母但很喜欢姐姐的一个小男孩" }); message.Add(new MessagesItem { role = "user", content = msg });
message.Add(new MessagesItem { role = "user", content = msg });
var ai = new aimessage() { model = "qwen-math-plus", messages = message }; var ai = new aimessage() { model = "qwen-math-plus", messages = message };
var msg1 = await SendPostRequestAsync("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", ai, "sk-c6f37689f4014b5bbf5fd8b2e872d20b"); var msg1 = await SendPostRequestAsync("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", ai, "sk-c6f37689f4014b5bbf5fd8b2e872d20b");
return msg1; return msg1;