Skip to content

Instantly share code, notes, and snippets.

@haykam821
Last active March 19, 2021 05:22
Show Gist options
  • Save haykam821/2cc86209806f095deb0b6f7c16b5eff0 to your computer and use it in GitHub Desktop.
Save haykam821/2cc86209806f095deb0b6f7c16b5eff0 to your computer and use it in GitHub Desktop.
here you go
var request = require("request");
var Discord = require('discord.io');
var bot = new Discord.Client({
autorun: true,
token: "my token"
});
// Really messy code. Do not code like this.
const DiscordWebhook = require("discord-webhooks");
const WebSocket = require('ws');
var t = 1;
const ws = new WebSocket('wss://pxls.space/ws');
var palette = ["#FFFFFF","#CDCDCD","#888888","#222222","#000000","#FFA7D1","#E50000","#800000","#FFDDCA","#E59500","#A06A42","#E5D900","#94E044","#02BE01","#00D3DD","#0083C7","#0000EA","#CF6EE4","#FF00FF","#820080"]
var officials = {
"285901641188769792": "fl"
}
ws.on('message', function incoming(data) {
try{
data = JSON.parse(data);
if (data.type!=='pixel')return;
if (t==false)return;
x = data.pixels[0].x;
y = data.pixels[0].y;
color = data.pixels[0].color;
if (!((x >= 1410 && x <= 1615) && (y >= 1114 && y <= 1200)))return;
// CORRECT remover
if ((x%2!==0||y%2!==0) && (color==14|color==16))return;
if ((x%2==0||y%2==0) && color==4)return;
//
//console.log(x,y,data.pixels[0].color)
//announce()
var data = {
username:'Pixel Updates',
avatar_url: "https://cdn.discordapp.com/attachments/299004474905722882/327326803553157120/pxls.png",
content: `**A new but incorrect pixel was placed in the Blue Lattice core!**\n\nX: ${x}\nY: ${y}\n\nColor ID: ${data.pixels[0].color}`
/*embeds: [{
color: parseInt(palette[data.pixels[0].color].replace('#',''),16),
title: "New Pixel",
description: "A new pixel was placed!",
fields: [{
name: "Coordinates",
value: `X: ${data.pixels[0].x}\nY: ${data.pixels[0].y}`
}, {
name: "Color ID",
value: data.pixels[0].color
}]
}]*/
}
var options = { method: 'POST',
url: "https://discordapp.com/api/webhooks/327590699157684224/CT5H9NNvnm_5OGwZjKnhJKGesWCjoYlXZXyY4xRKqiqgWwVAnbUxjgHB8c6gvWRDLlQd",//webhooks[Object.keys(webhooks)[i]][0],
headers:
{ 'postman-token': '83585dd7-5346-eea4-3800-35b76c1133c7',
'cache-control': 'no-cache',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' },
formData: data };
request(options, function (error, response, body) {
if (error) throw new Error(error);
});
} catch (e){
console.log(e)
}
});
function announce(data){
for (i in Object.keys(webhooks)){
var options = { method: 'POST',
url: webhooks[Object.keys(webhooks)[i]][0],
headers:
{ 'postman-token': '83585dd7-5346-eea4-3800-35b76c1133c7',
'cache-control': 'no-cache',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' },
formData: data };
request(options, function (error, response, body) {
if (error) throw new Error(error);
});}
}
function repeatTo(event,channelid){
var username = event.d.author.username// + Object.keys(officials).indexOf(event.d.author.id) > -1 ? ` [${Object.values(officials)[Object.keys(officials).indexOf(event.d.author.id)].toUpperCase()}]` : '';
//console.log(username);
var options = { method: 'POST',
url: webhooks[channelid][0],
headers:
{ 'postman-token': '83585dd7-5346-eea4-3800-35b76c1133c7',
'cache-control': 'no-cache',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' },
formData: {
content: event.d.content,
username: username,
avatar_url: `https://cdn.discordapp.com/avatars/${event.d.author.id}/${event.d.author.avatar}.png?size=256`,
//tts: event.d.tts,
//embeds: event.d.embeds,
//file: event.d.attachments
} };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
}
var webhooks = {
"318226363251425280": ["https://discordapp.com/api/webhooks/327174701535330304/vh7F3ZYqee1ZiYqtXimU9A7Ffp1gHN-RO1DHDshmsuM7aFlEPxGlIkFO0EVh3Yh0g62a","327174701535330304"],
"325895411602817024": ["https://discordapp.com/api/webhooks/327170663217627137/7LjfPFPEgEvO-MnWXwz_jv_EAzEd3GpH5vGnjbGw7UxpxU5PnOszQn6MLRuU4J82RkWn","327170663217627137"],
"327249039177416705": ["https://discordapp.com/api/webhooks/327255139301851146/6ZWLtTOrELOrVs7llc2mxcHBkhXF18hJ_4AsnmOsjKDqPARMdEyyiD6OTJaVWgY98Pk9","327255139301851146"],
"327498222069350401": ["https://discordapp.com/api/webhooks/327808428267405322/C29IE_2Am4jay1BhWARfr1H9hJNxjYPH6mJrypx5OTTOwLblPrQLejiRsJ9zKZLcam9u","327808428267405322"]
}
var webhookIds = [
"327174701535330304",
"327170663217627137",
"327255139301851146",
"327593935046311937"
]
// Horrible system below.
bot.on('message', function(user, userID, channelID, message, event) {
if (event.d.webhook_id==undefined){//Object.keys(webhookIds).indexOf(event.d.webhook_id) == -1) {
//console.log(Object.keys(webhookIds).indexOf(event.d.webhook_id))
if (channelID == '318226363251425280') {
repeatTo(event,'325895411602817024');
repeatTo(event,'327249039177416705');
repeatTo(event,'327498222069350401');
} else if (channelID == '325895411602817024') {
repeatTo(event,'318226363251425280');
repeatTo(event,'327249039177416705');
repeatTo(event,'327498222069350401');
} else if (channelID == '327249039177416705') {
repeatTo(event,'325895411602817024');
repeatTo(event,'318226363251425280');
repeatTo(event,'327498222069350401');
} else if (channelID == '327808369631166467') {
repeatTo(event,'325895411602817024');
repeatTo(event,'318226363251425280');
repeatTo(event,'327249039177416705');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment