Plugin
CustomIdle
Allows you to set the time before Discord goes idle (or disable auto-idle)
1
import { currentNotice, noticesQueue, popNotice, showNotice } from "@api/Notices";2
import { definePluginSettings } from "@api/Settings";3
import { Devs } from "@utils/constants";4
import definePlugin, { makeRange, OptionType } from "@utils/types";5
import { FluxDispatcher } from "@webpack/common";6
7
const settings = definePluginSettings({8
idleTimeout: {9
description: "Minutes before Discord goes idle (0 to disable auto-idle)",10
type: OptionType.SLIDER,11
markers: makeRange(0, 60, 5),12
default: 10,13
stickToMarkers: false,14
restartNeeded: true class="ts-cmt">// Because of the setInterval patch15
},16
remainInIdle: {17
description: "When you come back to Discord, remain idle until you confirm you want to go online",18
type: OptionType.BOOLEAN,19
default: true20
}21
});22
23
export default definePlugin({24
name: "CustomIdle",25
description: "Allows you to set the time before Discord goes idle (or disable auto-idle)",26
tags: ["Activity", "Customisation"],27
authors: [Devs.newwares],28
settings,29
patches: [30
{31
find: 039;type:"IDLE",idle:039;,32
replacement: [33
{34
match: /(?<=Date\.now\(\)-\i>)\i\.\i\|\|/,35
replace: "$self.getIdleTimeout()||"36
},37
{38
match: /Math\.min\((\i\*\i\.\i\.\i\.SECOND),\i\.\i\)/,39
replace: "$1" class="ts-cmt">// Decouple idle from afk (phone notifications will remain at user setting or 10 min maximum)40
},41
{42
match: /\i\.\i\.dispatch\({type:"IDLE",idle:!1}\)/,43
replace: "$self.handleOnline()"44
}45
]46
}47
],48
49
handleOnline() {50
if (!settings.store.remainInIdle) {51
FluxDispatcher.dispatch({52
type: "IDLE",53
idle: false54
});55
return;56
}57
58
const backOnlineMessage = "Welcome back! Click the button to go online. Click the X to stay idle until reload.";59
if (60
currentNotice?.[1] === backOnlineMessage ||61
noticesQueue.some(([, noticeMessage]) => noticeMessage === backOnlineMessage)62
) return;63
64
showNotice(backOnlineMessage, "Exit idle", () => {65
popNotice();66
FluxDispatcher.dispatch({67
type: "IDLE",68
idle: false69
});70
});71
},72
73
getIdleTimeout() { class="ts-cmt">// milliseconds, default is 6e574
const { idleTimeout } = settings.store;75
return idleTimeout === 0 ? Infinity : idleTimeout * 60000;76
}77
});78