/
TwitchChatLimitHelper.java
136 lines (117 loc) · 4.68 KB
/
TwitchChatLimitHelper.java
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
package com.github.twitch4j.chat.util;
import com.github.twitch4j.common.enums.TwitchLimitType;
import com.github.twitch4j.common.util.BucketUtils;
import io.github.bucket4j.Bandwidth;
import io.github.bucket4j.Bucket;
import lombok.experimental.UtilityClass;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Utility class for retrieving standard rate limits for {@link com.github.twitch4j.chat.TwitchChat}
*
* @see <a href="https://dev.twitch.tv/docs/irc/guide#command--message-limits">Official documentation</a>
*/
@UtilityClass
public class TwitchChatLimitHelper {
public final String MESSAGE_BANDWIDTH_ID = TwitchLimitType.CHAT_MESSAGE_LIMIT.getBandwidthId();
public final String JOIN_BANDWIDTH_ID = TwitchLimitType.CHAT_JOIN_LIMIT.getBandwidthId();
public final String AUTH_BANDWIDTH_ID = TwitchLimitType.CHAT_AUTH_LIMIT.getBandwidthId();
public final String WHISPER_MINUTE_BANDWIDTH_ID = TwitchLimitType.CHAT_WHISPER_LIMIT.getBandwidthId() + "-minute";
public final String WHISPER_SECOND_BANDWIDTH_ID = TwitchLimitType.CHAT_WHISPER_LIMIT.getBandwidthId() + "-second";
/**
* Users sending commands or messages to channels in which they do not have Moderator or Operator status
*/
public final Bandwidth USER_MESSAGE_LIMIT = Bandwidth.simple(20, Duration.ofSeconds(30)).withId(MESSAGE_BANDWIDTH_ID);
/**
* Users sending commands or messages to channels in which they have Moderator or Operator status
*/
public final Bandwidth MOD_MESSAGE_LIMIT = Bandwidth.simple(100, Duration.ofSeconds(30)).withId(MESSAGE_BANDWIDTH_ID);
/**
* Known bots
*/
public final Bandwidth KNOWN_MESSAGE_LIMIT = Bandwidth.simple(50, Duration.ofSeconds(30)).withId(MESSAGE_BANDWIDTH_ID);
/**
* Verified bots
*/
public final Bandwidth VERIFIED_MESSAGE_LIMIT = Bandwidth.simple(7500, Duration.ofSeconds(30)).withId(MESSAGE_BANDWIDTH_ID);
/**
* Users (not bots)
* <p>
* Note: this does <i>not</i> implement the target user count restriction.
*/
public final List<Bandwidth> USER_WHISPER_LIMIT = Collections.unmodifiableList(
Arrays.asList(
Bandwidth.simple(100, Duration.ofSeconds(60)).withId(WHISPER_MINUTE_BANDWIDTH_ID),
Bandwidth.simple(3, Duration.ofSeconds(1)).withId(WHISPER_SECOND_BANDWIDTH_ID)
)
);
/**
* Known bots
* <p>
* Note: this does <i>not</i> implement the target user count restriction.
*/
public final List<Bandwidth> KNOWN_WHISPER_LIMIT = Collections.unmodifiableList(
Arrays.asList(
Bandwidth.simple(200, Duration.ofSeconds(60)).withId(WHISPER_MINUTE_BANDWIDTH_ID),
Bandwidth.simple(10, Duration.ofSeconds(1)).withId(WHISPER_SECOND_BANDWIDTH_ID)
)
);
/**
* Verified bots
* <p>
* Note: this does <i>not</i> implement the target user count restriction.
* <p>
* Note: this only applies to legacy verified bots (pre July 2021)
*/
public final List<Bandwidth> VERIFIED_WHISPER_LIMIT = Collections.unmodifiableList(
Arrays.asList(
Bandwidth.simple(1200, Duration.ofSeconds(60)).withId(WHISPER_MINUTE_BANDWIDTH_ID),
Bandwidth.simple(20, Duration.ofSeconds(1)).withId(WHISPER_SECOND_BANDWIDTH_ID)
)
);
/**
* Join rate for users
*/
public final Bandwidth USER_JOIN_LIMIT = Bandwidth.simple(20, Duration.ofSeconds(10)).withId(JOIN_BANDWIDTH_ID);
/**
* Join rate for verified bots
*/
public final Bandwidth VERIFIED_JOIN_LIMIT = Bandwidth.simple(2000, Duration.ofSeconds(10)).withId(JOIN_BANDWIDTH_ID);
/**
* Authentication rate for users
*/
public final Bandwidth USER_AUTH_LIMIT = Bandwidth.simple(20, Duration.ofSeconds(10)).withId(AUTH_BANDWIDTH_ID);
/**
* Authentication rate for verified bots
*/
public final Bandwidth VERIFIED_AUTH_LIMIT = Bandwidth.simple(200, Duration.ofSeconds(10)).withId(AUTH_BANDWIDTH_ID);
/**
* @param limit bandwidth
* @return bucket
* @deprecated in favor of BucketUtils
*/
@Deprecated
public Bucket createBucket(Bandwidth limit) {
return BucketUtils.createBucket(limit);
}
/**
* @param limits bandwidths
* @return bucket
* @deprecated in favor of BucketUtils
*/
@Deprecated
public Bucket createBucket(Bandwidth... limits) {
return BucketUtils.createBucket(limits);
}
/**
* @param limits bandwidths
* @return bucket
* @deprecated in favor of BucketUtils
*/
@Deprecated
public Bucket createBucket(Iterable<Bandwidth> limits) {
return BucketUtils.createBucket(limits);
}
}