-
Notifications
You must be signed in to change notification settings - Fork 1
/
znc-dice.cpp
116 lines (109 loc) · 3.01 KB
/
znc-dice.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
/**
* ZNC dice bot
*
* Copyright (c) 2012 Romain Labolle
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#include <znc/znc.h>
#include <znc/Chan.h>
#include <znc/User.h>
#include <znc/Modules.h>
class CDiceMod : public CModule {
public:
MODCONSTRUCTOR(CDiceMod) {}
virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) {
user = GetUser();
HighScore = sArgs.Token(0).ToInt();
PutModule("HighScore: "+CString(HighScore));
lastturn = false;
return true;
}
virtual ~CDiceMod() {}
virtual void OnModCommand(const CString& sCommand) {
if (sCommand.Token(0).Equals("high")) {
HighScore = sCommand.Token(1).ToInt();
PutModule("HighScore: "+CString(HighScore));
}
}
virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) {
if (sMessage.Equals("!dice start")) {
PutIRC("PRIVMSG " + Channel.GetName() + " :!dice join");
return CONTINUE;
}
CNick nick = user->GetNick();
if (Nick.GetNick().Equals("Nimda3"))
{
if (sMessage.Token(0).Equals(nick.GetNick()+"\'s") && sMessage.Token(1).Equals("turn."))
{
PutIRC("PRIVMSG " + Channel.GetName() + " :!dice roll");
lastturn = false;
return CONTINUE;
}
if (sMessage.Token(0).Equals(nick.GetNick()) && sMessage.Token(1).Equals("rolls"))
{
// ravomavain rolls a 2. Points: 49 + 2 => 51 - roll again or stand?
int value = sMessage.Token(3).ToInt();
if (value == 6) {
return CONTINUE;
}
int saved = sMessage.Token(5).ToInt();
int temp = sMessage.Token(7).ToInt();
int total = saved + temp;
if (lastturn) {
if (total < score) {
PutIRC("PRIVMSG " + Channel.GetName() + " :!dice roll");
return CONTINUE;
}
PutIRC("PRIVMSG " + Channel.GetName() + " :!dice stand");
return CONTINUE;
}
if (total == 49 || total >= HighScore) {
PutIRC("PRIVMSG " + Channel.GetName() + " :!dice stand");
return CONTINUE;
}
if (total < 49)
{
if (temp >= 20)
{
PutIRC("PRIVMSG " + Channel.GetName() + " :!dice stand");
return CONTINUE;
}
}
PutIRC("PRIVMSG " + Channel.GetName() + " :!dice roll");
return CONTINUE;
}
if (sMessage.Left(37).Equals("You broke the highest sum record with"))
{
HighScore = sMessage.Token(7).ToInt()+1;
PutModule("HighScore: "+CString(HighScore));
return CONTINUE;
}
if (sMessage.Left(26).Equals("Dice game has been started"))
{
lastturn = false;
return CONTINUE;
}
if (sMessage.Left(39).Equals("It is a really bad idea to \x02stand\x02 now."))
{
PutIRC("PRIVMSG " + Channel.GetName() + " :!dice roll");
return CONTINUE;
}
if (sMessage.WildCmp("*get one more chance to beat your score*"))
{
lastturn = true;
score = sMessage.Token(11).ToInt();
return CONTINUE;
}
}
return CONTINUE;
}
private:
CUser *user;
int HighScore;
bool lastturn;
int score;
};
MODULEDEFS(CDiceMod, "Dice bot")