Last active
December 28, 2023 19:52
-
-
Save tooruu/9ede33a481a188cecbff5ab348caa1f4 to your computer and use it in GitHub Desktop.
Gain marriage XP in Holo bot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @name MarriageBooster | |
* @author tooru | |
* @description Gain marriage XP in Holo bot. | |
* @version 2.3 | |
*/ | |
let timeoutId | |
const configurables = { | |
token: "Token", | |
sessionId: "Session ID", | |
guildId: "Guild ID", | |
channelId: "Channel ID", | |
targetId: "Target user ID", | |
reactType: "Reaction type", | |
} | |
const settings = BdApi.Data.load("MarriageBooster", "settings") || {} | |
const reactions = BdApi.Data.load("MarriageBooster", "reactions") || {xpTier: 0} | |
const headers = {"Content-Type": "application/json", Authorization: settings.token} | |
const payload = { | |
type: 2, | |
application_id: "791766309611634698", | |
guild_id: settings.guildId, | |
channel_id: settings.channelId, | |
session_id: settings.sessionId, | |
data: { | |
version: "1078434589577592992", | |
id: "1014316902560059454", | |
name: "react", | |
options: [ | |
{ | |
type: 1, | |
name: settings.reactType, | |
options: [{type: 6, name: "target", value: settings.targetId}], | |
}, | |
], | |
}, | |
} | |
async function emitReaction() { | |
const r = await fetch("https://discord.com/api/v10/interactions", { | |
method: "POST", | |
headers: headers, | |
body: JSON.stringify(payload), | |
}) | |
return r.ok | |
} | |
function updatePayload(key, value) { | |
switch (key) { | |
case "token": | |
headers.Authorization = value | |
break | |
case "targetId": | |
payload.data.options[0].options[0].value = value | |
break | |
case "reactType": | |
payload.data.options[0].name = value | |
break | |
default: | |
payload[key] = value | |
} | |
} | |
function buildTextfieldSetting(text, key, value = "") { | |
const setting = document.createElement("div") | |
const label = Object.assign(document.createElement("span"), {textContent: text}) | |
const input = Object.assign(document.createElement("input"), { | |
type: "text", | |
name: key, | |
value: value, | |
oninput: () => { | |
updatePayload(key, (settings[key] = input.value)) | |
BdApi.Data.save("MarriageBooster", "settings", settings) | |
}, | |
}) | |
setting.append(label, input) | |
return setting | |
} | |
const verifySettings = () => Object.keys(configurables).every(key => key in settings) | |
function calculateTimeout() { | |
if (!reactions.lastReaction) return 0 | |
return reactions.lastReaction - Date.now() + (reactions.xpTier < 5 ? 10000 : 300000) | |
} | |
async function main() { | |
if (!verifySettings()) { | |
BdApi.UI.alert("MarriageBooster error", "Please fill in your settings") | |
return | |
} | |
if (!(await emitReaction())) { | |
BdApi.UI.alert("MarriageBooster error", "Please verify your settings") | |
return | |
} | |
const now = Date.now() | |
reactions.lastReaction = now | |
if (reactions.xpBonusResetCooldownStart <= now - 3600000) reactions.xpTier = 0 | |
if (++reactions.xpTier === 1) reactions.xpBonusResetCooldownStart = now | |
BdApi.Data.save("MarriageBooster", "reactions", reactions) | |
timeoutId = setTimeout(main, calculateTimeout()) | |
} | |
module.exports = () => ({ | |
start() { | |
if (reactions.xpBonusResetCooldownStart <= Date.now() - 3600000) reactions.xpTier = 0 | |
timeoutId = setTimeout(main, calculateTimeout()) | |
}, | |
stop() { | |
clearTimeout(timeoutId) | |
}, | |
getSettingsPanel() { | |
const settingsPanel = document.createElement("div") | |
for (const [key, description] of Object.entries(configurables)) | |
settingsPanel.append(buildTextfieldSetting(description, key, settings[key])) | |
return settingsPanel | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment