@quenty/textfilterutils 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/textfilterutils@5.0.0...@quenty/textfilterutils@5.1.0) (2022-07-31)
7
+
8
+ **Note:** Version bump only for package @quenty/textfilterutils
9
+
10
+
11
+
12
+
13
+
6
14
  # [5.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/textfilterutils@4.2.0...@quenty/textfilterutils@5.0.0) (2022-05-21)
7
15
 
8
16
  **Note:** Version bump only for package @quenty/textfilterutils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/textfilterutils",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Utility functions for filtering text",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -26,10 +26,10 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@quenty/loader": "^5.0.0",
29
- "@quenty/promise": "^5.0.0"
29
+ "@quenty/promise": "^5.1.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "9f7eaea7543c33c89d2e32c38491b13f9271f4f7"
34
+ "gitHead": "e31b3a35aa475bb5699a24898a8639e107165b36"
35
35
  }
@@ -1,5 +1,6 @@
1
1
  --[=[
2
- Utility functions for filtering text
2
+ Utility functions for filtering text wrapping [TextService] and legacy [Chat] API surfaces.
3
+
3
4
  @class TextFilterUtils
4
5
  ]=]
5
6
 
@@ -12,18 +13,44 @@ local Promise = require("Promise")
12
13
 
13
14
  local TextFilterUtils = {}
14
15
 
15
- function TextFilterUtils.promiseNonChatStringForBroadcast(str, fromUserId, textContext)
16
- assert(type(str) == "string", "Bad str")
16
+ --[=[
17
+ Returns a filtered string for broadcast. Tends to look like this:
18
+
19
+ ```lua
20
+ TextFilterUtils.promiseNonChatStringForBroadcast(text, player.UserId, Enum.TextFilterContext.PublicChat)
21
+ :Then(function(filtered)
22
+ print(filtered)
23
+ end)
24
+ ```
25
+
26
+ The two options for textFilterContext are `Enum.TextFilterContext.PublicChat` and `Enum.TextFilterContext.PrivateChat`.
27
+
28
+ @param text string
29
+ @param fromUserId number
30
+ @param textFilterContext TextFilterContext
31
+ @return Promise<string>
32
+ ]=]
33
+ function TextFilterUtils.promiseNonChatStringForBroadcast(text, fromUserId, textFilterContext)
34
+ assert(type(text) == "string", "Bad text")
17
35
  assert(type(fromUserId) == "number", "Bad fromUserId")
18
- assert(typeof(textContext) == "EnumItem", "Bad textContext")
36
+ assert(typeof(textFilterContext) == "EnumItem", "Bad textFilterContext")
19
37
 
20
38
  return TextFilterUtils._promiseTextResult(
21
39
  TextFilterUtils.getNonChatStringForBroadcastAsync,
22
- str,
40
+ text,
23
41
  fromUserId,
24
- textContext)
42
+ textFilterContext)
25
43
  end
26
44
 
45
+ --[=[
46
+ Legacy filter broadcast using the `Chat:FilterStringForBroadcast` API call. It's recommended
47
+ you use [TextFilterUtils.promiseNonChatStringForBroadcast] instead.
48
+
49
+
50
+ @param playerFrom Player
51
+ @param text string
52
+ @return Promise<string>
53
+ ]=]
27
54
  function TextFilterUtils.promiseLegacyChatFilter(playerFrom, text)
28
55
  assert(typeof(playerFrom) == "Instance" and playerFrom:IsA("Player"), "Bad playerFrom")
29
56
  assert(type(text) == "string", "Bad text")
@@ -44,63 +71,90 @@ function TextFilterUtils.promiseLegacyChatFilter(playerFrom, text)
44
71
  end)
45
72
  end
46
73
 
47
- function TextFilterUtils.promiseNonChatStringForUserAsync(str, fromUserId, toUserId, textContext)
48
- assert(type(str) == "string", "Bad str")
74
+ --[=[
75
+ Returns a filtered string for a specific user to another user. This is preferable over broadcast if
76
+ possible.
77
+
78
+ @param text string
79
+ @param fromUserId number
80
+ @param toUserId number
81
+ @param textFilterContext TextFilterContext
82
+ @return Promise<string>
83
+ ]=]
84
+ function TextFilterUtils.promiseNonChatStringForUserAsync(text, fromUserId, toUserId, textFilterContext)
85
+ assert(type(text) == "string", "Bad text")
49
86
  assert(type(fromUserId) == "number", "Bad fromUserId")
