summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/discord
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/discord')
-rw-r--r--plugins/discord/init.lua39
1 files changed, 25 insertions, 14 deletions
diff --git a/plugins/discord/init.lua b/plugins/discord/init.lua
index 21ec88ec79a..9e077f5d656 100644
--- a/plugins/discord/init.lua
+++ b/plugins/discord/init.lua
@@ -1,14 +1,16 @@
-- license:BSD-3-Clause
-- copyright-holders:Carl
-local exports = {}
-exports.name = "discord"
-exports.version = "0.0.1"
-exports.description = "Discord presence"
-exports.license = "The BSD 3-Clause License"
-exports.author = { name = "Carl" }
+local exports = {
+ name = "discord",
+ version = "0.0.1",
+ description = "Discord presence",
+ license = "BSD-3-Clause",
+ author = { name = "Carl" } }
local discord = exports
+local reset_subscription, pause_subscription, resume_subscription
+
function discord.startplugin()
local pipe = emu.file("rw")
local json = require("json")
@@ -40,16 +42,20 @@ function discord.startplugin()
if data:find("code", 1, true) then
error("discord: bad RPC reply, " .. data:sub(8) .. "\n")
end
+ if #data == 0 then
+ error("discord: timed out waiting for response\n");
+ end
end
local function update(status)
+ if not pipe then return end
local running = emu.romname() ~= "___empty"
local state = not running and "In menu" or status
- local details = running and manager:machine():system().description or nil
+ local details = running and manager.machine.system.description or nil
if emu.softname() ~= "" then
- for name, dev in pairs(manager:machine().images) do
- if dev:longname() then
- details = details .. " (" .. dev:longname() .. ")"
+ for name, dev in pairs(manager.machine.images) do
+ if dev.software_longname then
+ details = details .. " (" .. dev.software_longname .. ")"
break
end
end
@@ -78,27 +84,32 @@ function discord.startplugin()
local res = pipe:read(100)
data = data .. res
until #res == 0 and #data > 0 or time + 1 < os.time()
+ if #data == 0 then
+ emu.print_verbose("discord: timed out waiting for response, closing connection");
+ pipe = nil
+ end
--print(data)
end
do
local stat, err = pcall(init)
if not stat then
- emu.print_error(err)
+ emu.print_verbose(err)
+ pipe = nil
return
end
end
- emu.register_start(function()
+ reset_subscription = emu.add_machine_reset_notifier(function ()
starttime = os.time()
update("Playing")
end)
- emu.register_pause(function()
+ pause_subscription = emu.add_machine_pause_notifier(function ()
update("Paused")
end)
- emu.register_resume(function()
+ resume_subscription = emu.add_machine_resume_notifier(function ()
update("Playing")
end)
end