PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Finished Scripts => Topic started by: deseven on 11 November, 2010, 10:36:56

Title: AJAX Chat sync 2.0.1 [LUA 5.1.x] [API 2]
Post by: deseven on 11 November, 2010, 10:36:56
Info:
Simple solution for synchronization between PtokaX and AJAX Chat (https://blueimp.net/ajax/).

Requirements:
- AJAXChat (any version, as long as the ajax_chat_messages table have the same layout)
- luasql.mysql (http://www.keplerproject.org/luasql/index.html)

Installation:
First of all, edit settings inside the script, according to your needs. Then create file receivechat.id (the path to it described in the script) and write the last message id from AJAX Chat inside. If you're using new AJAX Chat then just write 1. If not - get the last message id by browsing the ajax_chat_messages table inside the AJAX Chat database.
Run the script from PtokaX. All should work, but don't forget to check /ptokax/logs/script.log for possible errors.

Notes:
- the script must be on top of any other scripts to work correctly, you can modify the order of scripts in the /cfg/scripts.xml file
- if you ban user from PtokaX - AJAX Chat will not perform ban-check until user's log-in. This is a default behavior in AJAX Chat and you probably can alter it easily by modding sources a little.

Known bugs:
- none

Version 2:
ajaxchatsync.lua (http://pastebin.com/Q1M3Dazk) - PtokaX <> AJAXChat sync

Version 1 (old and unsupported):
receivechat.lua (http://pastebin.com/VENmw7HE) - AJAX Chat to PtokaX
sendchat.lua (http://pastebin.com/NHVufqMr) - PtokaX to AJAX Chat
banchat.lua (http://pastebin.com/3CMsaQdU) - bans system
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: DEN 007 on 17 November, 2010, 10:14:41
My reason is not working ..
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 17 November, 2010, 13:53:13
Your reason... What?
I can't get what you mean.
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 20 November, 2010, 12:13:25
small update for sendchat.lua:
- fixed bad chars detection :)
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 24 November, 2010, 20:25:07
Hello, great script, but i have some Iconv problems:
- dc: ?rv?ztűrő t?k?rf?r?g?p
- chat: ?rv?zt?r? t?k?rf?r?g?p

The same backward:
- chat: ?rv?ztűrő t?k?rf?r?g?p
- dc: ??rv??zt??r?? t? 1/4 k??rf??r??g??p

And please ignore the commands eg. !startscript recievechat.lua

Can you help me?
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 26 November, 2010, 07:22:19
I'm not sure, but it seems that you can disable iconv.
Try to set UseIconv = false

If that doesn't work - edit the IconvFrom/IconvTo variable to fit your codepage. I don't know what codepage is default on your hub, so i can't say what do you need exactly. Use iconv -l to get the list of all possible codepages.

As for the second question - the latest update fixes that problem. Download new sendchat.lua or just edit line 24:
if string.sub(chat,1,1) == v then
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 26 November, 2010, 11:59:30
Command ignore is ok, but useiconv = false not :S

I tried another codepages but the result is not perfect

UseIconv = true
IconvFrom = "utf-8"
IconvTo = "cp1252//TRANSLIT"

ReplaceWhat = {"á","Ă?","Ă?","Ăł","Ă?","Ĺ?","Ăş","ĂĽ","Ĺ?","Ă?","Ă ","Ă?","Ă?","Ă?","Ăś","Ĺ?","%[b]","%[/b]","%[u]","%[/u]","%[i]","%[/i]",...}
ReplaceWith = { "?", "?", "?", "?", "?", "ő", "?", "?", "ű", "?", "?", "?", "?", "?", "?", "Ű",   "",     "",    "",     "",    "",     "",       "",        "",        "",         "" }

chat:?rv?ztűrő t?k?rf?r?g?p - ?RV?ZTŰRŐ T?K?RF?R?G?P
dc:   ?rv?ztűrő t?k?rf?r?g?p - Ă?RVĂ?ZTŰRĹ? T?K?RF?R?G?P

It seems dc can't display some characters. I still would be nice, but sending doesn't work accented characters. Maybe with repleca.
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 26 November, 2010, 12:50:02
I made some experiments and it seems that your codepage is latin2.
Try to use latin2 with and without the //TRANSLIT suffix.
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 26 November, 2010, 13:04:18
I tried but i got empty messages if the original chat message contains any accented character.
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 26 November, 2010, 13:12:34
Okay, can you upload a log file from your dc-client? Just enable main chat logging and get the output file with the original codepage.

I don't get what codepage is in use on your hub. According to wikipedia default codepage for hungarian language is latin2.  ???
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 26 November, 2010, 13:17:41
I found it. :)
Delete SET NAMES utf8; from recievechat.lua line 67 and also sendchat.lua line 43.
thx
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 26 November, 2010, 13:22:18
That's very strange.
Probably your AJAX Chat database uses codepage different from utf8?
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 26 November, 2010, 13:23:52
No, database and tables are UTF-8 (my vps use utf8 codepage also)
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 26 November, 2010, 13:29:55
Well, i'm glad that it works, but i can't figure out how  ::)
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 29 November, 2010, 21:11:38
Little change because of color codes
ReplaceWhat = { ...,"%[/color]","%[color=gray]","%[color=silver]","%[color=white]","%[color=yellow]","%[color=orange]","%[color=red]","%[color=fuchsia]","%[color=purple]","%[color=navy]","%[color=blue]","%[color=aqua]","%[color=teal]","%[color=green]","%[color=lime]","%[color=olive]","%[color=maroon]","%[color=black]",}
ReplaceWith = {   "",     "",    "",     "",    "",     "",       "",        "",        "",         "", "", "",   "", "",  "", "",   "",  "", "", "", "", "", "", "", "",  "", "", "",}
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 30 November, 2010, 14:50:40
oh, yeah, i forgot about url and color
by the way, you're doing it wrong

just add:
"%[color.-]","%[/color]","%[url.-]","[/url]"
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 30 November, 2010, 21:04:31
Thx
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 01 December, 2010, 20:33:55
fix: "[/url]" >> "%[/url]"
and please fix the new line character from chat (shift+enter) to dc: \n

very future request:
userlist of dc >> ajax_chat_online table of chat
ajax_chat_online table >> bot to dc
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 06 December, 2010, 11:31:35
I don't know yet how to translate new line codes to dc. Seems that \n or \r\n simply doesn't work the way it should.
I'll see what i can do when i'll have some free time.

Talking about user list synchronization - I don't think that this is a good idea.
If we will transport DC-users to AJAX Chat it'll be a pain in the ass :) For example - what about ajax chat private message feature? So we also need a private message transport and many other things besides of it...
The other way (chat > dc) is not too complex. I think i'll do something like that soon.
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 07 December, 2010, 20:29:34
Simply disable pm in ajax chat ( $config['allowPrivateMessages'] = false; ) if i would like to use userlist (dc > chat) or a bot send the private messages to user in dc. :D
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 30 December, 2010, 12:59:15
another update

sendchat.lua:
- added UseSetNames variable to settings

recievechat.lua:
- added UseSetNames variable to settings
- added replacement patterns for 'color' and 'url' bb-codes
- fixed new line characters

I also did some code management and added more informative version info.
Just to have an easy way to check whether your script updated or not :)

I started to write the userlist synchronization script but it's far from done.

Anyway, happy new year to everyone :)
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: SaymoN on 31 December, 2010, 11:06:49
why not windows version?  :)
or you can make it work?
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: Psycho_Chihuahua on 31 December, 2010, 14:21:22
Quote from: SaymoN on 31 December, 2010, 11:06:49
why not windows version?  :)
or you can make it work?

