def_occupant.lua

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