Compare commits
2 commits
a258dd4819
...
d4060c07e1
Author | SHA1 | Date | |
---|---|---|---|
Yash Karandikar | d4060c07e1 | ||
Yash Karandikar | 8c60211570 |
11
README.md
11
README.md
|
@ -1,3 +1,12 @@
|
|||
# wn2
|
||||
|
||||
weechat-notify 2, implemented as a native plugin instead of a script with a library.
|
||||
[weechat-notify](https://git.karx.xyz/karx/weechat-notify), implemented as a native plugin instead of a script with a library.
|
||||
|
||||
requires: rust, notify-send
|
||||
|
||||
to build, first run `cargo build --release` then move the generated .so (`target/release/libweechat_notify.so`) to your plugin directory (probably `~/.local/share/weechat/plugins` but could also be `~/.weechat/plugins`). then rename the .so to `weechat_notify.so`
|
||||
|
||||
next, run `/plugin load weechat_notify` and enjoy your notifications!
|
||||
|
||||
note: changes to the plugin are not reflected until you restart WeeChat.
|
||||
|
||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -16,9 +16,9 @@ struct WeechatNotify {
|
|||
|
||||
impl Plugin for WeechatNotify {
|
||||
fn init(_: &Weechat, _: Args) -> Result<Self, ()> {
|
||||
let _h1 = SignalHook::new("weechat_highlight", notify)?;
|
||||
let _h2 = SignalHook::new("irc_pv", notify)?;
|
||||
Ok(Self { _h1, _h2 })
|
||||
let h1 = SignalHook::new("weechat_highlight", notify)?;
|
||||
let h2 = SignalHook::new("irc_pv", notify)?;
|
||||
Ok(Self { _h1: h1, _h2: h2 })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,17 +28,16 @@ fn notify_inner(
|
|||
data: Option<SignalData>,
|
||||
) -> Result<(), String> {
|
||||
if let Some(SignalData::String(s)) = data {
|
||||
let mut arr: Vec<&str> = s.split("\t").collect();
|
||||
let mut arr: Vec<&str> = s.split('\t').collect();
|
||||
if arr.len() == 1 {
|
||||
let a = arr[0].split("PRIVMSG").collect::<Vec<&str>>();
|
||||
let b = a[0]
|
||||
.split("!")
|
||||
.split('!')
|
||||
.next()
|
||||
.map(|s| s.strip_prefix(":"))
|
||||
.flatten()
|
||||
.and_then(|s| s.strip_prefix(':'))
|
||||
.ok_or_else(|| "malformed data".to_string())?;
|
||||
let c = a[1]
|
||||
.split(":")
|
||||
.split(':')
|
||||
.nth(1)
|
||||
.ok_or_else(|| "malformed data".to_string())?;
|
||||
arr = vec![b, c];
|
||||
|
|
Loading…
Reference in a new issue