notificatioonnsss !

This commit is contained in:
WanderingPenwing 2024-07-14 11:34:38 +02:00
parent c06b0a9823
commit 8cfa9568d0
3 changed files with 25 additions and 4 deletions

View file

@ -1 +1 @@
{"categories":[{"name":"to do","content":[{"name":"ability to change token","description":"use a config file to store token so that \n\n1- it is away from github\n\n2- it is configurable if need be","id":1},{"name":"clean up bot code","description":"try to remove unnecessary code\n\nunindent\n\ngive sender to function ?","id":2},{"name":"trayable ?","description":"// Hello there","id":5},{"name":"new message marker","description":"perma if too complicated to detect read","id":2},{"name":"proper links","description":"when there is a link, ability to click it","id":3}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"run discord bot","description":"make it so the bot is running","id":1},{"name":"fixed token in github","description":"// Hello there","id":1},{"name":"fetch previous messages","description":"// Hello there","id":4},{"name":"ability to write messages","description":"// Hello there","id":5},{"name":"get incoming messages","description":"read","id":2},{"name":"unread system","description":"add a * when a channel just received a message","id":1},{"name":"remember channel id for dm","description":"and put in config file\n\nmaybe load message ? dm first ?","id":3},{"name":"bug : does not save notification state for dm","description":"// Hello there","id":1},{"name":"handle unknown channel better","description":"when receiving a message from a not yet scanned guild, create the channel and put the message\n\nallow scanning if guild selected\n\ndo not add duplicate channel","id":1},{"name":"guild unread ?","description":"// Hello there","id":2},{"name":"timestamps","description":"// Hello there","id":1},{"name":"better ui error display","description":"handle the error packet for better display","id":1}]},{"name":"bugs","content":[]},{"name":"v1.0","content":[{"name":"notifications !!!","description":"// Hello there","id":4}]},{"name":"+","content":[]}]}
{"categories":[{"name":"to do","content":[{"name":"ability to change token","description":"use a config file to store token so that \n\n1- it is away from github\n\n2- it is configurable if need be","id":1},{"name":"clean up bot code","description":"try to remove unnecessary code\n\nunindent\n\ngive sender to function ?","id":2},{"name":"trayable ?","description":"// Hello there","id":5},{"name":"new message marker","description":"perma if too complicated to detect read","id":2},{"name":"proper links","description":"when there is a link, ability to click it","id":3}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"run discord bot","description":"make it so the bot is running","id":1},{"name":"fixed token in github","description":"// Hello there","id":1},{"name":"fetch previous messages","description":"// Hello there","id":4},{"name":"ability to write messages","description":"// Hello there","id":5},{"name":"get incoming messages","description":"read","id":2},{"name":"unread system","description":"add a * when a channel just received a message","id":1},{"name":"remember channel id for dm","description":"and put in config file\n\nmaybe load message ? dm first ?","id":3},{"name":"bug : does not save notification state for dm","description":"// Hello there","id":1},{"name":"handle unknown channel better","description":"when receiving a message from a not yet scanned guild, create the channel and put the message\n\nallow scanning if guild selected\n\ndo not add duplicate channel","id":1},{"name":"guild unread ?","description":"// Hello there","id":2},{"name":"timestamps","description":"// Hello there","id":1},{"name":"better ui error display","description":"handle the error packet for better display","id":1},{"name":"notifications !!!","description":"// Hello there","id":4}]},{"name":"bugs","content":[]},{"name":"v1.0","content":[]},{"name":"+","content":[]}]}

View file

@ -63,6 +63,7 @@ impl Jiji {
} else {
println!("app: unknown channel");
self.guilds[guild_index].channels.push(discord_structure::Channel::create(message.channel_id.clone(), message.channel_id.clone(), message.guild_id.clone()));
let _ = self.sender.send(postman::Packet::FetchChannels(self.guilds[guild_index].id.clone()));
self.guilds[guild_index].channels.len() - 1
};
@ -71,9 +72,15 @@ impl Jiji {
}
if self.guilds[guild_index].channels[channel_index].notify && message.new != "" {
let mut body_text = format!("{} - {}", self.guilds[guild_index].name, self.guilds[guild_index].channels[channel_index].name);
if self.guilds[guild_index].id == "dm" {
body_text = format!("{}", self.guilds[guild_index].name);
}
let _ = Notification::new()
.summary(&message.author_name)
.body(&format!("{} - {}", self.guilds[guild_index].name, self.guilds[guild_index].channels[channel_index].name))
.body(&body_text)
.timeout(0)
.show();
}

View file

@ -1,4 +1,5 @@
use chrono::{DateTime, ParseError};
use notify_rust::Notification;
#[derive(PartialEq, Clone)]
pub struct Guild {
@ -21,11 +22,24 @@ impl Guild {
pub fn add_channel(&mut self, channel: Channel) {
let mut already_exist = false;
for existing_channel in self.channels.clone() {
if existing_channel.id != channel.id {
for i in 0..self.channels.len() {
if self.channels[i].id != channel.id {
continue
}
already_exist = true;
self.channels[i].name = channel.name.clone();
if channel.notify && !self.channels[i].notify {
self.channels[i].notify = true;
if self.channels[i].messages.len() > 0 {
let _ = Notification::new()
.summary(&self.channels[i].messages[self.channels[i].messages.len() - 1].author_name)
.body(&format!("{} - {}", self.name, self.channels[i].name))
.timeout(0)
.show();
}
}
}
if !already_exist {