worked on premium

pull/11/head
TheCodedProf 3 years ago
parent 161136741c
commit 633866ff68

@ -1,3 +1,4 @@
Role all (?)
Server rules
verificationRequired on welcome
Role User GUI

@ -25,23 +25,23 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
], components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel("Join").setURL("https://discord.gg/bPaNnxe"))] });
return;
}
const dbMember = await client.database.premium.fetchTotal(interaction.user.id)
let premium;
const dbMember = await client.database.premium.fetchUser(interaction.user.id)
let premium = `You do not have premium! You can't activate premium on any servers.`;
let count = 0;
if (member.roles.cache.has("1066468879309750313")) {
const {level, appliesTo} = dbMember || {level: 0, appliesTo: []}
if (level === 99) {
premium = `You have Infinite Premium! You have been gifted this by the developers as a thank you. You can give premium to any and all servers you are in.`;
count = 200;
} else if (member.roles.cache.has("1066465491713003520")) {
premium = `You have Premium tier 1! You can give premium to ${1 - dbMember}.`;
} else if (level === 1) {
premium = `You have Premium tier 1! You can give premium to ${1 - appliesTo.length} more servers.`;
count = 1;
} else if (member.roles.cache.has("1066439526496604194")) {
premium = `You have Premium tier 2! You can give premium to ${3 - dbMember}.`;
} else if (level === 2) {
premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more servers.`;
count = 3;
} else if (member.roles.cache.has("1066464134322978912")) {
premium = `You have Premium Mod! You already give premium to all servers you have a "manage" permission in.`
} else if (level === 3) {
premium = `You have Premium Mod! You can give premium to ${3 - appliesTo.length} more servers, as well as automatically giving premium to all servers you have a "manage" permission in.`
count = 3;
}
const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
let premiumGuild = ""
if (hasPremium) {
@ -82,8 +82,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
if (i) {
i.deferUpdate();
let guild = i.guild!;
let m = await client.database.premium.fetchTotal(interaction.user.id);
if (count - m <= 0) {
if (count - appliesTo.length <= 0) {
interaction.editReply({
embeds: [
new EmojiEmbed()

@ -1,5 +1,4 @@
import fetch from "node-fetch";
import FormData from "form-data";
import fs, { writeFileSync, createReadStream } from "fs";
import generateFileName from "../utils/temp/generateFileName.js";
import Tesseract from "node-tesseract-ocr";
@ -20,8 +19,9 @@ export async function testNSFW(link: string): Promise<NSFWSchema> {
const [p, hash] = await saveAttachment(link);
let alreadyHaveCheck = await client.database.scanCache.read(hash)
if(alreadyHaveCheck) return { nsfw: alreadyHaveCheck.data };
const data = new FormData();
data.append("file", createReadStream(p));
const data = new URLSearchParams();
let r = createReadStream(p)
data.append("file", r.read(fs.statSync(p).size));
const result = await fetch("https://unscan.p.rapidapi.com/", {
method: "POST",
headers: {

@ -1,6 +1,7 @@
import type Discord from "discord.js";
import { Collection, MongoClient } from "mongodb";
import config from "../config/main.json" assert { type: "json" };
import client from "../utils/client.js";
const mongoClient = new MongoClient(config.mongoUrl);
await mongoClient.connect();
@ -230,18 +231,55 @@ export class Premium {
this.premium = database.collection<PremiumSchema>("premium");
}
async updateUser(user: string, level: number) {
if(!(await this.userExists(user))) await this.createUser(user, level);
await this.premium.updateOne({ user: user }, { $set: { level: level } }, { upsert: true });
}
async userExists(user: string): Promise<boolean> {
const entry = await this.premium.findOne({ user: user });
return entry ? true : false;
}
async createUser(user: string, level: number) {
await this.premium.insertOne({ user: user, appliesTo: [], level: level });
}
async hasPremium(guild: string) {
const entry = await this.premium.findOne({
appliesTo: { $in: [guild] }
});
if (!entry) return false;
return entry.expires.valueOf() > Date.now();
return entry ? true : false;
}
async fetchTotal(user: string): Promise<number> {
async fetchUser(user: string): Promise<PremiumSchema | null> {
const entry = await this.premium.findOne({ user: user });
if (!entry) return 0;
return entry.appliesTo.length;
if (!entry) return null;
return entry;
}
async checkAllPremium() {
const entries = await this.premium.find({}).toArray();
for(const {user, expiresAt} of entries) {
if(expiresAt) expiresAt < new Date().getTime() ? await this.premium.deleteOne({user: user}) : null;
const member = await (await client.guilds.fetch("684492926528651336")).members.fetch(user)
let level: number = 0;
if (member.roles.cache.has("1066468879309750313")) {
level = 99;
} else if (member.roles.cache.has("1066465491713003520")) {
level = 1;
} else if (member.roles.cache.has("1066439526496604194")) {
level = 2;
} else if (member.roles.cache.has("1066464134322978912")) {
level = 3;
}
if (level > 0) {
await this.updateUser(user, level);
} else {
await this.premium.updateOne({ user: user }, { expiresAt: (new Date().getTime() + (1000*60*60*24*3)) })
}
}
}
addPremium(user: string, guild: string) {
@ -409,6 +447,6 @@ export interface ModNoteSchema {
export interface PremiumSchema {
user: string;
level: number;
expires: Date;
appliesTo: string[];
expiresAt?: number;
}

Loading…
Cancel
Save