plugins/tell.lua

Thu, 20 May 2010 17:36:47 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 20 May 2010 17:36:47 +0100
changeset 21
be3b031b986d
parent 20
4f4d98345952
child 29
11154ba6cbf6
permissions
-rw-r--r--

plugins.tell: Remove excess quote (thanks Florob)

8
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
1 local st = require "util.stanza";
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
2 local tellings = {};
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
3
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
4 function riddim.plugins.tell(bot)
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
5 bot:hook("commands/tell", function (command)
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
6 if command.room then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
7 local s, e = command.param:find(" ");
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
8 local nick = command.param:sub(0, s - 1);
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
9 local msg = command.param:sub(s + 1);
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
10 local found = false;
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
11
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
12 for tmp,_ in pairs(command.room.occupants) do
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
13 if tmp == nick then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
14 found = true;
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
15 break;
8
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
16 end
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
17 end
8
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
18
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
19 if not found then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
20 if(tellings[nick] == nil) then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
21 tellings[nick] = {};
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
22 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
23 tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg};
20
4f4d98345952 Merge with Chris
Matthew Wild <mwild1@gmail.com>
parents: 16 13
diff changeset
24 return "Ok!";
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
25 else
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
26 if nick == command.sender.nick then
21
be3b031b986d plugins.tell: Remove excess quote (thanks Florob)
Matthew Wild <mwild1@gmail.com>
parents: 20
diff changeset
27 return "Tell yourself.";
10
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
28 else
20
4f4d98345952 Merge with Chris
Matthew Wild <mwild1@gmail.com>
parents: 16 13
diff changeset
29 return "" .. nick .. " is currently online!";
8
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
30 end
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
31 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
32 else
20
4f4d98345952 Merge with Chris
Matthew Wild <mwild1@gmail.com>
parents: 16 13
diff changeset
33 return "This command is only available in groupchats.";
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
34 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
35 end);
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
36
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
37 bot:hook("groupchat/joined", function (room)
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
38 room:hook("occupant-joined", function (occupant)
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
39 if(tellings[occupant.nick] ~= nil) then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
40 for _,msg in ipairs(tellings[occupant.nick]) do
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
41 room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me, to tell you, \"" .. msg.msg .. "\".");
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
42 end
20
4f4d98345952 Merge with Chris
Matthew Wild <mwild1@gmail.com>
parents: 16 13
diff changeset
43 tellings[occupant.nick] = nil;
8
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
44 end
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
45 end);
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 10
diff changeset
46 end);
8
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
47 end
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
48

mercurial