promoteUserFromBadges

Infers a user's class based on their badge(s).

version(TwitchSupport && WithTwitchPlugin)
private pure @safe
void
promoteUserFromBadges
(,
const string badges
,,
const bool promoteVIPs
)

Parameters

class_ IRCUser.Class

Reference to the user's class.

badges string

String of comma-separated badges.

promoteModerators bool

Whether to promote moderators to operator.

promoteVIPs bool

Whether to promote VIPs to elevated.

Examples

1 import lu.conv : Enum;
2 
3 {
4     enum badges = "subscriber/12,sub-gift-leader/1";
5     auto class_ = IRCUser.Class.anyone;
6     promoteUserFromBadges(class_, badges, false, false);
7     enum expected = IRCUser.Class.registered;
8     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
9 }
10 {
11     enum badges = "premium/1";
12     auto class_ = IRCUser.Class.anyone;
13     promoteUserFromBadges(class_, badges, false, false);
14     enum expected = IRCUser.Class.anyone;
15     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
16 }
17 {
18     enum badges = "subscriber/12,vip/1";
19     auto class_ = IRCUser.Class.anyone;
20     promoteUserFromBadges(class_, badges, false, false);
21     enum expected = IRCUser.Class.registered;  // because promoteVIPs false
22     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
23 }
24 {
25     enum badges = "subscriber/12,vip/1";
26     auto class_ = IRCUser.Class.anyone;
27     promoteUserFromBadges(class_, badges, true, true);
28     enum expected = IRCUser.Class.elevated;
29     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
30 }
31 {
32     enum badges = "moderator/1,subscriber/3012";
33     auto class_ = IRCUser.Class.anyone;
34     promoteUserFromBadges(class_, badges, true, true);
35     enum expected = IRCUser.Class.operator;
36     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
37 }
38 {
39     enum badges = "moderator/1,subscriber/3012";
40     auto class_ = IRCUser.Class.anyone;
41     promoteUserFromBadges(class_, badges, false, true);
42     enum expected = IRCUser.Class.registered;
43     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
44 }
45 {
46     enum badges = "broadcaster/1,subscriber/12,partner/1";
47     auto class_ = IRCUser.Class.anyone;
48     promoteUserFromBadges(class_, badges, false, true);
49     enum expected = IRCUser.Class.registered;  // not staff because broadcasters are identified elsewhere
50     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
51 }
52 {
53     enum badges = "moderator/1";  // no comma splitter test
54     auto class_ = IRCUser.Class.anyone;
55     promoteUserFromBadges(class_, badges, true, true);
56     enum expected = IRCUser.Class.operator;
57     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
58 }
59 {
60     enum badges = "subscriber/1";
61     auto class_ = IRCUser.Class.operator;
62     promoteUserFromBadges(class_, badges, true, true);
63     enum expected = IRCUser.Class.operator;
64     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
65 }
66 {
67     enum badges = string.init;
68     auto class_ = IRCUser.Class.staff;
69     promoteUserFromBadges(class_, badges, true, true);
70     enum expected = IRCUser.Class.staff;
71     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
72 }
73 {
74     enum badges = string.init;
75     auto class_ = IRCUser.Class.anyone;
76     promoteUserFromBadges(class_, badges, false, false);
77     enum expected = IRCUser.Class.anyone;
78     assert((class_ == expected), Enum!(IRCUser.Class).toString(class_));
79 }