Chat plugin

dsouvik215

Member
May 25, 2018
896
0
16
Hey there,

I recently started using ruTorrent (before I was just using rTorrent and made a simple PHP page to upload/list/remove torrents from the watchdir) and I thought it might be nice to communicate with other users on the same ruTorrent setup.

So I made this chat plugin and thought other people might like it too so I'll share it here.

Latest version: v2.0

Main features:
  • chat with all other users on the ruTorrent setup
  • chat with individual users on the ruTorrent setup (PM)
  • auto popup on new message
  • clearing chat window (temporarily or permanent)
  • clickable URLs
  • smileys (2 different sets or disabled)
  • user modifiable settings
Screenshots:

Chat window:
chat.png

You can disable smileys so it shows the "raw" smiley instead of an image. You can also disable PMs and then chats list on the left won't be shown. Red nicks = cannot PM, blue nick = new message.

The smiley window:


Here you can either hover over a smiley to find out the smiley "code" or you can click it to append it to the message.

The settings window:


More information:
This plugin has its own googlecode page: http://code.google.com/p/rutorrent-chat/.

Want to use it right away?
Just move to your ruTorrent plugins dir, wget the tarball, unpack it and chown the files to your webuser:

Code:
cd /var/www/rutorrent/plugins/
wget http://rutorrent-chat.googlecode.com/files/chat-2.0.tar.gz
tar -zxf chat-2.0.tar.gz
chown -R www-user:www-user chat/
Of course feedback is appreciated, let me know if (or why) you (don't) like it and if you think it can use some improvements/bugfixes.

Enjoy wink.gif
 

das329717

Member
May 25, 2018
928
0
16
Looks nice. smiley.gif

Why aren't you using sourceforge or google code?

I haven't checked the code so I'm not sure if you already do this, but make sure you sanitize the messages a user writes so they can't inject HTML/JS code (i.e., XSS).

Quote
Since the messages are saved with a date+time of the server it will also calculate the difference between the local time of the user and adjust the output in the chat window as needed.​


It's easier if you just save the time as UTC on the server, and then let the JS code convert it back to local time.

Quote
Note: the main file where all the messages are written to does not get cleaned up automatically so you might want to remove some old lines from there every now and then. It would probably be hard to do this automatically since you don't know if all the users have logged in to ruTorrent and with that updated the file in their settings dir.​


What about creating a file per user? That way when the user loads the messages, your PHP script can clear the user's message file. The problem with this method is that new users, created after the previous messages were written, won't see the old messages.

Or you could have the script delete all messages older than N days.
 

jith45

Member
May 25, 2018
960
0
16
I think this is cool.

I also agree with brock. you should look into a googlecode page.

I've often set up ajax chat via a tab but this is a great idea.
 

somus1735

Member
May 25, 2018
833
0
16
Very good idea! I really like it. Like they said, host your project to googlecode, it's better.

I have a issue, for me the date/time appear as "undefined" (sound to work now...). I try to switch to english language but still same problem.

Also, at the begin I don't set proper permission to log file so chat doesn't work but I don't have the error message I see in lang file.

This is the french translation for your very good plugin (remember to set utf-8) :
Code:
theUILang.mnu_chat = "Discussion...";
theUILang.chat = "Discussion";
theUILang.chatMessages = "Messages";
theUILang.chatContribute = "Envoyer un message";
theUILang.chatSend = "Envoyer";
theUILang.chatClear = "vider";
theUILang.chatSmileys = "smileys";
theUILang.clearChat = "Vider la fenêtre de discussion";
theUILang.clearChatPrompt = "Voullez-vous vider la fenêtre : temporairement (restauration après un rafraichissement), permanent, ou annuler cette opération ?";
theUILang.clearChatTemp = "Temporairement";
theUILang.clearChatPerm = "Permanent";
theUILang.clearChatCancel = "Annuler";
theUILang.mainchatNotExist = "Le log principal de discussion n'existe pas.";
theUILang.mainchatUnreadable = "Impossible de lire le log principal de discussion.";
theUILang.mainchatUnwritable = "Impossible d'écrire dans le log principal de discussion.";
theUILang.userchatCreateFail = "Impossible de créer le log de discussion de l'utilisateur.";
theUILang.userchatUnreadable = "Impossible de lire le log de discussion de l'utilisateur.";
theUILang.userchatUnwritable = "Impossible d'écrire dans le log de discussion de l'utilisateur.";
theUILang.chatInvalidReq = "Requête invalide reçue.";

thePlugins.get("chat").langLoaded();
I have some idea of improvement :
- be able to connect different server to the same chat not only user on the same server with the possible to choose if i want send to all people or only on my server
- be able to PM a user in particulary

Thanks to improve our rutorrent experience!

++ Nico

EDIT : I forgot one thing, you need to update your css to have a correct color of font with oblivion theme :


Maybe ask to Brock, he have the same behavour with his IRC plugin.
 

dsouvik215

Member
May 25, 2018
896
0
16
I haven't checked the code so I'm not sure if you already do this, but make sure you sanitize the messages a user writes so they can't inject HTML/JS code (i.e., XSS).
Yup, I think this is enough to avoid XSS but correct me if I'm wrong:
Code:
text = text.replace(/&(?!\w+([;\s]|$))/g, "&");
text = text.replace(/</g, "&lt;").replace(/>/g, "&gt;");
It's easier if you just save the time as UTC on the server, and then let the JS code convert it back to local time.
Hadn't thought of that, that saves some lines of code and calculations too. I've updated the plugin with this change, thanks for the advice smiley.gif
Quote from: brock on November 27, 2010, 01:56:56 am
What about creating a file per user? That way when the user loads the messages, your PHP script can clear the user's message file. The problem with this method is that new users, created after the previous messages were written, won't see the old messages.​

So you mean no main chat file but instead each user gets a "waiting" file with messages in his settings dir? This would require some more work on the PHP end since first it would have to find out which users are on the ruTorrent setup (probably by listing the subdirs of rutorrent/share/users/ since I don't think there is a getUsers() function that returns all users, but I could be wrong) and then write the chat line to each of these users their "waiting" files. Not sure if that's much nicer than the current way it's done other than you take out the requirement for main chat file.

Quote
Also, at the begin I don't set proper permission to log file so chat doesn't work but I don't have the error message I see in lang file.​

I checked and indeed there is no output when sending a message and the file is unwritable, this is because I didn't have a onComplete function. I thought it wasn't needed since it's only adding a line to a file and usually nothing needs to be returned, but of course when there is an error it does need to get this response. I have updated the plugin with this fix.

Quote
This is the french translation for your very good plugin (remember to set utf-8) :​

Thanks for the translation smiley.gif The value for theUILang.clearChatTemp is too long though, it doesn't fit on the button properly and the last couple characters are being cut off.


Quote
I have some idea of improvement :
- be able to connect different server to the same chat not only user on the same server with the possible to choose if i want send to all people or only on my server
- be able to PM a user in particulary​

To be able to access the plugin (and with that send/pull messages to/from it) you need to be logged in to ruTorrent. So if you want to be able to chat with users on another ruTorrent setup you would need to be logged in there too and if you arn't the messages won't arrive. You could get a notification of this in the log but if you overlook this you are just sending messages to users on the current ruTorrent setup.
The ability to PM other users would be nice indeed however you have the problem mentioned previously: I don't think there is a function that lists all users on a ruTorrent setup, though as also mentioned previously you could probably get this by reading the contents of rutorrent/share/users/. I might look into this however don't expect anything soon since I think it requires some more work with an overview window, multiple chat windows etc.
It might not be that hard to implement a "whisper" functionality. That way you could select (with checkboxes or something) to which user(s) you want to send the message and it will just show up in the same chat window but with something like [whisper] appended. This would require a change to what was mentioned previously (in response to brock) about users having a "waiting" file rather than using a single file to send all chat to.

Quote
EDIT : I forgot one thing, you need to update your css to have a correct color of font with oblivion theme.
Maybe ask to Brock, he have the same behavour with his IRC plugin.​

I was running 3.1 myself so I just updated to 3.2 and grabbed the theme plugin to see what was wrong. I've updated the plugin with the needed changes, thanks for letting me know smiley.gif


Quote
Why aren't you using sourceforge or google code?​


Quote
I also agree with brock. you should look into a googlecode page.​


Quote
Like they said, host your project to googlecode, it's better.​


Well ok ... tongue.gif here you go: http://code.google.com/p/rutorrent-chat/
If you want the wiki markup of my project home page to put it in the wiki of ruTorrent let me know I'll send the person who wants to update it a PM with it.
 

jith45

Member
May 25, 2018
960
0
16
Quote
Thanks for the translation The value for theUILang.clearChatTemp is too long though, it doesn't fit on the button properly and the last couple characters are being cut off.​


Sorry I didn't check before send to you. I hope it's better :
Code:
theUILang.clearChatPrompt = "Purge de la fenêtre : temporaire (restauration après un rafraichissement), permanente, ou annuler cette opération?";
theUILang.clearChatTemp = "Temporaire";
theUILang.clearChatPerm = "Permanente";
Quote
To be able to access the plugin (and with that send/pull messages to/from it) you need to be logged in to ruTorrent. So if you want to be able to chat with users on another ruTorrent setup you would need to be logged in there too and if you arn't the messages won't arrive. You could get a notification of this in the log but if you overlook this you are just sending messages to users on the current ruTorrent setup.
The ability to PM other users would be nice indeed however you have the problem mentioned previously: I don't think there is a function that lists all users on a ruTorrent setup, though as also mentioned previously you could probably get this by reading the contents of rutorrent/share/users/. I might look into this however don't expect anything soon since I think it requires some more work with an overview window, multiple chat windows etc.
It might not be that hard to implement a "whisper" functionality. That way you could select (with checkboxes or something) to which user(s) you want to send the message and it will just show up in the same chat window but with something like [whisper] appended. This would require a change to what was mentioned previously (in response to brock) about users having a "waiting" file rather than using a single file to send all chat to.​


Maybe have a log file per server, users and one overall :

| Server A (log.a) - user1 (log.1);user2 (log.2);user3 (log.3);
Server A (log.all) -| Server B (log.b) - user4 (log.4);user5 (log.5);use6 (log.6);
| Server C (log.c) - user7 (log.7);user8 (log.cool.gif;user9 (log.9);

And one thing : date is show like this 28/10 (today) why not 28/11/10 or 28/11?
 

dsouvik215

Member
May 25, 2018
896
0
16
Did some major updates (currently only applied to the SVN version) to the plugin. Did some rewriting so each user gets a /chat/ dir in their settings dir with all available chats (main and PM). I fixed the bug where it showed the day of last month instead of this month, I didn't notice that getDate() returns 0-11 and not 1-12. I also added a page to the options where each user can customize their settings (enable PMs, update interval, date format, smileys).

Chat w/ userlist (I'm logged in as another user - your own username won't show up in the list, only others):


If there is a new chat the list item will change background to a darker grey and text color to blue. If the user has PMs enable the text color is red and you are unable to send messages. If the chat is closed and there is a new message it will automatically pop up (unless you have this setting disabled) and show the chat where there is a new message. If there are new messages in multiple chats it will open the first in the list.

Chat settings:


Would be nice if someone/some people could try it out and let me know if there's anything wrong :)

Thanks in advance!

P.S. I havn't done anything for support for multiple server because as I mentioned before you can't access the plugin if you're not logged in to the server. To be able to do this you would need to run a script outside the rutorrent directory which handles the requests (and with that anyone knowing the location of the script could add messages).
 

das329717

Member
May 25, 2018
928
0
16
Wooo Good work ! Work fine for me. Only one thing : you should filter hiden folder like .svn because it show up on user list.

New FR lang file :
Code:
theUILang.mnu_chat = "Discussion...";
theUILang.chat = "Discussion";
theUILang.chatWith = "Disc. avec";
theUILang.chatDisabled = "désactiver";
theUILang.chatEverybody = "Tous";
theUILang.chatError = "Erreur";
theUILang.chatListPromptText = "Vous ne pouvez pas en sélectionner plusieurs.";
theUILang.chatMessages = "Messages";
theUILang.chatAdd = "Envoyer un message";
theUILang.chatSend = "Envoyer";
theUILang.chatSmileys = "smileys";
theUILang.chatClear = "purger";
theUILang.chatClearPrompt = "Purger la fenêtre de discussion";
theUILang.chatClearPromptText = "Purge de la fenêtre : temporaire (restauration après un rafraichissement), permanente, ou annuler cette opération ?";
theUILang.chatTemporarily = "Temporaire";
theUILang.chatPermanently = "Permanente";
theUILang.chatSettings = "Configuration de la discussion";
theUILang.chatPopup = "Popup aux nouveaux messages";
theUILang.chatPMs = "Activer les PMs";
theUILang.chatActive = "MAJ quand ouvert :";
theUILang.chatInactive = "MAJ quand fermer :";
theUILang.chatFormat = "Format Date/Heure :";
theUILang.chatFormatHelp = "D = jours, M = mois, Y = année, h = heure, m = minute, s = seconde";
theUILang.chatShowSmileys = "Montrer les smileys";
theUILang.chatSmileySet = "Groupe de smiley :";
theUILang.chatSmileyRound = "rond";
theUILang.chatSmileySquare = "carré";
theUILang.chatRefresh = "Requiert un rafraichissement de la page";
theUILang.chatDirCreate = "Impossible de créer le répertoire de discussion";
theUILang.chatUnreadable = "Impossible de lire à partir de ";
theUILang.chatUnwritable = "Impossible d'écrire dans ";
theUILang.chatWriteError = "Erreur durant l'écriture dans ";
theUILang.chatDeleteFail = "Impossible de supprimer ";
theUILang.chatHandleOpen = "Impossible de créer le 'handle' pour ";
theUILang.chatHandleClose = "Impossible de fermer le 'handle' de ";
theUILang.chatAcquireLock = "Impossible de verrouiller ";
theUILang.chatReleaseLock = "Impossible de déverrouiller ";
theUILang.chatInvalidReq = "Requête de discussion reçue invalide";
theUILang.chatForUser = " pour l'utilisateur ";
theUILang.chatIIntervalError = "Valeur pour MAJ quand fermer invalide.";
theUILang.chatAIntervalError = "Valeur pour MAJ quand ouvert invalide.";
theUILang.chatSmileySetError = "Valeur du groupe de smiley invalide.";
theUILang.chatFormatError = "Format Date/Heure invalide.<br />(Les caractères autorisés sont D M Y h m s / . - : et espace)";
theUILang.chatPMError = "Impossible de changer la configuration de messagerie privée.";
theUILang.chatSettingsSave = "Impossible de sauvegarder la configuration de la discussion.";

thePlugins.get("chat").langLoaded();
Maybe, if you can, change the way you display window title on PM because Chat with in french is to long :
Code:
theUILang.chat = "Chat";
theUILang.chatWith = "Users";
theUILang.chatWithTitle = " with "And title : theUILang.chat+theUILang.chatWithTitle+[user]

In this case, in FR :
Code:
theUILang.chat = "Discussion";
theUILang.chatWith = "Utilisateurs";
theUILang.chatWithTitle = " avec "

Tks again for work it's great!
 

jith45

Member
May 25, 2018
960
0
16
Quote
Wooo Good work ! Work fine for me. Only one thing : you should filter hiden folder like .svn because it show up on user list.​

I changed the skipped from ".", ".." and your own name to your own name and anything that starts with "." (so all hidden files, and this obviously includes "." and ".." as well)

Quote
Maybe, if you can, change the way you display window title on PM because Chat with in french is to long​

I added a chatList language variable which displays "Chats". I think it's "Discussions" in french though of course correct me if I'm wrong :)

I also noticed a couple other hardcoded english language parts and changed those so I think it's a pretty complete v2.0 now, though of course if anyone finds any bugs let me know.

Thanks for testing :)
 

somus1735

Member
May 25, 2018
833
0
16
does this plugin have dependencies in php? I recently decided to try it and it doesn't work for me. I run solaris so it may be a php dependency.
 

dsouvik215

Member
May 25, 2018
896
0
16
I got it working...I'm nto sure why but it was failing to load originally.

I saw some error messages regaurding "PEAR" but upon reloading everything it seems to be working.
 

somus1735

Member
May 25, 2018
833
0
16
That's weird, it uses only normal PHP functions, as far as I know the only thing that might cause a problem is json_encode() if someone uses < PHP 5.2.
 

dsouvik215

Member
May 25, 2018
896
0
16
the solaris box has PHP 5.2.12 (mod_php) with apache 2.2

All my other boxes run php 5.3.3 (php-fpm) with nginx.

I will probably eventually build nginx and php-fpm for the solaris box but i haven't gotten around to it
 

das329717

Member
May 25, 2018
928
0
16
Great plugin!

Just a request: Ability to clear a person's PM. Ie right click on their username on the left box, and have the option "clear" to delete all logs of convo with that person.
 

somus1735

Member
May 25, 2018
833
0
16
Great plugin!

Just a request: Ability to clear a person's PM. Ie right click on their username on the left box, and have the option "clear" to delete all logs of convo with that person.
You can just use the clear above the message window for that. Click on the user to open their chat, above the message area behind the text "Messages" there is a "clear" option. That should clear the current chat.
 

das329717

Member
May 25, 2018
928
0
16
How can I let the CHAT settings NOT appear in the settings menu ??
It's the same way for any plugins : with plugins.ini in conf dir :
[chat]
enabled = yes
canChangeToolbar = yes
canChangeMenu = yes
canChangeOptions = no
canChangeTabs = yes
canChangeColumns = yes
canChangeStatusBar = yes