ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/IRC/smart_ison.cpp
Revision: 1262
Committed: 2010-03-20T20:07:58-07:00 (15 years, 3 months ago) by douglas
File size: 1366 byte(s)
Log Message:
Trout and the not yet useful beginnings of Smart ISON for ZNC.

File Contents

# Content
1 // Smart ISON
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #include <main.h>
8 #include <Modules.h>
9 #include <Chan.h>
10 #include <User.h>
11
12 #include <ext/hash_set>
13
14 #include "foreach.hpp"
15
16 #pragma GCC diagnostic ignored "-Wshadow"
17
18 namespace __gnu_cxx
19 {
20
21 template <>
22 struct hash<CString>
23 {
24 size_t operator()(const CString &x) const { return __stl_hash_string(x.c_str()); }
25 };
26
27 }
28
29 namespace ext { using namespace __gnu_cxx; }
30
31 class CSmartISON : public CModule
32 {
33 CString online_;
34
35 public:
36 MODCONSTRUCTOR(CSmartISON) {}
37 virtual ~CSmartISON() {}
38
39 virtual EModRet OnRaw(CString &line)
40 {
41 DEBUG("smart_ison: OnRaw() " << line.Token(1));
42
43 return CONTINUE;
44 }
45
46 virtual EModRet OnUserRaw(CString &line)
47 {
48 if (line.Token(0).Equals("ISON"))
49 {
50 ext::hash_set<CString> known;
51
52 _foreach (std::vector<CChan *>, channel, GetUser()->GetChans())
53 {
54 typedef std::map<CString, CNick *> NickMap;
55
56 _foreach (NickMap, nick, (*channel)->GetNicks())
57 known.insert(nick->first);
58 }
59
60 VCString nicks;
61
62 line.Token(1, true).TrimLeft_n(":").Split(" ", nicks, false);
63
64 CString online, unknown("ISON");
65
66 _foreach (VCString, nick, nicks)
67 ((known.find(*nick) != known.end()) ? online : unknown) += " " + *nick;
68
69 online_ = online.TrimLeft_n(" ");
70
71 if (unknown != "ISON")
72 line = unknown;
73 }
74
75 return CONTINUE;
76 }
77 };
78
79 MODULEDEFS(CSmartISON, "Smart ISON");

Properties

Name Value
svn:keywords Id