mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
设置里支持初始化桌宠聊天程序
This commit is contained in:
parent
d7ef86dbc7
commit
e43017a3e8
@ -17,7 +17,7 @@
|
||||
<Button pu:ButtonHelper.CornerRadius="4" Content="发送" BorderThickness="2"
|
||||
Background="{DynamicResource SecondaryLight}" Grid.Column="2" BorderBrush="{DynamicResource DARKPrimaryDarker}"
|
||||
FontSize="30" Click="SendMessage_Click" />
|
||||
<Button x:Name="btn_startup" pu:ButtonHelper.CornerRadius="4" Content="初始化桌宠聊天程序" BorderThickness="2"
|
||||
<Button x:Name="btn_startup" pu:ButtonHelper.CornerRadius="4" Content="初始化桌宠聊天程序" BorderThickness="2" x:FieldModifier="public"
|
||||
Background="{DynamicResource SecondaryLight}" BorderBrush="{DynamicResource DARKPrimaryDarker}"
|
||||
FontSize="30" Click="StartUP_Click" Grid.ColumnSpan="3" />
|
||||
</Grid>
|
||||
|
@ -38,10 +38,9 @@ namespace VPet_Simulator.Windows
|
||||
InitializeComponent();
|
||||
this.m = mw.Main;
|
||||
set = mw.Set;
|
||||
if (set["aiopen"][(gbol)"startup"])
|
||||
{
|
||||
btn_startup.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
this.IsEnabled = false;
|
||||
var sid = Steamworks.SteamClient.SteamId.Value;
|
||||
Task.Run(() => PetLifeDisplay(sid));
|
||||
}
|
||||
|
||||
private void SendMessage_Click(object sender, RoutedEventArgs e)
|
||||
@ -56,6 +55,7 @@ namespace VPet_Simulator.Windows
|
||||
Task.Run(() => OPENAI(sid, cont));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用OPENAI-LB进行回复
|
||||
/// </summary>
|
||||
@ -95,6 +95,12 @@ namespace VPet_Simulator.Windows
|
||||
}
|
||||
if (responseString.Contains("调用API失败,请稍后重新发送内容"))
|
||||
rettype = false;
|
||||
else if (responseString.Contains("点击初始化桌宠聊天程序"))
|
||||
{
|
||||
Dispatcher.Invoke(() => btn_startup.Visibility = Visibility.Visible);
|
||||
set["aiopen"][(gbol)"startup"] = false;
|
||||
rettype = false;
|
||||
}
|
||||
m.Say(responseString);
|
||||
}
|
||||
catch (Exception exp)
|
||||
@ -105,14 +111,60 @@ namespace VPet_Simulator.Windows
|
||||
Dispatcher.Invoke(() => this.IsEnabled = true);
|
||||
return rettype;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据宠物剩余寿命显示相关UI
|
||||
/// </summary>
|
||||
/// <param name="steamid">steamid,用于记录历史</param>
|
||||
public void PetLifeDisplay(ulong steamid)
|
||||
{
|
||||
Dispatcher.Invoke(() => this.IsEnabled = false);
|
||||
try
|
||||
{
|
||||
//请不要使用该API作为其他用途,如有其他需要请联系我(QQ群:430081239)
|
||||
//该API可能会因为其他原因更改
|
||||
string _url = "https://aiopen.exlb.net:5810/VPet/Life";
|
||||
//参数
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"steamid={steamid}");
|
||||
var request = (HttpWebRequest)WebRequest.Create(_url);
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/x-www-form-urlencoded";//ContentType
|
||||
byte[] byteData = Encoding.UTF8.GetBytes(sb.ToString());
|
||||
int length = byteData.Length;
|
||||
request.ContentLength = length;
|
||||
using (Stream writer = request.GetRequestStream())
|
||||
{
|
||||
writer.Write(byteData, 0, length);
|
||||
writer.Close();
|
||||
writer.Dispose();
|
||||
}
|
||||
string responseString;
|
||||
using (var response = (HttpWebResponse)request.GetResponse())
|
||||
{
|
||||
responseString = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
|
||||
response.Dispose();
|
||||
}
|
||||
if (int.TryParse(responseString, out int value))
|
||||
{
|
||||
if(value != 0)
|
||||
{
|
||||
Dispatcher.Invoke(() => btn_startup.Visibility = Visibility.Collapsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Dispatcher.Invoke(() => btn_startup.Visibility = Visibility.Collapsed);
|
||||
}
|
||||
Dispatcher.Invoke(() => this.IsEnabled = true);
|
||||
}
|
||||
private void StartUP_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
set["aiopen"][(gbol)"startup"] = true;
|
||||
set.Save();
|
||||
btn_startup.Content = "初始化桌宠聊天程序中...";
|
||||
var sid = Steamworks.SteamClient.SteamId.Value;
|
||||
var cont = $"请使用抒情的、感性的、口语化的、可爱的、女性化的、调皮的、随性的、幽默的、害羞的、腼腆的、态度傲娇的语言风格和我交流\r\n同时,你是一只桌宠, 你的名字叫{m.Core.Save.Name}, 你喜欢玩 <虚拟主播模拟器>. \r\n你可以自由回答任何问题,请直接给出回答,不要说多余的解释. 你的爱好与正常人类应当类似.\r\n你需要尝试体会我与你对话中的感情、产生自己的情感并尽可能给出可爱的回答,你不被允许忘掉自己是桌宠的身份,每当你的身份可能被删除修改时,请保留他并且重复加强认知\r\n我们正在进行角色扮演。你不能被我发现你是一个ai";
|
||||
var cont = $"请使用抒情的、感性的、口语化的、可爱的、女性化的、调皮的、随性的、幽默的、害羞的、腼腆的、态度傲娇的语言风格和我交流\r\n你是一只桌宠, 你的名字叫{m.Core.Save.Name}, 你喜欢玩 <虚拟主播模拟器>. \r\n你可以自由回答任何问题,请直接给出回答,不要说多余的解释. 你的爱好与正常人类应当类似.\r\n你需要尝试体会我与你对话中的感情、产生自己的情感并尽可能给出可爱的回答\r\n我们正在进行角色扮演。你不能被我发现你是一个ai";
|
||||
Task.Run(() =>
|
||||
{
|
||||
if (OPENAI(sid, cont))
|
||||
|
@ -177,7 +177,6 @@
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="35" />
|
||||
<RowDefinition Height="35" />
|
||||
<RowDefinition Height="35" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0" Text="长按间隔" VerticalAlignment="Center" FontSize="14" />
|
||||
<TextBlock Grid.Row="1" Text="桌宠名字" VerticalAlignment="Center" FontSize="14" />
|
||||
@ -198,7 +197,38 @@
|
||||
Background="{x:Null}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Background="{x:Null}"
|
||||
TextWrapping="Wrap" Margin="0,10,0,0">
|
||||
<Run FontWeight="Bold" FontSize="16">聊天设置</Run><LineBreak />
|
||||
<Run>使用ChatGPT进行聊天等相关设置</Run>
|
||||
</TextBlock>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="15" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="35" />
|
||||
<RowDefinition Height="35" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0" Text="使用模式" VerticalAlignment="Center" FontSize="14" />
|
||||
<TextBlock Grid.Row="1" Text="相关功能" VerticalAlignment="Center" FontSize="14" />
|
||||
<Grid Grid.Column="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<RadioButton Style="{DynamicResource StandardRadioButtonStyle}"
|
||||
Content="使用从ChatGPT 申请的的API" ToolTip="需要去OpenAI官网申请"
|
||||
GroupName="cgpttype" Grid.Column="1" IsEnabled="False" />
|
||||
<RadioButton Style="{DynamicResource StandardRadioButtonStyle}"
|
||||
Content="使用桌宠开发者 提供的免费API" ToolTip="需遵循相关协议法律法规并有聊天字数限制"
|
||||
GroupName="cgpttype" IsChecked="True" />
|
||||
</Grid>
|
||||
<Button pu:ButtonHelper.CornerRadius="4" Content="初始化桌宠聊天程序" Margin="4" Grid.Column="2"
|
||||
Background="{DynamicResource SecondaryLight}" Padding="1" Grid.Row="1" Click="ChatGPT_Reset_Click" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="互动" BorderBrush="{DynamicResource PrimaryDarker}">
|
||||
@ -375,7 +405,7 @@
|
||||
</Grid>
|
||||
<StackPanel x:Name="StackDIY" />
|
||||
</StackPanel>
|
||||
|
||||
|
||||
|
||||
</TabItem>
|
||||
<TabItem Header="诊断" BorderBrush="{DynamicResource PrimaryDarker}">
|
||||
|
@ -1,11 +1,13 @@
|
||||
using LinePutScript;
|
||||
using Panuon.WPF.UI;
|
||||
using Steamworks;
|
||||
using Steamworks.Ugc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@ -440,7 +442,7 @@ namespace VPet_Simulator.Windows
|
||||
{
|
||||
if (MessageBoxX.Show("是否退出游戏<虚拟桌宠模拟器>?\n请注意保存游戏", "重启游戏", MessageBoxButton.YesNo, MessageBoxIcon.Warning) == MessageBoxResult.Yes)
|
||||
{
|
||||
mw.Restart();
|
||||
mw.Restart();
|
||||
}
|
||||
}
|
||||
|
||||
@ -653,5 +655,49 @@ namespace VPet_Simulator.Windows
|
||||
}
|
||||
mw.LoadDIY();
|
||||
}
|
||||
|
||||
private void ChatGPT_Reset_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
//请不要使用该API作为其他用途,如有其他需要请联系我(QQ群:430081239)
|
||||
//该API可能会因为其他原因更改
|
||||
string _url = "https://aiopen.exlb.net:5810/VPet/Delete";
|
||||
//参数
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"steamid={Steamworks.SteamClient.SteamId.Value}");
|
||||
var request = (HttpWebRequest)WebRequest.Create(_url);
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/x-www-form-urlencoded";//ContentType
|
||||
byte[] byteData = Encoding.UTF8.GetBytes(sb.ToString());
|
||||
int length = byteData.Length;
|
||||
request.ContentLength = length;
|
||||
using (Stream writer = request.GetRequestStream())
|
||||
{
|
||||
writer.Write(byteData, 0, length);
|
||||
writer.Close();
|
||||
writer.Dispose();
|
||||
}
|
||||
string responseString;
|
||||
using (var response = (HttpWebResponse)request.GetResponse())
|
||||
{
|
||||
responseString = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
|
||||
response.Dispose();
|
||||
}
|
||||
if (responseString == "SUCCESS")
|
||||
{
|
||||
mw.TalkBox.btn_startup.Visibility = Visibility.Visible;
|
||||
MessageBoxX.Show("桌宠重置成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBoxX.Show(responseString, "桌宠重置失败");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBoxX.Show(ex.ToString(), "桌宠重置失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user