This commit is contained in:
杨毅 2024-10-19 20:09:00 +08:00
parent 1ed7f45ae7
commit 81447acb4a
12 changed files with 3412 additions and 41 deletions

View File

@ -23,8 +23,16 @@ namespace asg_form.Controllers
public string qqid { get; set; }
public int money { get; set; }
public DateTime time { get; set; }
}
class qquserConfig : IEntityTypeConfiguration<qquser>
{
public void Configure(EntityTypeBuilder<qquser> builder)
{
builder.ToTable("F_qquser");
}
}
class FormConfig : IEntityTypeConfiguration<form>
@ -45,7 +53,8 @@ namespace asg_form.Controllers
}
}
public void Configure(EntityTypeBuilder<form> builder)
{

View File

@ -142,7 +142,7 @@ namespace asg_form.Controllers
}
var message= new MessageBuilder().Add(new AtSegment(atuserqq)).Text(msg).Build();
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel,null,null,message,qqgrope);
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel,qqgrope,null,message,qqgrope);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace asg_form.Migrations
{
/// <inheritdoc />
public partial class qqbot2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace asg_form.Migrations
{
/// <inheritdoc />
public partial class qqbot3 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "F_qquser",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
qqid = table.Column<string>(type: "text", nullable: false),
money = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_F_qquser", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "F_qquser");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,30 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace asg_form.Migrations
{
/// <inheritdoc />
public partial class qqbot4 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "time",
table: "F_qquser",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "time",
table: "F_qquser");
}
}
}

View File

@ -575,6 +575,29 @@ namespace asg_form.Migrations
b.ToTable("F_form", (string)null);
});
modelBuilder.Entity("asg_form.Controllers.qquser", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("money")
.HasColumnType("integer");
b.Property<string>("qqid")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("time")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("F_qquser", (string)null);
});
modelBuilder.Entity("asg_form.Controllers.role", b =>
{
b.Property<long>("Id")

View File

@ -29,5 +29,15 @@
"EnableSsL": true,
"Switch": true
}
},
"Adapters": {
"OneBot": {
"Bots": [
{
"Protocol": "WebSocket",
"Endpoint": "ws://127.0.0.1:8080"
}
]
}
}
}

View File

@ -27,7 +27,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0-beta.1" />
<PackageReference Include="ChatGPT.Net" Version="2.0.0" />
<PackageReference Include="EntityFrameworkCore.DataEncryption" Version="5.0.0" />
<PackageReference Include="Flandre.Adapters.OneBot.Extensions" Version="2.0.0-rc.3" />

View File

@ -28,10 +28,10 @@ using System.Net.Http.Headers;
using System.Net.Http;
using System.Text;
using Azure.Identity;
using OpenAI.Chat;
using Azure.AI.OpenAI;
using Flandre.Core.Messaging;
using Flandre.Core.Common;
using Microsoft.OpenApi.Models;
using Flurl.Http;
namespace asg_form
{
@ -162,18 +162,26 @@ namespace asg_form
using(TestDbContext testDb=new TestDbContext())
{
Random ran = new Random();
int n = ran.Next(100, 200);
int n = ran.Next(30, 100);
if (!testDb.Qqusers.Any(a => a.qqid == ctx.UserId))
{
await testDb.Qqusers.AddAsync(new qquser { qqid = ctx.UserId, money = n });
await testDb.Qqusers.AddAsync(new qquser { qqid = ctx.UserId, money = n ,time=DateTime.Now});
}
else
{
var user=await testDb.Qqusers.FirstAsync(a=>a.qqid == ctx.UserId);
if (isToday(user.time))
{
return "你已经签到过了!";
}
user.money += n;
user.time = DateTime.Today;
}
await testDb.SaveChangesAsync();
return $"罗比很开心\r\n给你棒棒糖{n.ToString()}个";
}
@ -187,56 +195,72 @@ namespace asg_form
}
}
public class MessagesItem
{
/// <summary>
///
/// </summary>
public string role { get; set; }
/// <summary>
///
/// </summary>
public string content { get; set; }
}
public class aimessage
{
/// <summary>
///
/// </summary>
public string model { get; set; }
/// <summary>
///
/// </summary>
public List<MessagesItem> messages { get; set; }
}
private static async Task<string> SendPostRequestAsync(string url, aimessage Content, string apiKey)
{
var re= await url.WithOAuthBearerToken(apiKey).PostJsonAsync(Content);
var a= await re.GetJsonAsync();
return a.choices[0].message.content;
}
[Command]
public string ai(string msg)
public async Task<string> ai(string msg)
{
try
{
AzureOpenAIClient azureClient = new(
new Uri("https://dashscope.aliyuncs.com/compatible-mode/v1"),
new System.ClientModel.ApiKeyCredential("sk-c6f37689f4014b5bbf5fd8b2e872d20b"));
ChatClient chatClient = azureClient.GetChatClient("qwen-turbo");
ChatCompletion completion = chatClient.CompleteChat(
[
// System messages represent instructions or other guidance about how the assistant should behave
new UserChatMessage("我们来玩角色扮演接下来你是一个没有父母但很喜欢姐姐的一个小男孩"),
new UserChatMessage(msg),
]);
return completion.Content[0].Text;
var message= new List<MessagesItem> ();
message.Add(new MessagesItem {role="user", content = msg });
var ai1= new aimessage() { model= "qwen-turbo",messages=message };
var msg1= await SendPostRequestAsync("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", ai1, "sk-c6f37689f4014b5bbf5fd8b2e872d20b");
return msg1;
}
catch
catch(Exception ex)
{
return "出现错误";
return $"出现错误{ex.Message}";
}
}
[Command]
public string aimath(string msg)
public async Task<string> aimath(string msg)
{
try
{
AzureOpenAIClient azureClient = new(
new Uri("https://dashscope.aliyuncs.com/compatible-mode/v1"),
new System.ClientModel.ApiKeyCredential("sk-c6f37689f4014b5bbf5fd8b2e872d20b"));
ChatClient chatClient = azureClient.GetChatClient("qwen-math-plus");
ChatCompletion completion = chatClient.CompleteChat(
[
// System messages represent instructions or other guidance about how the assistant should behave
new UserChatMessage(msg),
]);
return completion.Content[0].Text;
var message = new List<MessagesItem>();
message.Add(new MessagesItem { role = "user", content = "我们来玩角色扮演接下来你是一个没有父母但很喜欢姐姐的一个小男孩" });
message.Add(new MessagesItem { role = "user", content = msg });
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");
return msg1;
}
catch
@ -244,6 +268,10 @@ namespace asg_form
return "出现错误";
}
}