Sat, 08 Jan 2011 11:58:39 +0100
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
53
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 | function riddim.plugins.msgforward(bot) |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 | local compare_jid = require "util.jid".compare; |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 | local forwards = bot.config.forwards or {}; |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 | bot:hook("message", function(event) |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 | local message = event.stanza; |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 | local from = message.attr.from; |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 | local body = message:get_child("body"); |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 | body = body and body:get_text(); |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 | if not body then return end |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 | for jid, room in pairs(forwards) do |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 | if compare_jid(from, jid) and bot.rooms[room] then |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 | bot.rooms[room]:send_message(body); |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 | return true; |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 | end |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 | end |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 | end); |
6e9f9fd3f64b
plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 | end |