Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ALTER TABLE `nf_news` ADD `published_discord` ENUM('0','1') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' AFTER `vote`;
- const Discord = require('discord.js');
- const client = new Discord.Client();
- var mysql = require('mysql');
- var connectionBDD = function(){
- var con = mysql.createConnection({
- host: "",
- user: "",
- password: "",
- database: "lionhell_neofrag"
- });
- return con;
- }
- /*
- SELECT * FROM nf_news AS p, nf_news_lang AS j WHERE j.news_id = p.news_id AND p.published_discord = '0'
- */
- client.on('ready', () => {
- console.log('I am ready!');
- var interval = setInterval (function () {
- // recuperer toute les news avec un published_discord a 0
- var con = connectionBDD();
- con.connect(function(err) {
- if (err) throw err;
- var sql1 = "SELECT * FROM nf_news AS p, nf_news_lang AS j WHERE j.news_id = p.news_id AND p.published_discord = '0'";
- con.query(sql1, function (err, result, fields) {
- if (err) throw err;
- if(result.length > 0){
- console.log('il y a '+result.length+' news a publier sur discord');
- result.forEach(function(element) {
- console.log(element.title);
- // mise a jour du statut de plublication vers discord
- var sql2 = "UPDATE `nf_news` SET `published_discord` = '1' WHERE `nf_news`.`news_id` = "+element.news_id+";";
- con.query(sql2, function (err, result, fields) {
- if (err) throw err;
- });
- // envois des news sur le channel de discord
- var channel = client.channels.get('352470272298975234'); // <= c'est id du channel.
- //channel.send(element.title);
- channel.send({embed: {
- color: 3447003,
- author: {
- name: client.user.username,
- icon_url: client.user.avatarURL
- },
- title: element.title,
- url: "http://google.com",
- description: element.introduction,
- fields: [{
- name: "Fields",
- value: "They can have different fields with small headlines."
- },
- {
- name: "Masked links",
- value: "You can put [masked links](http://google.com) inside of rich embeds."
- },
- {
- name: "Markdown",
- value: "You can put all the *usual* **__Markdown__** inside of them."
- }
- ],
- timestamp: new Date(),
- footer: {
- icon_url: client.user.avatarURL,
- text: "© Example"
- }
- }
- });
- });
- }
- });
- });
- }, 5000);
- });
- client.login('');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement