Smart Auto Replier

The main idea of the plugin is to provide possibility of auto replying, i.e. when you receive a message, plugin replies using message or/and a set of rules, specified by you.

Despite the fact that there is a word “Smart” in it’s name, SAR is designed to be simple and efficient and it can be used equally for very simple tasks as well as you can build very complex auto reply systems on top of it.

Blog.

SAR has now it’s own blog at the following address: http://www.shcherbyna.com/?cat=50

Support.

Feel free to ask any questions at official forum of Smart Auto Replier.

Enabling the plugin.

To enable plugin click on upper menu in Miranda and choose “Enable Smart Auto Replier” menu item.

Options.

Reply delay : is the delay (in seconds) after which the autoreply will be generated to user if user sends message again. Lets suppose that user sends message to plugin at 00:00 00 and Reply delay is 5 seconds. SAR will generate auto reply to user. User sends message again at 00.00 02, plugin woud not reply – reply will be generated only after 5 seconds – when user will send message again..i.e. – 00.00 07 and later.

– Disabling when miranda is on : disables plugin after restart of Miranda

– Action script : Lua script which is executed when a message is arrived

– Enable when status becomes : SAR will enable itself when specifyed status is set

– Disable when status becomes : SAR will disable itself when specified status is set

– Save autoreplies to History : plugin will save it’s autoreplies into history

– Ask to set autoreply message when mode changes : when mode changes to some state a dialog box appears providing possibility to edit auto reply script

– Add rule : adds a contact specific rule (note: you can also add rule by right clicking on user in contact list)

– Edit rule : edits contact specific rule

– Delete rule : deletes contact specific rule

– Rule : a rule that is applied to specific contact only

Default Options.

– Reply delay : 2 seconds
– Disabling when miranda is on : true

Action script :

function this.SAR(this, hUser, szMessage, szUser, szProtocol)
    this:SendMessage(hUser, "Here is my autoreply!")
end

Settings.

Plugin uses two files to store it’s settings:

– sar.rs – rules and common auto replier message

– sar.cs – reply delay, disabling when miranda is on, disable/enable when status becomes, etc. Settings files are stored in user profile folder, a typical path is: C:\Documents and Settings\volodymyr\Documents\Sar\

Lua.

Plugin may execute Lua scripts thus basically allowing any kind of customizations you may need. When message comes, plugin is executing a Lua function called SAR. A default SAR function looks like this:

Basics:

function this.SAR(this, hUser, szMessage, szUser, szProtocol)
    this:SendMessage(hUser, "Here is my autoreply!")
end

Lua is a powerful language, so you can write different conditions which will be executed when a message from user will come. For example:

Simple conditions:

function this.SAR(this, hUser, szMessage, szUser, szProtocol)
    index = string.find(szMessage, "hello")
    if index == nil
    then
        this:SendMessage(hUser, "you did not wrote me hello")
    else 
        this:SendMessage(hUser, "you wrote me hello")
    end
    
    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

Status conditions:

SAR is able to get or set the current status of Miranda, thus allowing to set different conditions related to status. For example:

function this.SAR(this, hUser, szMessage, szUser, szProtocol)
    if this:GetMyStatus() == "Online"
    then
        this:SendMessage(hUser, "My status now is Online")
        this:SendMessage(hUser, "But I am going to set it to DND")
        this:SetMyStatus("DND")
    end
end

The functions this:GetMyStatus and this:SetMyStatus return/accept the following statuses: Online, Offline, Away, DND, NA, Occupied, FreeChat, Invisible, OnThePhone and OutToLunch

Waiting:

You can wait in your script by calling the function this:Wait(…). It accepts one parameter: number of seconds to wait. For example:

function this.SAR(this, hUser, szMessage, szUser, szProtocol)
    this:SendMessage(hUser, "Hello! I am going to wait for 3 seconds and write again!")
    this:Wait(3)
    this:SendMessage(hUser, "Here I am! Now I am going to pick-up random number between 1 and 15 seconds. I choose: ")
    nRandom = math.random(15)
    this:SendMessage(hUser, nRandom)
    this:SendMessage(hUser, "So I will wait these random seconds!")
    this:Wait(nRandom)
    this:SendMessage(hUser, "Here I am back again!")
end

Finding another users by name:

You can “find” another users in your contact list by using the function this:FinderUser(szUserName, szProtocol). The main idea is that you can find another user and send him some message if you need. For example:

function this.SAR(this, hUser, szMessage, szUser, szProtocol)
    this:SendMessage(hUser, "I just got message from one user, le's resend it to another user!")
    this:Wait(3)
    hAnotherUser = this:FindUser("Sad", szProtocol)
    this:SendMessage(hAnotherUser, szMessage)
end

Storing variables by name<->value pair:

You can can store some custom variables by using functions SetVariable(szVarName, szVarValue) and GetVariable(szVarName). An application of these functions may be useful if you need to implement a state machine, and thus, you need to store some values based on some conditions. Here is an example which illustrates how you can store the last message sent by user and resend it to him:

function this.SAR(this, hUser, szMessage, szUser, szProtocol)
    if this:GetVariable("LastMessage") == nil
    then
        this:SetVariable("LastMessage", szMessage)
    else
        this:SendMessage(hUser, this:GetVariable("LastMessage"))
    end
end

P.S. Source code of SAR is licensed under GPL v3 license and can be downloaded here.

Support Smart Auto Replier development by donating money:





2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Identify yourself * Time limit is exhausted. Please reload CAPTCHA.