Projektdateien hinzufügen.
This commit is contained in:
parent
a5e3c8bef2
commit
c9a57e431a
25
Chatbot_v0.8.1Beta.sln
Normal file
25
Chatbot_v0.8.1Beta.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.13.35931.197 d17.13
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chatbot_v0.8.1Beta", "Chatbot_v0.8.1Beta\Chatbot_v0.8.1Beta.csproj", "{8DF403AC-FAB2-4607-B5B1-B0964E43ED12}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{8DF403AC-FAB2-4607-B5B1-B0964E43ED12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{8DF403AC-FAB2-4607-B5B1-B0964E43ED12}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{8DF403AC-FAB2-4607-B5B1-B0964E43ED12}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{8DF403AC-FAB2-4607-B5B1-B0964E43ED12}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {E3A49929-220B-45FE-A161-0101E469E51B}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
9
Chatbot_v0.8.1Beta/App.xaml
Normal file
9
Chatbot_v0.8.1Beta/App.xaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<Application x:Class="Chatbot_v0._8._1Beta.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:Chatbot_v0._8._1Beta"
|
||||||
|
StartupUri="MainWindow.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
14
Chatbot_v0.8.1Beta/App.xaml.cs
Normal file
14
Chatbot_v0.8.1Beta/App.xaml.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Configuration;
|
||||||
|
using System.Data;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace Chatbot_v0._8._1Beta
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for App.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
10
Chatbot_v0.8.1Beta/AssemblyInfo.cs
Normal file
10
Chatbot_v0.8.1Beta/AssemblyInfo.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
[assembly: ThemeInfo(
|
||||||
|
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// or application resource dictionaries)
|
||||||
|
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// app, or any theme specific resource dictionaries)
|
||||||
|
)]
|
12
Chatbot_v0.8.1Beta/Chatbot_v0.8.1Beta.csproj
Normal file
12
Chatbot_v0.8.1Beta/Chatbot_v0.8.1Beta.csproj
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<RootNamespace>Chatbot_v0._8._1Beta</RootNamespace>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
44
Chatbot_v0.8.1Beta/MainWindow.xaml
Normal file
44
Chatbot_v0.8.1Beta/MainWindow.xaml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<Window x:Class="Chatbot_WPF_Projekt.MainWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:Chatbot_WPF_Projekt"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="ChatBot" Height="450" Width="880">
|
||||||
|
<Grid Margin="10">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
<!-- Chatverlauf -->
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<!-- Eingabefeld und Buttons -->
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<!-- Chat-Ausgabe (oben) -->
|
||||||
|
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto">
|
||||||
|
<TextBlock Name="ChatOutput"
|
||||||
|
TextWrapping="Wrap"
|
||||||
|
FontSize="14"
|
||||||
|
Background="#FFF0F0F0"
|
||||||
|
Padding="10"
|
||||||
|
/>
|
||||||
|
</ScrollViewer>
|
||||||
|
|
||||||
|
<!-- Eingabe + Buttons (unten) -->
|
||||||
|
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Bottom" Margin="0,10,0,0">
|
||||||
|
<TextBox Name="InputTextBox"
|
||||||
|
Width="500"
|
||||||
|
Height="30"
|
||||||
|
Margin="0,0,10,0"
|
||||||
|
KeyDown="InputTextBox_KeyDown"
|
||||||
|
VerticalContentAlignment="Center"
|
||||||
|
FontSize="14" Text=""
|
||||||
|
/>
|
||||||
|
<Button Name="SendButton" Content="Senden" Width="80" Height="30" Click="SendButton_Click"/>
|
||||||
|
<Button Name="ClearButton" Content="Löschen" Width="80" Height="30" Margin="10,0,0,0" Click="ClearButton_Click"/>
|
||||||
|
<Button Name="SaveButton" Content="Speichern" Click="SaveButton_Click" Margin="5"/>
|
||||||
|
<CheckBox x:Name="Color_theme" Content="Colortheme" Width="88" Cursor="Arrow" Checked="Color_theme_Checked" Unchecked="Color_theme_Unchecked" Margin="10,0,0,0" Background="#FFDDDDDD"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
|
|
240
Chatbot_v0.8.1Beta/MainWindow.xaml.cs
Normal file
240
Chatbot_v0.8.1Beta/MainWindow.xaml.cs
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Chatbot_WPF_Projekt
|
||||||
|
{
|
||||||
|
public partial class MainWindow : Window
|
||||||
|
{
|
||||||
|
// Variable für standort
|
||||||
|
private string currentLocation = "";
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Methode für Senden-Button
|
||||||
|
private async void SendButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// Hole den Text und entferne führende Leerzeichen
|
||||||
|
string userInput = InputTextBox.Text.Trim();
|
||||||
|
|
||||||
|
// Überprüfe, ob der Text leer ist
|
||||||
|
if (string.IsNullOrEmpty(userInput))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Bitte gib eine Nachricht ein!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Füge die Nachricht des Benutzers zum Chat-Verlauf hinzu
|
||||||
|
ChatOutput.Text += $"Du: {userInput}\n";
|
||||||
|
|
||||||
|
// Deklariere die Variable botResponse
|
||||||
|
string botResponse = "";
|
||||||
|
|
||||||
|
|
||||||
|
// Überprüfe die Eingabe und reagiere entsprechend
|
||||||
|
if (userInput.ToLower() == "!hilfe")
|
||||||
|
{
|
||||||
|
botResponse = "Ich bin ein Chatbot. Du kannst folgende Befehle verwenden:\n!hilfe - Zeigt diese Nachricht\n!joke - Erzählt einen Witz\n!standort - Setzt deinen Standort\n!zeit - Zeigt die aktuelle Zeit am Standort\n!wetter - Zeigt das Wetter am Standort\n";
|
||||||
|
}
|
||||||
|
else if (userInput.ToLower() == "!joke")
|
||||||
|
{
|
||||||
|
string[] witze = new string[10];
|
||||||
|
witze[0] = "Warum können Geister so schlecht lügen? Weil man durch sie hindurchsieht.";
|
||||||
|
witze[1] = "Programmierer beim Bäcker: 'Ich hätte gern 2^3 Brötchen.'";
|
||||||
|
witze[2] = "Warum war der Entwickler pleite? Weil er in C# gearbeitet hat, aber nur in Cent bezahlt wurde.";
|
||||||
|
witze[3] = "Was sagt ein Bit zum anderen? 'Bist du noch ganz bei 0?'";
|
||||||
|
witze[4] = "Warum ging der Java-Entwickler ins Kloster? Er wollte finally blocken.";
|
||||||
|
witze[5] = "Wie nennt man einen falschen Programmierer? Einen *C#arlatan*.";
|
||||||
|
witze[6] = "Warum weinen Entwickler nie? Sie behandeln ihre Gefühle mit Try-Catch.";
|
||||||
|
witze[7] = "Was macht ein Informatiker beim Sport? Er läuft in Schleifen.";
|
||||||
|
witze[8] = "Warum ging der C#-Code nicht ins Kino? Zu viele Exceptions.";
|
||||||
|
witze[9] = "Was macht ein Arduino im Gefängnis? Er sitzt wegen Widerstands.";
|
||||||
|
|
||||||
|
Random zufall = new Random();
|
||||||
|
int zahl = zufall.Next(0, 10);
|
||||||
|
|
||||||
|
string output = witze[zahl];
|
||||||
|
botResponse = output;
|
||||||
|
}
|
||||||
|
else if (userInput.ToLower().StartsWith("!standort"))
|
||||||
|
{
|
||||||
|
string[] parts = userInput.Split(' ', 2);
|
||||||
|
if (parts.Length == 2)
|
||||||
|
{
|
||||||
|
currentLocation = parts[1].Trim();
|
||||||
|
botResponse = $"Standort wurde auf '{currentLocation}' gesetzt.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
botResponse = "Verwendung: !standort [stadtname]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (userInput.ToLower() == "!zeit")
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(currentLocation))
|
||||||
|
{
|
||||||
|
botResponse = "Bitte gib zuerst einen Standort mit !standort an.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
botResponse = $"Aktuelle Uhrzeit in {currentLocation}: {DateTime.Now.ToShortTimeString()}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (userInput.ToLower() == "!wetter")
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(currentLocation))
|
||||||
|
{
|
||||||
|
botResponse = "Bitte gib zuerst einen Standort mit !standort an.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
botResponse = await GetWeatherAsync(currentLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
botResponse = "Befehl nicht erkannt. Versuche es mit !hilfe.";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Füge die Antwort des Bots zum Chat-Verlauf hinzu
|
||||||
|
ChatOutput.Text += $"Bot: {botResponse}\n";
|
||||||
|
|
||||||
|
// Eingabefeld leeren
|
||||||
|
InputTextBox.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Methode für Enter-Taste, um eine Nachricht zu senden
|
||||||
|
private void InputTextBox_KeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Key == Key.Enter)
|
||||||
|
{
|
||||||
|
SendButton_Click(sender, e); // Gleich wie der Button
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methode für Löschen-Button
|
||||||
|
private void ClearButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
ChatOutput.Text = string.Empty; // Lösche den Chatverlauf
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Color_theme_Checked(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Colortheme Charcoleblack aktiviert!");
|
||||||
|
|
||||||
|
//dunkles Theme
|
||||||
|
this.Background = new SolidColorBrush(Color.FromRgb(30, 30, 30));
|
||||||
|
SendButton.Background = new SolidColorBrush(Color.FromRgb(70, 70, 70));
|
||||||
|
SendButton.Foreground = new SolidColorBrush(Color.FromRgb(230, 230, 230));
|
||||||
|
|
||||||
|
ClearButton.Background = new SolidColorBrush(Color.FromRgb(70, 70, 70));
|
||||||
|
ClearButton.Foreground = new SolidColorBrush(Color.FromRgb(230, 230, 230));
|
||||||
|
|
||||||
|
Color_theme.Background = new SolidColorBrush(Color.FromRgb(70, 70, 70));
|
||||||
|
Color_theme.Foreground = new SolidColorBrush(Color.FromRgb(230, 230, 230));
|
||||||
|
|
||||||
|
SaveButton.Background = new SolidColorBrush(Color.FromRgb(70, 70, 70));
|
||||||
|
SaveButton.Foreground = new SolidColorBrush(Color.FromRgb(230, 230, 230));
|
||||||
|
|
||||||
|
ChatOutput.Background = new SolidColorBrush(Color.FromRgb(70, 70, 70));
|
||||||
|
ChatOutput.Foreground = new SolidColorBrush(Color.FromRgb(230, 230, 230));
|
||||||
|
|
||||||
|
InputTextBox.Background = new SolidColorBrush(Color.FromRgb(70, 70, 70));
|
||||||
|
InputTextBox.Foreground = new SolidColorBrush(Color.FromRgb(230, 230, 230));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Color_theme_Unchecked(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Colortheme Perlwhite aktiviert!");
|
||||||
|
|
||||||
|
//helles Theme
|
||||||
|
this.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
|
||||||
|
SendButton.Background = new SolidColorBrush(Color.FromRgb(221, 221, 221));
|
||||||
|
SendButton.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
||||||
|
|
||||||
|
ClearButton.Background = new SolidColorBrush(Color.FromRgb(221, 221, 221));
|
||||||
|
ClearButton.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
||||||
|
|
||||||
|
SaveButton.Background = new SolidColorBrush(Color.FromRgb(221, 221, 221));
|
||||||
|
SaveButton.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
||||||
|
|
||||||
|
Color_theme.Background = new SolidColorBrush(Color.FromRgb(221, 221, 221));
|
||||||
|
Color_theme.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
||||||
|
|
||||||
|
ChatOutput.Background = new SolidColorBrush(Color.FromRgb(240, 240, 240));
|
||||||
|
ChatOutput.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
||||||
|
|
||||||
|
InputTextBox.Background = new SolidColorBrush(Color.FromRgb(240, 240, 240));
|
||||||
|
InputTextBox.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Hole das Verzeichnis, in dem die .exe liegt
|
||||||
|
string projectDirectory = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName;
|
||||||
|
|
||||||
|
|
||||||
|
// Erstelle Dateinamen mit Zeitstempel, z. B. Chat_2025-05-06_1532.txt
|
||||||
|
string fileName = $"Chat_{DateTime.Now:yyyy-MM-dd_HHmm}.txt";
|
||||||
|
|
||||||
|
// Kompletter Pfad zur Datei
|
||||||
|
string fullPath = System.IO.Path.Combine(projectDirectory, fileName);
|
||||||
|
|
||||||
|
// Schreibe den Chatverlauf in die Datei
|
||||||
|
System.IO.File.WriteAllText(fullPath, ChatOutput.Text);
|
||||||
|
|
||||||
|
MessageBox.Show($"Chatverlauf gespeichert als:\n{fileName}", "Gespeichert", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Fehler beim Speichern:\n" + ex.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//mehtohde für die wetter Api
|
||||||
|
private async Task<string> GetWeatherAsync(string city)
|
||||||
|
{
|
||||||
|
string apiKey = "d3348e2e2c9dba104f58d7d44f6f623e";
|
||||||
|
string url = $"https://api.openweathermap.org/data/2.5/weather?q={Uri.EscapeDataString(city)}&units=metric&lang=de&appid={apiKey}";
|
||||||
|
|
||||||
|
using HttpClient client = new HttpClient();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponseMessage response = await client.GetAsync(url);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
string json = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
using JsonDocument doc = JsonDocument.Parse(json);
|
||||||
|
JsonElement root = doc.RootElement;
|
||||||
|
|
||||||
|
double temp = root.GetProperty("main").GetProperty("temp").GetDouble();
|
||||||
|
string description = root.GetProperty("weather")[0].GetProperty("description").GetString();
|
||||||
|
|
||||||
|
return $"Aktuelles Wetter in {city}: {temp}°C, {description}";
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return $"Fehler beim Abrufen der Wetterdaten: {ex.Message}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user