Author Topic: Regex Reply  (Read 12603 times)

0 Members and 1 Guest are viewing this topic.

Offline Kingsombra

  • Newbie
  • *
  • Posts: 5
Regex Reply
« on: 23 09 2015, 03:39:17 »
The one feature that is keeping me on Pidgin is the ability to auto-respond to certain rare words posted to a room/channel using a regular expression.

Yes I know this is not a direct feature of Pidgin but I did it through a perl plugin.

I am hating this because more and more, it is looking like Pidgin is becoming abandoned.  :(

Since MSP(mbot) is pretty much gone for MirandaNG I don't have that option here either.

I would really love to either have this as a feature/plugin or have at least some way of scripting.

Just wanted to post this out as a suggestion.
 

Offline Robyer

Re: Regex Reply
« Reply #1 on: 23 09 2015, 18:59:46 »
There is new MirLua scripting plugin. Maybe you can achieve it by that.
I was developing mainly Facebook, Omegle, Steam, Dummy and MobileState plugins. Now I'm retired. Goodbye, everyone. ~ You can still find me on Facebook.
 
The following users thanked this post: watcher

Offline Kingsombra

  • Newbie
  • *
  • Posts: 5
Re: Regex Reply
« Reply #2 on: 23 09 2015, 20:17:04 »
Oh great thanks.

Looks like I am going to be learning a new scripting language. I didn't even know that one existed.

Thanks for pointing that out.

I have been wanting to learn a new language recently. (I'm an old perl head.) I have been thinking about learning python as well.

EDIT: Although I might need someone to point me to an official list of events/functions etc, for miranda, that is unless they are the same as what is listed in MSP.
« Last Edit: 23 09 2015, 20:25:14 by Kingsombra »
 

Offline xaos

  • Newbie
  • *
  • Posts: 24
Re: Regex Reply
« Reply #3 on: 24 09 2015, 07:58:18 »
I don't read Russian but here's the MirLua thread.

I myself have been playing with the ListeningTo script posted by watcher.

Based upon the development updates on the main site, this recent update:
15405 unsane MirLua?: added OnMsgWindowEvent? to m_message 19.9.2015, 23:17
looks like it may end up being helpful toward what you're looking to do. (someone else is going to have to elaborate though)

(Robyer clarified below)

(mayhap we'll need to start an english MirLua thread eventually)
« Last Edit: 24 09 2015, 09:37:04 by xaos »
 

Offline Robyer

Re: Regex Reply
« Reply #4 on: 24 09 2015, 09:02:47 »
15405 unsane MirLua?: added OnMsgWindowEvent? to m_message 19.9.2015, 23:17
This is related to opening/closing/... communication windows only, not messages directly.
I was developing mainly Facebook, Omegle, Steam, Dummy and MobileState plugins. Now I'm retired. Goodbye, everyone. ~ You can still find me on Facebook.
 

Offline AnrDaemon

Re: Regex Reply
« Reply #5 on: 24 09 2015, 11:33:21 »
Lua is very simple to learn, but hard to master.
It has so many things that hide under the hood and not apparent from a first glance.

P.S.
Regarding MirLua wiki page, I would suggest adding a literal word "scripting" somewhere there, so it can be found through search.
 

Offline unsane

Re: Regex Reply
« Reply #6 on: 24 09 2015, 20:07:55 »
Kingsombra,
This example will work in next MirLua nightly build
Code: [Select]
local proto = require('m_protocols')
local message = require('m_message')

proto.OnReceiveMessage(function(w, l)
  -- check words
  message.Send(l.hContact, l.Message)
end)

p.s. You can use lua pattern instead regex.
« Last Edit: 24 09 2015, 20:13:46 by unsane »
Si no estas con nosotros, estas contra nosotros.
 
The following users thanked this post: Kingsombra

Offline AnrDaemon

Re: Regex Reply
« Reply #7 on: 25 09 2015, 09:04:37 »
Not "proto:OnReceiveMessage()" ?
 

Offline unsane

Re: Regex Reply
« Reply #8 on: 25 09 2015, 10:35:13 »
Operator ":" transparently send the left side as the first parameter of the function.
E.g. "s:len()"  is equal to "string.len(s)".
So, not "proto:OnReceiveMessage()".
Si no estas con nosotros, estas contra nosotros.
 

Offline AnrDaemon

Re: Regex Reply
« Reply #9 on: 25 09 2015, 10:41:07 »
Yes, I know that. I was asking a different question.
 

Offline Kingsombra

  • Newbie
  • *
  • Posts: 5
Re: Regex Reply
« Reply #10 on: 25 09 2015, 17:39:57 »
Kingsombra,
This example will work in next MirLua nightly build
Code: [Select]
local proto = require('m_protocols')
local message = require('m_message')

proto.OnReceiveMessage(function(w, l)
  -- check words
  message.Send(l.hContact, l.Message)
end)

p.s. You can use lua pattern instead regex.

Oh man thanks for that unsane. I have been doing some reading on lua and I can do the searches I want with lua's string.find/string.match

However I do have some minor questions. Forinstance in your example is "w" a table of the words in the incoming message? Or does the "Message" member of "l" also return the entire incoming message? Or both? I just want to know what to search on. Also, (this probably goes without saying) "message.Send" probably should be inside a conditional based on the search results, right?
 

Offline unsane

Re: Regex Reply
« Reply #11 on: 25 09 2015, 19:28:00 »
w - useless parameter.
l - table that contains:
  hContact - handle of the contact, who send a message
  Message - text of incoming message.
message - lua module that allow to send message and etc.
you can rename it if it confused you (e.g. "local m_msg = require('m_message')" and "m_msg .Send(l.hContact, l.Message)")

Answering the last question, you're right. for example:
Code: [Select]
-- check words
if l.Message:find('Hello') than
  message.Send(l.hContact, 'Hi')
end
Si no estas con nosotros, estas contra nosotros.
 

Offline Kingsombra

  • Newbie
  • *
  • Posts: 5
Re: Regex Reply
« Reply #12 on: 25 09 2015, 19:49:30 »
w - useless parameter.
l - table that contains:
  hContact - handle of the contact, who send a message
  Message - text of incoming message.
message - lua module that allow to send message and etc.
you can rename it if it confused you (e.g. "local m_msg = require('m_message')" and "m_msg .Send(l.hContact, l.Message)")

Answering the last question, you're right. for example:
Code: [Select]
-- check words
if l.Message:find('Hello') than
  message.Send(l.hContact, 'Hi')
end

Great. Thanks again unsane. I'm going to give this a try when I get a little time to do so.

And ya it would be great to have a mirlua document or entry in the wiki or something. But no hurries. I know you guys are probably really busy. If you do come out with one, there are some other scripts that I have in mind that I might just type up.  :)
 

Offline unsane

Re: Regex Reply
« Reply #13 on: 25 09 2015, 20:06:56 »
Kingsombra, there is a bit of docs.
Si no estas con nosotros, estas contra nosotros.
 

Offline Robyer

Re: Regex Reply
« Reply #14 on: 25 09 2015, 20:38:58 »
Btw I see that you originally wanted to have this for chatrooms, but this unsane's solution works only for direct conversations.
Support for chats must use different APIs to handle it.
I was developing mainly Facebook, Omegle, Steam, Dummy and MobileState plugins. Now I'm retired. Goodbye, everyone. ~ You can still find me on Facebook.