From 1da5474826026df60a2d3da434aa910aca3a6d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=AF=85?= <2667210109@qq.com> Date: Sat, 26 Oct 2024 12:18:50 +0800 Subject: [PATCH 1/2] 11 --- asg_form/Controllers/admin.cs | 28 ++++++++++++++++++++++++++++ asg_form/qqbot.cs | 26 +------------------------- asg_form/return.cs | 14 ++++++++++++++ 3 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 asg_form/return.cs diff --git a/asg_form/Controllers/admin.cs b/asg_form/Controllers/admin.cs index 6f5f12a..68b2d98 100644 --- a/asg_form/Controllers/admin.cs +++ b/asg_form/Controllers/admin.cs @@ -309,6 +309,34 @@ namespace asg_form.Controllers } + + /// + /// 设置管理员,需要superadmin + /// + /// + /// + [Route("api/v1/admin/removeadmin")] + [HttpPost] + [Authorize] + public async Task> removeadmin(string userid) + { + if (this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) + { + var ouser = await userManager.FindByIdAsync(userid); + + await userManager.RemoveFromRoleAsync(ouser, "admin"); + + return Ok(new { message = "用户成功设置为管理员" }); + } + else + { + return BadRequest(new error_mb { code = 400, message = "无权访问" }); + + } + + } + + //管理员设置用户的职位 [Route("api/v1/admin/setop")] [HttpPost] diff --git a/asg_form/qqbot.cs b/asg_form/qqbot.cs index 23f7e5c..7fc4756 100644 --- a/asg_form/qqbot.cs +++ b/asg_form/qqbot.cs @@ -98,31 +98,7 @@ namespace asg_form } - [Command] - public string 近期赛程1() - { - try - { - TestDbContext testDb = new TestDbContext(); - int q = testDb.team_Games.Count(); - var t = (DateTime.Now); - var a = testDb.team_Games.Where(a => string.Compare(a.opentime, t.ToString()) >= 0).Take(7); - string msg = ""; - foreach (var b in a) - { - msg = $"{msg}\r\n{b.team1_name} VS {b.team2_name}\r\n时间:{b.opentime.ToString()}"; - } - return msg; - - - } - catch - { - return "出现错误"; - } - - } - + [Command] public string 查询冠军() diff --git a/asg_form/return.cs b/asg_form/return.cs new file mode 100644 index 0000000..6ae4619 --- /dev/null +++ b/asg_form/return.cs @@ -0,0 +1,14 @@ +namespace asg_form +{ + public class TReturn + { + public int Code { get; set; } + public object Msg { get; set; } + } + + public class TReturn_total + { + public int Total { get; set; } + public object Msg { get; set; } + } +} From 4a9400329770853e63d82fb42633126a2024809e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=AF=85?= <2667210109@qq.com> Date: Sat, 26 Oct 2024 17:45:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B5=9B=E7=A8=8B=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- asg_form/Controllers/schedule.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/asg_form/Controllers/schedule.cs b/asg_form/Controllers/schedule.cs index 019ca86..6bceeba 100644 --- a/asg_form/Controllers/schedule.cs +++ b/asg_form/Controllers/schedule.cs @@ -8,6 +8,10 @@ using NPOI.OpenXmlFormats.Spreadsheet; using Castle.Components.DictionaryAdapter; using Flandre.Core.Messaging; using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal; +using Flandre.Core.Common; +using Flandre.Core.Messaging.Segments; +using static asg_form.Controllers.InviteReferee; +using Mirai.Net.Data.Shared; namespace asg_form.Controllers { @@ -170,6 +174,21 @@ namespace asg_form.Controllers } } await testDb.SaveChangesAsync(); + + try + { + + var message1 = new MessageBuilder().Image(GetPictureData($@"{AppDomain.CurrentDomain.BaseDirectory}loge\{game.belong}\{winteam}.png")).Text($"恭喜战队{winteam}获胜!").Build(); + await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "456414070", null, message1, "456414070"); + + } + catch + { + var message1 = new MessageBuilder().Text($"恭喜战队{winteam}获胜!").Build(); + await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "456414070", null, message1, "456414070"); + + } + return "ok"; } else @@ -179,7 +198,14 @@ namespace asg_form.Controllers } } - + public byte[] GetPictureData(string imagePath) + { + FileStream fs = new FileStream(imagePath, FileMode.Open); + byte[] byteData = new byte[fs.Length]; + fs.Read(byteData, 0, byteData.Length); + fs.Close(); + return byteData; + } /// /// 删除竞猜比赛