Advertisement
n3k4a

KOS BOT BACKUP LAST V 2019

May 19th, 2020
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.29 KB | None | 0 0
  1. //كود الزريف المنيوك الي اسمه ايدت الي دفع عليهف فلوس في الاخر سربت كسمه للمره 3 ياله خلي الشعب يلعب
  2. var users = [
  3. ["gaber","asd"],
  4. ["Liz","Smith"],
  5. ["Ahmed","Khan"]
  6. ];
  7. var User;
  8.  
  9. const { Client, RichEmbed } = require('discord.js');
  10. const client = new Client();
  11. const { Sequelize, DataTypes } = require('sequelize');
  12. const fs = require('fs');
  13. let prefix = "%"
  14. const express = require('express');
  15. const app = express();
  16. const mustache = require('mustache');
  17. const readline = require('readline');
  18.  
  19.  
  20.  
  21.  
  22. const sequelize = new Sequelize('database', "edit", "kos kber", {
  23. host: '0.0.0.1',
  24. 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.
  25. pool: {
  26. max: 5,
  27. min: 0,
  28. idle: 10000
  29. },
  30. // Security note: the database is saved to the file `database.sqlite` on the local filesystem. It's deliberately placed in the `.data` directory
  31. // which doesn't get copied if someone remixes the project.
  32. storage: '.data/database.sqlite'
  33. });
  34.  
  35.  
  36.  
  37. // populate table with default users
  38.  
  39.  
  40. // http://expressjs.com/en/starter/static-files.html
  41.  
  42.  
  43.  
  44. const backups = sequelize.define('backups', {
  45. id: {
  46. type: DataTypes.UUID,
  47. defaultValue: DataTypes.UUIDV4,
  48. primaryKey: true
  49. },
  50. guild: {
  51. type: DataTypes.BIGINT,
  52. allowNull: false
  53. },
  54. backup: {
  55. type: DataTypes.JSONB,
  56. defaultValue: {}
  57. }
  58. }, {
  59. timestamps: false,
  60. indexes: [
  61. { fields: ['guild'] }
  62. ]
  63. })
  64. sequelize.sync()
  65.  
  66.  
  67.  
  68. client.on('message', async message => {
  69. if (message.author.bot) return;
  70. if(message.channel.type !== 'text') return;
  71.  
  72. const [command, ...rest] = message.content.slice(prefix.length).trim().split(/ +/g);
  73. const code = rest.join();
  74.  
  75. if (command.toLowerCase() === 'createbackup') {
  76. const currentBackup = await backups.findOne({ where: { guild: message.guild.id } });
  77. if(!message.guild.member(message.author).hasPermission("ADMINISTRATOR")) return;
  78. if (currentBackup) return message.channel.send(`**You can make 1 backup copy only.**`);
  79.  
  80. const roles = message.guild.roles.array().map(r => {
  81. const role = {
  82. name: r.name,
  83. color: r.color,
  84. hoist: r.hoist,
  85. permissions: r.permissions,
  86. mentionable: r.mentionable,
  87. position: r.position
  88. }
  89. return role;
  90. });
  91. const channels = message.guild.channels.array().map(c => {
  92. const channel = {
  93. type: c.type,
  94. name: c.name,
  95. postion: c.calculatedPosition
  96. }
  97. if (c.parent) channel.parent = c.parent.name
  98. return channel;
  99. });
  100.  
  101. const guild = {
  102. icon: message.guild.iconURL,
  103. name: message.guild.name,
  104. roles,
  105. channels
  106. };
  107.  
  108. const backup = await backups.create({
  109. guild: message.guild.id,
  110. backup: guild
  111. })
  112. console.log(backup);
  113. const embed = new RichEmbed()
  114. .setAuthor(message.guild.id, message.guild.iconURL)
  115. .setDescription(`**Created a backup**\n**CODE: ${backup.id}**`)
  116. .setFooter(`Requested by ${message.author.tag}`, message.author.avatarURL)
  117. .setColor('GREEN');
  118. return message.author.send(embed).catch(err => message.channel.send('**i can\'t send messages to you :x:**'));
  119. }
  120.  
  121. if (command.toLowerCase() === 'usebackup') {
  122. if (!code) return message.channel.send(`**Please let me know what backup you want to use? ${prefix}backup use <code>.**`);
  123. try {
  124. var guildBackup = await backups.findByPk(code)
  125. } catch (error) {
  126. return message.channel.send(`**I couldn't find a backup with this code ${code} :x:**`);
  127. }
  128. if (!guildBackup) return message.channel.send(`**This UUID might be deleted ${code} :x:**`);
  129. if (!message.guild.me.hasPermission('ADMINISTRATOR')) return message.channel.send('**I need Administartor to use the back up :x:**');
  130. if(!message.guild.member(message.author).hasPermission("ADMINISTRATOR")) return;
  131.  
  132. // 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`)
  133. try {
  134. var id = await useBackup(message, guildBackup)
  135. } catch (error) {
  136. return message.channel.send(`**Error occur while trying to use backup: \`${error}\` :x:**`);
  137. }
  138. const embed = new RichEmbed()
  139. .setAuthor(message.guild.id, message.guild.iconURL)
  140. .setDescription(`**You've used this backup**\n**CODE: ${guildBackup.id}**\n**Guild: ${guildBackup.backup.name} (${guildBackup.guild}).**`)
  141. .setFooter(`Requested by ${message.author.tag}`, message.author.avatarURL)
  142. .setColor('GREEN');
  143. try {
  144. return message.author.send(embed);
  145. } catch (error) {}
  146. }
  147.  
  148. if (command.toLowerCase() === 'delbackup') {
  149. if (!code) return message.channel.send(`**Please let me know what backup you want to use? ${prefix}delbackup <code>.**`);
  150. try {
  151. var guildBackup = await backups.findByPk(code)
  152. } catch (error) {
  153. return message.channel.send(`**I couldn't find a backup with this code ${code} :x:**`);
  154. }
  155. if(!message.guild.member(message.author).hasPermission("ADMINISTRATOR")) return;
  156.  
  157. if (!guildBackup) return message.channel.send(`**This UUID might be deleted ${code} :x:**`);
  158. const embed = new RichEmbed()
  159. .setAuthor(message.guild.id, message.guild.iconURL)
  160. .setDescription(`**Deleted backup**\n**CODE: ${code}**\n**Guild: ${guildBackup.backup.name} (${guildBackup.guild}).**`)
  161. .setFooter(`Requested by ${message.author.tag}`, message.author.avatarURL)
  162. .setColor('GREEN');
  163. message.channel.send(embed);
  164. return guildBackup.destroy();
  165. }
  166.  
  167. });
  168.  
  169.  
  170. /**
  171. *
  172. * @param {import('discord.js').Message} message
  173. */
  174. async function useBackup(message, guildBackup) {
  175. console.log(guildBackup.backup.channels);
  176. await message.guild.roles.filter(role => role.members.every(member => !member.user.bot) && role.members.size !== 1).forEach(role => {
  177. role.delete('• Backup Forced •')
  178. })
  179. await message.guild.channels.forEach(channel => {
  180. if (channel.deletable) channel.delete('• Backup Forced •')
  181. })
  182. message.guild.setIcon(guildBackup.backup.icon);
  183. message.guild.setName(guildBackup.backup.name);
  184. guildBackup.backup.roles.forEach(role => {
  185. message.guild.createRole({ nلame: role.name, color: role.color, permissions: role.permissions, hoist: role.hoist, mentionable: role.mentionable, position: role.position })
  186. })
  187. guildBackup.backup.channels.filter(channel => channel.type === 'category').forEach(channel => {
  188. message.guild.createChannel(channel.name, channel.type)
  189. });
  190. guildBackup.backup.channels.filter(channel => channel.type !== 'category').forEach(channel => {
  191. message.guild.createChannel(channel.name, channel.type).then(c => {
  192. const parent = message.guild.channels.filter(c => c.type === 'category').find(c => c.name === channel.parent);
  193. channel.parent ? c.setParent(parent) : '';
  194. })
  195. })
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement