-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMinigameBackseat.cs
94 lines (78 loc) · 2.23 KB
/
MinigameBackseat.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
87
88
89
90
91
92
93
94
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace AbevBot
{
public static class MinigameBackseat
{
private const int MAXLADDERENTRIES = 10;
public static void AddBackseatPoint(string userName, int point)
{
Task.Run(() => StartAddBackseatPoint(userName, point));
}
private static void StartAddBackseatPoint(string userName, int point)
{
string chatter = userName?.Trim();
if (chatter.StartsWith('@')) { chatter = chatter[1..]; }
if (string.IsNullOrWhiteSpace(chatter))
{
GetBackseatLadder();
return;
}
Chatter c = Chatter.GetChatterByName(chatter);
if (c != null)
{
c.AddBackseatPoint(point);
Chat.AddMessageToQueue(string.Concat(
"1 point ",
point > 0 ? "awarded to " : "taken from ",
c.Name, ". Now has ",
c.BackseatPoints,
c.BackseatPoints > 1 ? " points" : " point"
));
}
}
private static void GetBackseatLadder()
{
List<(int, string)> ladder = new();
var chatter = Chatter.GetChatters().GetEnumerator();
Chatter c;
while (chatter.MoveNext())
{
c = chatter.Current.Value;
if (c.BackseatPoints != 0)
{
ladder.Add((c.BackseatPoints, c.Name));
}
}
if (ladder.Count == 0)
{
Chat.AddMessageToQueue("Backseat points ladder -> empty... No helpers in chat? Susge");
return;
}
ladder.Sort((a, b) =>
{
if (a.Item1 == b.Item1) return b.Item2.CompareTo(a.Item2);
return b.Item1.CompareTo(a.Item1);
});
StringBuilder sb = new();
sb.Append("Backseat points ladder -> ");
var ladderEntry = ladder.GetEnumerator();
int index = 0;
bool first = true;
while (ladderEntry.MoveNext())
{
if (index >= MAXLADDERENTRIES) break;
if (!first) sb.Append(" | ");
sb.Append(ladderEntry.Current.Item2).Append(": ").Append(ladderEntry.Current.Item1);
first = false;
index++;
}
Chat.AddMessageToQueue(sb.ToString());
}
public static string GetCommands()
{
return "!point/unpoint chatter_name";
}
}
}