ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Collector.cpp
(Generate patch)

Comparing trunk/Collector.cpp (file contents):
Revision 21 by douglas, 2004-07-16T23:37:41-07:00 vs.
Revision 69 by douglas, 2004-12-15T16:14:13-08:00

# Line 16 | Line 16 | extern "C"
16   #include <unistd.h>
17   }
18  
19 < Collector::Collector(const ext::String& login, ext::String& password, const
20 <        std::set<Buddy>& buddies, const Database& database, bool start) :
21 <        login(login), password(password), buddies(buddies), database(database),
19 > Collector::Collector(const ext::String& login, ext::String& password, const     std::set<Buddy>& buddies,
20 >        const Database& database, bool start) : login(login), password(password), buddies(buddies), database(database),
21          start(start), prompted(false)
22   {
23          if (start)
24          {
25                  if (password.IsEmpty()) prompt();
26  
27 <                collector.Spawn(etl::Bind<0>(&Collector::collect, this));
27 > //              collector.Spawn(etl::Bind<0>(&Collector::collect, this));
28          }
29   }
30  
31   int Collector::collect()
32   {
33 <        cerr << "Collector::collect()\n";
33 >        api::Cerr << bright << green << "Started collector daemon at " << Stamp()
34 >                << ".\n" << reset;
35  
36          net::Oscar::Session session;
37          net::Oscar::AuthTool auth(session);
# Line 46 | Line 46 | int Collector::collect()
46  
47          this->buddy = &buddy;
48          this->icbm = &icbm;
49 +        this->info = &info;
50  
51 < //      buddy.OnOnline += etl::Bind<0>(&Collector::status, this);
52 <        icbm.OnReceive += etl::Bind<0>(&Collector::reply, this);
51 >        buddy.OnOnline += etl::Bind<0>(&Collector::status, this);
52 >        icbm.OnReceive += etl::Bind<0>(&Collector::receive, this);
53  
54          net::Oscar::StringSet buddies;
55  
56 <        for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy !=
57 <                this->buddies.end(); ++buddy) buddies.Insert(*buddy);
56 >        for (std::set<Buddy>::const_iterator buddy(this->buddies.begin());
57 >                buddy != this->buddies.end(); ++buddy) buddies.Insert(*buddy);
58  
59          buddy.Insert(buddies);
59        icbm.RequestParams();
60  
61          net::Oscar::Capabilities capabilities;
62  
63          capabilities.Insert(net::Oscar::ChatCapability);
64 <        info.SetProfile("<font size=3>I am <a href=\"http://computers.douglasthrift.net/zoe.xml\">Zoe</a>.</font> :-*", "<font size=3>Mommy told me not to talk to strangers.</font> O:-)", capabilities);
64 >        info.SetProfile("<font face=\"Tahoma\" size=2>I am <a href=\""
65 >                + Zoe::generator(Zoe::url) + "\">Zoe</a>.</font> :-*", "<font face=\""
66 >                "Tahoma\" size=2>Mommy told me not to talk to strangers.</font> O:-)",
67 >                capabilities);
68  
69 <        // figure out whether or not we logged in
69 >        // XXX figure out whether or not we logged in
70  
71 <        while (true) sleep(60);
71 >        while (true) sleep(Hour(1));
72   }
73  
74   void Collector::prompt()
# Line 81 | Line 84 | void Collector::prompt()
84                  password[index - 1] = '\0';
85   }
86  
87 < void Collector::reply(const Buddy& buddy, const ext::String& message)
87 > void Collector::status(const net::Oscar::UserInfo& user)
88   {
89 +        Buddy buddy(*buddies.find(user));
90 +        AwayMessage message(buddy, *info);
91 +
92 +        if (!ext::String(message).IsEmpty()) // XXX
93 +        {
94 +                if (Zoe::debug) api::Cerr << "buddy = " << buddy << "\nmessage = "
95 +                        << message << "\n";
96 +
97 +                ext::Handle<dbi::Driver> driver(dbi::GetDriver(database.driver));
98 +                ext::Handle<dbi::Connection> db(driver->Connect(database.host,
99 +                        database.user, database.password, database.db));
100 +                ext::Handle<dbi::ResultSet> previous(db->Execute(ios::String()
101 +                        << "SELECT message FROM messages WHERE stamp=(SELECT MAX(stamp) "
102 +                        << "FROM messages WHERE id='" << buddy.getId() << "') AND id='"
103 +                        << buddy.getId() << "'"));
104 +
105 +                if (previous->MoveNext())
106 +                {
107 +                        if (ext::String(message) == previous->GetString("message")) return;
108 +                }
109 +
110 +                db->Execute(ios::String() << "INSERT INTO messages (stamp, message, id)"
111 +                        << " VALUES ('" << message.getStamp() << "', '"
112 +                        << db->Escape(message) << "', '" << buddy.getId() << "')");
113 +
114 +                api::Cerr << bright << red << "Collected away message from " << blue
115 +                        << buddy << red << " at " << Stamp() << ".\n" << reset;
116 +        }
117 +
118 +        if (user.screenname != buddy.getDisplay(database))
119 +        {
120 +                buddy.setDisplay(user.screenname, database);
121 +
122 +                sleep(1);
123 +
124 +                icbm->Simple(buddy, "<font face=\"Tahoma\" size=2>So sexy!</font> :-*");
125 +        }
126 + }
127 +
128 + void Collector::receive(const ext::String& buddy, const ext::String& message)
129 + {
130 +        if (Zoe::debug) api::Cerr << "buddy = " << Buddy(buddy) << "\nmessage = "
131 +                << message << "\n";
132 +
133          if (buddies.find(buddy) != buddies.end())
134          {
135 <                //
135 >                Buddy buddy_(*buddies.find(buddy));
136 >                
137 >                sleep(1);
138 >
139 >                icbm->Simple(buddy, "<font face=\"Tahoma\" size=2>Hello! I am Zoe. I am"
140 >                        " supposed to be collecting your <a href=\"" + buddy_.getLink()
141 >                        + "\">Away Messages</a> (<a href=\"" + buddy_.getRssLink() + "\">"
142 >                        "RSS 2.0</a>) (<a href=\"" + buddy_.getAtomLink() + "\">Atom</a>)."
143 >                        "</font> :-*");
144          }
145          else
146          {
147                  sleep(1);
148  
149 <                icbm->Simple(buddy, "<font size=3>Mommy told me not to talk to strangers. O:-)");
149 >                icbm->Simple(buddy, "<font face=\"Tahoma\" size=2>Mommy told me not to "
150 >                        "talk to strangers.</font> O:-)");
151          }
152   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines