I hate throwing away good things. Lately I was doing backup of my hard drive and I noticed a bunch of code I wrote in 2004 known as Smart Auto Replier plugin for Miranda. To my surprise it was quite big amount of code and it was pity to let it just fade away.
Given the fact that many things have changed in the last 8 years, and the code from 2004 looks just awful for me, I decided to boost it with some interesting idea and base it on top of ugly existing code :). I said to myself, that when doing auto replying, people would most likely need some level of flexibility, so that they will be able to make different conditions based on different input data. The best way to implement this is to implement a programming language inside SAR. However, I have just a 30 minutes of free time per normal day, so re-implementing a wheel is not the best way for me.
This is how I decided to hook-in Lua programming language into SAR. Lua is fast and well-known and can provide a huge level of customization to SAR. User will be able to set different conditions as well as write/read to files, and with time I will develop more functionality regarding conditions part. So, starting from now, SAR will have basically one script function which will get’s executed when you write a message to a client equipped with SAR:
function this.SAR(this, hUser, szMessage, szUser, szProtocol) this:SendMessage(hUser, "Here is my autoreply!") end
As you can see, the function this.SAR accepts a few parameters: this, hUser, szMessage, szUser, szProtocol. These parameters are actually indicating the input to function, so you can set different conditions which will let you to auto reply in a smart way. For example, let’s assume that you want to auto reply only to a user named “Sad”. In this way, your SAR function should look like this:
function this.SAR(this, hUser, szMessage, szUser, szProtocol) if szUser == "Sad" then this:SendMessage(hUser, "you are user Sad") else this:SendMessage(hUser, "you are not user Sad you are: ") this:SendMessage(hUser, szUser) end end
Now, assume you want to reply only if user is writing you from ICQ protocol. This is easy with Lua: you can combine code as a blocks:
function this.SAR(this, hUser, szMessage, szUser, szProtocol) if szUser == "Sad" then this:SendMessage(hUser, "you are user Sad") else this:SendMessage(hUser, "you are not user Sad you are: ") this:SendMessage(hUser, szUser) end index = string.find(szProtocol, "ICQ") if index == nil then this:SendMessage(hUser, "you are not writing from ICQ protocol") else this:SendMessage(hUser, "you are writing via ICQ protocol") end end
The best way to master SAR is to check the documentation for Lua: http://www.lua.org/docs.html. I agree that it may be not very user friendly to start from reading the docs for Lua, but on the other hand, I am trying to cover basic things which already may work out for newbies and provide them a good start.
Starting from now, SAR will have it’s own official forum where questions should be asked: http://shcherbyna.com/forum/viewforum.php?f=8. Do now hesitate to ask anything, I will try to be responsive. (well, still remember about 30 minutes per day … :))
Despite that, SAR will have it’s own web-page which will list all configuration options and well-known scripts: http://www.shcherbyna.com/?page_id=1747