Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //كود الزريف المنيوك الي اسمه ايدت الي دفع عليهف فلوس في الاخر سربت كسمه للمره 3 ياله خلي الشعب يلعب
- var users = [
- ["gaber","asd"],
- ["Liz","Smith"],
- ["Ahmed","Khan"]
- ];
- var User;
- const { Client, RichEmbed } = require('discord.js');
- const client = new Client();
- const { Sequelize, DataTypes } = require('sequelize');
- const fs = require('fs');
- let prefix = "%"
- const express = require('express');
- const app = express();
- const mustache = require('mustache');
- const readline = require('readline');
- const sequelize = new Sequelize('database', "edit", "kos kber", {
- host: '0.0.0.1',
- dialect: 'sqlite', // Security note: the database is saved to the file `database.sqlite` on the local filesystem. It's deliberately placed in the `.data` directory // which doesn't get copied if someone remixes the project.
- pool: {
- max: 5,
- min: 0,
- idle: 10000
- },
- // Security note: the database is saved to the file `database.sqlite` on the local filesystem. It's deliberately placed in the `.data` directory
- // which doesn't get copied if someone remixes the project.
- storage: '.data/database.sqlite'
- });
- // populate table with default users
- // http://expressjs.com/en/starter/static-files.html
- const backups = sequelize.define('backups', {
- id: {
- type: DataTypes.UUID,
- defaultValue: DataTypes.UUIDV4,
- primaryKey: true
- },
- guild: {
- type: DataTypes.BIGINT,
- allowNull: false
- },
- backup: {
- type: DataTypes.JSONB,
- defaultValue: {}
- }
- }, {
- timestamps: false,
- indexes: [
- { fields: ['guild'] }
- ]
- })
- sequelize.sync()
- client.on('message', async message => {
- if (message.author.bot) return;
- if(message.channel.type !== 'text') return;
- const [command, ...rest] = message.content.slice(prefix.length).trim().split(/ +/g);
- const code = rest.join();
- if (command.toLowerCase() === 'createbackup') {
- const currentBackup = await backups.findOne({ where: { guild: message.guild.id } });
- if(!message.guild.member(message.author).hasPermission("ADMINISTRATOR")) return;
- if (currentBackup) return message.channel.send(`**You can make 1 backup copy only.**`);
- const roles = message.guild.roles.array().map(r => {
- const role = {
- name: r.name,
- color: r.color,
- hoist: r.hoist,
- permissions: r.permissions,
- mentionable: r.mentionable,
- position: r.position
- }
- return role;
- });
- const channels = message.guild.channels.array().map(c => {
- const channel = {
- type: c.type,
- name: c.name,
- postion: c.calculatedPosition
- }
- if (c.parent) channel.parent = c.parent.name
- return channel;
- });
- const guild = {
- icon: message.guild.iconURL,
- name: message.guild.name,
- roles,
- channels
- };
- const backup = await backups.create({
- guild: message.guild.id,
- backup: guild
- })
- console.log(backup);
- const embed = new RichEmbed()
- .setAuthor(message.guild.id, message.guild.iconURL)
- .setDescription(`**Created a backup**\n**CODE: ${backup.id}**`)
- .setFooter(`Requested by ${message.author.tag}`, message.author.avatarURL)
- .setColor('GREEN');
- return message.author.send(embed).catch(err => message.channel.send('**i can\'t send messages to you :x:**'));
- }
- if (command.toLowerCase() === 'usebackup') {
- if (!code) return message.channel.send(`**Please let me know what backup you want to use? ${prefix}backup use <code>.**`);
- try {
- var guildBackup = await backups.findByPk(code)
- } catch (error) {
- return message.channel.send(`**I couldn't find a backup with this code ${code} :x:**`);
- }
- if (!guildBackup) return message.channel.send(`**This UUID might be deleted ${code} :x:**`);
- if (!message.guild.me.hasPermission('ADMINISTRATOR')) return message.channel.send('**I need Administartor to use the back up :x:**');
- if(!message.guild.member(message.author).hasPermission("ADMINISTRATOR")) return;
- // if (!message.guild.me.highestRole.calculatedPosition !== 1) return message.channel.send(`:x: To ensure I delete all channels and use this backup please let my role have the highest postion in this server`)
- try {
- var id = await useBackup(message, guildBackup)
- } catch (error) {
- return message.channel.send(`**Error occur while trying to use backup: \`${error}\` :x:**`);
- }
- const embed = new RichEmbed()
- .setAuthor(message.guild.id, message.guild.iconURL)
- .setDescription(`**You've used this backup**\n**CODE: ${guildBackup.id}**\n**Guild: ${guildBackup.backup.name} (${guildBackup.guild}).**`)
- .setFooter(`Requested by ${message.author.tag}`, message.author.avatarURL)
- .setColor('GREEN');
- try {
- return message.author.send(embed);
- } catch (error) {}
- }
- if (command.toLowerCase() === 'delbackup') {
- if (!code) return message.channel.send(`**Please let me know what backup you want to use? ${prefix}delbackup <code>.**`);
- try {
- var guildBackup = await backups.findByPk(code)
- } catch (error) {
- return message.channel.send(`**I couldn't find a backup with this code ${code} :x:**`);
- }
- if(!message.guild.member(message.author).hasPermission("ADMINISTRATOR")) return;
- if (!guildBackup) return message.channel.send(`**This UUID might be deleted ${code} :x:**`);
- const embed = new RichEmbed()
- .setAuthor(message.guild.id, message.guild.iconURL)
- .setDescription(`**Deleted backup**\n**CODE: ${code}**\n**Guild: ${guildBackup.backup.name} (${guildBackup.guild}).**`)
- .setFooter(`Requested by ${message.author.tag}`, message.author.avatarURL)
- .setColor('GREEN');
- message.channel.send(embed);
- return guildBackup.destroy();
- }
- });
- /**
- *
- * @param {import('discord.js').Message} message
- */
- async function useBackup(message, guildBackup) {
- console.log(guildBackup.backup.channels);
- await message.guild.roles.filter(role => role.members.every(member => !member.user.bot) && role.members.size !== 1).forEach(role => {
- role.delete('• Backup Forced •')
- })
- await message.guild.channels.forEach(channel => {
- if (channel.deletable) channel.delete('• Backup Forced •')
- })
- message.guild.setIcon(guildBackup.backup.icon);
- message.guild.setName(guildBackup.backup.name);
- guildBackup.backup.roles.forEach(role => {
- message.guild.createRole({ nلame: role.name, color: role.color, permissions: role.permissions, hoist: role.hoist, mentionable: role.mentionable, position: role.position })
- })
- guildBackup.backup.channels.filter(channel => channel.type === 'category').forEach(channel => {
- message.guild.createChannel(channel.name, channel.type)
- });
- guildBackup.backup.channels.filter(channel => channel.type !== 'category').forEach(channel => {
- message.guild.createChannel(channel.name, channel.type).then(c => {
- const parent = message.guild.channels.filter(c => c.type === 'category').find(c => c.name === channel.parent);
- channel.parent ? c.setParent(parent) : '';
- })
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement