Skip to content

Commit

Permalink
refactor: replace process.env with Deno.env.get for environment varia…
Browse files Browse the repository at this point in the history
…ble access
  • Loading branch information
renhiyama committed Nov 2, 2024
1 parent 152190a commit 0ecfd76
Show file tree
Hide file tree
Showing 31 changed files with 195 additions and 917 deletions.
800 changes: 39 additions & 761 deletions deno.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/bot/commands/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (client.owners.some((x) => x === message.author.id)) {
let code = eval(`(async()=>{${codein}})()`);
if (typeof code !== "string")
code = (await import("util")).inspect(code, { depth: 0 });
if (code == process.env.TOKEN) {
if (code == Deno.env.get("TOKEN") {
code =
"You're too intelligent right?\nBut im intelligent <:smart:794453219605610509>";
}
Expand Down
4 changes: 2 additions & 2 deletions src/bot/commands/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ if (message.channel.type == "DM") {
message.reply({ content: "📨 Successfully Mailed The Team!" });
const at = message.attachments.array();

fetch(`${process.env.DOMAIN}/api/client/log`, {
fetch(`${Deno.env.get("DOMAIN")}/api/client/log`, {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
secret: process.env.SECRET,
secret: Deno.env.get("SECRET"),
channel: "838067036080963584",
title: `[MAIL] Incoming 📥`,
desc: `**From:** ${message.author.tag} (${
Expand Down
4 changes: 2 additions & 2 deletions src/bot/commands/pending.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Cache.Bots.find({ added: false }).then(async (bots) => {
if (args.includes("-t")) {
let msg = `> Showing the Oldest ${bots.length} Bot(s) for testing:\n`;
for await (const bot of bots) {
await fetch(`${process.env.DOMAIN}/api/client/mainserver/${bot.id}`)
await fetch(`${Deno.env.get("DOMAIN")}/api/client/mainserver/${bot.id}`)
.then((r) => r.json())
.then(async (d) => {
if (!d.condition) {
Expand All @@ -20,7 +20,7 @@ Cache.Bots.find({ added: false }).then(async (bots) => {
} else {
let msg = `> Showing the Oldest ${bots.length} Bot(s) that are not added to this server:\n`;
for await (const bot of bots) {
await fetch(`${process.env.DOMAIN}/api/client/mainserver/${bot.id}`)
await fetch(`${Deno.env.get("DOMAIN")}/api/client/mainserver/${bot.id}`)
.then((r) => r.json())
.then(async (d) => {
if (!d.condition) {
Expand Down
2 changes: 1 addition & 1 deletion src/bot/events/guildMemberUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ client.on("guildMemberUpdate", (olduser, newuser) => {
Users.findOne({ id: newuser.id }).then((user) => {
if (!user) {
} else {
fetch(`${process.env.DOMAIN}/api/client/users/${user.id}`)
fetch(`${Deno.env.get("DOMAIN")}/api/client/users/${user.id}`)
.then((r) => r.json())
.then((u) => {
if (
Expand Down
4 changes: 2 additions & 2 deletions src/bot/events/presenceUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ client.on("presenceUpdate", (olduserr, newuser) => {
.setTitle(`${bot.tag} is OFFLINE`)
.setColor("#36393f")
.setDescription(`${bot.username} (${bot.id}) is Offline!`)
.setURL(`${process.env.DOMAIN}/bots/${bot.id}`)
.setURL(`${Deno.env.get("DOMAIN")}/bots/${bot.id}`)
.setTimestamp()
.setThumbnail(bot.avatarURL);

Expand All @@ -39,7 +39,7 @@ client.on("presenceUpdate", (olduserr, newuser) => {
.setTitle(`${bot.tag} is ONLINE!`)
.setColor("#FEF40E")
.setDescription(`${bot.username} (${bot.id}) is back Online!`)
.setURL(`${process.env.DOMAIN}/bots/${bot.id}`)
.setURL(`${Deno.env.get("DOMAIN")}/bots/${bot.id}`)
.setTimestamp()
.setThumbnail(bot.avatarURL);

Expand Down
22 changes: 11 additions & 11 deletions src/bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ var client = new Discord.Client({
intents: [new Discord.Intents(32767)],
allowedMentions: { parse: ["users", "roles"], repliedUser: true },
});
if (process.env.TOKEN)
client.login(process.env.TOKEN);
if (Deno.env.get("TOKEN"))
client.login(Deno.env.get("TOKEN"));
globalThis.privatebot = client;
import { fetch } from "rovel.js";
import { owners, emojiapprovers, mods, contributors } from "../data.js";
Expand All @@ -16,7 +16,7 @@ client.emojiapprovers = emojiapprovers;
client.mods = mods;
client.contributors = contributors;
client.commands = [];
const prefix = process.env.PRIVATE_PREFIX;
const prefix = Deno.env.get("PRIVATE_PREFIX");

function getMention(mention) {
if (!mention) return;
Expand Down Expand Up @@ -85,9 +85,9 @@ function DiscordLog({ title, desc, color }) {
.setTitle(title)
.setColor(color || "#5865F2")
.setDescription(desc)
.setURL(process.env.DOMAIN)
.setURL(Deno.env.get("DOMAIN"))
.setTimestamp()
.setThumbnail(`${process.env.DOMAIN}/favicon.ico`);
.setThumbnail(`${Deno.env.get("DOMAIN")}/favicon.ico`);

client.guilds.cache
.get("602906543356379156")
Expand All @@ -105,7 +105,7 @@ router.post("/eval", (req, res) => {
if (!req.body.secret) {
res.json({ err: "no_secret" });
} else {
if (req.body.secret == process.env.SECRET) {
if (req.body.secret == Deno.env.get("SECRET")) {
const resp = eval(`(async()=>{${req.body.code}})()`);
res.json({ resp });
} else {
Expand Down Expand Up @@ -212,7 +212,7 @@ router.get("/contributors/:id", (req, res) => {
});
router.post("/log", (req, res) => {
try {
if (req.body.secret === process.env.SECRET) {
if (req.body.secret === Deno.env.get("SECRET")) {
if (req.body.desc.length > 2000) {
req.body.desc = req.body.desc.slice(0, 1997) + "...";
}
Expand All @@ -221,11 +221,11 @@ router.post("/log", (req, res) => {
.setColor(req?.body?.color || "#5865F2")
.setDescription(req?.body?.desc || "No description provided.\n:/&&")
.setImage(req?.body?.attachment)
.setURL(req?.body?.url || process.env.DOMAIN)
.setURL(req?.body?.url || Deno.env.get("DOMAIN"))
.setTimestamp()
.setThumbnail(
req?.body?.img ||
`${process.env.DOMAIN}/assets/img/bot/logo-512.png`
`${Deno.env.get("DOMAIN")}/assets/img/bot/logo-512.png`
);
if (req.body.channel != "private") {
client.guilds.cache
Expand All @@ -251,11 +251,11 @@ router.post("/log", (req, res) => {
req.body.desc || "No description provided.\n:/&&"
)
.setImage(req.body.attachment)
.setURL(req.body.url || process.env.DOMAIN)
.setURL(req.body.url || Deno.env.get("DOMAIN"))
.setTimestamp()
.setThumbnail(
req.body.img ||
`${process.env.DOMAIN}/assets/img/bot/logo-512.png`
`${Deno.env.get("DOMAIN")}/assets/img/bot/logo-512.png`
)
.setFooter(
`${client.users.cache.get(owner).username
Expand Down
2 changes: 1 addition & 1 deletion src/bot/publicbot/commands/bal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if (!args.length) {
if (!user)
message.reply({
content:
`Oi! You need to login to get an account on RDL!\nLogin link:\n${process.env.DOMAIN}/login`,
`Oi! You need to login to get an account on RDL!\nLogin link:\n${Deno.env.get("DOMAIN")}/login`,
});
else {
message.reply({
Expand Down
2 changes: 1 addition & 1 deletion src/bot/publicbot/commands/earn.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (cooldownearn.has(message.author.id)) {
if (!user)
message.reply({
content:
`Nani?! You're not logged in!\nPlease login to RDL to make an account in order to recieve money!\nLogin link:\n${process.env.DOMAIN}`,
`Nani?! You're not logged in!\nPlease login to RDL to make an account in order to recieve money!\nLogin link:\n${Deno.env.get("DOMAIN")}`,
});
else {
let act = false;
Expand Down
2 changes: 1 addition & 1 deletion src/bot/publicbot/commands/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (client.owners.some((x) => x === message.author.id)) {
let code = eval((`(async()=>{${codein}})()`););
if (typeof code !== "string")
code = (await import("util")).inspect(code, { depth: 0 });
if (code == process.env.TOKEN) {
if (code == Deno.env.get("TOKEN") {
code = "Fool!\nI'm intelligent too <:smart:794453219605610509>";
}
message.channel.send(
Expand Down
2 changes: 1 addition & 1 deletion src/bot/publicbot/commands/qrcode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (!args.length) {
message.reply({
content: `Usage: \`${process.env.PUBLIC_PREFIX}qrcode <your text to for creating qrcode\``,
content: `Usage: \`${Deno.env.get("PUBLIC_PREFIX")}qrcode <your text to for creating qrcode\``,
});
} else {
qr = args.join("%20");
Expand Down
6 changes: 3 additions & 3 deletions src/bot/publicbot/commands/remove-server.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
if (message.author.id === message.guild.ownerId) {
Cache.models.servers.findOne({ id: message.guild.id }).then((server) => {
if (server) {
fetch(`${process.env.DOMAIN}/api/client/log`, {
fetch(`${Deno.env.get("DOMAIN")}/api/client/log`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
secret: process.env.SECRET,
secret: Deno.env.get("SECRET"),
desc: `Server ${server.name} has been deleted by <@!${
message.author.id
}>\nThe data deleted is:\n\`\`\`\n${JSON.stringify(
Expand All @@ -17,7 +17,7 @@ if (message.author.id === message.guild.ownerId) {
color: "#ff0000",
owners: message.author.id,
img: server.iconURL,
url: process.env.DOMAIN,
url: Deno.env.get("DOMAIN"),
}),
});
Cache.models.servers.deleteOne({ id: message.guild.id }, () => {});
Expand Down
10 changes: 5 additions & 5 deletions src/bot/publicbot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { owners, emojiapprovers, mods, contributors } from "../../data.js";
var client = new Discord.Client({
intents: [new Discord.Intents(32767)], //32509
});
if (process.env.PUBLIC_TOKEN)
client.login(process.env.PUBLIC_TOKEN);
if (Deno.env.get("PUBLIC_TOKEN"))
client.login(Deno.env.get("PUBLIC_TOKEN"));
globalThis.publicbot = client;
client.owners = owners;
client.emojiapprovers = emojiapprovers;
client.mods = mods;
client.contributors = contributors;
client.commands = [];
const prefix = process.env.PUBLIC_PREFIX || "R!";
const prefix = Deno.env.get("PUBLIC_PREFIX") || "R!";
var cooldownearn = new Set();
client.cooldownearn = cooldownearn;

Expand Down Expand Up @@ -84,9 +84,9 @@ function DiscordLog({ title, desc, color }) {
.setTitle(title)
.setColor(color || "#5865F2")
.setDescription(desc)
.setURL(process.env.DOMAIN)
.setURL(Deno.env.get("DOMAIN"))
.setTimestamp()
.setThumbnail(`${process.env.DOMAIN}/favicon.ico`);
.setThumbnail(`${Deno.env.get("DOMAIN")}/favicon.ico`);

client.guilds.cache
.get("602906543356379156")
Expand Down
2 changes: 1 addition & 1 deletion src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Bots.importByID = function (id, message) {
website: bot.website,
imported: "Backup DB",
};
fetch(`${process.env.DOMAIN}/api/bots/new`, {
fetch(`${Deno.env.get("DOMAIN")}/api/bots/new`, {
method: "POST",
headers: {
"content-type": "application/json",
Expand Down
24 changes: 12 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ rovel.fetch = function (url, opts) {
return fetch(encodeURI(url), opts);
};
import mongoose from "mongoose";
mongoose.connect(process.env.DB || "mongodb://127.0.0.1:27017/test", {
mongoose.connect(Deno.env.get("DB") || "mongodb://127.0.0.1:27017/test", {
useNewUrlParser: true,
useNewUrlParser: true,
useUnifiedTopology: true,
});
import shell from "shelljs";
globalThis.shell = shell;
import * as loggy from "./utils/loggy.js";
if (process.env.WEBLOG_CONSOLE == "true") {
if (Deno.env.get("WEBLOG_CONSOLE") == "true") {
globalThis.logg = console.log;
globalThis.console.log = loggy.log;
globalThis.logerr = console.error;
Expand All @@ -37,12 +37,12 @@ globalThis.console.debug = function (obj) {
} else console.log(obj);
};

if (!process.env.DOMAIN) {
if (!Deno.env.get("DOMAIN")) {
console.error("[ERROR] No Domain Given!");
process.exit(0);
}
if (process.env.DOMAIN.endsWith("/")) {
process.env.DOMAIN = process.env.DOMAIN.slice(0, -1);
if (Deno.env.get("DOMAIN").endsWith("/")) {
Deno.env.set("DOMAIN",Deno.env.get("DOMAIN").slice(0, -1));
}
globalThis.db = mongoose.connection;

Expand All @@ -56,9 +56,9 @@ import "./bot/index.js"

import Sentry from "@sentry/node";
import Tracing from "@sentry/tracing";
if (process.env.SENTRY) {
if (Deno.env.get("SENTRY")) {
Sentry.init({
dsn: process.env.SENTRY,
dsn: Deno.env.get("SENTRY"),
tracesSampleRate: 1.0,
});
console.log(
Expand Down Expand Up @@ -118,8 +118,8 @@ process.on("SIGINT", () => {

globalThis.isCopy = function () {
if (
process.env.DOMAIN != "https://discord.rovelstars.com" &&
(!process.env.DOMAIN.includes("localhost:") || !process.env.DOMAIN.includes("127.0.0.1:"))
Deno.env.get("DOMAIN") != "https://discord.rovelstars.com" &&
(!Deno.env.get("DOMAIN").includes("localhost:") || !Deno.env.get("DOMAIN").includes("127.0.0.1:"))
) {
return false;
} else return true;
Expand All @@ -136,11 +136,11 @@ globalThis.server = app.listen(port, () => {
globalThis.selfbot = async function (path) {
return await fetch(`https://discord.com/api/v9${path}`, {
headers: {
Authorization: process.env.SELFBOT_TOKEN || "failure management",
Authorization: Deno.env.get("SELFBOT_TOKEN") || "failure management",
},
}).then((r) => r.json());
};
if (process.env.SELFBOT_TOKEN) {
if (Deno.env.get("SELFBOT_TOKEN")) {
selfbot("/users/@me").then((user) => {
if (user.message == "401: Unauthorized") {
console.log("[SELFBOT] Failed to login:");
Expand Down Expand Up @@ -237,7 +237,7 @@ rovel.approx = function (num, opts) {
}
};

globalThis.TOPTOKENS = process.env.TOPTOKEN?.split?.("|") || [];
globalThis.TOPTOKENS = Deno.env.get("TOPTOKEN")?.split?.("|") || [];
globalThis.TOPGGTOKEN = function () {
const index = Math.floor(Math.random() * (TOPTOKENS.length - 1) + 1);
return TOPTOKENS[index];
Expand Down
8 changes: 4 additions & 4 deletions src/server/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const port = process.env.PORT || 3000;
process.env.ANNOUNCE = "No Announcements to show!";
const port = Deno.env.get("PORT") || 3000;
Deno.env.set("ANNOUNCE", "No Announcements to show!");
import fs from "node:fs";
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
Expand Down Expand Up @@ -164,7 +164,7 @@ app.use("/api/comments", comments);
app.use("/api/embeds", embeds);
app.use("/api/preferences", prefers);
app.get("/api/download", (req, res) => {
if (req.query.pass != process.env.DOWNLOAD_PASS)
if (req.query.pass != Deno.env.get("DOWNLOAD_PASS"))
return res.status(401).json({ err: "Unauthorized" });
if (!req.query.pass)
return res.status(400).json({ err: "Bad Request" });
Expand Down Expand Up @@ -216,7 +216,7 @@ app.get("/api/*", (req, res) => { res.status(404).json({ err: 404 }); });
app.get("/comments", (req, res) => { res.render("comments.ejs"); });
app.use("/comments", express.static(path.resolve("src/comments")));
app.get + ("/hi", (req, res) => {
fetch(`${process.env.DOMAIN}`).then((r) => r.text()).then((d) => {
fetch(`${Deno.env.get("DOMAIN")}`).then((r) => r.text()).then((d) => {
translate(d, { to: "hi" }).then((re) => { res.send(re.text); });
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/server/mw/checkBanned.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export default async function (req, res, next) {
const Isbanned = BannedList.includes(user.id) ? true : false;
if (Isbanned) {
res.sendFile(path.resolve("src/public/assets/banned.html"));
fetch(`${process.env.DOMAIN}/api/client/log`, {
fetch(`${Deno.env.get("DOMAIN")}/api/client/log`, {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
secret: process.env.SECRET,
secret: Deno.env.get("SECRET"),
title: `Banned User ${user.tag} tried to visit us!`,
color: "#ff0000",
desc: `**${user.tag}** (${user.id}) was banned before, and they tried to visit our site at path:\n\`${req.path}\``,
Expand Down
Loading

1 comment on commit 0ecfd76

@deno-deploy
Copy link
Contributor

@deno-deploy deno-deploy bot commented on 0ecfd76 Nov 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

UNCAUGHT_EXCEPTION

ReferenceError: process is not defined
    at file:///src/src/server/app.js:97:1

Please sign in to comment.