def_occupant.lua

changeset 0
cc66ad6b0d75
equal deleted inserted replaced
-1:000000000000 0:cc66ad6b0d75
1
2 occupant =
3 {
4 _properties = {},
5 _default = function (self, e)
6 PSay(e.room, e.nick, " ", "<not-implemented/>");
7 end,
8 sit = function (self, e)
9 self:_action("sits down");
10 end,
11 reload = function (self, e)
12 local success, message = pcall(dofile, "bot.lua");
13 if not success then self:_tell(string.format("Error reloading: %s", message)); end
14 end,
15 refresh = function (self, e)
16 classes = nil;
17 dofile("bot.lua");
18 end,
19 who = function (self, e)
20 local p = {};
21 for nick, t in pairs(self.room.people) do
22 table.insert(p, nick.." ("..(t.jid or "Unknown JID")..")\n");
23 end
24 self:_tell("People in "..self.room._properties.name..":\n"..table.concat(p, ","));
25 end,
26 allwho = function (self, e)
27 local p = {};
28 for jid, t in pairs(people) do
29 table.insert(p, t.nick.." ("..jid..") in "..t.room._properties.name.."\n");
30 end
31 PSay(e.room, e.nick, " ", "People in MOO:\n"..table.concat(p, ","));
32 end,
33 _say = function (self, text, who)
34 BroadcastMessage(self.room.people, self.nick , text, who);
35 end,
36 _action = function (self, text, who)
37 return self:_say("/me "..text, who);
38 end,
39 _tell = function (self, text)
40 SendMessage(self.jid, self.occjid, text or "", "groupchat");
41 end,
42 i = function (self, e)
43 local contents = {};
44 local contents2 = {};
45 contents = self._contents["in"]:getallobjects();
46 for o, exists in pairs(contents) do
47 table.insert(contents2, o._properties.longname or o._properties.name or "Something");
48 end
49 self:_tell("You are carrying: "..table.concat(contents2,", "));
50 end,
51 jump = function (self, e) self:_action("jumps"); end
52 };
53
54
55 function occupant:_processCommand(line)
56 person = self;
57
58 if line:match("^%..*$") then BroadcastMessage(person.room.people, person.nick, line:match("^%.%s?(.*)$")); return nil; end
59 if line:match("^,.*$") then person:_action(line:match("^,%s?(.*)$")); return nil; end
60 action, object = commands:_parse(self, line); -- line:match("^(%a+)%s(%a+)$");
61 if commands:_handle(self, action, object) == false then person:_tell(string.format("Sorry, I don't know how you can '%s'",line)); end
62 end
63
64 occupant._findobject = classes.default._findobject;
65 occupant._get = classes.default._get;
66 occupant._unlink = classes.default._unlink;
67
68 function occupant:_sendto(roomname)
69 MoveToRoom(self, roomname);
70 end

mercurial