qqbot
This commit is contained in:
parent
1ed7f45ae7
commit
81447acb4a
@ -23,8 +23,16 @@ namespace asg_form.Controllers
|
|||||||
|
|
||||||
public string qqid { get; set; }
|
public string qqid { get; set; }
|
||||||
public int money { 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>
|
class FormConfig : IEntityTypeConfiguration<form>
|
||||||
@ -45,7 +53,8 @@ namespace asg_form.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void Configure(EntityTypeBuilder<form> builder)
|
public void Configure(EntityTypeBuilder<form> builder)
|
||||||
{
|
{
|
||||||
|
@ -142,7 +142,7 @@ namespace asg_form.Controllers
|
|||||||
}
|
}
|
||||||
var message= new MessageBuilder().Add(new AtSegment(atuserqq)).Text(msg).Build();
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1057
asg_form/Migrations/20241019092355_qqbot2.Designer.cs
generated
Normal file
1057
asg_form/Migrations/20241019092355_qqbot2.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
asg_form/Migrations/20241019092355_qqbot2.cs
Normal file
22
asg_form/Migrations/20241019092355_qqbot2.cs
Normal 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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1077
asg_form/Migrations/20241019092814_qqbot3.Designer.cs
generated
Normal file
1077
asg_form/Migrations/20241019092814_qqbot3.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
36
asg_form/Migrations/20241019092814_qqbot3.cs
Normal file
36
asg_form/Migrations/20241019092814_qqbot3.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1080
asg_form/Migrations/20241019101331_qqbot4.Designer.cs
generated
Normal file
1080
asg_form/Migrations/20241019101331_qqbot4.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
asg_form/Migrations/20241019101331_qqbot4.cs
Normal file
30
asg_form/Migrations/20241019101331_qqbot4.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -575,6 +575,29 @@ namespace asg_form.Migrations
|
|||||||
b.ToTable("F_form", (string)null);
|
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 =>
|
modelBuilder.Entity("asg_form.Controllers.role", b =>
|
||||||
{
|
{
|
||||||
b.Property<long>("Id")
|
b.Property<long>("Id")
|
||||||
|
@ -29,5 +29,15 @@
|
|||||||
"EnableSsL": true,
|
"EnableSsL": true,
|
||||||
"Switch": true
|
"Switch": true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"Adapters": {
|
||||||
|
"OneBot": {
|
||||||
|
"Bots": [
|
||||||
|
{
|
||||||
|
"Protocol": "WebSocket",
|
||||||
|
"Endpoint": "ws://127.0.0.1:8080"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0-beta.1" />
|
|
||||||
<PackageReference Include="ChatGPT.Net" Version="2.0.0" />
|
<PackageReference Include="ChatGPT.Net" Version="2.0.0" />
|
||||||
<PackageReference Include="EntityFrameworkCore.DataEncryption" Version="5.0.0" />
|
<PackageReference Include="EntityFrameworkCore.DataEncryption" Version="5.0.0" />
|
||||||
<PackageReference Include="Flandre.Adapters.OneBot.Extensions" Version="2.0.0-rc.3" />
|
<PackageReference Include="Flandre.Adapters.OneBot.Extensions" Version="2.0.0-rc.3" />
|
||||||
|
@ -28,10 +28,10 @@ using System.Net.Http.Headers;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Azure.Identity;
|
using Azure.Identity;
|
||||||
using OpenAI.Chat;
|
|
||||||
using Azure.AI.OpenAI;
|
|
||||||
using Flandre.Core.Messaging;
|
using Flandre.Core.Messaging;
|
||||||
using Flandre.Core.Common;
|
using Flandre.Core.Common;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Flurl.Http;
|
||||||
|
|
||||||
namespace asg_form
|
namespace asg_form
|
||||||
{
|
{
|
||||||
@ -162,18 +162,26 @@ namespace asg_form
|
|||||||
using(TestDbContext testDb=new TestDbContext())
|
using(TestDbContext testDb=new TestDbContext())
|
||||||
{
|
{
|
||||||
Random ran = new Random();
|
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))
|
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
|
else
|
||||||
{
|
{
|
||||||
var user=await testDb.Qqusers.FirstAsync(a=>a.qqid == ctx.UserId);
|
var user=await testDb.Qqusers.FirstAsync(a=>a.qqid == ctx.UserId);
|
||||||
|
if (isToday(user.time))
|
||||||
|
{
|
||||||
|
return "你已经签到过了!";
|
||||||
|
}
|
||||||
user.money += n;
|
user.money += n;
|
||||||
|
user.time = DateTime.Today;
|
||||||
}
|
}
|
||||||
|
|
||||||
await testDb.SaveChangesAsync();
|
await testDb.SaveChangesAsync();
|
||||||
return $"罗比很开心\r\n给你棒棒糖:{n.ToString()}个";
|
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]
|
[Command]
|
||||||
public string ai(string msg)
|
public async Task<string> ai(string msg)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var message= new List<MessagesItem> ();
|
||||||
AzureOpenAIClient azureClient = new(
|
message.Add(new MessagesItem {role="user", content = msg });
|
||||||
new Uri("https://dashscope.aliyuncs.com/compatible-mode/v1"),
|
var ai1= new aimessage() { model= "qwen-turbo",messages=message };
|
||||||
new System.ClientModel.ApiKeyCredential("sk-c6f37689f4014b5bbf5fd8b2e872d20b"));
|
var msg1= await SendPostRequestAsync("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", ai1, "sk-c6f37689f4014b5bbf5fd8b2e872d20b");
|
||||||
ChatClient chatClient = azureClient.GetChatClient("qwen-turbo");
|
return msg1;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
return "出现错误";
|
return $"出现错误{ex.Message}";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public string aimath(string msg)
|
public async Task<string> aimath(string msg)
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var message = new List<MessagesItem>();
|
||||||
AzureOpenAIClient azureClient = new(
|
message.Add(new MessagesItem { role = "user", content = "我们来玩角色扮演接下来你是一个没有父母但很喜欢姐姐的一个小男孩" });
|
||||||
new Uri("https://dashscope.aliyuncs.com/compatible-mode/v1"),
|
message.Add(new MessagesItem { role = "user", content = msg });
|
||||||
new System.ClientModel.ApiKeyCredential("sk-c6f37689f4014b5bbf5fd8b2e872d20b"));
|
var ai = new aimessage() { model = "qwen-math-plus", messages = message };
|
||||||
ChatClient chatClient = azureClient.GetChatClient("qwen-math-plus");
|
var msg1 = await SendPostRequestAsync("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", ai, "sk-c6f37689f4014b5bbf5fd8b2e872d20b");
|
||||||
|
return msg1;
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@ -244,6 +268,10 @@ namespace asg_form
|
|||||||
return "出现错误";
|
return "出现错误";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user