Skip to content

Commit 4883a87

Browse files
authored
Improve Trello behavior (#1928)
* Update Trello plugin - Add better debug logs - Add warning message for empty AppKey * Remove legacy board remover No longer needed * Add debug logs for HTTP * Made trello api print use print * Allow pooling HttpService from API * Fix? * Fix HttpService reference in TrelloAPI
1 parent cc63eaf commit 4883a87

File tree

4 files changed

+71
-37
lines changed

4 files changed

+71
-37
lines changed

MainModule/Server/Core/HTTP.luau

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ return function(Vargs, GetEnv)
3030

3131
if Settings.Trello_Enabled then
3232
HTTP.Trello.API = require(server.Deps.TrelloAPI)(Settings.Trello_AppKey, Settings.Trello_Token)
33+
Logs:AddLog("Script", `Loaded Trello API as {HTTP.Trello.API}`)
3334
end
3435

3536
-- Check HTTP asynchronously
3637
task.spawn(function()
3738
if service.RunService:IsStudio() then
38-
server.HTTP.HttpEnabled = service.HttpService.HttpEnabled
39+
HTTP.HttpEnabled = service.HttpService.HttpEnabled
40+
Logs:AddLog("Script", `Pooled HttpEnabled from service as {HTTP.HttpEnabled}`)
3941
else
4042
local success, res = pcall(service.HttpService.GetAsync, service.HttpService, Variables.HTTPCheckUrl)
41-
server.HTTP.HttpEnabled = not (not success and res:find("Http requests are not enabled.")) or true
43+
HTTP.HttpEnabled = not (not success and res:find("Http requests are not enabled.")) or true
44+
Logs:AddLog("Script", `Pooled HttpEnabled from request as {HTTP.HttpEnabled}. Status {success}`)
4245
end
43-
Logs:AddLog("Script", "Successfully pooled HttpEnabled")
4446
end)
4547

4648
HTTP.Init = nil;

MainModule/Server/Dependencies/TrelloAPI.luau

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ end
4242
local HttpFunctions; HttpFunctions = {
4343
Decode = function(str)
4444
local success, tab = pcall(function()
45-
return HttpService:JSONDecode(str)
45+
return HttpFunctions.HttpService:JSONDecode(str)
4646
end)
4747

4848
if success then
@@ -54,7 +54,7 @@ local HttpFunctions; HttpFunctions = {
5454

5555
Encode = function(tab)
5656
local success, str = pcall(function()
57-
return HttpService:JSONEncode(tab)
57+
return HttpFunctions.HttpService:JSONEncode(tab)
5858
end)
5959

6060
if success then
@@ -65,19 +65,19 @@ local HttpFunctions; HttpFunctions = {
6565
end;
6666

6767
UrlEncode = function(str)
68-
return HttpService:UrlEncode(str)
68+
return HttpFunctions.HttpService:UrlEncode(str)
6969
end;
7070

7171
Request = function(Url, Method, Headers, Body)
72-
local RequestID = HttpService:GenerateGUID(false)
72+
local RequestID = HttpFunctions.HttpService:GenerateGUID(false)
7373
local ran, response = pcall(function()
7474
local Request = {
7575
Url = Url;
7676
Method = Method;
7777
Headers = {
7878
["Content-Type"] = "application/json"
7979
};
80-
Body = HttpService:JSONEncode(Body);
80+
Body = HttpFunctions.HttpService:JSONEncode(Body);
8181
}
8282

8383
Queue[RequestID] = Request
@@ -87,7 +87,7 @@ local HttpFunctions; HttpFunctions = {
8787
end
8888

8989
RateLimit()
90-
return HttpService:RequestAsync(Request)
90+
return HttpFunctions.HttpService:RequestAsync(Request)
9191
end)
9292

9393
Queue[RequestID] = nil
@@ -100,12 +100,12 @@ local HttpFunctions; HttpFunctions = {
100100
end;
101101

102102
Get = function(Url)
103-
local RequestID = HttpService:GenerateGUID(false)
103+
local RequestID = HttpFunctions.HttpService:GenerateGUID(false)
104104
Queue[RequestID] = Url
105105
RateLimit()
106106

107107
local ran, response = pcall(function()
108-
return HttpService:GetAsync(Url, true)
108+
return HttpFunctions.HttpService:GetAsync(Url, true)
109109
end)
110110

111111
Queue[RequestID] = nil
@@ -118,12 +118,12 @@ local HttpFunctions; HttpFunctions = {
118118
end;
119119

120120
Post = function(Url, Data, Type)
121-
local RequestID = HttpService:GenerateGUID(false)
121+
local RequestID = HttpFunctions.HttpService:GenerateGUID(false)
122122
Queue[RequestID] = Url
123123
RateLimit()
124124

125125
local ran, response = pcall(function()
126-
return HttpService:PostAsync(Url, Data, Type)
126+
return HttpFunctions.HttpService:PostAsync(Url, Data, Type)
127127
end)
128128

129129
Queue[RequestID] = nil
@@ -155,12 +155,18 @@ local HttpFunctions; HttpFunctions = {
155155
end
156156
end
157157
end;
158+
159+
HttpService = HttpService;
158160
}
159161

160-
return function(AppKey, Token)
162+
return function(AppKey, Token, HttpService)
161163
AppKey = AppKey or ""
162164
Token = Token or ""
163165

166+
if HttpService and HttpService.IsA and HttpService:IsA("HttpService") then
167+
HttpFunctions.HttpService = HttpService
168+
end
169+
164170
local Arguments = `key={AppKey}&token={Token}`
165171

166172
local GetUrl = function(str)
@@ -175,13 +181,14 @@ return function(AppKey, Token)
175181

176182
local CheckHttp = function()
177183
local enabled, err = pcall(function()
178-
HttpService:GetAsync(GetUrl("members/trello?fields=id"))
184+
HttpFunctions.HttpService:GetAsync(GetUrl("members/trello?fields=id"))
179185
end)
180186

181187
return enabled
182188
end;
183189

184-
if not HttpService.HttpEnabled then -- https://devforum.roblox.com/t/allow-scripts-to-access-httpenabled/73975/
190+
191+
if not HttpFunctions.HttpService.HttpEnabled then -- https://devforum.roblox.com/t/allow-scripts-to-access-httpenabled/73975/
185192
warn("Unable to connect to trello, Http requests are not enabled. Enable them via game settings.")
186193
return
187194
end;
@@ -368,7 +375,7 @@ return function(AppKey, Token)
368375
API[ind] = func
369376
end
370377

371-
API.http = HttpService
378+
API.http = HttpFunctions.HttpService
372379
API.getListObj = API.GetListObject
373380
API.checkHttp = CheckHttp
374381
API.CheckHttp = CheckHttp
@@ -400,7 +407,7 @@ return function(AppKey, Token)
400407
return HttpFunctions.Decode(HttpFunctions.Get(GetUrl(subUrl)))
401408
end
402409
end;
403-
410+
API.httpFunctions = HttpFunctions
404411
API.getUrl = GetUrl
405412

406413
return API

MainModule/Server/Plugins/Misc_Features.luau

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ return function(Vargs, GetEnv)
88
local Functions, Commands, Admin, Anti, Core, HTTP, Logs, Remote, Process, Variables, Deps =
99
server.Functions, server.Commands, server.Admin, server.Anti, server.Core, server.HTTP, server.Logs, server.Remote, server.Process, server.Variables, server.Deps
1010

11-
-- // Remove legacy trello board
12-
local epix_board_index = type(Settings.Trello_Secondary) == "table" and table.find(Settings.Trello_Secondary, "9HH6BEX2")
13-
14-
if epix_board_index then
15-
table.remove(Settings.Trello_Secondary, epix_board_index)
16-
Logs:AddLog("Script", "Removed legacy trello board")
17-
end
18-
1911
--// AutoClean
2012
if Settings.AutoClean then
2113
service.StartLoop("AUTO_CLEAN", Settings.AutoCleanDelay, Functions.CleanWorkspace, true)

MainModule/Server/Plugins/Trello.luau

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
-- Trello plugin
2+
type Card = {id: string, name: string, desc: string, labels: {any}?}
3+
type List = {id: string, name: string, cards: {Card}}
4+
15
return function(Vargs, GetEnv)
26
local server = Vargs.Server;
37
local service = Vargs.Service;
@@ -8,11 +12,13 @@ return function(Vargs, GetEnv)
812

913
HTTP.Trello.Update = function()
1014
if not HTTP.Trello.API or not Settings.Trello_Enabled then
15+
Logs:AddLog("Script", "Not running Trello API update")
1116
return
1217
end
1318

1419
if not HTTP.HttpEnabled then
1520
warn("Unable to connect to Trello. Make sure HTTP Requests are enabled in Game Settings.")
21+
Logs:AddLog("Script", "Not running Trello API update due to HTTP request being disabled.")
1622
return
1723
else
1824
local data = {
@@ -41,6 +47,7 @@ return function(Vargs, GetEnv)
4147
for _, override in HTTP.Trello.Overrides do
4248
if table.find(override.Lists, list.name) then
4349
foundOverride = true
50+
Logs:AddLog("Script", `Found override {list.name} for board {board} with {type(list.cards) == "table" and #list.cards or list.cards} cards.`)
4451
for _, card in list.cards do
4552
override.Process(card, data)
4653
end
@@ -58,6 +65,7 @@ return function(Vargs, GetEnv)
5865
table.insert(users, card.name)
5966
end
6067
data.Ranks[list.name] = users
68+
Logs:AddLog("Script", `Found custom rank override {list.name} for board {board} with {type(list.cards) == "table" and #list.cards or list.cards} cards.`)
6169
end
6270
end
6371
end
@@ -68,15 +76,19 @@ return function(Vargs, GetEnv)
6876
Settings.Trello_Primary,
6977
unpack(Settings.Trello_Secondary)
7078
}
71-
for i,v in boards do
79+
for _, v in boards do
7280
if not v or service.Trim(v) == "" then
7381
continue
7482
end
83+
Logs:AddLog("Script", `Attempting to pool data from Trello board {v}.`)
7584
local ran, err = pcall(grabData, v)
7685
if not ran then
7786
warn("Unable to reach Trello. Ensure your board IDs, Trello key, and token are all correct. If issue persists, try increasing HttpWait in your Adonis settings.")
87+
Logs:AddLog("Script", `Failed to pool data from Trello board {v} due to {err}.`)
7888
success = false
7989
break
90+
else
91+
Logs:AddLog("Script", `Successfully pooled data from Trello board {v}.`)
8092
end
8193
end
8294

@@ -108,7 +120,7 @@ return function(Vargs, GetEnv)
108120
}
109121
end
110122

111-
for i, v in service.GetPlayers() do
123+
for _, v in service.GetPlayers() do
112124
local isBanned, Reason = Admin.CheckBan(v)
113125
if isBanned then
114126
v:Kick(string.format("%s | Reason: %s", Variables.BanMessage, (Reason or "No reason provided")))
@@ -128,8 +140,8 @@ return function(Vargs, GetEnv)
128140

129141
Remote.Commands.TrelloOperation = function(p: Player, args: {[number]: any})
130142
local adminLevel = Admin.GetLevel(p)
131-
132143
local data = args[1]
144+
133145
if data.Action == "MakeCard" then
134146
local command = Commands.MakeCard
135147
if command and Admin.CheckComLevel(adminLevel, command.AdminLevel) then
@@ -141,7 +153,7 @@ return function(Vargs, GetEnv)
141153

142154
for _, overrideList in HTTP.Trello.GetOverrideLists() do
143155
if service.Trim(string.lower(overrideList)) == service.Trim(string.lower(listName)) then
144-
Functions.Hint("You cannot create a card in that list", {p})
156+
Functions.Hint("You cannot create a card in that list", {p}) -- Why??
145157
return
146158
end
147159
end
@@ -172,15 +184,15 @@ return function(Vargs, GetEnv)
172184
TrelloRequired = true;
173185
AdminLevel = "Moderators";
174186
ListUpdater = function(plr: Player)
175-
local tab = table.create(#HTTP.Trello.Bans)
187+
local tab = table.create(#HTTP.Trello.Bans + 2)
188+
tab[1] = `# Banned Users: {#HTTP.Trello.Bans}`
189+
tab[2] = "―――――――――――――――――――――――"
176190
for _, banData in HTTP.Trello.Bans do
177191
table.insert(tab, {
178192
Text = banData.Name,
179193
Desc = banData.Reason or "No reason specified",
180194
})
181195
end
182-
table.insert(tab, 1, `# Banned Users: {#HTTP.Trello.Bans}`)
183-
table.insert(tab, 2, "―――――――――――――――――――――――")
184196
return tab
185197
end;
186198
Function = function(plr: Player, args: {string})
@@ -252,19 +264,17 @@ return function(Vargs, GetEnv)
252264
TrelloRequired = true;
253265
AdminLevel = "HeadAdmins";
254266
Function = function(plr: Player, args: {string})
255-
assert(args[1], "You need to supply a list name.")
256-
257267
local trello = HTTP.Trello.API
258268
if not Settings.Trello_Enabled or trello == nil then return Functions.Hint('Trello has not been configured in settings', {plr}) end
259269

260-
local list = trello.Boards.MakeList(Settings.Trello_Primary, args[1])
270+
local list = trello.Boards.MakeList(Settings.Trello_Primary, assert(args[1], "You need to supply a list name."))
261271
Functions.Hint(`Made list {list.name}`, {plr})
262272
end
263273
}
264274

265275
Commands.ViewList = {
266276
Prefix = Settings.Prefix;
267-
Commands = {"viewlist", "viewtrellolist"};
277+
Commands = {"viewtrellolist", "viewlist"};
268278
Args = {"name"};
269279
Description = "Views the specified Trello list from the primary board set in Settings.";
270280
TrelloRequired = true;
@@ -298,6 +308,29 @@ return function(Vargs, GetEnv)
298308
-- // Initialization
299309
if Settings.Trello_Enabled then
300310
service.StartLoop("TRELLO_UPDATER", Settings.HttpWait, HTTP.Trello.Update, true)
311+
Logs:AddLog("Script", `Trello update loop has been started to run every {Settings.HttpWait} seconds.`)
312+
313+
if not Settings.Trello_AppKey or Settings.Trello_AppKey == "" then
314+
table.insert(server.Messages, {
315+
Level = 301;
316+
Title = "Potential Trello issue!";
317+
Message = "You have enabled Trello without having an AppKey and thus Trello will likely not work! For better behavior it is adviced to also add a Trello Token. Click to see more";
318+
Time = 15;
319+
Icon = "MatIcon://Description";
320+
onClick = (server.Data and server.Data.NightlyMode) and Core.Bytecode([[ -- TODO: Upload image for this tutorial
321+
local window = client.UI.Make("Window", {
322+
Title = "How to change the DataStore key";
323+
Size = {700,300};
324+
Icon = "rbxassetid://7510994359";
325+
})
326+
327+
window:Add("ImageLabel", {
328+
Image = "rbxassetid://1059543904";
329+
})
330+
331+
window:Ready()
332+
]]) or nil})
333+
end
301334
end
302335
Logs:AddLog("Script", "Trello Module Loaded")
303336
end

0 commit comments

Comments
 (0)