-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.php
67 lines (48 loc) · 1.6 KB
/
commands.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
<?php
$commands = [];
use Discord\Parts\Embed\Embed;
use function Discord\getColor;
define('EMBED_CLR', getColor("#7ba0a0"));
$commands['rank'] = function($discord, $message) {
$user = $message->author;
$xp = result("SELECT xp FROM levels WHERE id = ?", [$user->id]);
$rank = 0;
$levels = query("SELECT id FROM levels ORDER BY xp DESC");
while ($level = $levels->fetch()) {
$rank++;
if ($level['id'] == $user->id) break;
}
$mbd = new Embed($discord);
$mbd->setTitle(sprintf(
'Stats for %s (%s) ',
$user->displayname, $user->username))
->setDescription(
":sparkles: $xp Server XP\n".
":medal: Rank #$rank")
->setThumbnail($user->getAvatarAttribute())
->setColor(EMBED_CLR);
return $mbd;
};
$commands['top'] = function($discord, $message, $args) {
$page = (int)($args[1] ?? 1);
// 100 pages means 2k members. If this ever needs to be increased then we're suffering from success.
$page = clamp($page, 0, 100);
$top = query("SELECT id,xp FROM levels ORDER BY xp DESC ".paginate($page, 20));
$names = $xps = [];
$rank = ($page-1)*20;
while ($user = $top->fetch()) {
$rank++;
$names[] = '`'.leftpad($rank, 3).'.` <@'.$user['id'].'>';
$xps[] = '`'.leftpad(fmtnum($user['xp']), 7).'`';
}
$pagelbl = ($page > 1 ? " (Page $page)" : '');
$mbd = new Embed($discord);
$mbd->setTitle(":sparkles: **Top 20 Members**$pagelbl :sparkles:")
->addFieldValues('Rank Name', join("\n", $names), true)
->addFieldValues('XP', join("\n", $xps), true)
->setColor(EMBED_CLR);
return $mbd;
};
$commands['help'] = function() {
return "What, are you hanging off a cliff or something?";
};