Fri, 02 Oct 2020 17:02:37 +0200
plugins/groupchat.lua: Add support for muc passwords
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
1 | local st = require "util.stanza"; |
41
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
2 | local memory_ns = "http://code.matthewwild.co.uk/riddim/plugins/tell" |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
3 | local serializer = false; |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
4 | local tellings = {}; |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
5 | |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
6 | function riddim.plugins.tell(bot) |
41
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
7 | if bot.config.remember_tells then |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
8 | bot.stream:add_plugin("private"); |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
9 | serializer = require "json"; --TODO other serializer? |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
10 | end |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
11 | |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
12 | local sameroom = bot.config.tell_in_same_room; |
41
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
13 | |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
14 | local function remember() |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
15 | if serializer then |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
16 | bot.stream:private_set("tellings", memory_ns, serializer.encode(tellings), function () end); |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
17 | end |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
18 | end |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
19 | |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
20 | bot:hook("commands/tell", function (command) |
29
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
21 | if not command.room then |
20 | 22 | return "This command is only available in groupchats."; |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
23 | end |
29
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
24 | if not command.param then |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
25 | return "If you want me to tell someone something then do so"; |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
26 | end |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
27 | |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
28 | local s, e = command.param:find(" "); |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
29 | |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
30 | if not s then |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
31 | return "if you have nothing to say to "..command.param..", then leave me alone, please"; |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
32 | end |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
33 | |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
34 | local nick = command.param:sub(0, s - 1); |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
35 | local msg = command.param:sub(s + 1); |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
36 | |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
37 | if nick == command.sender.nick then |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
38 | return "Tell yourself."; |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
39 | end |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
40 | |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
41 | for tmp,_ in pairs(command.room.occupants) do |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
42 | if tmp == nick then |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
43 | return "" .. nick .. " is currently online!"; |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
44 | end |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
45 | end |
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
46 | |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
47 | local nick_id = sameroom and command.room.jid .. "/" .. nick or nick; |
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
48 | |
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
49 | if tellings[nick_id] == nil then |
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
50 | tellings[nick_id] = {}; |
29
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
51 | end |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
52 | tellings[nick_id][#tellings[nick_id] + 1] = {from=command.sender.nick, msg=msg}; |
41
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
53 | remember(); |
29
11154ba6cbf6
plugins.tell: More validation on inputs, to prevent crashes
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
21
diff
changeset
|
54 | return "Ok!"; |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
55 | end); |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
56 | |
30
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
57 | bot:hook("commands/untell", function (command) |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
58 | if not command.room then |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
59 | return "This command is only available in groupchats."; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
60 | end |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
61 | if not command.param then |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
62 | return "If you changed your mind tell me for who"; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
63 | end |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
64 | |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
65 | local s, e = command.param:find(" "); |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
66 | local nick; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
67 | local id; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
68 | |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
69 | -- parameter parsing |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
70 | if not s then |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
71 | nick = command.param; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
72 | id = nil; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
73 | else |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
74 | nick = command.param:sub(0, s - 1); |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
75 | id = command.param:sub(s + 1); |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
76 | end |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
77 | |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
78 | -- no message for that user |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
79 | local nick_id = sameroom and command.room.jid .. "/" .. nick or nick; |
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
80 | if not tellings[nick_id] then |
30
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
81 | return "I have no messages for "..nick; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
82 | end |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
83 | |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
84 | -- no message id and message for that user |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
85 | if id == nil then |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
86 | local response = "I am supposed to relay the following message to "..nick.." :"; |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
87 | for index,msg in ipairs(tellings[nick_id]) do |
30
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
88 | response = response .. "\n#"..index.." : "..msg.msg; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
89 | end |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
90 | return response; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
91 | end |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
92 | |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
93 | -- check the message id is valid |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
94 | local number = #tellings[nick_id]; |
30
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
95 | id = tonumber(id) |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
96 | if id == nil or id < 1 or id > number then |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
97 | return "I need a valid message #id .. sigh !!\n"..nick.." has "..number.." message(s)"; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
98 | end |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
99 | |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
100 | if tellings[nick_id][id].from ~= command.sender.nick then |
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
101 | return "you never said that, "..tellings[nick_id][id].from.." did !"; |
30
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
102 | end |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
103 | |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
104 | -- remove the message |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
105 | if number > 1 then |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
106 | tellings[nick_id][id] = tellings[nick_id][number]; |
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
107 | tellings[nick_id][number] = nil; |
41
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
108 | remember(); |
30
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
109 | return "what was I supposed to tell "..nick.." again ?"; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
110 | else |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
111 | tellings[nick_id] = nil; |
41
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
112 | remember(); |
30
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
113 | return "who is "..nick.." anyway ?"; |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
114 | end |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
115 | end); |
7bfe0d739b1c
plugins.tell: Add !untell <nick> and !untell <nick> <id> to remove tells
Thomas Mangin <thomas.mangin@exa-networks.co.uk>
parents:
29
diff
changeset
|
116 | |
41
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
117 | if serializer then |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
118 | bot:hook("started", function() -- restore memory |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
119 | bot.stream:private_get("tellings", memory_ns, function (what) |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
120 | if what then |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
121 | local data = tostring(what:get_text()); |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
122 | if data and #data > 0 then |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
123 | tellings = serializer.decode(data); |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
124 | end |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
125 | end |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
126 | end); |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
127 | end); |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
128 | end |
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
129 | |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
130 | bot:hook("groupchat/joined", function (room) |
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
131 | room:hook("occupant-joined", function (occupant) |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
132 | local nick_id = sameroom and room.jid .. "/" .. occupant.nick or occupant.nick; |
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
133 | if(tellings[nick_id] ~= nil) then |
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
134 | for _,msg in ipairs(tellings[nick_id]) do |
103
c0235605d6d5
plugins.tell: Adjust format of delivered tells (fixes issues with some linkifiers)
Kim Alvefur <zash@zash.se>
parents:
41
diff
changeset
|
135 | room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me to tell you:\n" .. msg.msg); |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
136 | end |
40
313c0662100d
plugins.tell: Optinally deliver !tells only in the same room.
Kim Alvefur <zash@zash.se>
parents:
30
diff
changeset
|
137 | tellings[nick_id] = nil; |
41
b00d05814d0d
plugins.tell: Optinally store !tells in iq:private for persistence (requires json)
Kim Alvefur <zash@zash.se>
parents:
40
diff
changeset
|
138 | remember(); |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
139 | end |
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
140 | end); |
16
ae69cea97598
Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents:
10
diff
changeset
|
141 | end); |
8
9663866ca475
add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
142 | end |