-
Notifications
You must be signed in to change notification settings - Fork 7
/
Commands.cs
86 lines (63 loc) · 2.81 KB
/
Commands.cs
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
using System.Linq;
using System.Text;
using Cpp2IL.Core.Extensions;
using ProjectM;
using ProjectM.Network;
using VampireCommandFramework;
namespace Killfeed;
public class Commands
{
[Command("killfeed leaderboard", shortHand: "kf top")]
public void TopCommand(ChatCommandContext ctx)
{
// TODO: Enhance with cache and such
int num = 10;
int offset = 5;
var topKillers = DataStore.PlayerDatas.Values.OrderByDescending(k => k.Kills).Take(num).ToArray();
offset = offset > topKillers.Length ? topKillers.Length : offset;
num = num > topKillers.Length ? topKillers.Length : num;
var pad = (string name) => new string('\t'.Repeat(6 - name.Length / 5).ToArray());
var sb = new StringBuilder();
var sb2 = new StringBuilder();
sb2.AppendLine("");
sb.AppendLine($"{Markup.Prefix} <size=18><u>Top Kills</u></size>");
//var message = (DataStore.PlayerStatistics k) => $"{Markup.Highlight(k.LastName)}{pad(k.LastName)}<color={Markup.SecondaryColor}><b>{k.Kills}</b> / {k.Deaths}</color>";
var message = (DataStore.PlayerStatistics k) => $"\t<color={Markup.SecondaryColor}><b>{k.Kills,-3}</b> / {k.Deaths,3}</color>\t{Markup.Highlight(k.LastName)}";
for (var i = 0; i < offset; i++)
{
var k = topKillers[i];
sb.AppendLine($"{i + 1}. {message(k)}");
//sb.AppendLine($"{i + 1}. {Markup.Highlight(k.LastName.PadRight(1, ' '))}{pad(k.LastName)}{Markup.Secondary(k.LastName.Length)}");
}
for (var i = offset; i < num; i++)
{
var k = topKillers[i];
sb2.AppendLine($"{i + 1}. {message(k)}");
//sb2.AppendLine($"{i + 1}. {Markup.Highlight(k.LastName.PadRight(1, ' '))}{pad(k.LastName)}{Markup.Secondary(k.LastName.Length)}");
}
ctx.Reply(sb.ToString());
ctx.Reply(sb2.ToString());
}
[Command("killfeed", shortHand: "kf", description: "Shows Killfeed info")]
public void KillfeedCommand(ChatCommandContext ctx)
{
var steamId = ctx.User.PlatformId;
// append current rank based on kills
if (!DataStore.PlayerDatas.TryGetValue(steamId, out _))
{
throw ctx.Error($"You have no stats yet!");
}
var (stats, rank) = DataStore.PlayerDatas.Values.OrderByDescending(k => k.Kills)
.Select((stats, rank) => (stats, rank))
.First(u => u.stats.SteamId == ctx.User.PlatformId);
var sb = new StringBuilder();
sb.AppendLine($"{Markup.Prefix} <size=21><u>Killfeed Stats for {Markup.Highlight(stats.LastName)}</u>");
var rankStr = $"{Markup.Highlight($"{(rank + 1)}")} / {Markup.Secondary(DataStore.PlayerDatas.Count)}";
sb.AppendLine($"Rank: {rankStr}</size>");
sb.AppendLine($"Kills: {Markup.Highlight(stats.Kills)}");
sb.AppendLine($"Deaths: {Markup.Highlight(stats.Deaths)}");
sb.AppendLine($"Current Streak: {Markup.Highlight(stats.CurrentStreak)}");
sb.AppendLine($"Highest Streak: {Markup.Highlight(stats.HighestStreak)}");
ctx.Reply(sb.ToString());
}
}