From what i see Ajax Chat is web based you should be able to use it on either Linux, MacOS or Linux as long as you have a Webserver running (for example Apache) so the OS you're running is irrelevant in that aspect. The scripts are for PtokaX so OS is irrelevant here as well as PtokaX uses the same scripts no matter which OS you are running.
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 31 December, 2010, 15:56:34
Quote from: Psycho_Chihuahua on 31 December, 2010, 14:21:22
so the OS you're running is irrelevant in that aspect
I'm using some system binaries, so it isn't possible to run my srcipts without a little modification...
Well, it'll actually run but it'll not work :)

Quote from: SaymoN on 31 December, 2010, 11:06:49
why not windows version?  :)
Because i have no servers running windows.
You can try to run it anyway. Just get a windows version of mysql client and iconv (http://gnuwin32.sourceforge.net/packages/libiconv.htm). Then make sure that paths to those binaries described in your system %PATH% variable. After that run script and check the error log for possible problems.
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: SaymoN on 06 January, 2011, 17:48:43
ok.

(19:51:35) ChatBot: Error: Connection status: 403

Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 07 January, 2011, 23:53:02
That's not about my scripts, check your AJAX Chat installation.
Basicaly the 403 error means that you don't have the access to some required files. Probably this is caused by the configuration of your web-server.
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 09 March, 2011, 20:40:42
1.
I tried the private message in webchat (I never want to use it)

webchat:
(20:43:27) (test): (whispers to (test2)) pm_test_message

dc:
[20:43:27] <(test1)> /privmsgto (test2) pm_test_message
[20:43:27] <(test1)> /privmsg pm_test_message

2.1
Webchat:
(22:04:34) (test1): | test

dc:
[22:04:34] <(test1)>
[22:04:34] ***  test

2.2
dc:
[22:03:49] <test2>  | test

webchat:
(22:03:49) test2: & #124;  test (without space after &)
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: deseven on 18 March, 2011, 19:38:12
fixed :)

sendchat.lua 1.0.2:
- fixed | and $ chars

receivechat.lua 1.0.4:
- fixed | char
- added workaround for AJAX Chat private messaging
Title: Re: AJAX Chat sync LUA 5.1.x [API 2]
Post by: cspetee on 19 March, 2011, 13:38:08
Perfect job. :)
Thx
Title: Re: AJAX Chat sync 2.0.1 [LUA 5.1.x] [API 2]
Post by: deseven on 18 May, 2011, 21:25:13
I'm glad to present the new version - 2.0.1 :)

- based on the luasql - no more system dependencies, text files and other mess
- one script for all

tested with PtokaX 0.4.1.2 (luasql-2.1.1) and 300+ users without any noticable problems

UPD: it seems that no one is interested in this, so i'll not bother anyone with updates anymore - links in the first post contain actual versions, always. PM me if you have problems.