-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounters.cpp
750 lines (646 loc) · 27 KB
/
counters.cpp
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
#include <vector>
#include <string>
#include <ctime>
#include <functional>
#include <znc/main.h>
#include <znc/Modules.h>
#include <znc/IRCNetwork.h>
#include <znc/Chan.h>
#include <znc/User.h>
#include "argparse.hpp"
//CONSTANTS DEFAULTS
const int DEFAULT_INITIAL = 0;
const int DEFAULT_STEP = 1;
const int DEFAULT_COOLDOWN = 0;
const int DEFAULT_DELAY = 0;
const std::string DEFAULT_MESSAGE = "{NAME} has value : {CURRENT_VALUE}";
class MyMap : public MCString {
private:
MyMap() {
}
~MyMap() {
}
protected:
public:
//CONSTRUCTORS AND DESCTRUTORS FOR SINGLETON
static MyMap& getInstance() {
static MyMap instance;
return instance;
}
MyMap(MyMap const&) = delete;
void operator=(MyMap const&) = delete;
};
class CCounter {
protected:
//DATA MEMBERS
//"constants" defined by constructor and can be changed by user with "set" command
CString m_sName;
int m_initial;
int m_step;
int m_cooldown; /**< Cooldown between 2 messages when value change. */
int m_delay; /**< Delay to send message when value change. */
CString m_sMessage; /**< The message to send when value change. */
//values that can change
int m_current_value;
int m_previous_value;
int m_minimum_value;
int m_maximum_value;
std::time_t m_last_change;
double m_time_chrono;
//other variable
std::time_t m_creation_datetime;
//MEMBER FUNCTIONS
/**
* Set the previous value at current value and set last_change to now.
* Should be called before changing current value.
*/
void preChangeValue() {
m_previous_value = m_current_value;
//to improve : it's possible to send multiple messages in same time !
time_t now = time(nullptr);
double diffTime = difftime(now, m_last_change);
m_time_chrono -= diffTime;
if (m_time_chrono < 0) {
m_time_chrono = m_cooldown;
}
//to avoid flood of messages when the difference between 'm_last_change' and 'now' is 0
if (diffTime == 0) {
m_time_chrono -= 1;
}
m_last_change = now;
}
/**
* Change minimum and maximum values depending of current value.
* Should be called after changing current valaue.
*/
void postChangeValue() {
if (m_current_value < m_minimum_value) {
m_minimum_value = m_current_value;
}
if (m_current_value > m_maximum_value) {
m_maximum_value = m_current_value;
}
}
/**
* Reset minimum, maximum, previous values to current value.
*/
void resetValues() {
m_maximum_value = m_minimum_value = m_previous_value = m_current_value;
}
public:
//CONSTRUCTORS & DESTRUCTOR
CCounter(const CString& sName, const int initial = DEFAULT_INITIAL, const int step = DEFAULT_STEP,
const int cooldown = DEFAULT_COOLDOWN, const int delay = DEFAULT_DELAY,
const CString& sMessage = DEFAULT_MESSAGE) : m_sName(sName), m_initial(initial),
m_step(step), m_cooldown(cooldown), m_delay(delay), m_sMessage(sMessage) {
m_previous_value = m_current_value = initial;
m_maximum_value = m_minimum_value = m_current_value;
m_last_change = m_creation_datetime = time(nullptr);
m_time_chrono = -1;
}
~CCounter() {
}
//GETTERS
CString getInfos(CUser* user) {
return CString("Name : " + m_sName + "\nCreated at : " + getCreationTime(user)
+ "\nInitial : " + CString(m_initial) + "\nStep : " + CString(m_step)
+ "\nCooldown : " + CString(m_cooldown) + "\nDelay : " + CString(m_delay)
+ "\nMessage : " + m_sMessage + "\nCurrent : " + CString(m_current_value)
+ "\nPrevious : " + CString(m_previous_value) + "\nMinimum : "
+ CString(m_minimum_value) + "\nMaximum : " + CString(m_maximum_value)
+ "\nLast change : " + getLastChangeTime(user));
}
CTable getInfosTable(CUser* user) {
CTable tableInfos = CTable();
tableInfos.AddColumn("Attribute");
tableInfos.AddColumn("Value");
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Name");
tableInfos.SetCell("Value",m_sName);
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Created at");
tableInfos.SetCell("Value",getCreationTime(user));
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Initial");
tableInfos.SetCell("Value",CString(m_initial));
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Step");
tableInfos.SetCell("Value",CString(m_step));
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Cooldown");
tableInfos.SetCell("Value",CString(m_cooldown));
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Delay");
tableInfos.SetCell("Value",CString(m_delay));
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Message");
tableInfos.SetCell("Value",m_sMessage);
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Current value");
tableInfos.SetCell("Value",CString(m_current_value));
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Previous value");
tableInfos.SetCell("Value",CString(m_previous_value));
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Minimum value");
tableInfos.SetCell("Value",CString(m_minimum_value));
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Maximum value");
tableInfos.SetCell("Value",CString(m_maximum_value));
tableInfos.AddRow();
tableInfos.SetCell("Attribute","Last change");
tableInfos.SetCell("Value",getLastChangeTime(user));
return tableInfos;
}
CString getName() {
return m_sName;
}
int getDelay() {
return m_delay;
}
CString getCreationTime(CUser* user) {
return CUtils::FormatTime(m_creation_datetime, "%Y/%m/%d %H:%M:%S", user->GetTimezone());
}
CString getLastChangeTime(CUser* user) {
return CUtils::FormatTime(m_last_change, "%Y/%m/%d %H:%M:%S", user->GetTimezone());
}
//to improve ?
bool hasActiveCooldown() {
return m_time_chrono < m_cooldown && m_cooldown != 0;
}
CString getCurrentValue() {
return CString(m_current_value);
}
int getPreviousValue() {
return m_previous_value;
}
int getMinimumValue() {
return m_previous_value;
}
int getMaximumValue() {
return m_maximum_value;
}
double getDiffTime() {
return m_time_chrono;
}
CString getNamedFormat() {
MyMap::getInstance().at("NAME") = m_sName;
MyMap::getInstance().at("INITIAL") = CString(m_initial);
MyMap::getInstance().at("STEP") = CString(m_step);
MyMap::getInstance().at("COOLDOWN") = CString(m_cooldown);
MyMap::getInstance().at("DELAY") = CString(m_delay);
MyMap::getInstance().at("PREVIOUS_VALUE") = CString(m_previous_value);
MyMap::getInstance().at("CURRENT_VALUE") = CString(m_current_value);
MyMap::getInstance().at("MINIMUM_VALUE") = CString(m_minimum_value);
MyMap::getInstance().at("MAXIMUM_VALUE") = CString(m_maximum_value);
return CString::NamedFormat(m_sMessage,MyMap::getInstance());
}
//SETTERS
void setName(const CString sName) {
m_sName = sName;
}
void setInitial(const int initial) {
m_initial = initial;
}
void setStep(const int step) {
m_step = step;
}
void setCooldown(const int cooldown) {
m_cooldown = cooldown;
}
void setDelay(const int delay) {
m_delay = delay;
}
void setMessage(const CString& sMessage) {
m_sMessage = sMessage;
}
/**
* Reset the counter at resetValue.
* @param resetValue the value that counter will take.
*/
void reset(const int resetValue) {
preChangeValue();
m_current_value = resetValue;
resetValues();
}
/**
* Reset the counter at the initial value.
*/
void resetDefault() {
reset(m_initial);
}
void increment(int step) {
preChangeValue();
m_current_value += step;
postChangeValue();
}
void incrementDefault() {
increment(m_step);
}
void decrement(const int step) {
preChangeValue();
m_current_value -= step;
postChangeValue();
}
void decrementDefault() {
decrement(m_step);
}
};
#ifdef HAVE_PTHREAD
class CCounterJob : public CModuleJob {
protected:
CCounter m_counter;
public:
CCounterJob(CModule* pModule, CCounter counter) : CModuleJob(pModule, "counters",
"Send message for counter on channel after a delay"), m_counter(counter) {
}
virtual ~CCounterJob() override {
// if (wasCancelled()) {
// GetModule()->PutModule("Counter job cancelled");
// }
// else {
// GetModule()->PutModule("Counter job destroyed");
// }
}
virtual void runThread() override {
int delay = m_counter.getDelay();
for (int i = 0; i < delay; i++) {
if (wasCancelled()) {
return;
}
sleep(1);
}
}
virtual void runMain() override {
CString formattedMessage = m_counter.getNamedFormat();
CIRCNetwork* network = GetModule()->GetNetwork();
std::vector<CChan*> channels = network->GetChans();
for (CChan* channel : channels) {
GetModule()->PutIRC("PRIVMSG " + channel->GetName() + " :" + formattedMessage);
}
}
};
#endif
class CCounterListener {
};
class CCountersMod : public CModule {
protected:
//DATA MEMBERS
std::map<CString,CCounter> m_counters;
/**
* map with keys as couple (nickname,listener_name) and value as counter_name
*/
std::map<std::pair<CString,CString>,CString> m_listeners;
ArgumentParser m_parserCreate;
//FUNCTIONS
/**
* Casts a CString to another type (specially int). If the cast fails,
* return the specified value.
* @param text string to cast
* @param value default value if fail
* @return value represented by text, or value in fail
*/
template<typename T>
T convertWithDefaultValue(const CString text, const T value) {
std::stringstream ss(text);
T result;
return ss >> result ? result : value;
}
/**
* Check if a string is empty.
* @param text
* @param defaultText
* @return if text is empty, returns defaultText, else returns text.
*/
CString checkStringValue(const CString text, CString defaultText) {
return text.empty() ? defaultText : text;
}
/**
* Create a counter.
* @param sName the name of the counter
* @param initial the initial value of counter
* @param step the step by default to increment of decrement
* @param cooldown the cooldown between 2 increment or decrement
* @param delay the delay to write message on channel
* @param sMessage the message to write on channel when current value change
*/
void createCounter(const CString& sName, const int initial,
const int step, const int cooldown, const int delay, const CString& sMessage) {
if (!m_counters.count(sName)) {
CCounter addCounter = CCounter(sName, initial, step, cooldown, delay, sMessage);
auto created = m_counters.insert(std::pair<CString, CCounter>(sName, addCounter));
if (created.second) {
PutModule("Counter '" + addCounter.getName() + "' created.");
}
}
else {
PutModule("Counter '" + sName + "' already exists.");
}
}
void createListener(const CString sName, const CString sNickname, const CString sListenerName) {
auto created = m_listeners.insert(std::make_pair(std::make_pair(sNickname,sListenerName),sName));
if (created.second) {
PutModule("Listener '" + sListenerName + "' for user '" + sNickname +
"' and counter '" + sName + "' created.");
}
}
void deleteListener(const CString sNickname, const CString sListenerName) {
std::map<std::pair<CString,CString>,CString>::size_type removed = m_listeners.erase(std::make_pair(sNickname,sListenerName));
if (removed) {
PutModule("Listener '" + sListenerName + "' for user '" + sNickname + "' deleted.");
}
else {
PutModule("Listener '" + sListenerName + "' for user '" + sNickname + "' not found.");
}
}
//MODULE'S HOOKS
virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) override {
CString sListenerName = sMessage.Token(0);
CString sNickname = Nick.GetNick();
try {
CString sCounterName = m_listeners.at(std::make_pair(sNickname, sListenerName));
if (!sCounterName.empty()) {
try {
CCounter counter = m_counters.at(sCounterName);
CString sCommand = sMessage.Token(1);
CString sArgs = sMessage.Token(2, true);
OnModCommand(sCommand + " " + counter.getName() + " " + sArgs);
}
catch (const std::out_of_range oor) {
PutModule("Counter '" + sCounterName + "' not found.");
}
}
}
catch (const std::out_of_range oor) {
}
return CONTINUE;
}
//MODULE'S COMMANDS
//COUNTERS COMMANDS
/**
* Module command to create counter, parse sCommand.
* @param sCommand command written by user to parse
*/
void createCounterCommand(const CString& sCommand) {
VCString vsArgs;
sCommand.Split(" ", vsArgs, false, "\"", "\"", true, true);
std::vector<std::string> args = std::vector<std::string>();
for (const CString& arg : vsArgs) {
if (!arg.empty()) {
args.push_back((std::string)arg);
}
}
try {
m_parserCreate.parse(args);
}
catch (std::invalid_argument ex) {
PutModule("Error invalid argument : " + CString(ex.what()));
return;
}
// catch (std::bad_cast) {
// PutModule("error bad cast");
// }
//retrieve all arguments as strings because i get std::bad_cast with other typenames like int
CString sInitial = CString(m_parserCreate.retrieve<std::string>("initial"));
CString sStepValue = CString(m_parserCreate.retrieve<std::string>("step"));
CString sCooldownValue = CString(m_parserCreate.retrieve<std::string>("cooldown"));
CString sDelayValue = CString(m_parserCreate.retrieve<std::string>("delay"));
CString sMessage = CString(m_parserCreate.retrieve<std::string>("message"));
CString sName = CString(m_parserCreate.retrieve<std::string>("name"));
createCounter(checkStringValue(sName,"counter"),convertWithDefaultValue(sInitial,DEFAULT_INITIAL),
convertWithDefaultValue(sStepValue,DEFAULT_STEP),convertWithDefaultValue(sCooldownValue,DEFAULT_COOLDOWN),
convertWithDefaultValue(sDelayValue,DEFAULT_DELAY),checkStringValue(sMessage,DEFAULT_MESSAGE));
m_parserCreate.clearVariables();
// MCString msRet;
// CString::size_type tokensNb4 = sCommand.OptionSplit(msRet);
// PutModule("Commande séparée en : " + CString(tokensNb4) + " chaines avec OptionSplit.");
// MCString::iterator itMap;
// for (itMap = msRet.begin(); itMap != msRet.end(); itMap++) {
// PutModule("clé : " + itMap->first + " , valeur : " + itMap->second);
// }
}
void deleteCounterCommand(const CString& sCommand) {
CString sName = sCommand.Token(1);
std::map<CString,CCounter>::size_type erased = m_counters.erase(sName);
if (erased) {
PutModule("Counter '" + sName + "' deleted.");
}
else {
PutModule("Counter " + sName + " not found.");
}
}
/**
* Execute a simple command (with the name of counter, and an optional second
* value) for a counter.\n
* If second value is specified, execute first function as argument with value.\n
* If second value is not specified, execute function that doesn't require value
* (use default value from the counter for this command).
* @param sCommand command written by user
* @param execute function to execute with value
* @param executeWithDefault function to execute without value
*/
void executeSimpleCommand(const CString& sCommand, std::function<void(CCounter&,int)> execute,
std::function<void(CCounter&)> executeWithDefault) {
CString sName = sCommand.Token(1);
CString sStep = sCommand.Token(2);
if (!sName.empty()) {
try {
CCounter& counter = m_counters.at(sName);
if (sStep.empty()) {
executeWithDefault(counter);
}
else {
execute(counter, sStep.ToInt());
}
if (!counter.hasActiveCooldown()) {
#ifdef HAVE_PTHREAD
AddJob(new CCounterJob(this, counter));
#else
CString formattedMessage = counter.getNamedFormat();
PutModule(formattedMessage);
CIRCNetwork *network = GetNetwork();
std::vector<CChan*> channels = network->GetChans();
for (CChan* channel : channels) {
PutIRC("PRIVMSG " + channel->GetName() + " :" + formattedMessage);
}
#endif
}
}
catch (const std::out_of_range oor) {
PutModule("Counter " + sName + " not found.");
}
}
}
void resetCounterCommand(const CString& sCommand) {
executeSimpleCommand(sCommand,&CCounter::reset,&CCounter::resetDefault);
}
void incrementCounterCommand(const CString& sCommand) {
executeSimpleCommand(sCommand,&CCounter::increment,&CCounter::incrementDefault);
}
void decrementCounterCommand(const CString& sCommand) {
executeSimpleCommand(sCommand,&CCounter::decrement,&CCounter::decrementDefault);
}
void printCounterCommand(const CString& sCommand) {
CString sName = sCommand.Token(1);
try {
CCounter& counter = m_counters.at(sName);
CString formattedMessage = counter.getNamedFormat();
CIRCNetwork* network = GetNetwork();
std::vector<CChan*> channels = network->GetChans();
for (CChan* channel : channels) {
PutIRC("PRIVMSG " + channel->GetName() + " :" + formattedMessage);
}
}
catch (const std::out_of_range oor) {
PutModule("Counter '" + sName + "' not found.");
}
}
void infoCounterCommand(const CString& sCommand) {
CString sName = sCommand.Token(1);
try {
CCounter& counter = m_counters.at(sName);
PutModule(counter.getInfosTable(GetUser()));
}
catch (const std::out_of_range oor) {
PutModule("Counter " + sName + " not found.");
}
}
//TODO : to improve or change because it's possible to change counter's name
//but this doesn't change used name in the map m_counters
void setPropertyCounterCommand(const CString& sCommand) {
VCString vsArgs;
sCommand.Split(" ", vsArgs, false, "\"", "\"", true, true);
try {
CString sName = vsArgs.at(1);
CString sProperty = vsArgs.at(2);
CString sValue = vsArgs.at(3);
try {
CCounter& counter = m_counters.at(sName);
if (sProperty.Equals("NAME"))
counter.setName(sValue);
else if (sProperty.Equals("INITIAL"))
counter.setInitial(convertWithDefaultValue(sValue, 0));
else if (sProperty.Equals("STEP"))
counter.setStep(convertWithDefaultValue(sValue, 1));
else if (sProperty.Equals("COOLDOWN"))
counter.setCooldown(convertWithDefaultValue(sValue, 0));
else if (sProperty.Equals("DELAY"))
counter.setDelay(convertWithDefaultValue(sValue, 0));
else if (sProperty.Equals("MESSAGE"))
counter.setMessage(sValue);
else
PutModule("Incorrect property ! Possibles properties are : name, "
"initial, step, cooldown, delay and message.");
PutModule("Property '" + sProperty + "' of counter '" + sName +
"' changed to '" + sValue + "' value.");
}
catch (const std::out_of_range oor) {
PutModule("Counter '" + sName + "' not found.");
}
}
catch (const std::out_of_range oor) {
PutModule("Too few arguments.");
}
}
void listCountersCommand(const CString& sCommand) {
CString sCounters = "Your counters : ";
for (std::map<CString,CCounter>::const_iterator it = m_counters.cbegin(); it != m_counters.cend(); ++it) {
sCounters.append(it->first);
if (it != std::prev(m_counters.cend())) {
sCounters.append(", ");
}
}
PutModule(sCounters);
}
//LISTENERS COMMANDS
void createListenerCommand(const CString& sCommand) {
CString sName = sCommand.Token(1);
if (m_counters.count(sName)) {
CString sNickname = sCommand.Token(2);
CString sListenerName = sCommand.Token(3);
if (sNickname.empty()) {
sNickname = GetUser()->GetNick();
}
if (sListenerName.empty()) {
sListenerName = "!" + sName;
}
createListener(sName, sNickname, sListenerName);
}
else {
PutModule("Counter '" + sName + "' not found.");
}
}
void deleteListenerCommand(const CString& sCommand) {
CString sNickname = sCommand.Token(1);
CString sListenerName = sCommand.Token(2);
deleteListener(sNickname, sListenerName);
}
void listListenersCommand(const CString& sCommand) {
CString sListeners = "Your listeners : ";
for (std::map<std::pair<CString,CString>,CString>::const_iterator it = m_listeners.cbegin(); it != m_listeners.cend(); ++it) {
sListeners.append(it->first.second + " for user " + it->first.first + " and counter " + it->second);
if (it != std::prev(m_listeners.cend())) {
sListeners.append(", ");
}
}
PutModule(sListeners);
}
public:
MODCONSTRUCTOR(CCountersMod) {
//create ArgumentParser to parse arguments for the command that create a counter
m_parserCreate = ArgumentParser();
m_parserCreate.useExceptions(true);
m_parserCreate.ignoreFirstArgument(true);
m_parserCreate.addArgument("-i", "--initial", 1, true);
m_parserCreate.addArgument("-s", "--step", 1, true);
m_parserCreate.addArgument("-c", "--cooldown", 1, true);
m_parserCreate.addArgument("-d", "--delay", 1, true);
m_parserCreate.addArgument("-m", "--message", 1, true);
m_parserCreate.addFinalArgument("name", 1, false);
MyMap::getInstance().insert(std::make_pair<CString, CString>("NAME", ""));
MyMap::getInstance().insert(std::make_pair<CString, CString>("INITIAL", ""));
MyMap::getInstance().insert(std::make_pair<CString, CString>("STEP", ""));
MyMap::getInstance().insert(std::make_pair<CString, CString>("COOLDOWN", ""));
MyMap::getInstance().insert(std::make_pair<CString, CString>("DELAY", ""));
MyMap::getInstance().insert(std::make_pair<CString, CString>("PREVIOUS_VALUE", ""));
MyMap::getInstance().insert(std::make_pair<CString, CString>("CURRENT_VALUE", ""));
MyMap::getInstance().insert(std::make_pair<CString, CString>("MINIMUM_VALUE", ""));
MyMap::getInstance().insert(std::make_pair<CString, CString>("MAXIMUM_VALUE", ""));
AddHelpCommand();
//COMMAND FOR COUNTERS
AddCommand("Create", t_d("[--initial | -i <initial>] [--step | -s <step>] [--cooldown | -c <cooldown>]"
"[--delay | -d <delay>] [--message | -m \"<message>\"] <name>"),
t_d("Create a counter."),
[ = ](const CString & sLine){CCountersMod::createCounterCommand(sLine);});
AddCommand("Delete", "<name>", "Delete <name> counter.",
[ = ](const CString & sLine){CCountersMod::deleteCounterCommand(sLine);});
AddCommand("Reset", "<name> [reset_value]", "Reset <name> counter.",
[ = ](const CString & sLine){CCountersMod::resetCounterCommand(sLine);});
AddCommand("Incr", "<name> [step]", "Increment <name> counter.",
[ = ](const CString & sLine){CCountersMod::incrementCounterCommand(sLine);});
AddCommand("Decr", "<name> [step]", "Decrement <name> counter.",
[ = ](const CString & sLine){CCountersMod::decrementCounterCommand(sLine);});
AddCommand("Info", "<name>", "Show information of <name> counter.",
[ = ](const CString & sLine){CCountersMod::infoCounterCommand(sLine);});
AddCommand("Set", "<name> <property> <value>", "Set property <property> to <value> for counter <name>.",
[ = ](const CString & sLine){CCountersMod::setPropertyCounterCommand(sLine);});
AddCommand("List", "", "List counters.",
[ = ](const CString & sLine){CCountersMod::listCountersCommand(sLine);});
AddCommand("Print", "<name>", "Print message for <name> counter.",
[ = ](const CString & sLine){CCountersMod::printCounterCommand(sLine);});
//COMMANDS FOR LISTENERS
AddCommand("CreateListener", "<name> <nickname> <listener_name>", "Create a listener : alias that can be used "
"on any IRC client (like Twitch).",
[ = ](const CString & sLine){CCountersMod::createListenerCommand(sLine);});
AddCommand("DeleteListener", "<nickname> <listener_name>", "Delete a listener.",
[ = ](const CString & sLine){CCountersMod::deleteListenerCommand(sLine);});
AddCommand("ListListeners", "", "List listeners.",
[ = ](const CString & sLine){CCountersMod::listListenersCommand(sLine);});
}
virtual bool OnLoad(const CString& sArgs, CString& sMessage) override {
return true;
}
virtual ~CCountersMod() {
}
};
NETWORKMODULEDEFS(CCountersMod, "Module to count things using commands")