logo

dotfiles

My dotfiles, one branch per machine, rebased on base git clone https://anongit.hacktivis.me/git/dotfiles.git/

highmon.pl (36654B)


  1. #
  2. # highmon.pl - Highlight Monitoring for weechat 0.3.0
  3. # Version 2.5
  4. #
  5. # Add 'Highlight Monitor' buffer/bar to log all highlights in one spot
  6. #
  7. # Usage:
  8. # /highmon [help] | [monitor [channel [server]]] | [clean default|orphan|all] | clearbar
  9. # Command wrapper for highmon commands
  10. #
  11. # /highmon clean default|orphan|all will clean the config section of default 'on' entries,
  12. # channels you are no longer joined, or both
  13. #
  14. # /highmon clearbar will clear the contents of highmon's bar output
  15. #
  16. # /highmon monitor [channel] [server] is used to toggle a highlight monitoring on and off, this
  17. # can be used in the channel buffer for the channel you wish to toggle, or be given
  18. # with arguments e.g. /highmon monitor #weechat freenode
  19. #
  20. # /set plugins.var.perl.highmon.alignment
  21. # The config setting "alignment" can be changed to;
  22. # "channel", "schannel", "nchannel", "channel,nick", "schannel,nick", "nchannel,nick"
  23. # to change how the monitor appears
  24. # The 'channel' value will show: "#weechat"
  25. # The 'schannel' value will show: "6"
  26. # The 'nchannel' value will show: "6:#weechat"
  27. #
  28. # /set plugins.var.perl.highmon.short_names
  29. # Setting this to 'on' will trim the network name from highmon, ala buffers.pl
  30. #
  31. # /set plugins.var.perl.highmon.merge_private
  32. # Setting this to 'on' will merge private messages to highmon's display
  33. #
  34. # /set plugins.var.perl.highmon.color_buf
  35. # This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
  36. # This *must* be a valid color name, or weechat will likely do unexpected things :)
  37. #
  38. # /set plugins.var.perl.highmon.hotlist_show
  39. # Setting this to 'on' will let the highmon buffer appear in hotlists
  40. # (status bar/buffer.pl)
  41. #
  42. # /set plugins.var.perl.highmon.away_only
  43. # Setting this to 'on' will only put messages in the highmon buffer when
  44. # you set your status to away
  45. #
  46. # /set plugins.var.perl.highmon.logging
  47. # Toggles logging status for highmon buffer (default: off)
  48. #
  49. # /set plugins.var.perl.highmon.output
  50. # Changes where output method of highmon; takes either "bar" or "buffer" (default; buffer)
  51. # /set plugins.var.perl.highmon.bar_lines
  52. # Changes the amount of lines the output bar will hold.
  53. # (Only appears once output has been set to bar, defaults to 10)
  54. # /set plugins.var.perl.highmon.bar_scrolldown
  55. # Toggles the bar scrolling at the bottom when new highlights are received
  56. # (Only appears once output has been set to bar, defaults to off)
  57. #
  58. # /set plugins.var.perl.highmon.nick_prefix
  59. # /set plugins.var.perl.highmon.nick_suffix
  60. # Sets the prefix and suffix chars in the highmon buffer
  61. # (Defaults to <> if nothing set, and blank if there is)
  62. #
  63. # servername.#channel
  64. # servername is the internal name for the server (set when you use /server add)
  65. # #channel is the channel name, (where # is whatever channel type that channel happens to be)
  66. #
  67. # Optional, set up tweaks; Hide the status and input lines on highmon
  68. #
  69. # /set weechat.bar.status.conditions "${window.buffer.full_name} != perl.highmon"
  70. # /set weechat.bar.input.conditions "${window.buffer.full_name} != perl.highmon"
  71. #
  72. # Bugs and feature requests at: https://github.com/KenjiE20/highmon
  73. # History:
  74. # 2014-08-16, KenjiE20 <longbow@longbowslair.co.uk>:
  75. # v2.5: -add: clearbar command to clear bar output
  76. # -add: firstrun output prompt to check the help text for set up hints as they were being missed
  77. # and update hint for conditions to use eval
  78. # -change: Make all outputs use the date callback for more accurate timestamps (thanks Germainz)
  79. # 2013-12-04, KenjiE20 <longbow@longbowslair.co.uk>:
  80. # v2.4: -add: Support for eval style colour codes in time format used for bar output
  81. # 2013-10-22, KenjiE20 <longbow@longbowslair.co.uk>:
  82. # v2.3.3.2: -fix: Typo in fix command
  83. # 2013-10-10, KenjiE20 <longbow@longbowslair.co.uk>:
  84. # v2.3.3.1: -fix: Typo in closed buffer warning
  85. # 2013-10-07, KenjiE20 <longbow@longbowslair.co.uk>:
  86. # v2.3.3: -add: Warning and fixer for accidental buffer closes
  87. # 2013-01-15, KenjiE20 <longbow@longbowslair.co.uk>:
  88. # v2.3.2: -fix: Let bar output use the string set in weechat's config option
  89. # -add: github info
  90. # 2012-04-15, KenjiE20 <longbow@longbowslair.co.uk>:
  91. # v2.3.1: -fix: Colour tags in bar timestamp string
  92. # 2012-02-28, KenjiE20 <longbow@longbowslair.co.uk>:
  93. # v2.3: -feature: Added merge_private option to display private messages (default: off)
  94. # -fix: Channel name colours now show correctly when set to on
  95. # 2011-08-07, Sitaktif <romainchossart_at_gmail.com>:
  96. # v2.2.1: -feature: Add "bar_scrolldown" option to have the bar display the latest hl at anytime
  97. # -fix: Set up bar-specific config at startup if 'output' is already configured as 'bar'
  98. # 2010-12-22, KenjiE20 <longbow@longbowslair.co.uk>:
  99. # v2.2: -change: Use API instead of config to find channel colours, ready for 0.3.4 and 256 colours
  100. # 2010-12-13, idl0r & KenjiE20 <longbow@longbowslair.co.uk>:
  101. # v2.1.3: -fix: perl errors caused by bar line counter
  102. # -fix: Add command list to inbuilt help
  103. # 2010-09-30, KenjiE20 <longbow@longbowslair.co.uk>:
  104. # v2.1.2: -fix: logging config was not correctly toggling back on (thanks to sleo for noticing)
  105. # -version sync w/ chanmon
  106. # 2010-08-27, KenjiE20 <longbow@longbowslair.co.uk>:
  107. # v2.1: -feature: Add 'nchannel' option to alignment to display buffer and name
  108. # 2010-04-25, KenjiE20 <longbow@longbowslair.co.uk>:
  109. # v2.0: Release as version 2.0
  110. # 2010-04-24, KenjiE20 <longbow@longbowslair.co.uk>:
  111. # v1.9: Rewrite for v2.0
  112. # Bring feature set in line with chanmon 2.0
  113. # -code change: Made more subs to shrink the code down in places
  114. # -fix: Stop highmon attempting to double load/hook
  115. # -fix: Add version dependant check for away status
  116. # 2010-01-25, KenjiE20 <longbow@longbowslair.co.uk>:
  117. # v1.7: -fixture: Let highmon be aware of nick_prefix/suffix
  118. # and allow custom prefix/suffix for chanmon buffer
  119. # (Defaults to <> if nothing set, and blank if there is)
  120. # (Thanks to m4v for these)
  121. # 2009-09-07, KenjiE20 <longbow@longbowslair.co.uk>:
  122. # v1.6: -feature: colored buffer names
  123. # -change: version sync with chanmon
  124. # 2009-09-05, KenjiE20 <longbow@longbowslair.co.uk>:
  125. # v1.2: -fix: disable buffer highlight
  126. # 2009-09-02, KenjiE20 <longbow@longbowslair.co.uk>:
  127. # v.1.1.1 -change: Stop unsightly text block on '/help'
  128. # 2009-08-10, KenjiE20 <longbow@longbowslair.co.uk>:
  129. # v1.1: In-client help added
  130. # 2009-08-02, KenjiE20 <longbow@longbowslair.co.uk>:
  131. # v1.0: Initial Public Release
  132. # Copyright (c) 2009 by KenjiE20 <longbow@longbowslair.co.uk>
  133. #
  134. # This program is free software; you can redistribute it and/or modify
  135. # it under the terms of the GNU General Public License as published by
  136. # the Free Software Foundation; either version 3 of the License, or
  137. # (at your option) any later version.
  138. #
  139. # This program is distributed in the hope that it will be useful,
  140. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  141. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  142. # GNU General Public License for more details.
  143. #
  144. # You should have received a copy of the GNU General Public License
  145. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  146. #
  147. @bar_lines = ();
  148. @bar_lines_time = ();
  149. # Replicate info earlier for in-client help
  150. $highmonhelp = weechat::color("bold")."/highmon [help] | [monitor [channel [server]]] | [clean default|orphan|all] | clearbar".weechat::color("-bold")."
  151. Command wrapper for highmon commands
  152. ".weechat::color("bold")."/highmon clean default|orphan|all".weechat::color("-bold")." will clean the config section of default 'on' entries, channels you are no longer joined, or both
  153. ".weechat::color("bold")."/highmon clearbar".weechat::color("-bold")." will clear the contents of highmon's bar output
  154. ".weechat::color("bold")."/highmon monitor [channel] [server]".weechat::color("-bold")." is used to toggle a highlight monitoring on and off, this can be used in the channel buffer for the channel you wish to toggle, or be given with arguments e.g. /highmon monitor #weechat freenode
  155. ".weechat::color("bold")."/set plugins.var.perl.highmon.alignment".weechat::color("-bold")."
  156. The config setting \"alignment\" can be changed to;
  157. \"channel\", \"schannel\", \"nchannel\", \"channel,nick\", \"schannel,nick\", \"nchannel,nick\"
  158. to change how the monitor appears
  159. The 'channel' value will show: \"#weechat\"
  160. The 'schannel' value will show: \"6\"
  161. The 'nchannel' value will show: \"6:#weechat\"
  162. ".weechat::color("bold")."/set plugins.var.perl.highmon.short_names".weechat::color("-bold")."
  163. Setting this to 'on' will trim the network name from highmon, ala buffers.pl
  164. ".weechat::color("bold")."/set plugins.var.perl.highmon.merge_private".weechat::color("-bold")."
  165. Setting this to 'on' will merge private messages to highmon's display
  166. ".weechat::color("bold")."/set plugins.var.perl.highmon.color_buf".weechat::color("-bold")."
  167. This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
  168. This ".weechat::color("bold")."must".weechat::color("-bold")." be a valid color name, or weechat will likely do unexpected things :)
  169. ".weechat::color("bold")."/set plugins.var.perl.highmon.hotlist_show".weechat::color("-bold")."
  170. Setting this to 'on' will let the highmon buffer appear in hotlists (status bar/buffer.pl)
  171. ".weechat::color("bold")."/set plugins.var.perl.highmon.away_only".weechat::color("-bold")."
  172. Setting this to 'on' will only put messages in the highmon buffer when you set your status to away
  173. ".weechat::color("bold")."/set plugins.var.perl.highmon.logging".weechat::color("-bold")."
  174. Toggles logging status for highmon buffer (default: off)
  175. ".weechat::color("bold")."/set plugins.var.perl.highmon.output".weechat::color("-bold")."
  176. Changes where output method of highmon; takes either \"bar\" or \"buffer\" (default; buffer)
  177. ".weechat::color("bold")."/set plugins.var.perl.highmon.bar_lines".weechat::color("-bold")."
  178. Changes the amount of lines the output bar will hold.
  179. (Only appears once output has been set to bar, defaults to 10)
  180. ".weechat::color("bold")."/set plugins.var.perl.highmon.bar_scrolldown".weechat::color("-bold")."
  181. Toggles the bar scrolling at the bottom when new highlights are received
  182. (Only appears once output has been set to bar, defaults to off)
  183. ".weechat::color("bold")."/set plugins.var.perl.highmon.nick_prefix".weechat::color("-bold")."
  184. ".weechat::color("bold")."/set plugins.var.perl.highmon.nick_suffix".weechat::color("-bold")."
  185. Sets the prefix and suffix chars in the highmon buffer
  186. (Defaults to <> if nothing set, and blank if there is)
  187. ".weechat::color("bold")."servername.#channel".weechat::color("-bold")."
  188. servername is the internal name for the server (set when you use /server add)
  189. #channel is the channel name, (where # is whatever channel type that channel happens to be)
  190. ".weechat::color("bold")."Optional, set up tweaks;".weechat::color("-bold")." Hide the status and input lines on highmon
  191. ".weechat::color("bold")."/set weechat.bar.status.conditions \"\${window.buffer.full_name} != perl.highmon\"".weechat::color("-bold")."
  192. ".weechat::color("bold")."/set weechat.bar.input.conditions \"\${window.buffer.full_name} != perl.highmon\"".weechat::color("-bold");
  193. # Print verbose help
  194. sub print_help
  195. {
  196. weechat::print("", "\t".weechat::color("bold")."Highmon Help".weechat::color("-bold")."\n\n");
  197. weechat::print("", "\t".$highmonhelp);
  198. return weechat::WEECHAT_RC_OK;
  199. }
  200. # Bar item build
  201. sub highmon_bar_build
  202. {
  203. # Get max lines
  204. $max_lines = weechat::config_get_plugin("bar_lines");
  205. $max_lines = $max_lines ? $max_lines : 10;
  206. $str = '';
  207. $align_num = 0;
  208. $count = 0;
  209. # Keep lines within max
  210. while ($#bar_lines > $max_lines)
  211. {
  212. shift(@bar_lines);
  213. shift(@bar_lines_time);
  214. }
  215. # So long as we have some lines, build a string
  216. if (@bar_lines)
  217. {
  218. # Build loop
  219. $sep = " ".weechat::config_string(weechat::config_get("weechat.look.prefix_suffix"))." ";
  220. foreach(@bar_lines)
  221. {
  222. # Find max align needed
  223. $prefix_num = (index(weechat::string_remove_color($_, ""), $sep));
  224. $align_num = $prefix_num if ($prefix_num > $align_num);
  225. }
  226. foreach(@bar_lines)
  227. {
  228. # Get align for this line
  229. $prefix_num = (index(weechat::string_remove_color($_, ""), $sep));
  230. # Make string
  231. $str = $str.$bar_lines_time[$count]." ".(" " x ($align_num - $prefix_num)).$_."\n";
  232. # Increment count for sync with time list
  233. $count++;
  234. }
  235. }
  236. return $str;
  237. }
  238. # Make a new bar
  239. sub highmon_bar_open
  240. {
  241. # Make the bar item
  242. weechat::bar_item_new("highmon", "highmon_bar_build", "");
  243. $highmon_bar = weechat::bar_new ("highmon", "off", 100, "root", "", "bottom", "vertical", "vertical", 0, 0, "default", "cyan", "default", "on", "highmon");
  244. return weechat::WEECHAT_RC_OK;
  245. }
  246. # Close bar
  247. sub highmon_bar_close
  248. {
  249. # Find if bar exists
  250. $highmon_bar = weechat::bar_search("highmon");
  251. # If is does, close it
  252. if ($highmon_bar ne "")
  253. {
  254. weechat::bar_remove($highmon_bar);
  255. }
  256. # Find if bar item exists
  257. $highmon_bar_item = weechat::bar_item_search("highmon_bar");
  258. # If is does, close it
  259. if ($highmon_bar_item ne "")
  260. {
  261. weechat::bar_remove($highmon_bar_item);
  262. }
  263. @bar_lines = ();
  264. return weechat::WEECHAT_RC_OK;
  265. }
  266. # Make a new buffer
  267. sub highmon_buffer_open
  268. {
  269. # Search for pre-existing buffer
  270. $highmon_buffer = weechat::buffer_search("perl", "highmon");
  271. # Make a new buffer
  272. if ($highmon_buffer eq "")
  273. {
  274. $highmon_buffer = weechat::buffer_new("highmon", "highmon_buffer_input", "", "highmon_buffer_close", "");
  275. }
  276. # Turn off notify, highlights
  277. if ($highmon_buffer ne "")
  278. {
  279. if (weechat::config_get_plugin("hotlist_show" eq "off"))
  280. {
  281. weechat::buffer_set($highmon_buffer, "notify", "0");
  282. }
  283. weechat::buffer_set($highmon_buffer, "highlight_words", "-");
  284. weechat::buffer_set($highmon_buffer, "title", "Highlight Monitor");
  285. # Set no_log
  286. if (weechat::config_get_plugin("logging") eq "off")
  287. {
  288. weechat::buffer_set($highmon_buffer, "localvar_set_no_log", "1");
  289. }
  290. }
  291. return weechat::WEECHAT_RC_OK;
  292. }
  293. # Buffer input has no action
  294. sub highmon_buffer_input
  295. {
  296. return weechat::WEECHAT_RC_OK;
  297. }
  298. # Close up
  299. sub highmon_buffer_close
  300. {
  301. $highmon_buffer = "";
  302. # If user hasn't changed output style warn user
  303. if (weechat::config_get_plugin("output") eq "buffer")
  304. {
  305. weechat::print("", "\tHighmon buffer has been closed but output is still set to buffer, unusual results may occur. To recreate the buffer use ".weechat::color("bold")."/highmon fix".weechat::color("-bold"));
  306. }
  307. return weechat::WEECHAT_RC_OK;
  308. }
  309. # Highmon command wrapper
  310. sub highmon_command_cb
  311. {
  312. $data = $_[0];
  313. $buffer = $_[1];
  314. $args = $_[2];
  315. my $cmd = '';
  316. my $arg = '';
  317. if ($args ne "")
  318. {
  319. # Split argument up
  320. @arg_array = split(/ /,$args);
  321. # Take first as command
  322. $cmd = shift(@arg_array);
  323. # Rebuild string to pass to subs
  324. if (@arg_array)
  325. {
  326. $arg = join(" ", @arg_array);
  327. }
  328. }
  329. # Help command
  330. if ($cmd eq "" || $cmd eq "help")
  331. {
  332. print_help();
  333. }
  334. # /monitor command
  335. elsif ($cmd eq "monitor")
  336. {
  337. highmon_toggle($data, $buffer, $arg);
  338. }
  339. # /highclean command
  340. elsif ($cmd eq "clean")
  341. {
  342. highmon_config_clean($data, $buffer, $arg);
  343. }
  344. # clearbar command
  345. elsif ($cmd eq "clearbar")
  346. {
  347. if (weechat::config_get_plugin("output") eq "bar")
  348. {
  349. @bar_lines = ();
  350. weechat::bar_item_update("highmon");
  351. }
  352. }
  353. # Fix closed buffer
  354. elsif ($cmd eq "fix")
  355. {
  356. if (weechat::config_get_plugin("output") eq "buffer" && $highmon_buffer eq "")
  357. {
  358. highmon_buffer_open();
  359. }
  360. }
  361. return weechat::WEECHAT_RC_OK;
  362. }
  363. # Clean up config entries
  364. sub highmon_config_clean
  365. {
  366. $data = $_[0];
  367. $buffer = $_[1];
  368. $args = $_[2];
  369. # Don't do anything if bad option given
  370. if ($args ne "default" && $args ne "orphan" && $args ne "all")
  371. {
  372. weechat::print("", "\thighmon.pl: Unknown option");
  373. return weechat::WEECHAT_RC_OK;
  374. }
  375. @chans = ();
  376. # Load an infolist of highmon options
  377. $infolist = weechat::infolist_get("option", "", "*highmon*");
  378. while (weechat::infolist_next($infolist))
  379. {
  380. $name = weechat::infolist_string($infolist, "option_name");
  381. $name =~ s/perl\.highmon\.(\w*)\.([#&\+!])(.*)/$1.$2$3/;
  382. if ($name =~ /^(.*)\.([#&\+!])(.*)$/)
  383. {
  384. $action = 0;
  385. # Clean up all 'on's
  386. if ($args eq "default" || $args eq "all")
  387. {
  388. # If value in config is "on"
  389. if (weechat::config_get_plugin($name) eq "on")
  390. {
  391. # Unset and if successful flag as changed
  392. $rc = weechat::config_unset_plugin($name);
  393. if ($rc eq weechat::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED)
  394. {
  395. $action = 1;
  396. }
  397. }
  398. }
  399. # Clean non joined
  400. if ($args eq "orphan" || $args eq "all")
  401. {
  402. # If we can't find the buffer for this entry
  403. if (weechat::buffer_search("irc", $name) eq "")
  404. {
  405. # Unset and if successful flag as changed
  406. $rc = weechat::config_unset_plugin($name);
  407. if ($rc eq weechat::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED)
  408. {
  409. $action = 1;
  410. }
  411. }
  412. }
  413. # Add changed entry names to list
  414. push (@chans, $name) if ($action);
  415. }
  416. }
  417. weechat::infolist_free($infolist);
  418. # If channels were cleaned from config
  419. if (@chans)
  420. {
  421. # If only one entry
  422. if (@chans == 1)
  423. {
  424. $str = "\thighmon.pl: Cleaned ".@chans." entry from the config:";
  425. }
  426. else
  427. {
  428. $str = "\thighmon.pl: Cleaned ".@chans." entries from the config:";
  429. }
  430. # Build a list of channels
  431. foreach(@chans)
  432. {
  433. $str = $str." ".$_;
  434. }
  435. # Print what happened
  436. weechat::print("",$str);
  437. }
  438. # Config seemed to be clean
  439. else
  440. {
  441. weechat::print("", "\thighmon.pl: No entries removed");
  442. }
  443. return weechat::WEECHAT_RC_OK;
  444. }
  445. # Check config elements
  446. sub highmon_config_init
  447. {
  448. # First run default
  449. if (!(weechat::config_is_set_plugin ("first_run")))
  450. {
  451. if (weechat::config_get_plugin("first_run") ne "true")
  452. {
  453. weechat::print("", "\tThis appears to be the first time highmon has been run. For help and common set up hints see /highmon help");
  454. weechat::config_set_plugin("first_run", "true");
  455. }
  456. }
  457. # Alignment default
  458. if (!(weechat::config_is_set_plugin ("alignment")))
  459. {
  460. weechat::config_set_plugin("alignment", "channel");
  461. }
  462. if (weechat::config_get_plugin("alignment") eq "")
  463. {
  464. weechat::config_set_plugin("alignment", "none");
  465. }
  466. # Short name default
  467. if (!(weechat::config_is_set_plugin ("short_names")))
  468. {
  469. weechat::config_set_plugin("short_names", "off");
  470. }
  471. # Coloured names default
  472. if (!(weechat::config_is_set_plugin ("color_buf")))
  473. {
  474. weechat::config_set_plugin("color_buf", "on");
  475. }
  476. # Hotlist show default
  477. if (!(weechat::config_is_set_plugin ("hotlist_show")))
  478. {
  479. weechat::config_set_plugin("hotlist_show", "off");
  480. }
  481. # Away only default
  482. if (!(weechat::config_is_set_plugin ("away_only")))
  483. {
  484. weechat::config_set_plugin("away_only", "off");
  485. }
  486. # highmon log default
  487. if (!(weechat::config_is_set_plugin ("logging")))
  488. {
  489. weechat::config_set_plugin("logging", "off");
  490. }
  491. # Output default
  492. if (!(weechat::config_is_set_plugin ("output")))
  493. {
  494. weechat::config_set_plugin("output", "buffer");
  495. }
  496. # Private message merging
  497. if (!(weechat::config_is_set_plugin ("merge_private")))
  498. {
  499. weechat::config_set_plugin("merge_private", "off");
  500. }
  501. # Set bar config in case output was set to "bar" before even changing the setting
  502. if (weechat::config_get_plugin("output") eq "bar")
  503. {
  504. # Output bar lines default
  505. if (!(weechat::config_is_set_plugin ("bar_lines")))
  506. {
  507. weechat::config_set_plugin("bar_lines", "10");
  508. }
  509. if (!(weechat::config_is_set_plugin ("bar_scrolldown")))
  510. {
  511. weechat::config_set_plugin("bar_scrolldown", "off");
  512. }
  513. }
  514. # Check for exisiting prefix/suffix chars, and setup accordingly
  515. $prefix = weechat::config_get("irc.look.nick_prefix");
  516. $prefix = weechat::config_string($prefix);
  517. $suffix = weechat::config_get("irc.look.nick_suffix");
  518. $suffix = weechat::config_string($suffix);
  519. if (!(weechat::config_is_set_plugin("nick_prefix")))
  520. {
  521. if ($prefix eq "" && $suffix eq "")
  522. {
  523. weechat::config_set_plugin("nick_prefix", "<");
  524. }
  525. else
  526. {
  527. weechat::config_set_plugin("nick_prefix", "");
  528. }
  529. }
  530. if (!(weechat::config_is_set_plugin("nick_suffix")))
  531. {
  532. if ($prefix eq "" && $suffix eq "")
  533. {
  534. weechat::config_set_plugin("nick_suffix", ">");
  535. }
  536. else
  537. {
  538. weechat::config_set_plugin("nick_suffix", "");
  539. }
  540. }
  541. }
  542. # Get config updates
  543. sub highmon_config_cb
  544. {
  545. $point = $_[0];
  546. $name = $_[1];
  547. $value = $_[2];
  548. $name =~ s/^plugins\.var\.perl\.highmon\.//;
  549. # Set logging on buffer
  550. if ($name eq "logging")
  551. {
  552. # Search for pre-existing buffer
  553. $highmon_buffer = weechat::buffer_search("perl", "highmon");
  554. if ($value eq "off")
  555. {
  556. weechat::buffer_set($highmon_buffer, "localvar_set_no_log", "1");
  557. }
  558. else
  559. {
  560. weechat::buffer_set($highmon_buffer, "localvar_del_no_log", "");
  561. }
  562. }
  563. # Output changer
  564. elsif ($name eq "output")
  565. {
  566. if ($value eq "bar")
  567. {
  568. # Search for pre-existing buffer
  569. $highmon_buffer = weechat::buffer_search("perl", "highmon");
  570. # Close if it exists
  571. if ($highmon_buffer ne "")
  572. {
  573. weechat::buffer_close($highmon_buffer)
  574. }
  575. # Output bar lines default
  576. if (!(weechat::config_is_set_plugin ("bar_lines")))
  577. {
  578. weechat::config_set_plugin("bar_lines", "10");
  579. }
  580. if (!(weechat::config_is_set_plugin ("bar_scrolldown")))
  581. {
  582. weechat::config_set_plugin("bar_scrolldown", "off");
  583. }
  584. # Make a bar if doesn't exist
  585. highmon_bar_open();
  586. }
  587. elsif ($value eq "buffer")
  588. {
  589. # If a bar exists, close it
  590. highmon_bar_close();
  591. # Open buffer
  592. highmon_buffer_open();
  593. }
  594. }
  595. # Change if hotlist config changes
  596. elsif ($name eq "hotlist_show")
  597. {
  598. # Search for pre-existing buffer
  599. $highmon_buffer = weechat::buffer_search("perl", "highmon");
  600. if ($value eq "off" && $highmon_buffer)
  601. {
  602. weechat::buffer_set($highmon_buffer, "notify", "0");
  603. }
  604. elsif ($value ne "off" && $highmon_buffer)
  605. {
  606. weechat::buffer_set($highmon_buffer, "notify", "3");
  607. }
  608. }
  609. elsif ($name eq "weechat.look.prefix_suffix")
  610. {
  611. if (weechat::config_get_plugin("output") eq "bar")
  612. {
  613. @bar_lines = ();
  614. weechat::print("", "\thighmon: weechat.look.prefix_suffix changed, clearing highmon bar");
  615. weechat::bar_item_update("highmon");
  616. }
  617. }
  618. return weechat::WEECHAT_RC_OK;
  619. }
  620. # Set up weechat hooks / commands
  621. sub highmon_hook
  622. {
  623. weechat::hook_print("", "", "", 0, "highmon_new_message", "");
  624. weechat::hook_command("highclean", "Highmon config clean up", "default|orphan|all", " default: Cleans all config entries with the default \"on\" value\n orphan: Cleans all config entries for channels you aren't currently joined\n all: Does both defaults and orphan", "default|orphan|all", "highmon_config_clean", "");
  625. weechat::hook_command("highmon", "Highmon help", "[help] | [monitor [channel [server]]] | [clean default|orphan|all] | clearbar", " help: Print help on config options for highmon\n monitor: Toggles monitoring for a channel\n clean: Highmon config clean up (/highclean)\nclearbar: Clear Highmon bar", "help || monitor %(irc_channels) %(irc_servers) || clean default|orphan|all || clearbar", "highmon_command_cb", "");
  626. weechat::hook_config("plugins.var.perl.highmon.*", "highmon_config_cb", "");
  627. weechat::hook_config("weechat.look.prefix_suffix", "highmon_config_cb", "");
  628. }
  629. # Main body, Callback for hook_print
  630. sub highmon_new_message
  631. {
  632. my $net = "";
  633. my $chan = "";
  634. my $nick = "";
  635. my $outstr = "";
  636. my $window_displayed = "";
  637. my $dyncheck = "0";
  638. # DEBUG point
  639. # $string = "\t"."0: ".$_[0]." 1: ".$_[1]." 2: ".$_[2]." 3: ".$_[3]." 4: ".$_[4]." 5: ".$_[5]." 6: ".$_[6]." 7: ".$_[7];
  640. # weechat::print("", "\t".$string);
  641. $cb_datap = $_[0];
  642. $cb_bufferp = $_[1];
  643. $cb_date = $_[2];
  644. $cb_tags = $_[3];
  645. $cb_disp = $_[4];
  646. $cb_high = $_[5];
  647. $cb_prefix = $_[6];
  648. $cb_msg = $_[7];
  649. # Only work on highlighted messages or private message when enabled
  650. if ($cb_high == "1" || (weechat::config_get_plugin("merge_private") eq "on" && $cb_tags =~ /notify_private/))
  651. {
  652. # Pre bug #29618 (0.3.3) away detect
  653. if (weechat::info_get("version_number", "") <= 197120)
  654. {
  655. $away = '';
  656. # Get infolist for this server
  657. $infolist = weechat::infolist_get("irc_server", "", weechat::buffer_get_string($cb_bufferp, "localvar_server"));
  658. while (weechat::infolist_next($infolist))
  659. {
  660. # Get away message is is_away is on
  661. $away = weechat::infolist_string($infolist, "away_message") if (weechat::infolist_integer($infolist, "is_away"));
  662. }
  663. weechat::infolist_free($infolist);
  664. }
  665. # Post bug #29618 fix
  666. else
  667. {
  668. $away = weechat::buffer_get_string($cb_bufferp, "localvar_away");
  669. }
  670. if (weechat::config_get_plugin("away_only") ne "on" || ($away ne ""))
  671. {
  672. # Check buffer name is an IRC channel
  673. $bufname = weechat::buffer_get_string($cb_bufferp, 'name');
  674. if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
  675. {
  676. # Are we running on this channel
  677. if (weechat::config_get_plugin($bufname) ne "off" && $cb_disp eq "1")
  678. {
  679. # Format nick
  680. # Line isn't action or topic notify
  681. if (!($cb_tags =~ /irc_action/) && !($cb_tags =~ /irc_topic/))
  682. {
  683. # Strip nick colour
  684. $uncolnick = weechat::string_remove_color($cb_prefix, "");
  685. # Format nick
  686. $nick = " ".weechat::config_get_plugin("nick_prefix").weechat::color("chat_highlight").$uncolnick.weechat::color("reset").weechat::config_get_plugin("nick_suffix");
  687. }
  688. # Topic line
  689. elsif ($cb_tags =~ /irc_topic/)
  690. {
  691. $nick = " ".$cb_prefix.weechat::color("reset");
  692. }
  693. # Action line
  694. else
  695. {
  696. $uncolnick = weechat::string_remove_color($cb_prefix, "");
  697. $nick = weechat::color("chat_highlight").$uncolnick.weechat::color("reset");
  698. }
  699. # Send to output
  700. highmon_print ($cb_msg, $cb_bufferp, $nick, $cb_date, $cb_tags);
  701. }
  702. }
  703. # Or is private message
  704. elsif (weechat::config_get_plugin("merge_private") eq "on" && $cb_tags =~ /notify_private/)
  705. {
  706. # Strip nick colour
  707. $uncolnick = weechat::buffer_get_string($cb_bufferp, 'short_name');
  708. # Format nick
  709. $nick = " ".weechat::config_get_plugin("nick_prefix").weechat::color("chat_highlight").$uncolnick.weechat::color("reset").weechat::config_get_plugin("nick_suffix");
  710. #Send to output
  711. highmon_print ($cb_msg, $cb_bufferp, $nick, $cb_date, $cb_tags);
  712. }
  713. }
  714. }
  715. return weechat::WEECHAT_RC_OK;
  716. }
  717. # Output formatter and printer takes (msg bufpointer nick)
  718. sub highmon_print
  719. {
  720. $cb_msg = $_[0];
  721. my $cb_bufferp = $_[1] if ($_[1]);
  722. my $nick = $_[2] if ($_[2]);
  723. my $cb_date = $_[3] if ($_[3]);
  724. my $cb_tags = $_[4] if ($_[4]);
  725. #Normal channel message
  726. if ($cb_bufferp && $nick)
  727. {
  728. # Format buffer name
  729. $bufname = format_buffer_name($cb_bufferp);
  730. # If alignment is #channel | nick msg
  731. if (weechat::config_get_plugin("alignment") eq "channel")
  732. {
  733. $nick =~ s/\s(.*)/$1/;
  734. # Build string
  735. $outstr = $bufname."\t".$nick." ".$cb_msg;
  736. }
  737. # or if it is channel number | nick msg
  738. elsif (weechat::config_get_plugin("alignment") eq "schannel")
  739. {
  740. $nick =~ s/\s(.*)/$1/;
  741. # Use channel number instead
  742. $bufname = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer($cb_bufferp, 'number').weechat::color("reset");
  743. # Build string
  744. $outstr = $bufname."\t".$nick." ".$cb_msg;
  745. }
  746. # or if it is number:#channel | nick msg
  747. elsif (weechat::config_get_plugin("alignment") eq "nchannel")
  748. {
  749. $nick =~ s/\s(.*)/$1/;
  750. # Place channel number in front of formatted name
  751. $bufname = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer($cb_bufferp, 'number').":".weechat::color("reset").$bufname;
  752. # Build string
  753. $outstr = $bufname."\t".$nick." ".$cb_msg;
  754. }
  755. # or if it is #channel nick | msg
  756. elsif (weechat::config_get_plugin("alignment") eq "channel,nick")
  757. {
  758. # Build string
  759. $outstr = $bufname.":".$nick."\t".$cb_msg;
  760. }
  761. # or if it is channel number nick | msg
  762. elsif (weechat::config_get_plugin("alignment") eq "schannel,nick")
  763. {
  764. # Use channel number instead
  765. $bufname = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer($cb_bufferp, 'number').weechat::color("reset");
  766. # Build string
  767. $outstr = $bufname.":".$nick."\t".$cb_msg;
  768. }
  769. # or if it is number:#channel nick | msg
  770. elsif (weechat::config_get_plugin("alignment") eq "nchannel,nick")
  771. {
  772. # Place channel number in front of formatted name
  773. $bufname = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer($cb_bufferp, 'number').":".weechat::color("reset").$bufname;
  774. # Build string
  775. $outstr = $bufname.":".$nick."\t".$cb_msg;
  776. }
  777. # or finally | #channel nick msg
  778. else
  779. {
  780. # Build string
  781. $outstr = "\t".$bufname.":".$nick." ".$cb_msg;
  782. }
  783. }
  784. # highmon channel toggle message
  785. elsif ($cb_bufferp && !$nick)
  786. {
  787. # Format buffer name
  788. $bufname = format_buffer_name($cb_bufferp);
  789. # If alignment is #channel * | *
  790. if (weechat::config_get_plugin("alignment") =~ /channel/)
  791. {
  792. # If it's actually channel number * | *
  793. if (weechat::config_get_plugin("alignment") =~ /schannel/)
  794. {
  795. # Use channel number instead
  796. $bufname = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer($cb_bufferp, 'number').weechat::color("reset");
  797. }
  798. # Or if it's actually number:#channel * | *
  799. if (weechat::config_get_plugin("alignment") =~ /nchannel/)
  800. {
  801. # Place channel number in front of formatted name
  802. $bufname = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer($cb_bufferp, 'number').":".weechat::color("reset").$bufname;
  803. }
  804. $outstr = $bufname."\t".$cb_msg;
  805. }
  806. # or if alignment is | *
  807. else
  808. {
  809. $outstr = $bufname.": ".$cb_msg;
  810. }
  811. }
  812. # highmon dynmon
  813. elsif (!$cb_bufferp && !$nick)
  814. {
  815. $outstr = "\t".$cb_msg;
  816. }
  817. # Send string to buffer
  818. if (weechat::config_get_plugin("output") eq "buffer")
  819. {
  820. # Search for and confirm buffer
  821. $highmon_buffer = weechat::buffer_search("perl", "highmon");
  822. # Print
  823. if ($cb_date)
  824. {
  825. weechat::print_date_tags($highmon_buffer, $cb_date, $cb_tags, $outstr);
  826. }
  827. else
  828. {
  829. weechat::print($highmon_buffer, $outstr);
  830. }
  831. }
  832. elsif (weechat::config_get_plugin("output") eq "bar")
  833. {
  834. # Add time string
  835. use POSIX qw(strftime);
  836. if ($cb_date)
  837. {
  838. $time = strftime(weechat::config_string(weechat::config_get("weechat.look.buffer_time_format")), localtime($cb_date));
  839. }
  840. else
  841. {
  842. $time = strftime(weechat::config_string(weechat::config_get("weechat.look.buffer_time_format")), localtime);
  843. }
  844. # Colourise
  845. if ($time =~ /\$\{(?:color:)?[\w,]+\}/) # Coloured string
  846. {
  847. while ($time =~ /\$\{(?:color:)?([\w,]+)\}/)
  848. {
  849. $color = weechat::color($1);
  850. $time =~ s/\$\{(?:color:)?[\w,]+\}/$color/;
  851. }
  852. $time .= weechat::color("reset");
  853. }
  854. else # Default string
  855. {
  856. $colour = weechat::color(weechat::config_string(weechat::config_get("weechat.color.chat_time_delimiters")));
  857. $reset = weechat::color("reset");
  858. $time =~ s/(\d*)(.)(\d*)/$1$colour$2$reset$3/g;
  859. }
  860. # Push updates to bar lists
  861. push (@bar_lines_time, $time);
  862. # Change tab char
  863. $delim = " ".weechat::color(weechat::config_string(weechat::config_get("weechat.color.chat_delimiters"))).weechat::config_string(weechat::config_get("weechat.look.prefix_suffix")).weechat::color("reset")." ";
  864. $outstr =~ s/\t/$delim/;
  865. push (@bar_lines, $outstr);
  866. # Trigger update
  867. weechat::bar_item_update("highmon");
  868. if (weechat::config_get_plugin("bar_scrolldown") eq "on")
  869. {
  870. weechat::command("", "/bar scroll highmon * ye")
  871. }
  872. }
  873. }
  874. # Start the output display
  875. sub highmon_start
  876. {
  877. if (weechat::config_get_plugin("output") eq "buffer")
  878. {
  879. highmon_buffer_open();
  880. }
  881. elsif (weechat::config_get_plugin("output") eq "bar")
  882. {
  883. highmon_bar_open();
  884. }
  885. }
  886. # Takes two optional args (channel server), toggles monitoring on/off
  887. sub highmon_toggle
  888. {
  889. $data = $_[0];
  890. $buffer = $_[1];
  891. $args = $_[2];
  892. # Check if we've been told what channel to act on
  893. if ($args ne "")
  894. {
  895. # Split argument up
  896. @arg_array = split(/ /,$args);
  897. # Check if a server was given
  898. if ($arg_array[1])
  899. {
  900. # Find matching
  901. $bufp = weechat::buffer_search("irc", $arg_array[1].".".$arg_array[0]);
  902. }
  903. else
  904. {
  905. $found_chans = 0;
  906. # Loop through defined servers
  907. $infolist = weechat::infolist_get("buffer", "", "");
  908. while (weechat::infolist_next($infolist))
  909. {
  910. # Only interesting in IRC buffers
  911. if (weechat::infolist_string($infolist, "plugin_name") eq "irc")
  912. {
  913. # Find buffers that maych
  914. $sname = weechat::infolist_string($infolist, "short_name");
  915. if ($sname eq $arg_array[0])
  916. {
  917. $found_chans++;
  918. $bufp = weechat::infolist_pointer($infolist, "pointer");
  919. }
  920. }
  921. }
  922. weechat::infolist_free($infolist);
  923. # If the infolist found more than one channel, halt as we need to know which one
  924. if ($found_chans > 1)
  925. {
  926. weechat::print("", "Channel name is not unique, please define server");
  927. return weechat::WEECHAT_RC_OK;
  928. }
  929. }
  930. # Something didn't return right
  931. if ($bufp eq "")
  932. {
  933. weechat::print("", "Could not find buffer");
  934. return weechat::WEECHAT_RC_OK;
  935. }
  936. }
  937. else
  938. {
  939. # Get pointer from where we are
  940. $bufp = weechat::current_buffer();
  941. }
  942. # Get buffer name
  943. $bufname = weechat::buffer_get_string($bufp, 'name');
  944. # Test if buffer is an IRC channel
  945. if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
  946. {
  947. if (weechat::config_get_plugin($bufname) eq "off")
  948. {
  949. # If currently off, set on
  950. weechat::config_set_plugin($bufname, "on");
  951. # Send to output formatter
  952. highmon_print("Highlight Monitoring Enabled", $bufp);
  953. return weechat::WEECHAT_RC_OK;
  954. }
  955. elsif (weechat::config_get_plugin($bufname) eq "on" || weechat::config_get_plugin($bufname) eq "")
  956. {
  957. # If currently on, set off
  958. weechat::config_set_plugin($bufname, "off");
  959. # Send to output formatter
  960. highmon_print("Highlight Monitoring Disabled", $bufp);
  961. return weechat::WEECHAT_RC_OK;
  962. }
  963. }
  964. }
  965. # Takes a buffer pointer and returns a formatted name
  966. sub format_buffer_name
  967. {
  968. $cb_bufferp = $_[0];
  969. $bufname = weechat::buffer_get_string($cb_bufferp, 'name');
  970. # Set colour from buffer name
  971. if (weechat::config_get_plugin("color_buf") eq "on")
  972. {
  973. # Determine what colour to use
  974. $color = weechat::info_get("irc_nick_color", $bufname);
  975. if (!$color)
  976. {
  977. $color = 0;
  978. @char_array = split(//,$bufname);
  979. foreach $char (@char_array)
  980. {
  981. $color += ord($char);
  982. }
  983. $color %= 10;
  984. $color = sprintf "weechat.color.chat_nick_color%02d", $color+1;
  985. $color = weechat::config_get($color);
  986. $color = weechat::config_string($color);
  987. $color = weechat::color($color);
  988. }
  989. # Private message just show network
  990. if (weechat::config_get_plugin("merge_private") eq "on" && weechat::buffer_get_string($cb_bufferp, "localvar_type") eq "private")
  991. {
  992. $bufname = weechat::buffer_get_string($cb_bufferp, "localvar_server");
  993. }
  994. # Format name to short or 'nicename'
  995. elsif (weechat::config_get_plugin("short_names") eq "on")
  996. {
  997. $bufname = weechat::buffer_get_string($cb_bufferp, 'short_name');
  998. }
  999. else
  1000. {
  1001. $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
  1002. }
  1003. # Build a coloured string
  1004. $bufname = $color.$bufname.weechat::color("reset");
  1005. }
  1006. # User set colour name
  1007. elsif (weechat::config_get_plugin("color_buf") ne "off")
  1008. {
  1009. # Private message just show network
  1010. if (weechat::config_get_plugin("merge_private") eq "on" && weechat::buffer_get_string($cb_bufferp, "localvar_type") eq "private")
  1011. {
  1012. $bufname = weechat::buffer_get_string($cb_bufferp, "localvar_server");
  1013. }
  1014. # Format name to short or 'nicename'
  1015. elsif (weechat::config_get_plugin("short_names") eq "on")
  1016. {
  1017. $bufname = weechat::buffer_get_string($cb_bufferp, 'short_name');
  1018. }
  1019. else
  1020. {
  1021. $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
  1022. }
  1023. $color = weechat::config_get_plugin("color_buf");
  1024. $bufname = weechat::color($color).$bufname.weechat::color("reset");
  1025. }
  1026. # Stick with default colour
  1027. else
  1028. {
  1029. # Private message just show network
  1030. if (weechat::config_get_plugin("merge_private") eq "on" && weechat::buffer_get_string($cb_bufferp, "localvar_type") eq "private")
  1031. {
  1032. $bufname = weechat::buffer_get_string($cb_bufferp, "localvar_server");
  1033. }
  1034. # Format name to short or 'nicename'
  1035. elsif (weechat::config_get_plugin("short_names") eq "on")
  1036. {
  1037. $bufname = weechat::buffer_get_string($cb_bufferp, 'short_name');
  1038. }
  1039. else
  1040. {
  1041. $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
  1042. }
  1043. }
  1044. return $bufname;
  1045. }
  1046. # Check result of register, and attempt to behave in a sane manner
  1047. if (!weechat::register("highmon", "KenjiE20", "2.5", "GPL3", "Highlight Monitor", "", ""))
  1048. {
  1049. # Double load
  1050. weechat::print ("", "\tHighmon is already loaded");
  1051. return weechat::WEECHAT_RC_OK;
  1052. }
  1053. else
  1054. {
  1055. # Start everything
  1056. highmon_hook();
  1057. highmon_config_init();
  1058. highmon_start();
  1059. }