Skip to content

Commit

Permalink
Merge pull request #9 from RoguedBear/feature-0.3.0
Browse files Browse the repository at this point in the history
Feature 0.3.0
  • Loading branch information
RoguedBear committed Feb 1, 2022
2 parents 2de1ad9 + f2e7f12 commit 5763a1d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "betterdiscordplugin-autoidleonafk",
"version": "0.2.0",
"version": "0.3.0",
"description": "Automatically updates your discord status to 'idle' when you haven't opened your discord client for more than 5 minutes",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
Binary file modified readme_assets/settings_panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 31 additions & 6 deletions release/AutoIdleOnAFK.plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @name AutoIdleOnAFK
* @authorLink https://github.com/RoguedBear
* @version 0.2.0
* @version 0.3.0
* @website https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK
* @source https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK/releases/latest/download/AutoIdleOnAFK.plugin.js
*/
Expand Down Expand Up @@ -30,7 +30,7 @@
@else@*/

module.exports = (() => {
const config = {"info":{"name":"AutoIdleOnAFK","authors":[{"name":"RoguedBear","github_username":"RoguedBear"}],"authorLink":"https://github.com/RoguedBear","version":"0.2.0","description":"Automatically updates your discord status to 'idle' when you haven't opened your discord client for more than 5 minutes.\nPlugin only works when your status is 'online' and you are not in a voice channel. \n\nFor Bugs or Feature Requests open an issue on my Github","github":"https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK","github_raw":"https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK/releases/latest/download/AutoIdleOnAFK.plugin.js"},"changelog":[{"type":"added","title":"What's New?","items":["added `Do Not Disturb` as an AFK status option"]},{"type":"fixed","title":"Fixed","items":["fixed an undocumented bug: Status is changed back to `online` from AFK when you join a VC (and then unfocus discord)"]},{"type":"improved","title":"Improved/optimised","items":["avoid repeated webpack searches by searching & storing the modules on startup"]},{"title":"~~~~~~~~~~~~~~~","type":"progress","items":["If you find any bugs or have some feature requests, feel free to open an issue on this plugin's Github","https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK/issues","(PS: thank you codeSpicer & Windy for beta testing the plugin out 👀)"]}],"main":"index.js","DEBUG":false,"DEBUG_ActuallyChangeStatus":false,"defaultConfig":[{"type":"radio","name":"Change Status To:","note":"the status selected will be switched to when AFK. default: Idle","id":"afkStatus","value":"idle","options":[{"name":"Idle","value":"idle"},{"name":"Invisible","value":"invisible"},{"name":"Do Not Disturb","value":"dnd"}]},{"type":"slider","name":"AFK Timeout (minutes)","note":"minutes to wait before changing your status to Idle/Invisible","id":"afkTimeout","value":5,"defaultValue":5,"min":5,"max":30,"units":"min","markers":[5,10,15,20,25,30]},{"type":"slider","name":"Back To Online Delay (Grace/Cooldown Period)","note":"seconds to wait before changing your status back to Online. if you close or unfocus discord window, status will not be changed","id":"backToOnlineDelay","defaultValue":10,"value":10,"min":5,"max":120,"units":"s","markers":[5,10,30,60,90,120]}]};
const config = {"info":{"name":"AutoIdleOnAFK","authors":[{"name":"RoguedBear","github_username":"RoguedBear"}],"authorLink":"https://github.com/RoguedBear","version":"0.3.0","description":"Automatically updates your discord status to 'idle' when you haven't opened your discord client for more than 5 minutes.\nPlugin only works when your status is 'online' and you are not in a voice channel. \n\nFor Bugs or Feature Requests open an issue on my Github","github":"https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK","github_raw":"https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK/releases/latest/download/AutoIdleOnAFK.plugin.js"},"changelog":[{"type":"added","title":"What's New?","items":["A settings toggle that changes status from AFK to `online` even if this plugin didn't make the change. Useful for multiple devices. *[Disabled by default]* \n(thanks Bobbyl140!)","A settings toggle to disable toast notification `\"Changing status back to online\"`. \n*[notifications Enabled by default]*"]},{"title":"~~~~~~~~~~~~~~~","type":"progress","items":["If you find any bugs or have some feature requests, feel free to open an issue on this plugin's Github","https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK/issues"]}],"main":"index.js","DEBUG":false,"DEBUG_ActuallyChangeStatus":false,"defaultConfig":[{"type":"radio","name":"Change Status To:","note":"the status selected will be switched to when AFK. default: Idle","id":"afkStatus","value":"idle","options":[{"name":"Idle","value":"idle"},{"name":"Invisible","value":"invisible"},{"name":"Do Not Disturb","value":"dnd"}]},{"type":"slider","name":"AFK Timeout (minutes)","note":"minutes to wait before changing your status to Idle/Invisible","id":"afkTimeout","value":5,"defaultValue":5,"min":5,"max":30,"units":"min","markers":[5,10,15,20,25,30]},{"type":"slider","name":"Back To Online Delay (Grace/Cooldown Period)","note":"seconds to wait before changing your status back to Online. if you close or unfocus discord window, status will not be changed","id":"backToOnlineDelay","defaultValue":10,"value":10,"min":5,"max":120,"units":"s","markers":[5,10,30,60,90,120]},{"type":"switch","name":"Always Revert To Online","note":"Come back online even if this plugin didn't change your status. Useful for multiple devices.","id":"alwaysOnline","value":false,"defaultValue":false},{"type":"switch","name":"Show toast messages?","note":"toggles the visibility of \"Changing status back to online\" toast message","id":"showToasts","defaultValue":true,"value":true}]};

return !global.ZeresPluginLibrary ? class {
constructor() {this._config = config;}
Expand Down Expand Up @@ -131,6 +131,9 @@ module.exports = (() => {
var inVoiceChannelAndIdleSetByPlugin =
this.inVoiceChannel() && __afkSetByPlugin;

var inVoiceChannelAndAlwaysOnlineEnabled =
this.inVoiceChannel() && this.settings.alwaysOnline;

if (this.onlineStatusAndNotInVC()) {
var _timeout_ms =
this.settings.afkTimeout * (DEBUG ? 2 : 60) * 1000;
Expand All @@ -149,13 +152,13 @@ module.exports = (() => {
} else if (
// if the user is in a VC, idle was set by plugin &
// their current status == afkStatus
inVoiceChannelAndIdleSetByPlugin &&
(inVoiceChannelAndIdleSetByPlugin ||
// OR, is user in VC and always online is enabled
inVoiceChannelAndAlwaysOnlineEnabled) &&
this.currentStatus() == this.settings.afkStatus
) {
this.updateStatus("online");
BdApi.showToast(
"Changing status back to online, You are in VC"
);
this.showToast("Changing status back to online, You are in VC");
BdApi.saveData(
this._config.info.name,
this.keyIdleSetByPlugin,
Expand Down Expand Up @@ -187,7 +190,19 @@ module.exports = (() => {
this.currentStatus() === this.settings.afkStatus &&
__afkSetByPlugin === true;

var statusIsAFKAndAlwaysOnlineIsTrue =
this.currentStatus() === this.settings.afkStatus &&
this.settings.alwaysOnline === true;

if (statusIsAFKAndWasSetByPlugin) {
this.showToast("Changing status back to online");
this.updateStatus("online");
BdApi.saveData(
this._config.info.name,
this.keyIdleSetByPlugin,
false
);
} else if (statusIsAFKAndAlwaysOnlineIsTrue) {
BdApi.showToast("Changing status back to online");
this.updateStatus("online");
BdApi.saveData(
Expand Down Expand Up @@ -264,6 +279,16 @@ module.exports = (() => {
status: toStatus,
});
}

/**
* shows toast message based on showToast settings
* @param {string} msg
*/
showToast(msg) {
if (this.settings.showToasts) {
BdApi.showToast(msg);
}
}
};
};
return plugin(Plugin, Api);
Expand Down
38 changes: 20 additions & 18 deletions src/AutoIdleOnAFK/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"authorLink": "https://github.com/RoguedBear",
"version": "0.2.0",
"version": "0.3.0",
"description": "Automatically updates your discord status to 'idle' when you haven't opened your discord client for more than 5 minutes.\nPlugin only works when your status is 'online' and you are not in a voice channel. \n\nFor Bugs or Feature Requests open an issue on my Github",
"github": "https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK",
"github_raw": "https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK/releases/latest/download/AutoIdleOnAFK.plugin.js"
Expand All @@ -18,30 +18,16 @@
"type": "added",
"title": "What's New?",
"items": [
"added `Do Not Disturb` as an AFK status option"
]
},
{
"type": "fixed",
"title": "Fixed",
"items": [
"fixed an undocumented bug: Status is changed back to `online` from AFK when you join a VC (and then unfocus discord)"
]
},
{
"type": "improved",
"title": "Improved/optimised",
"items": [
"avoid repeated webpack searches by searching & storing the modules on startup"
"A settings toggle that changes status from AFK to `online` even if this plugin didn't make the change. Useful for multiple devices. *[Disabled by default]* \n(thanks Bobbyl140!)",
"A settings toggle to disable toast notification `\"Changing status back to online\"`. \n*[notifications Enabled by default]*"
]
},
{
"title": "~~~~~~~~~~~~~~~",
"type": "progress",
"items": [
"If you find any bugs or have some feature requests, feel free to open an issue on this plugin's Github",
"https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK/issues",
"(PS: thank you codeSpicer & Windy for beta testing the plugin out 👀)"
"https://github.com/RoguedBear/BetterDiscordPlugin-AutoIdleOnAFK/issues"
]
}
],
Expand Down Expand Up @@ -107,6 +93,22 @@
90,
120
]
},
{
"type": "switch",
"name": "Always Revert To Online",
"note": "Come back online even if this plugin didn't change your status. Useful for multiple devices.",
"id": "alwaysOnline",
"value": false,
"defaultValue": false
},
{
"type": "switch",
"name": "Show toast messages?",
"note": "toggles the visibility of \"Changing status back to online\" toast message",
"id": "showToasts",
"defaultValue": true,
"value": true
}
]
}
33 changes: 29 additions & 4 deletions src/AutoIdleOnAFK/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ module.exports = (Plugin, Library) => {
var inVoiceChannelAndIdleSetByPlugin =
this.inVoiceChannel() && __afkSetByPlugin;

var inVoiceChannelAndAlwaysOnlineEnabled =
this.inVoiceChannel() && this.settings.alwaysOnline;

if (this.onlineStatusAndNotInVC()) {
var _timeout_ms =
this.settings.afkTimeout * (DEBUG ? 2 : 60) * 1000;
Expand All @@ -147,13 +150,13 @@ module.exports = (Plugin, Library) => {
} else if (
// if the user is in a VC, idle was set by plugin &
// their current status == afkStatus
inVoiceChannelAndIdleSetByPlugin &&
(inVoiceChannelAndIdleSetByPlugin ||
// OR, is user in VC and always online is enabled
inVoiceChannelAndAlwaysOnlineEnabled) &&
this.currentStatus() == this.settings.afkStatus
) {
this.updateStatus("online");
BdApi.showToast(
"Changing status back to online, You are in VC"
);
this.showToast("Changing status back to online, You are in VC");
BdApi.saveData(
this._config.info.name,
this.keyIdleSetByPlugin,
Expand Down Expand Up @@ -185,7 +188,19 @@ module.exports = (Plugin, Library) => {
this.currentStatus() === this.settings.afkStatus &&
__afkSetByPlugin === true;

var statusIsAFKAndAlwaysOnlineIsTrue =
this.currentStatus() === this.settings.afkStatus &&
this.settings.alwaysOnline === true;

if (statusIsAFKAndWasSetByPlugin) {
this.showToast("Changing status back to online");
this.updateStatus("online");
BdApi.saveData(
this._config.info.name,
this.keyIdleSetByPlugin,
false
);
} else if (statusIsAFKAndAlwaysOnlineIsTrue) {
BdApi.showToast("Changing status back to online");
this.updateStatus("online");
BdApi.saveData(
Expand Down Expand Up @@ -262,5 +277,15 @@ module.exports = (Plugin, Library) => {
status: toStatus,
});
}

/**
* shows toast message based on showToast settings
* @param {string} msg
*/
showToast(msg) {
if (this.settings.showToasts) {
BdApi.showToast(msg);
}
}
};
};

0 comments on commit 5763a1d

Please sign in to comment.