Compare commits

...

No commits in common. 'master' and '842ee0405949242a5b6933c999269be07fefd295' have entirely different histories.

@ -11,7 +11,6 @@ panic = "abort"
[dependencies]
eframe = "0.19.0"
egui-toast = "0.4.0"
serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0.86"
tungstenite = "0.17.3"

@ -1,19 +1,16 @@
use std::sync::mpsc::Receiver;
use std::time::Duration;
use eframe::{
egui::{self, RichText, ScrollArea, Window},
emath::Align,
epaint::Color32,
};
use egui_toast::Toasts;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use tungstenite::Message;
pub struct App {
rx: Receiver<Message>,
history: Vec<MessageLog>,
history: Vec<Log>,
autoscroll: bool,
description: String,
selected_channel: String,
@ -21,27 +18,13 @@ pub struct App {
description_shown: bool,
}
#[derive(Deserialize)]
struct MessageLog {
#[derive(Serialize, Deserialize)]
struct Log {
name: String,
description: String,
message: String,
channel: String,
}
#[derive(Deserialize)]
struct InteractionLog {
name: String,
command: String,
arguments: String,
channel: String,
}
#[derive(Deserialize)]
#[serde(tag = "type")]
enum Loggers {
InteractionLog(InteractionLog),
MessageLog(MessageLog),
is_interaction: bool
}
impl App {
@ -60,38 +43,15 @@ impl App {
impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
let mut toasts = Toasts::new()
.anchor((10.0, 10.0))
.direction(egui::Direction::TopDown)
.align_to_end(false);
let message = self.rx.try_recv();
// TODO: Add toasts for things like debug information and status changes (https://github.com/urholaukkarinen/egui-toast)
if let Ok(message) = message {
let text = message.to_string();
let json = serde_json::from_str(&text);
if let Ok(json) = json {
let json: Loggers = json;
match json {
Loggers::MessageLog(msg) => {
self.history.push(msg);
}
Loggers::InteractionLog(msg) => {
if self.selected_channel == msg.channel {
toasts.info(
format!(
"User {} called command /{} with arguments {}",
msg.name, msg.command, msg.arguments
),
Duration::from_secs(5),
);
}
}
}
} else if let Err(json) = json {
println!("{}", json);
self.history.push(json);
}
}
egui::CentralPanel::default().show(ctx, |ui| {
@ -139,15 +99,23 @@ impl eframe::App for App {
}
if msg.channel == self.selected_channel {
ui.horizontal(|ui| {
ui.label(RichText::new(&msg.name).color(Color32::LIGHT_GRAY));
if !&msg.description.is_empty() {
self.description = (&msg.description).to_owned();
ui.label(RichText::new("[AI]").color(Color32::DARK_GRAY));
}
});
ui.label(&msg.message);
ui.separator();
if msg.is_interaction {
ui.horizontal(|ui| {
ui.label(RichText::new(&msg.name).color(Color32::LIGHT_GRAY));
ui.label(&msg.message);
});
ui.separator();
} else {
ui.horizontal(|ui| {
ui.label(RichText::new(&msg.name).color(Color32::LIGHT_GRAY));
if !&msg.description.is_empty() {
self.description = (&msg.description).to_owned();
ui.label(RichText::new("[AI]").color(Color32::DARK_GRAY));
}
});
ui.label(&msg.message);
ui.separator();
}
}
if self.autoscroll {
@ -158,6 +126,5 @@ impl eframe::App for App {
});
ctx.request_repaint();
toasts.show(ctx);
}
}

@ -21,10 +21,10 @@ fn main() {
socket
.write_message(Message::Text("__PONG__".to_string()))
.expect("Failed to respond to ping! Did the WebSocket server die?");
} else {
tx.send(message)
.expect("Failed to send message to channel! (This shouldn't be possible)");
}
tx.send(message)
.expect("Failed to send message to channel! (This shouldn't be possible)");
}
});

Loading…
Cancel
Save