AJAX Chat sync 2.0.1 [LUA 5.1.x] [API 2]
 

AJAX Chat sync 2.0.1 [LUA 5.1.x] [API 2]

Started by deseven, 11 November, 2010, 10:36:56

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

deseven

Info:
Simple solution for synchronization between PtokaX and AJAX Chat.

Requirements:
- AJAXChat (any version, as long as the ajax_chat_messages table have the same layout)
- luasql.mysql

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 - PtokaX <> AJAXChat sync

Version 1 (old and unsupported):
receivechat.lua - AJAX Chat to PtokaX
sendchat.lua - PtokaX to AJAX Chat
banchat.lua - bans system

DEN 007


deseven

Your reason... What?
I can't get what you mean.

deseven

small update for sendchat.lua:
- fixed bad chars detection :)

cspetee

#4
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?

deseven

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


cspetee

#6
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.

deseven

I made some experiments and it seems that your codepage is latin2.
Try to use latin2 with and without the //TRANSLIT suffix.

cspetee

I tried but i got empty messages if the original chat message contains any accented character.

deseven

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.  ???

cspetee

#10
I found it. :)
Delete
SET NAMES utf8;
from recievechat.lua line 67 and also sendchat.lua line 43.
thx

deseven

That's very strange.
Probably your AJAX Chat database uses codepage different from utf8?

cspetee

#12
No, database and tables are UTF-8 (my vps use utf8 codepage also)

deseven

Well, i'm glad that it works, but i can't figure out how  ::)

cspetee

#14
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 = {	   "",     "",    "",     "",    "",     "",       "",        "",        "",         "",		 "",				"",			   "",				"",				  "",				"",			   "",				  "",				"",				"",				"",				"",				"",				 "",			 "",			  "",				"",				 "",}

deseven

oh, yeah, i forgot about url and color
by the way, you're doing it wrong

just add:
"%[color.-]","%[/color]","%[url.-]","[/url]"



cspetee

#17
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

deseven

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.

cspetee

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

deseven

#20
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 :)

SaymoN

why not windows version?  :)
or you can make it work?

Psycho_Chihuahua

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.
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

deseven

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. 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.

SaymoN

ok.

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


SMF spam blocked by CleanTalk