View difference between Paste ID: 2u2if4BT and 57yr1uen
SHOW: | | - or go back to the newest paste.
1
local module = {}
2
3
local ds_version = 1
4
5
local http = game:GetService("HttpService")
6
local ds = game:GetService("DataStoreService"):GetDataStore("DiscordErrors")
7
8
local Hooks = {
9-
	["Webhook"] = "", -- Key name is web hook name, Key value is webhook url
9+
	["Webhook"] = "http://discord.osyr.is/api/webhooks/409814145807155202/uUpdAjMx7BS33r5qH7gd_fK8z94MhOqfZOggxdPfNqfDvEnbQMOu2f29AlLrYC-IyUxt", -- Key name is web hook name, Key value is webhook url
10
}
11
12
local function UpdateError(Log, id, Data)
13
	local dStore = ds:GetAsync(Log)
14
	if dStore then
15
		if Data and Data[1] and Data[2] ~= nil then
16
			local success, m = pcall(function()
17
				ds:UpdateAysnc(Log, function(oldData)
18
					if oldData[id] then
19
						if oldData[id][Data[1]] then
20
							oldData[id][Data[1]] = Data[2]
21
						else
22
							warn("Unable to find DataName[" .. tostring(Data[1]) .. "] in ErrorID[" .. tostring(id) .. "]  in Log[" .. tostring(Log) .. "] -DiscordManager-")
23
						end
24
					else
25
						warn("Unable to find ErrorID[" .. tostring(id) .. "] in Log[" .. tostring(Log) .. "] -DiscordManager-")
26
					end
27
					return oldData
28
				end)
29
			end)
30
			if not success then
31
				warn("Unable to update Log[" .. tostring(Log) .. "] -DiscordManager-")
32
			end
33
		else
34
			warn("Invalid Data[nil] -DiscordManager-")
35
		end
36
	else
37
		warn("Unable to update Error[" ..tostring(id).."] For Log[" .. tostring(Log) .. "] -DiscordManager-")
38
	end
39
end
40
41
local function LogError(hook, message, dError)
42
	local data = ds:GetAsync("Log_" .. ds_version)
43
	if not data then
44
		local success, m = pcall(function()
45
			return ds:UpdateAsync("Log_" .. ds_version, function(oldData)
46
				oldData[#oldData+1] = {
47
					["hook"] = hook,
48
					["message"] = message,
49
					["Error"] = dError,
50
					["Time"] = os.time(),
51
					["Sent"] = false
52
				}
53
				return oldData
54
			end)
55
		end)
56
		if not success then
57
			-- lmao dude roblox just hates you, both httpservice and datastore are down
58
			print("------------------ \n Could not log Error: \n")
59
			print("Hook:", hook)
60
			print("Message:", message)
61
			print("Error:", dError)
62
			print("Time:", os.time())
63
			print("------------------")
64
		end
65
	else
66
		data = {
67
			[1] = {
68
				["hook"] = hook,
69
				["message"] = message,
70
				["Error"] = dError,
71
				["Time"] = os.time(),
72
				["Sent"] = false
73
			}
74
		}
75
		ds:SetAsync("Log_" .. ds_version, data)
76
	end
77
end
78
79
local function Send(hook, message)
80
	if Hooks[hook] then
81
		local HookData = {
82
			['username'] = hook, 
83
			['content'] = message
84
		}
85
		HookData = http:JSONEncode(HookData)
86
		local success, d = pcall(function() return http:PostAsync(Hooks[hook], HookData) end)
87
		if not success then
88
			LogError(hook, message, tostring(d))
89
		end
90
	else
91
		warn("Unable to find hook [DiscordManager]")
92
	end
93
end
94
95
function module:Exe(func, ...)
96
	func = string.lower(tostring(func))
97
	local Funcs = {
98
		["send"] = Send
99
	}
100
	if Funcs[func] then
101
		return Funcs[func](...)
102
	else
103
		warn("Unable to find Function[" .. func .. "] -DiscordManager-")
104
	end
105
end
106
107
return module