-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.php
277 lines (224 loc) · 9.71 KB
/
run.php
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
<?php
include __DIR__.'/vendor/autoload.php';
require("token.php");
$discord = new \Discord\Discord([
'token' => $token
]);
$discord->on('ready', function ($discord) {
echo "Bot is ready.", PHP_EOL;
// Listen for events here
$discord->on('message', function ($message) {
global $compliments;
$clientID = "YOUR_CLIENT_ID_HERE";
// uncomment following line while debugging
echo "{$message->author->username}: {$message->content}", PHP_EOL;
if ( !preg_match("/(!)?".$clientID."/", "{$message->author->id}") ) { // don't respond to yourself.
/*if ( "{$message->channel->id}" != "339769590982770689" ) { // only post in channels(s) of your choice
echo "Can't post in channel #{$message->channel->id}.", PHP_EOL;
return;
}
else {*/
$thismessage = "{$message->content}";
$thisuser = "{$message->author->id}";
//********** BEGIN COMMANDS
//***** hello nicebot
if ( preg_match("/^(((hello|hi|hey)(\s+there)?)|greetings|(ay\s+)?yo|good\s+(morning|afternoon|day|evening))([,!])?(\s+)<@(!)?".$clientID.">/i",$thismessage) ) {
$message->channel->sendMessage("Hello <@!$thisuser>!");
}
//***** doom for fimion
if ( preg_match("/doo+m/i",$thismessage) ) {
$message->channel->sendMessage("Doomed. *Doooooooomed!* <@!$thisuser>");
}
//**** dice roll for grey <3
// syntax: !roll (4)d20(+3)( for initiative) ( -v)
// we can't roll more than 9999 9999-sided dice +- 9999 to prevent overflow
if (preg_match("/^!roll\s+(\d*)d(\d+)([+-])?(\d*)?(\s+for initiative)?(\s+-v)?/",$thismessage,$roll)) {
if (isset($roll[1]) && strlen($roll[1]) < 5) { // checking how many dice
if (isset($roll[2]) && strlen($roll[2]) < 5) {// checking how many sides
if ($roll[2] > 1) { // you can't roll less than a 2
if ( strlen($roll[4]) < 5) { // our additions must also be less than 5 digits
$results = array(); // for later...
$modifier = 0;
$output = "";
$grandtotal = 0;
/* planning:
* "user rolled (these dice) <for initiative>! <Showing all rolls.>"
* reset array
* roll dice, store in array
* check verbose mode
* if on: print each roll, then modifier, then total, then grand total
* if off: add each (roll+modifier) and just print total
*/
// count number of dice and how many sides, then roll it and stick the result in an array
// if number of dice is not specified, make it 0
if ($roll[1] != "") {
$numdice = $roll[1];
}
else {
$numdice = 1;
}
for ($d = 0; $d < $numdice; $d++) {
$result = mt_rand(1,$roll[2]);
$results[$d] = $result;
}
// look at the modifier
if (isset($roll[3]) && isset($roll[4])) {
if ($roll[3] === "+") {
$modifier = $roll[4];
}
if ($roll[3] === "-") {
$modifier = ($roll[4]*-1);
}
}
// check for initiative
if (isset($roll[5]) && $roll[5] != "") {
$forin = " for initiative!";
}
else {
$forin = "!";
}
// check for verbose mode, HOWEVER you cannot use it if you're only rolling one die
if (isset($roll[6]) && $roll[6] != "" && $roll[1] > 1) { // VERBOSE IS ON
// go through array, display dice result, then modifier, then total result
foreach ($results as $r) {
// check if modifier is 0
if ($roll[4] > 0 && $roll[4] != "") {
$output = $output."Rolled $r, and with $modifier it's **".($r+$modifier)."**!\n";
}
else {
$output = $output."Rolled **$r**!\n";
}
$grandtotal += $r+$modifier;
}
$output .= "\n<@!$thisuser> rolled **$grandtotal**$forin";
}
else { // VERBOSE IS OFF
foreach ($results as $r) {
$grandtotal += $r+$modifier;
}
$output .= "\n<@!$thisuser> rolled **$grandtotal**$forin";
}
// output EVERYTHING to channel here
$message->channel->sendMessage($output);
// dump array contents
//var_dump($results);
//var_dump($roll);
}
else {
$message->channel->sendMessage("I don't know what to do with these long numbers, <@!$thisuser>! :confounded: ");
} // end addition/subtraction checker
}
else {
$message->channel->sendMessage("But <@!$thisuser> you can't roll a ".$roll[2]."-sided die! :fearful:");
} // end if die is less than 2 sides
}
else {
$message->channel->sendMessage("But <@!$thisuser> I can't count that high! :sob:");
} // end # of sides
}
else {
$message->channel->sendMessage("But <@!$thisuser> I can't roll *that* many dice! :sweat:");
} // end # of dice
}
//***** random compliments
if ( preg_match("/^!compliment(\s+<@(!)?\d+>)?/i",$thismessage,$user) ){
/* i am not creative
* some compliments adapted from:
* peoplearenice.blogspot.com/p/compliment-list.html
* happier.com/blog/nice-things-to-say-100-compliments
*/
// if the array does not exist or if the array has been reduced to zero length, regenerate it
if ( !isset($compliments) || (isset($compliments) && count($compliments)==0) ) {
$compliments = array(
0 => "{NAME}, you're cooler than ice on the rocks.",
1 => "{NAME} makes me smile.",
2 => "{NAME} is my sunshine on a rainy day.",
3 => "{NAME} looks really good today!",
4 => "I like {NAME}'s style.",
5 => "Hey {NAME}, your mouse told me that you have very soft hands.",
6 => "Is it hot in here or is it just {NAME}?",
7 => "{NAME}'s every thought and motion contributes to the beauty of the universe.",
8 => "Hey {NAME}, can you teach me how to be as awesome as you?",
9 => "I'm having trouble coming up with a compliment worthy of {NAME}.",
10 => "{NAME}'s more fun than bubble wrap.",
11 => "On a scale of 1 to 10, {NAME} is [OVERFLOW ERROR]"
);
}
// randomize the compliments
shuffle($compliments);
// construct our compliment. we'll take the last one on the list
$which = count($compliments)-1;
if (isset($user[1])) {
$output = str_replace("{NAME}",$user[1],$compliments[$which]);
}
else {
$output = str_replace("{NAME}","<@!$thisuser>",$compliments[$which]);
}
// display compliment
$message->channel->sendMessage($output);
// remove that item from the the array
array_pop($compliments);
//echo "array length now: ".count($compliments);
}
//***** COIN FLIP
// syntax: !coinflip< number>
// if no number specified, it'll flip only one.
// limit 9999 coins
if ( preg_match("/^!coinflip(\s+\d*)?/",$thismessage,$flip) ) {
$heads = 0;
$tails = 0;
// # coins not set or set to one coin
if (!isset($flip[1]) || $flip[1] == 1) {
$r = mt_rand(0,1);
if ($r == 0) { // heads
$result = "heads";
}
else {
$result = "tails";
}
$output = "<@!$thisuser> flipped **$result**!";
}
// more than one coin
if (isset($flip[1]) && $flip[1] > 1 && strlen($flip[1]) < 5) {
for ($r = 0; $r < $flip[1]; $r++) {
$thisflip = mt_rand(0,1);
if ($thisflip == 0) {
$heads++;
}
else {
$tails++;
}
}
$output = "<@!$thisuser>'s results:\n\n";
$output .= "Heads: **$heads**\n";
$output .= "Tails: **$tails**\n";
}
// too many coins
if (isset($flip[1]) && strlen($flip[1]) > 4) {
$output = "But <@!$thisuser> I don't even *have* that many coins! :scream:";
}
// not enough coins
if (isset($flip[1]) && $flip[1] < 1) {
$output = "I have to flip at least one coin, <@!$thisuser>... :sweat:";
}
// output
$message->channel->sendMessage($output);
} // end coin flip
//***** HELP FILE
if ( preg_match("/^!help/",$thismessage) ) {
// here comes some fugly formatting...
$output .= "Hello <@!$thisuser>! I'm nicebot. I'm made by alleZSoyez.\n";
$output .= "Here's a list of what I can do:\n\n";
$output .= "**(some greeting) (ping me)** I'm a nice bot who loves to say hello to humans.\n\n";
$output .= "**Doom** is a magic word.\n\n";
$output .= "**!compliment <user>** I'll compliment whoever you want. If no one is specified, I'll compliment *you!*\n\n";
$output .= "**!roll <#>d<#><+ or -#> <for initiative> <-v>** I'll roll dice for you.\n - Example: **!roll 2d20+5** to roll two d20 dice and add 5 to each result.\n - If you don't tell me how many to roll, I'll assume you wanted only one.\n - If you'd like to **view** each individual roll, add **-v** to the end.\n\n";
$output .= "**!coinflip <#>** I'll flip a coin for you.\n - You can tell me how many coins you want, otherwise I'll just flip one.";
$message->channel->sendMessage($output);
}
//********* END COMMANDS
//} // end channel restriction
} // end user id check
});
});
$discord->run();