HexChat 2.10+ Python Scripting Question: Nickname Shortening Script Causes Infinite Loops reddit / irc ---------------------------------------------------------------------- --george--clooney · 2015-06-18 07:50 Hello all! I've been working on a little HexChat 2.10.2 Python 2.7 script to visually shorten long nicknames in Channel Messages so that the separator bar doesn't crush the actual message text into a little ball on the right half side of my client window. Since I almost always have HexChat taking up about half of the screen or less, utilizing the bulk of the client's horizontal real-estate for long messages is paramount. Thanks to TingPing sharing a similar script, I have amended by earlier attempt. If you're interested in shortening long nicknames, [check out the working script here](https://gist.github.com/anonymous/732449fffe32c817bab1).   _____ ~~So far my thinking towards how to accomplish this goes like so:~~ ~~* Hook into any message event that contains a nickname field to be displayed while in a channel.~~ ~~* Right now the events I have are Channel Message and Channel Msg Highlight~~ ~~* Take the information from the print event, edit it so that any nicknames over N characters are truncated with a tilde (e.g. LongUsernameGuy becomes LongUserna~)~~ ~~* Recreate the message with the new shortened nick and print to the associated context as an emit_print() with the same event type that it was recieved as. (Channel Messages are printed as Channel Message and Highlights are printed as Highlights)~~   ~~The only flaw with this process is that when I perform the emit_print() of the new edited message it in turn gets caught by the script's hook_print() function, causing an infinite look. The entire client instantly seizes up until an eventual hard crash.~~ ____ ~~**So my question is this:** How would one edit the information in a print event then reprint it (with all the nice formatting the normal event receives^1) without causing an infinite hook_print() loop?~~   ~~Here is the script in its current, broken form: [\[GitHub Gist\]](https://gist.github.com/anonymous/78a5082a772888243e0e)~~   ~~^1 In this case, the formatting I want to preserve is the Nickname coloration and the separator bar.~~ ---------------------------------------------------------------------- TingPing · 2015-06-18 15:11 Do something like this - https://github.com/TingPing/plugins/blob/master/HexChat/wordhl.py ---------------------------------------------------------------------- --george--clooney · 2015-06-18 19:05 I'll check that out fully when I get home for work. Looks like the main idea is to check a global variable to see if the message getting printed is from the context or the output of the script itself. Makes sense. Thanks for pointing me in the right direction and thank you so much for your hard work on HexChat, TingPing! ---------------------------------------------------------------------- TingPing · 2015-06-18 19:15 Yup that's the easiest way. Also your script should not re-emit events when they don't need to be modified; That alone would actually stop your specific issue I believe. Though my method always works. It should also be HIGH priority and EAT_ALL to avoid other scripts getting bogus events. (Though since you make up fake users other scripts may explode anyway). ---------------------------------------------------------------------- --george--clooney · 2015-06-18 22:29 Thanks for the advice and sorry for my awful coding! Using your highlight script as a guide, I [successfully rewrote it](https://gist.github.com/anonymous/732449fffe32c817bab1) and now the script does [exactly what I want](http://i.imgur.com/pcuyAct.png). The only problem is the entire client crashes whenever I reload the script but that is a small issue now that it works. Thanks again! ---------------------------------------------------------------------- TingPing · 2015-06-18 23:06 > The only problem is the entire client crashes whenever I reload the script but that is a small issue now that it works. Yea known issue =\ Also you do realize there is an option to just turn off nick identing in Preferences? ---------------------------------------------------------------------- --george--clooney · 2015-06-19 00:44 Yeah, I have played with that option. Even though I dislike when long nicks shove the separator bar around, I can't live without it. :) One last thing: Has anyone [reported this issue with the Edit Network URL textbox](https://vid.me/Yswn)? After typing in the IRC server URL, if the user clicks anywhere outside of the textbox, it reverts back to newserver/6667. If it's a new bug, I can write up a formal bug report on the GitHub project for you. Even though it's a small issue, it really confuses new users when they enter the server URL and it reverts back to the placeholder text. Or even worse: They don't notice it, fill out the rest of the form information, and try to connect to newserver/6667. ---------------------------------------------------------------------- TingPing · 2015-06-19 01:52 > After typing in the IRC server URL, if the user clicks anywhere outside of the textbox, it reverts back to newserver/6667. Hit enter to confirm changes, this applies to all editable lists in HexChat.