Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Store webhook token here so you do not have to enter it every time
- webhook_id = "300699421580984320"
- webhook_token = "7WqjfFDcVVyUfQZ8-S1WqxdBf7ZxeVHWLxdy8Joq6Wj2za-_dx_SZzp-b7aTC-3ZraT6"
- nicks = {}
- http_header =
- {['ContentType'] = "application/json",
- }
- function say(_tText)
- _tText = _tText or ""
- peripheral.call("left","say",_tText)
- end
- if not fs.exists("nicks.tbl") then
- file = fs.open("nicks.tbl","w")
- file.write("{}")
- file.close()
- end
- if not fs.exists("jsonapi") then
- shell.run("pastebin get 4nRg9CHU jsonapi")
- end
- os.loadAPI("jsonapi")
- function hasNick(_sUser)
- if nicks[_sUser] then
- return true,nicks[_sUser]
- else
- return false,nil
- end
- end
- function reload()
- file = fs.open("nicks.tbl","r")
- nickFile = textutils.unserialize(file.readAll())
- file.close()
- nicks = nickFile
- end
- function flush()
- file = fs.open("nicks.tbl","w")
- file.write(textutils.serialize(nicks))
- file.close()
- end
- if type(nicks) ~= "table" then
- print("The file went corrupt!")
- nicks = {}
- flush()
- reload()
- end
- function http_post(_sURL,_sFORM)
- local httphandle = http.post("http://smaller.hol.es/proxy.php?url=" .. _sURL,_sFORM,http_header)
- local httpread = httphandle.readAll()
- httphandle.close()
- return httpread
- end
- function http_get(_sURL)
- local httphandle = http.get("http://smaller.hol.es/proxy.php?url=" .. _sURL,http_header)
- local httpread = httphandle.readAll()
- httphandle.close()
- return httpread
- end
- if not webhook_id or #webhook_id ~= 18 then
- print("Webhook ID:")
- while true do
- webhook_id = io.read()
- if #webhook_id ~= 18 then
- print("Invalid bot id")
- else
- break
- end
- end
- end
- if not webhook_token or #webhook_token ~= 68 then
- print("Webhook Token:")
- while true do
- webhook_token = io.read()
- if #webhook_token ~= 68 then
- print("Invalid bot token")
- else
- break
- end
- end
- end
- print("Connecting...")
- webhook_info = jsonapi.decode(http_get("https://discordapp.com/api/webhooks/" .. webhook_id .. "/" .. webhook_token))
- if type(webhook_info) ~= "table" then
- printError("A fatal error has occured!")
- printError(http_get("https://discordapp.com/api/webhooks/" .. webhook_id .. "/" .. webhook_token))
- return
- elseif webhook_info.code then
- print("An error occured:")
- print("Code: " .. webhook_info.code .. ": " .. webhook_info.message)
- return
- end
- function discord_say(_sText) -- send message c:
- return http_post("https://discordapp.com/api/webhooks/" .. webhook_id .. "/" .. webhook_token,"content=" .. _sText)
- end
- discord_say("***:ok_hand: DiscordBridge 1.0 :ok_hand:***")
- print("loaded")
- reload()
- while true do
- event,arg1,arg2,arg3 = os.pullEvent()
- if event == "chat_message" then
- if string.sub(arg2,1,1) == "+" then
- print("Command")
- local args = {}
- for word in arg2:gmatch("%w+") do table.insert(args,word) end
- if args[1] == "setnick" then
- if args[2] then
- nicks[arg1] = args[2]
- say("Set " .. arg1 .. "'s nick to '" .. args[2] .. "'")
- discord_say("Set **" .. arg1 .. "**'s nick to " .. args[2])
- print("Set " .. arg1 .. " nick to " .. args[2])
- flush()
- reload()
- end
- end
- else
- gotNick,nick = hasNick(arg1)
- if gotNick then
- arg1 = nick
- end
- print(arg1 .. ": " .. arg2)
- discord_say("**" .. arg1 .. "**: " .. arg2)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement