plugins/tell.lua

Thu, 20 May 2010 13:57:56 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 20 May 2010 13:57:56 +0100
changeset 13
ff9790b827b7
parent 12
d7ce8ba2c462
child 20
4f4d98345952
permissions
-rw-r--r--

Remove tellings after someone comes online (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)
10
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
6 if command.room then
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
7 local s, e = command.param:find(" ");
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
8 local nick = command.param:sub(0, s - 1);
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
9 local msg = command.param:sub(s + 1);
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
10 local found = false;
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
11
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
12 for tmp,_ in pairs(command.room.occupants) do
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
13 if tmp == nick then
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
14 found = true;
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
15 break;
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
16 end
8
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
17 end
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
18
10
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
19 if not found then
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
20 if(tellings[nick] == nil) then
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
21 tellings[nick] = {};
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
22 end
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
23 tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg};
12
d7ce8ba2c462 plugins.tell: Change responses (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
24 return "Ok!";
10
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
25 else
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
26 if nick == command.sender.nick then
12
d7ce8ba2c462 plugins.tell: Change responses (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents: 10
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
12
d7ce8ba2c462 plugins.tell: Change responses (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
29 return "" .. nick .. " is currently online!";
10
77753bce939a tell.lua: prevent executing the command in a non-groupchat environment.
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
30 end
8
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
31 end
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
32 else
12
d7ce8ba2c462 plugins.tell: Change responses (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
33 return "This command is only available in groupchats.";
8
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
34 end
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
35 end);
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
36
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
37 bot:hook("groupchat/joined", function (room)
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
38 room:hook("occupant-joined", function (occupant)
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
39 if(tellings[occupant.nick] ~= nil) then
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
40 for _,msg in ipairs(tellings[occupant.nick]) do
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
41 room:send_message(occupant.nick .. ": Welcome back! " .. msg.from .. " told me, to tell you, \"" .. msg.msg .. "\".");
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
42 end
13
ff9790b827b7 Remove tellings after someone comes online (thanks Florob)
Matthew Wild <mwild1@gmail.com>
parents: 12
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);
9663866ca475 add basic command tell support
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
46 end);
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