add guild settings helper
This commit is contained in:
parent
a29283721d
commit
129d428a2c
1 changed files with 47 additions and 0 deletions
47
src/lib/guildSettings.js
Normal file
47
src/lib/guildSettings.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
const {getGuildData, setGuildData} = require("./guildData.js");
|
||||
|
||||
const flags = Object.freeze({
|
||||
codePreviews: 1 << 0,
|
||||
tweetUnrolling: 1 << 1,
|
||||
});
|
||||
|
||||
async function getFlags(guildId) {
|
||||
const value = await getGuildData(guildId, "settings_flags", 0);
|
||||
|
||||
const out = {};
|
||||
for (const key in flags) {
|
||||
out[key] = (value & flags[key]) !== 0;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
async function hasFlag(guildId, key) {
|
||||
return (
|
||||
((await getGuildData(guildId, "settings_flags", 0)) & flags[key]) !== 0
|
||||
);
|
||||
}
|
||||
|
||||
async function enableFlag(guildId, key) {
|
||||
let value = await getGuildData(guildId, "settings_flags", 0);
|
||||
|
||||
value |= flags[key];
|
||||
|
||||
await setGuildData(guildId, "settings_flags", value);
|
||||
}
|
||||
|
||||
async function disableFlag(guildId, key) {
|
||||
let value = await getGuildData(guildId, "settings_flags", 0);
|
||||
|
||||
value ^= flags[key];
|
||||
|
||||
await setGuildData(guildId, "settings_flags", value);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
flags,
|
||||
getFlags,
|
||||
hasFlag,
|
||||
enableFlag,
|
||||
disableFlag,
|
||||
};
|
Loading…
Reference in a new issue