def_occupant.lua

Sat, 27 Mar 2010 17:43:08 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 27 Mar 2010 17:43:08 +0000
changeset 0
cc66ad6b0d75
permissions
-rw-r--r--

Initial commit (importing from old SVN repo which got lost)

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

mercurial