some shit

This commit is contained in:
Anna 2022-09-05 19:23:55 -04:00
parent 3009ca8935
commit 4496e80cfe
12 changed files with 70 additions and 22 deletions

View File

@ -12,5 +12,6 @@ public class Configuration : IPluginConfiguration {
public bool DisableDeepDungeon = true;
public bool RemoveGlow = true;
public bool AutoViewer;
public bool AutoViewerClose = true;
public float ViewerOpacity = 100.0f;
}

View File

@ -1,5 +1,5 @@
name: Orange Guidance Tomestone
author: ascclemes
author: ascclemens
punchline: Leave messages like in Souls games. Great chest ahead.
description: |-
Dark Souls-like messaging system.

View File

@ -54,13 +54,7 @@ public class Plugin : IDalamudPlugin {
this.Commands = new Commands(this);
if (this.Config.ApiKey == string.Empty) {
Task.Run(async () => {
var resp = await new HttpClient().PostAsync("https://tryfingerbuthole.anna.lgbt/account", null);
var key = await resp.Content.ReadAsStringAsync();
this.Config.ApiKey = key;
this.SaveConfig();
this.Messages.SpawnVfx();
});
this.GetApiKey();
}
}
@ -84,4 +78,14 @@ public class Plugin : IDalamudPlugin {
stream.CopyTo(File.Create(path));
return path;
}
internal void GetApiKey() {
Task.Run(async () => {
var resp = await new HttpClient().PostAsync("https://tryfingerbuthole.anna.lgbt/account", null);
var key = await resp.Content.ReadAsStringAsync();
this.Config.ApiKey = key;
this.SaveConfig();
this.Messages.SpawnVfx();
});
}
}

View File

@ -31,20 +31,43 @@ internal class MainWindow {
return;
}
if (ImGui.BeginTabBar("##ogt-main-tabs")) {
foreach (var tab in this.Tabs) {
if (!ImGui.BeginTabItem(tab.Name)) {
continue;
}
tab.Draw();
ImGui.EndTabItem();
}
ImGui.EndTabBar();
if (this.Plugin.Config.ApiKey == string.Empty) {
this.DrawApiKey();
} else {
this.DrawTabs();
}
ImGui.End();
}
private void DrawTabs() {
if (!ImGui.BeginTabBar("##ogt-main-tabs")) {
return;
}
foreach (var tab in this.Tabs) {
if (!ImGui.BeginTabItem(tab.Name)) {
continue;
}
tab.Draw();
ImGui.EndTabItem();
}
ImGui.EndTabBar();
}
private void DrawApiKey() {
ImGui.PushTextWrapPos();
ImGui.TextUnformatted($"Somehow, {this.Plugin.Name} wasn't able to register you an account automatically.");
ImGui.TextUnformatted("Click the button below to try again.");
ImGui.PopTextWrapPos();
if (ImGui.Button("Register")) {
this.Plugin.GetApiKey();
}
}
}

View File

@ -23,6 +23,7 @@ internal class Settings : ITab {
anyChanged |= vfx |= ImGui.Checkbox("Disable in Deep Dungeons", ref this.Plugin.Config.DisableDeepDungeon);
anyChanged |= vfx |= ImGui.Checkbox("Remove glow effect from signs", ref this.Plugin.Config.RemoveGlow);
anyChanged |= ImGui.Checkbox("Open the viewer automatically when near a sign", ref this.Plugin.Config.AutoViewer);
anyChanged |= ImGui.Checkbox("Close the viewer automatically when no signs are nearby", ref this.Plugin.Config.AutoViewerClose);
anyChanged |= ImGui.SliderFloat("Viewer opacity", ref this.Plugin.Config.ViewerOpacity, 0f, 100.0f, $"{this.Plugin.Config.ViewerOpacity:N3}%%");
if (anyChanged) {

View File

@ -36,7 +36,7 @@ internal class Viewer {
.OrderBy(msg => msg.Id)
.ToList();
if (nearby.Count == 0) {
if (this.Plugin.Config.AutoViewer) {
if (this.Plugin.Config.AutoViewerClose) {
this.Visible = false;
} else {
ImGui.TextUnformatted("No nearby messages");

View File

@ -0,0 +1 @@
create index votes_message_idx on votes (message);

View File

@ -19,6 +19,7 @@ mod message;
mod web;
mod util;
mod config;
mod task;
static MIGRATOR: Migrator = sqlx::migrate!();

View File

@ -1,3 +1,4 @@
use chrono::{Duration, Utc};
use serde::{Deserialize, Serialize};
use sqlx::types::chrono::NaiveDateTime;
use uuid::Uuid;
@ -38,6 +39,13 @@ pub struct RetrievedMessage {
pub user: String,
}
impl RetrievedMessage {
pub fn adjusted_time_since_posting(&self) -> Duration {
let score = (self.positive_votes - self.negative_votes).max(0);
Utc::now().naive_utc().signed_duration_since(a.created) - Duration::weeks(score as i64)
}
}
#[derive(Debug, Serialize)]
pub struct RetrievedMessageTerritory {
pub id: String,

1
server/src/task.rs Normal file
View File

@ -0,0 +1 @@
mod delete_old;

View File

@ -0,0 +1,8 @@
use std::sync::Arc;
use crate::State;
pub fn delete_old(state: Arc<State>) {
tokio::task::spawn(async move {
});
}

View File

@ -87,7 +87,7 @@ fn filter_messages(messages: &mut Vec<RetrievedMessage>, id: i64) {
}
let score = (a.positive_votes - a.negative_votes).max(0);
let time_since_creation = Utc::now().naive_utc().signed_duration_since(a.created) - Duration::weeks(score as i64);
let time_since_creation = a.adjusted_time_since_posting();
if time_since_creation > Duration::weeks(1) {
continue;
}