50
87
  assert(type(toUserId) == "number", "Bad toUserId")
51
- assert(typeof(textContext) == "EnumItem", "Bad textContext")
88
+ assert(typeof(textFilterContext) == "EnumItem", "Bad textFilterContext")
52
89
 
53
90
  return TextFilterUtils._promiseTextResult(
54
91
  TextFilterUtils.getNonChatStringForUserAsync,
55
- str,
92
+ text,
56
93
  fromUserId,
57
94
  toUserId,
58
- textContext)
95
+ textFilterContext)
59
96
  end
60
97
 
61
- function TextFilterUtils.getNonChatStringForBroadcastAsync(str, fromUserId, textContext)
62
- assert(type(str) == "string", "Bad str")
98
+ --[=[
99
+ Blocking call to get a non-chat string for broadcast. Wraps [TextService.FilterStringAsync].
100
+
101
+ @param text string
102
+ @param fromUserId number
103
+ @param textFilterContext TextFilterContext
104
+ @return Promise<string>
105
+ ]=]
106
+ function TextFilterUtils.getNonChatStringForBroadcastAsync(text, fromUserId, textFilterContext)
107
+ assert(type(text) == "string", "Bad text")
63
108
  assert(type(fromUserId) == "number", "Bad fromUserId")
64
- assert(typeof(textContext) == "EnumItem", "Bad textContext")
109
+ assert(typeof(textFilterContext) == "EnumItem", "Bad textFilterContext")
65
110
 
66
- local text = nil
111
+ local resultText = nil
67
112
  local ok, err = pcall(function()
68
- local result = TextService:FilterStringAsync(str, fromUserId, textContext)
113
+ local result = TextService:FilterStringAsync(text, fromUserId, textFilterContext)
69
114
  if not result then
70
115
  error("No TextFilterResult")
71
116
  end
72
117
 
73
- text = result:GetNonChatStringForBroadcastAsync()
118
+ resultText = result:GetNonChatStringForBroadcastAsync()
74
119
  end)
75
120
 
76
121
  if not ok then
77
122
  return false, err
78
123
  end
79
124
 
80
- return text
125
+ return resultText
81
126
  end
82
127
 
83
- function TextFilterUtils.getNonChatStringForUserAsync(str, fromUserId, toUserId, textContext)
84
- assert(type(str) == "string", "Bad str")
128
+ --[=[
129
+ Blocking call to get a non-chat string for a user.
130
+
131
+ @param text string
132
+ @param fromUserId number
133
+ @param toUserId number
134
+ @param textFilterContext TextFilterContext
135
+ @return Promise<string>
136
+ ]=]
137
+ function TextFilterUtils.getNonChatStringForUserAsync(text, fromUserId, toUserId, textFilterContext)
138
+ assert(type(text) == "string", "Bad text")
85
139
  assert(type(fromUserId) == "number", "Bad fromUserId")
86
140
  assert(type(toUserId) == "number", "Bad toUserId")
87
- assert(typeof(textContext) == "EnumItem", "Bad textContext")
141
+ assert(typeof(textFilterContext) == "EnumItem", "Bad textFilterContext")
88
142
 
89
- local text = nil
143
+ local textResult = nil
90
144
  local ok, err = pcall(function()
91
- local result = TextService:FilterStringAsync(str, fromUserId, textContext)
145
+ local result = TextService:FilterStringAsync(text, fromUserId, textFilterContext)
92
146
  if not result then
93
147
  error("No TextFilterResult")
94
148
  end
95
149
 
96
- text = result:GetNonChatStringForUserAsync(toUserId)
150
+ textResult = result:GetNonChatStringForUserAsync(toUserId)
97
151
  end)
98
152
 
99
153
  if not ok then
100
154
  return false, err
101
155
  end
102
156
 
103
- return text
157
+ return textResult
104
158
  end
105
159
 
106
160
  function TextFilterUtils._promiseTextResult(getResult, ...)