This repository has been archived by the owner on May 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvotes.h
533 lines (432 loc) · 14.6 KB
/
votes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/**
* COPYRIGHT 2014 (C) Jason Volk
* COPYRIGHT 2014 (C) Svetlana Tkachenko
*
* DISTRIBUTED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) (see: LICENSE)
*/
///////////////////////////////////////////////////////////////////////////
//
// Common vote attributes
//
// The issue is a nickname
class NickIssue : virtual Vote
{
protected:
User user; // Copy of the user at start of vote
void event_nick(User &user, const std::string &old) override;
void starting() override;
template<class... Args> NickIssue(Args&&... args);
};
// The issue is an account name
class AcctIssue : virtual Vote
{
protected:
User user; // Copy of the user at start of vote
void event_nick(User &user, const std::string &old) override;
template<class... Args> AcctIssue(Args&&... args);
};
// The effect is a reversible mode Delta
class ModeEffect : virtual Vote
{
void expired() override;
protected:
template<class... Args> ModeEffect(Args&&... args):
Vote(std::forward<Args>(args)...) {}
};
// There is no 'for' time with a future expiration
class ForNow : virtual Vote
{
protected:
template<class... Args> ForNow(Args&&... args);
};
///////////////////////////////////////////////////////////////////////////
//
// Vote types
//
namespace vote
{
extern std::set<std::string> names;
class Config : public virtual Vote,
public virtual ForNow
{
std::string key;
std::string oper;
std::string val;
void passed() override;
void starting() override;
public:
template<class... Args> Config(Args&&... args);
};
class Mode : public virtual Vote,
public virtual ModeEffect
{
void passed() override;
void starting() override;
public:
template<class... Args> Mode(Args&&... args):
Vote("mode",std::forward<Args>(args)...),
ModeEffect("mode",std::forward<Args>(args)...) {}
};
class Appeal : public virtual Vote,
public virtual ModeEffect,
public virtual ForNow
{
void passed() override;
void starting() override;
public:
template<class... Args> Appeal(Args&&... args):
Vote("appeal",std::forward<Args>(args)...),
ModeEffect("appeal",std::forward<Args>(args)...),
ForNow("appeal",std::forward<Args>(args)...) {}
};
class Trial : public virtual Vote,
public virtual ModeEffect
{
void starting() override;
public:
template<class... Args> Trial(Args&&... args):
Vote("trial",std::forward<Args>(args)...),
ModeEffect("trial",std::forward<Args>(args)...) {}
};
class Kick : public virtual Vote,
public virtual NickIssue,
public virtual ForNow
{
void passed() override;
public:
template<class... Args> Kick(Args&&... args):
Vote("kick",std::forward<Args>(args)...),
NickIssue("kick",std::forward<Args>(args)...),
ForNow("kick",std::forward<Args>(args)...) {}
};
class Invite : public virtual Vote,
public virtual ForNow
{
void passed() override;
public:
template<class... Args> Invite(Args&&... args):
Vote("invite",std::forward<Args>(args)...),
ForNow("invite",std::forward<Args>(args)...) {}
};
class Topic : public Vote
{
void passed() override;
void starting() override;
public:
template<class... Args> Topic(Args&&... args):
Vote("topic",std::forward<Args>(args)...) {}
};
class Opine : public Vote
{
void passed() override;
public:
template<class... Args> Opine(Args&&... args):
Vote("opine",std::forward<Args>(args)...) {}
};
class Quote : public Vote
{
User user;
void passed() override;
void starting() override;
public:
template<class... Args> Quote(Args&&... args);
};
class Ban : public virtual Vote,
public virtual NickIssue,
public virtual ModeEffect
{
void passed() override;
void starting() override;
void effective() override;
public:
template<class... Args> Ban(Args&&... args):
Vote("ban",std::forward<Args>(args)...),
NickIssue("ban",std::forward<Args>(args)...),
ModeEffect("ban",std::forward<Args>(args)...) {}
};
class UnBan : public virtual Vote,
public virtual ModeEffect,
public virtual ForNow
{
void effective() override;
void starting() override;
public:
template<class... Args> UnBan(Args&&... args):
Vote("unban",std::forward<Args>(args)...),
ModeEffect("unban",std::forward<Args>(args)...),
ForNow("unban",std::forward<Args>(args)...) {}
};
class Quiet : public virtual Vote,
public virtual NickIssue,
public virtual ModeEffect
{
void effective() override;
void starting() override;
public:
template<class... Args> Quiet(Args&&... args):
Vote("quiet",std::forward<Args>(args)...),
NickIssue("quiet",std::forward<Args>(args)...),
ModeEffect("quiet",std::forward<Args>(args)...) {}
};
class UnQuiet : public virtual Vote,
public virtual NickIssue,
public virtual ModeEffect,
public virtual ForNow
{
void effective() override;
public:
template<class... Args> UnQuiet(Args&&... args):
Vote("unquiet",std::forward<Args>(args)...),
NickIssue("unquiet",std::forward<Args>(args)...),
ModeEffect("unquiet",std::forward<Args>(args)...),
ForNow("unquiet",std::forward<Args>(args)...) {}
};
class Voice : public virtual Vote,
public virtual NickIssue,
public virtual ModeEffect
{
void effective() override;
void starting() override;
public:
template<class... Args> Voice(Args&&... args):
Vote("voice",std::forward<Args>(args)...),
NickIssue("voice",std::forward<Args>(args)...),
ModeEffect("voice",std::forward<Args>(args)...) {}
};
class DeVoice : public virtual Vote,
public virtual NickIssue,
public virtual ModeEffect,
public virtual ForNow
{
void effective() override;
void starting() override;
public:
template<class... Args> DeVoice(Args&&... args):
Vote("devoice",std::forward<Args>(args)...),
NickIssue("devoice",std::forward<Args>(args)...),
ModeEffect("devoice",std::forward<Args>(args)...),
ForNow("devoice",std::forward<Args>(args)...) {}
};
class Op : public virtual Vote,
public virtual NickIssue,
public virtual ModeEffect
{
void effective() override;
void starting() override;
public:
template<class... Args> Op(Args&&... args):
Vote("op",std::forward<Args>(args)...),
NickIssue("op",std::forward<Args>(args)...),
ModeEffect("op",std::forward<Args>(args)...) {}
};
class DeOp : public virtual Vote,
public virtual NickIssue,
public virtual ForNow
{
void effective() override;
void starting() override;
public:
template<class... Args> DeOp(Args&&... args):
Vote("deop",std::forward<Args>(args)...),
NickIssue("deop",std::forward<Args>(args)...),
ForNow("deop",std::forward<Args>(args)...) {}
};
class Exempt : public virtual Vote,
public virtual NickIssue,
public virtual ModeEffect
{
void effective() override;
void starting() override;
public:
template<class... Args> Exempt(Args&&... args):
Vote("exempt",std::forward<Args>(args)...),
NickIssue("exempt",std::forward<Args>(args)...),
ModeEffect("exempt",std::forward<Args>(args)...) {}
};
class UnExempt : public virtual Vote,
public virtual NickIssue,
public virtual ForNow
{
void effective() override;
void starting() override;
public:
template<class... Args> UnExempt(Args&&... args):
Vote("unexempt",std::forward<Args>(args)...),
NickIssue("unexempt",std::forward<Args>(args)...),
ForNow("unexempt",std::forward<Args>(args)...) {}
};
class Invex : public virtual Vote,
public virtual NickIssue,
public virtual ModeEffect
{
void effective() override;
void starting() override;
public:
template<class... Args> Invex(Args&&... args):
Vote("invex",std::forward<Args>(args)...),
NickIssue("invex",std::forward<Args>(args)...),
ModeEffect("invex",std::forward<Args>(args)...) {}
};
class UnInvex : public virtual Vote,
public virtual NickIssue,
public virtual ForNow
{
void effective() override;
void starting() override;
public:
template<class... Args> UnInvex(Args&&... args):
Vote("uninvex",std::forward<Args>(args)...),
NickIssue("uninvex",std::forward<Args>(args)...),
ForNow("uninvex",std::forward<Args>(args)...) {}
};
class Flags : public Vote
{
void passed() override;
void expired() override;
void starting() override;
public:
template<class... Args> Flags(Args&&... args):
Vote("flags",std::forward<Args>(args)...) {}
};
class Import : public virtual Vote,
public virtual ForNow
{
std::stringstream received;
std::string get_target_chan() const { return split(get_issue()).first; }
std::string get_target_bot() const { return split(get_issue()).second; }
void passed() override;
void starting() override;
void event_notice(User &u, const std::string &text) override;
public:
template<class... Args> Import(Args&&... args):
Vote("import",std::forward<Args>(args)...),
ForNow("import",std::forward<Args>(args)...) {}
};
class Civis : public virtual Vote,
public virtual AcctIssue
{
void passed() override;
void expired() override;
void starting() override;
public:
template<class... Args> Civis(Args&&... args):
Vote("civis",std::forward<Args>(args)...),
AcctIssue("civis",std::forward<Args>(args)...) {}
};
class Censure : public virtual Vote,
public virtual AcctIssue
{
void passed() override;
void expired() override;
void starting() override;
public:
template<class... Args> Censure(Args&&... args):
Vote("censure",std::forward<Args>(args)...),
AcctIssue("censure",std::forward<Args>(args)...) {}
};
class Staff : public virtual Vote,
public virtual AcctIssue
{
void passed() override;
void expired() override;
void starting() override;
public:
template<class... Args> Staff(Args&&... args):
Vote("staff",std::forward<Args>(args)...),
AcctIssue("staff",std::forward<Args>(args)...) {}
};
class DeStaff : public virtual Vote,
public virtual AcctIssue,
public virtual ForNow
{
void passed() override;
void starting() override;
public:
template<class... Args> DeStaff(Args&&... args):
Vote("destaff",std::forward<Args>(args)...),
AcctIssue("destaff",std::forward<Args>(args)...),
ForNow("destaff",std::forward<Args>(args)...) {}
};
}
template<class... Args>
vote::Config::Config(Args&&... args)
try:
Vote("config",std::forward<Args>(args)...),
ForNow("config",std::forward<Args>(args)...),
key(tokens(get_issue()).at(0)),
oper(tokens(get_issue()).at(1)),
val([this]
{
const auto toks(tokens(get_issue()));
return toks.size() >= 3? detok(toks.begin()+2,toks.end()) : std::string{};
}())
{
}
catch(const std::out_of_range &e)
{
throw Exception("Invalid syntax to assign a configuration variable.");
}
template<class... Args>
NickIssue::NickIssue(Args&&... args):
Vote(std::forward<Args>(args)...),
user([&]
{
auto &users(get_users());
const auto toks(tokens(get_issue()));
const auto &nick(toks.at(0));
return users.has(nick)? users.get(nick) : User(nick);
}())
{
}
template<class... Args>
AcctIssue::AcctIssue(Args&&... args):
Vote(std::forward<Args>(args)...),
user([&]
{
const auto toks(tokens(get_issue()));
if(toks.size() > 1)
throw Exception("This vote requires only an authenticated nickname as the issue.");
const auto &name(toks.at(0));
// If the vote has started we populate the account name only
if(get_began())
return User("","",name);
auto &users(get_users());
if(!users.has(name))
throw Exception("Unable to find this nickname to resolve into an account name");
auto &user(users.get(name));
if(!user.is_logged_in())
throw Exception("This nickname is not logged in, and I must resolve an account name");
const Adoc info(user.get("info"));
if(info.empty())
user.info();
set_issue(user.get_acct());
return user;
}())
{
}
template<class... Args>
ForNow::ForNow(Args&&... args):
Vote(std::forward<Args>(args)...)
{
const auto &cfg(get_cfg());
if(secs_cast(cfg["for"]) != 0)
{
auto cpy(cfg);
cpy.put("for",0);
set_cfg(cpy);
}
}
template<class... Args>
vote::Quote::Quote(Args&&... args):
Vote("quote",std::forward<Args>(args)...),
user([this]
{
const auto toks(tokens(get_issue()));
if(toks.size() < 2)
throw Exception("Usage: !vote quote <nickname> <message...> | note that nickname must actually be surrounded by classic IRC < and > brackets.");
auto &users(get_users());
const auto &nick(between(toks.at(0),"<",">"));
return users.has(nick)? users.get(nick) : User(nick);
}())
{
}