Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const commando = require('discord.js-commando');
- const mysql = require('mysql');
- const { RichEmbed } = require('discord.js');
- // This function is adding into database, removing all previous messages and displaying the new registered list in the #attractive-ico channel
- var channel = require('./channel.json');
- const con = mysql.createConnection({
- host: "localhost",
- user: "root",
- password: "apple",
- database: "icoprediction"
- });
- class Register extends commando.Command {
- constructor(client){
- super(client, {
- name: 'register',
- group: 'ico',
- memberName: 'register',
- description: 'Register an ico Admins Only!',
- examples: ['ICO Webpage Presale/Mainsale Whitelist Time(in CET). e.g. \n Gems https://gems.org/ Presale Yes 18:00']
- });
- }
- async run(message, args) {
- var ico = args.split(' ');
- if(ico.length == 6) {
- var command = `INSERT INTO ICOPrediction (name, website, sale, whitelist, datetime) VALUES (?, ?, ?, ?, ?);`;
- var select = `SELECT name, website, sale, whitelist, datetime, DATEDIFF(datetime, NOW()) AS timeRemaining FROM icoprediction ORDER BY datetime ASC`;
- con.query(command, [ico[0], ico[1], ico[2], ico[3], ico[4] + " " + ico[5]], function(err) {
- if(!err) {
- message.reply("Registered ICO");
- }
- else message.reply("Output Error");
- });
- this.client.channels.get(channel.id).bulkDelete(20);
- con.query(select, (err, results) => {
- if(err) {
- message.reply("Database Error");
- }
- var currentDate = new Date();
- var conversion;
- var output = [];
- results.forEach(result => {
- if(result.timeRemaining >= 0) {
- if(result.whitelist == 1) {
- conversion = 'Yes';
- }
- else {conversion = 'No';}
- output.push(`${result.name} - <${result.website}> - ${result.sale} - Whitelisted : ${conversion} - ${result.datetime} \n\n`);
- }
- });
- const embed = new RichEmbed()
- .setDescription('output')
- .setColor(0x00AE86)
- this.client.channels.get(channel.id).send(output.join(""));
- });
- }
- else message.reply("Input Error : You added or wrote wrong datatype");
- }
- }
- module.exports = Register;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement