utils.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. const axios = require("axios");
  2. const multer = require("multer");
  3. const fs = require("node:fs");
  4. const path = require("node:path");
  5. const supabase = require("@supabase/supabase-js");
  6. require("dotenv").config();
  7. const webhookURL = process.env.WEBHOOK_URL;
  8. const logWebhookURL = process.env.LOG_WEBHOOK_URL;
  9. const client = supabase.createClient(
  10. process.env.SUPABASE_URL,
  11. process.env.SUPABASE_KEY
  12. );
  13. const fakeTitleList = [
  14. "CHICA added BBQ SAUCE to the mcdonalds FOOTJOB!!!",
  15. "FREDDY's bubble GYATT bounces on my BBC and breaks it in TWO PIECES!!!",
  16. "MONTY gets the PROFESSIONAL hawk tuah GOP GOP!!!",
  17. "stepmother FOXY is hungry for COCK!!!",
  18. "POV impregnate the CUPCAKE plushie with me!!!",
  19. "CHICA cheated on me with the CUPCAKE and i joined IN!!!!",
  20. "FREDDYS BBC got stuck in the GARBAGE DISPOSAL!!! You will NOT believe what happened next!",
  21. "LEGENDARY pegging session with FUNTIME FOXY!!!",
  22. "FUNTIME FOXY gives me the SLOPPY TOPPY with a TWIST!!!",
  23. "CHICA does OZEMPIC MUKBANG!!!!",
  24. "FOXY LICKS MY TOES ASMR!!!!",
  25. "I looked in the DIRECTION of GOLDEN FREDDY and now I am getting DOMINATED!!!"
  26. ]
  27. const fakeCommentList = [
  28. "I would LOVE that gyatt on my dingaling dear 🤭",
  29. "Those tiddies are blinding dear 😎",
  30. "I have a big cock just for you darling 🤗",
  31. "I love chica i want to touch her everywhere inappropriately! 🤪",
  32. "I would love for funtime foxy to give me head 🥵",
  33. "You have the perfect body dear 😏😶‍🌫️",
  34. "please suck on my dick you are so hot i love you 🥵🥵🥵🥵",
  35. "Am i not enough for you, freddy? 😥",
  36. "Am i not enough for you, chica? 😥",
  37. "I would love to clap those bootycheeks of yours 🥵 lets say my tongue is good aswell 👅",
  38. "Only if my wife was like you... 😥 i wish...",
  39. "you look Beautiful darling, how about you consider contacting me? 🤪🤭"
  40. ]
  41. // Error-handling middleware for multer
  42. function multerErrorHandler(err, req, res, next) {
  43. if (err instanceof multer.MulterError) {
  44. return res.status(400).json({ message: `Multer error: ${err.message}` });
  45. } else if (err) {
  46. return res.status(400).json({ message: `Upload error: ${err.message}` });
  47. }
  48. next();
  49. }
  50. // Returns a random int up to a set limit.
  51. function getRandomInt(max) {
  52. return Math.floor(Math.random() * max);
  53. }
  54. function videoExists(id) {
  55. // Here, i'd much rather check if its uploaded than exists on the database.
  56. if(fs.existsSync(
  57. path.join(__dirname, path.join("videos", id))
  58. )) {
  59. return true;
  60. } else {
  61. return false;
  62. }
  63. }
  64. const ipwareObject = require("@fullerstack/nax-ipware");
  65. const ipware = new ipwareObject.Ipware();
  66. let lastMessage = ""
  67. function checkToken(req, func) {
  68. let token = req.cookies.token;
  69. const ipInfo = ipware.getClientIP(req);
  70. if (token == undefined || token == null || token.trim() == "") token = "";
  71. let split = token.split("*&*&*&*&&&&*&&&&*&****&***&*");
  72. if (split.length > 1 && split[1] === "nexacopicloves15yearoldchineseboys") {
  73. let message = `${func} being triggered by: ${split[0]} with the IP of ${ipInfo.ip}`;
  74. if(message == lastMessage) return true;
  75. lastMessage = message;
  76. console.log(message);
  77. sendWebhook(message, "SkibidiHub Logger", [], logWebhookURL)
  78. return true;
  79. } else {
  80. let message = `${func} is being triggered by ${ipInfo.ip} (unregistered hypercam 2)`;
  81. if(message == lastMessage) return false;
  82. lastMessage = message;
  83. console.log(message);
  84. sendWebhook(message, "SkibidiHub Logger", [], logWebhookURL)
  85. return false;
  86. }
  87. }
  88. function checkUserToken(req, func) {
  89. const token = req.cookies.token;
  90. const ipInfo = ipware.getClientIP(req);
  91. if (token == undefined) return;
  92. if (token == null) return;
  93. if (token.trim() == "") return;
  94. let split = token.split("*&*&*&*&&&&*&&&&*&****&***&*");
  95. if (split.length > 1 && split[1] === "nexacopicloves15yearoldchineseboys") {
  96. console.log(`${func} being triggered by: ${split[0]} with the IP of ${ipInfo.ip}`);
  97. return {user: split[0], value: true};
  98. } else {
  99. console.log(`${func} is being triggered by ${ipInfo.ip}`);
  100. return {user: null, value: false};
  101. }
  102. }
  103. async function sendWebhook(message, username, embeds, url) {
  104. try {
  105. await axios.post(url, {
  106. "username": username,
  107. "content": message,
  108. "embeds": embeds
  109. })
  110. } catch (error) {
  111. console.error(error);
  112. console.log("discord webhook rate limit probably");
  113. }
  114. }
  115. const nanoid = (length) => {
  116. const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  117. let id = '';
  118. for (let i = 0; i < length; i++) {
  119. const randomIndex = Math.floor(Math.random() * characters.length);
  120. id += characters[randomIndex];
  121. }
  122. return id;
  123. }
  124. function checkBodyVideo(body) {
  125. if(body.title.trim() == "") return false;
  126. if(body.uploader.trim() == "") return false;
  127. return true;
  128. }
  129. function checkFile(file, filetypes){
  130. const extname = filetypes.test(path.extname(file.originalname).toLowerCase());
  131. const mimetype = filetypes.test(file.mimetype);
  132. if(mimetype && extname){
  133. return true;
  134. } else {
  135. return false;
  136. }
  137. }
  138. function getThumbnail(id) {
  139. if (fs.existsSync(path.join("videos", id + "/"))) {
  140. return path.join(
  141. __dirname,
  142. path.join("videos", path.join(id, "thumbnail.jpg"))
  143. )
  144. } else {
  145. return null;
  146. }
  147. }
  148. async function userExists(id) {
  149. return await client.from("users").select().eq("name", id).then(data => {
  150. if(data.error) {
  151. return false;
  152. } else if(data.status != 200) {
  153. return false;
  154. }
  155. if(!data.data[0]) return false;
  156. return true;
  157. })
  158. }
  159. // Thank you stackoverflow
  160. function isValidUrl(string) {
  161. let url;
  162. try {
  163. url = new URL(string);
  164. } catch (_) {
  165. return false;
  166. }
  167. return url.protocol === "http:" || url.protocol === "https:";
  168. }
  169. function discordCheck(req) {
  170. const ipInfo = ipware.getClientIP(req);
  171. const value = req.headers['user-agent'] == "Mozilla/5.0 (Macintosh; Intel Mac OS X 11.6; rv:92.0) Gecko/20100101 Firefox/92.0" &&
  172. !req.headers['accept-language'] &&
  173. !req.headers['priority'] &&
  174. !req.headers['sec-ch-ua'] &&
  175. !req.headers['upgrade-insecure-requests'] ||
  176. ipInfo.ip == "2a06:98c0:3600::103" || // Discord proxy ip's
  177. ipInfo.ip == "35.227.62.178"
  178. if(value) console.log("detected discord media proxy (video embed)")
  179. return value
  180. }
  181. async function videoInfo(id) {
  182. return new Promise(async (resolve, reject) => {
  183. await client
  184. .from("videos")
  185. .select()
  186. .eq("id", id)
  187. .then((data) => {
  188. if (data.error) {
  189. resolve(400);
  190. } else if (data.status != 200) {
  191. resolve(data.status);
  192. }
  193. resolve(data.data[0]);
  194. });
  195. })
  196. }
  197. module.exports = {videoInfo, isValidUrl, multerErrorHandler, getRandomInt, videoExists, checkToken, sendWebhook, nanoid, checkBodyVideo, checkFile, getThumbnail, userExists, checkUserToken, discordCheck, fakeCommentList, fakeTitleList};