-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
257 lines (216 loc) · 9.56 KB
/
setup.php
File metadata and controls
257 lines (216 loc) · 9.56 KB
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
<?php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/keys.php';
foreach(glob(__DIR__ . '/commands/*.php') as $filename) {
require $filename;
}
use Discord\Discord;
use Discord\Builders\MessageBuilder;
use Discord\Parts\Channel\Message;
use Discord\Parts\User\Member;
use Discord\WebSockets\Intents;
use Discord\WebSockets\Event;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
$discord = new Discord([
'token' => $token,
'loadAllMembers' => true,
'intents' => Intents::getDefaultIntents() | Intents::GUILD_MEMBERS,
]);
$logger = new Logger('MannBot Logs');
$logger->pushHandler(new StreamHandler(__DIR__ . '/application.log', Logger::DEBUG));
$discord->on('ready', function ($discord) use ($logger, $thoughts_folder, $levels, $currency, $bot_image, $slot_icons, $slot_winnings, $meme_reactions) {
$logger->info('MannBot Online');
// If no user data exists, generate a new users json file
if (!file_get_contents(__DIR__ . '/users.json')) {
foreach ($discord->guilds as $guild) {
$users = [];
foreach ($guild->members as $member) {
if ($member->user->bot) {
continue;
}
$users[] = [
'id' => $member->user->id,
'username' => $member->user->username,
'nickname' => $member->nick,
'alias' => null,
'xp' => 0,
'level' => 1,
'balance' => 1000,
'daily_bonus' => strtotime('now'),
'caught' => 0,
'jailed' => null,
];
}
file_put_contents(__DIR__ . '/users.json', json_encode($users));
}
}
/* @todo test */
// If the bot is added to a new server, grab all the users in that server and generate data for them
// $discord->on(Event::GUILD_CREATE, function (Guild $guild, Discord $discord) {
// $users = json_decode(file_get_contents(__DIR__ . '/users.json'));
// foreach ($guild->members as $member) {
// // If this is a bot, skip the member
// if ($member->user->bot) {
// continue;
// }
// // If they already exist within the user data the bot holds, skip the member
// foreach ($users as $user) {
// if ($user->id == $member->user->id) {
// continue 2;
// }
// }
// $users[] = [
// 'id' => $member->user->id,
// 'username' => $member->user->username,
// 'nickname' => $member->user->nick,
// 'alias' => null,
// 'xp' => 0,
// 'level' => 1,
// 'balance' => 1000,
// 'daily_bonus' => strtotime('now'),
// 'caught' => 0,
// 'jailed' => null,
// ];
// }
// file_put_contents(__DIR__ . '/users.json', json_encode($users));
// });
/* @todo test */
// If a new user joins the server, add them to the users data file
// $discord->on(Event::GUILD_MEMBER_ADD, function (Member $member, Discord $discord) {
// if (!$member->user->bot) {
// $users = json_decode(file_get_contents(__DIR__ . '/users.json'));
// // If they already exist within the user data the bot holds, skip the member
// foreach ($users as $user) {
// if ($user->id == $member->user->id) {
// $logger->info('A new user has joined the server');
// break;
// }
// }
// $users[] = [
// 'id' => $member->user->id,
// 'username' => $member->user->username,
// 'nickname' => $member->user->nick,
// 'alias' => null,
// 'xp' => 0,
// 'level' => 1,
// 'balance' => 1000,
// 'daily_bonus' => strtotime('now'),
// 'caught' => 0,
// 'jailed' => null,
// ];
// file_put_contents(__DIR__ . '/users.json', json_encode($users));
// $logger->info('A new user has joined the server');
// }
// });
// Listen for messages.
$discord->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) use ($logger, $thoughts_folder, $levels, $currency, $bot_image, $slot_icons, $slot_winnings, $meme_reactions) {
// Add 1xp to the user every time they message
addXp($message->channel, $message->author, $levels);
// See if the command character was called
$is_command = str_contains(strtolower($message->content), '!');
if (str_contains(strtolower($message->content), 'thanks mannbot')) {
$message_builder = MessageBuilder::new()->setContent("Thank you, working hard!");
$message->channel->sendMessage($message_builder);
}
if ($is_command) {
$command_at_start_or_end = substr(strtolower($message->content), strpos($message->content, "!"));
$command_in_message = strstr($command_at_start_or_end, ' ', true);
if (!empty($command_in_message)) {
$command = $command_in_message;
} else {
$command = $command_at_start_or_end;
}
switch ($command) {
case '!commands':
commandCommands($message->channel, $currency, $bot_image);
break;
case '!hey':
commandHey($message->channel, $message->author);
break;
case '!levelsleaderboard':
commandLevelsLeaderboard($message->channel);
break;
// Admin Commands
case '!setalias':
commandSetAlias($message->channel, $message->author, $message->content);
break;
// Gambling Commands
// case '!blackjack':
// commandBlackjack($message->channel, $message->author, $currency);
// break;
case '!double':
commandDouble($message->channel, $message->author, $message->content, $currency);
break;
case '!slots':
commandSlots($message->channel, $message->author, $currency, $slot_icons, $slot_winnings);
break;
case '!steal':
commandSteal($message->channel, $message->author, $message->content, $currency);
break;
case '!jailtime':
commandJailtime($message->channel, $message->author);
break;
case '!leaderboard':
commandLeaderboard($message->channel, $currency);
break;
case '!checkbalance':
commandCheckBalance($message->channel, $message->author, $currency);
break;
case '!claimbonus':
commandClaimBonus($message->channel, $message->author, $currency);
break;
case '!slotspayout':
commandSlotsPayout($message->channel, $currency, $slot_icons, $slot_winnings);
break;
case '!givemoney':
commandGiveMoney($message->channel, $message->author, $message->content, $currency);
break;
case '!addmoney':
commandAddMoney($message->channel, $message->author, $message->content, $currency);
break;
case '!removemoney':
commandRemoveMoney($message->channel, $message->author, $message->content, $currency);
break;
// Images Commands
case '!meme':
commandMeme($message, $meme_reactions);
break;
// Music Commands
// Parrot Commands
// case '!parrot':
// commandParrot($message->channel, $message);
// break;
// case '!updateparrot':
// commandUpdateParrot($message->channel, $message->author, $logger);
// break;
// RNG Commands
case '!8ball':
commandEightBall($message->channel);
break;
case '!coinflip':
commandCoinFlip($message->channel);
break;
case '!rate':
commandRate($message->channel);
break;
case '!roll':
commandRoll($message->channel);
break;
case '!roll20':
commandRollTwenty($message->channel);
break;
case '!thoughts':
commandThoughts($message->channel, $thoughts_folder, $message->content);
break;
case '!whois':
commandWhoIs($message->channel, $message->guild->members, $message->content);
break;
}
}
});
// @todo Update the saved users record upon any updates E.G. nickname changes
// $discord->on(Event::GUILD_MEMBER_UPDATE, function (Member $new_member_record, Discord $discord, $old_member_record) {
// });
});
$discord->run();