Skip to content

Commit

Permalink
hmm
Browse files Browse the repository at this point in the history
  • Loading branch information
tumble1999 committed May 10, 2020
1 parent 72be123 commit 48668bd
Show file tree
Hide file tree
Showing 9 changed files with 1,011 additions and 140 deletions.
1 change: 1 addition & 0 deletions ENV
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PORT
DISCORD_TOKEN
DISCORD_SECRET
GH_SECRET
47 changes: 28 additions & 19 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ function decode(code) {
return JSON.parse(atob(code));
}

async function getTPCode(installUrl) {
return new Promise((resolve, reject) => {
request(installUrl, { json: true }, (err, res, body) => {
if (err) {
console.log(err);
reject(err);
}
resolve(body);
});
});
}

var app = express();
app.set('trust proxy', 1) // trust first proxy
app.use(session({
Expand All @@ -33,9 +45,16 @@ app.get('/approve/fail', (req, res) => {

app.get('/auth/github', github.Authenticate())

app.get('/approve', async (req, res, next) => {
app.get('/approve/:code', async (req, res, next) => {
if (req.user) {
res.send('YAY');
var info = decode(req.params.code);
github.publishTP(req.user.token,info).then(tpURL=>{
res.send(tpURL);
}).catch(err=>{
res.send(err);
});

} else {
req.session.returnTo = req.originalUrl
res.redirect('/auth/github')
Expand All @@ -60,30 +79,19 @@ app.post('/submit', async (req, res) => {
var infoCode = req.body.info;

var info = decode(infoCode);
var tpcode;
var tp;
if (!info.code) {
if (info.install) {
var asynctpcode = async ()=>
new Promise((resolve, reject) => {
request(info.install, { json: true }, (err, res, body) => {
if (err) {
console.log(err);
reject(err);
}
resolve(body);
});
});
tpcode = await asynctpcode();
console.log(tpcode);


tp = await getTPCode(info.install);
} else {
res.send("no tp data");
return;
}
} else {
tpcode = atob(info.code);
var tpcode = atob(info.code);
tp = JSON.parse(tpcode);
}
var tp = JSON.parse(tpcode);




Expand All @@ -95,7 +103,8 @@ app.post('/submit', async (req, res) => {
code: info.code,
icon: info.icon,
banner: info.banner,
video: info.video
video: info.video,
install:info.install
}
console.log(info);

Expand Down
6 changes: 5 additions & 1 deletion config/global.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
console.log("Setting Global Vars...");
global = {
url: 'static.tumblenet.ga',
discord: {
serverID:"567030108003631104",
token: require('./token.js').discord || process.env.DISCORD_TOKEN,
submissionsChannelID: "588060601910034458"
submissionsChannelID: "588060601910034458",

clientid:"588066376590163974",
secret: require('./token.js').discordLogin|| process.env.DISCORD_SECRET,
},
github: {
clientid: "f7ea22c76f3ab07934aa",
Expand Down
19 changes: 19 additions & 0 deletions discord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const passport = require('passport');
const DiscordStrategy = require('passport-discord').Strategy;

passport.use(new GitHubStrategy({
clientID: global.github.clientid,
clientSecret: global.discord.secret,
callbackURL: "http://" + global.url + "/auth/discord/callback"
},
function(accessToken,refreshToken, profile, cb) {
console.log("Setup Discord OAuth");

var user = {
token: accessToken
}

return cb(null, user);
var user =
}
));
93 changes: 43 additions & 50 deletions discordBot.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,56 @@
const Discord = require('discord.js');
const btoa = require('btoa-lite');

var client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
console.log(`Logged in as ${client.user.tag}!`);
});
client.guilds.forEach(guildCheck);
client.guilds.cache.forEach(guildCheck);
client.on("guildCreate",guildCheck);

client.on("message",(m)=>{
if(m.author.id==client.user.id) return;
if(!m.mentions.has(client.user)&&m.channel.id!="693492173915815947") return;
/*m.channel.send(m.author.toString() + m.content);
m.channel.typing = true;
bot.ask(m.content, function (err, response) {
m.channel.send(m.author.toString() + " " + response);// Will likely be: "Living in a lonely world"
});*/
})


function start(token) {
client.login(token);
client.login(token);
}


function guildCheck(guild) {
if(guild.id !== global.discord.serverID) guild.leave();
}

async function getGuild() {
return new Promise((resolve,reject)=>{
client.guilds.forEach(guild=>{
if(guild.id === global.discord.serverID) {
resolve(guild);
}
});
})
function getGuild(guild) {
return client.guilds.cache.get(guild||global.discord.serverID);
}
async function getChannel(channelID) {
var guild = await getGuild();
return new Promise((resolve,reject)=>{
guild.channels.forEach(channel=>{
if(channel.id === channelID) {
resolve(channel);
}
});
})
function getChannel(channelID,g) {
var guild = g ||getGuild();
return guild.channels.cache.get(channelID);
}

async function getMember(memberID) {
var guild = await getGuild();
return new Promise((resolve,reject)=>{
guild.members.forEach(member=>{
if(member.id === memberID) {
resolve(member);
}
});
})
function getMember(memberID) {
var guild = getGuild();
return guild.members.cache.get(memberID);
}



async function SubmitTP(tp) {
var submissionsChannel = await getChannel(global.discord.submissionsChannelID)
var author = await getMember(tp.authorid)
var submissionsChannel = getChannel(global.discord.submissionsChannelID)
var author = getMember(tp.authorid)
author.send("Your texture pack " + tp.name + ", has been submitted, a staff member will now review your submission.")
var embeddata = {
author:{
name:`${tp.authorname} (submitted by ${author.displayName})`,
icon_url: author.user.avatarURL,
icon_url: author.user.avatarURL(),
url: `https://boxcritters.github.io/authors?a=${tp.authorname}`
},
description:tp.description,
Expand All @@ -75,8 +71,8 @@ async function SubmitTP(tp) {
}
}

if(tp.installurl){
embeddata.url = tp.installurl;
if(tp.install){
embeddata.url = tp.install;
}


Expand All @@ -95,10 +91,10 @@ async function SubmitTP(tp) {

msg.react('✅');
msg.react('❎');

var filterAccept = (reaction,user)=>reaction.emoji.name == '✅' && user.id != client.user.id;
var collectAccept = msg.createReactionCollector(filterAccept,{maxEmojis:1});
collectAccept.on('collect', r => {
var filter = (test)=>(reaction,user)=>reaction.emoji.name == test && user.id != client.user.id;
msg.createReactionCollector(filter('✅'),{maxEmojis:1})
.on('collect', (r,u) => {
msg.delete();
if(codemsg) {
codemsg.delete();
Expand All @@ -107,16 +103,13 @@ async function SubmitTP(tp) {
videomsg.delete();
}

var url = "http://localhost:3000/approve/"
url += btoa(JSON.stringify(tp));

r.users.last().send(`Link to Approve the puplishing of **${tp.name}** by ${tp.authorname} (submitted by ${author}): ${url}`);
});


var filterDeny = (reaction,user)=>reaction.emoji.name == '❎' && user.id != client.user.id;
var collectDeny = msg.createReactionCollector(filterDeny,{maxEmojis:1});
collectDeny.on('collect', r => {
var url = "http://" + global.url + "/approve/"
url += btoa(JSON.stringify(tp));
u.send(`Link to Approve the publishing of **${tp.name}** by ${tp.authorname} (submitted by ${author}): ${url}`);
});

msg.createReactionCollector(filter('❎'),{maxEmojis:1})
.on('collect', (r,u) => {
msg.delete();
if(codemsg) {
codemsg.delete();
Expand All @@ -131,7 +124,7 @@ async function SubmitTP(tp) {


async function getAvatar(id) {
return (await getMember(id)).user.avatarURL;
return getMember(id).user.avatarURL;
}

module.exports = {SubmitTP,start,getAvatar};
module.exports = {SubmitTP,start,getAvatar,getMember};
Loading

0 comments on commit 48668bd

Please sign in to comment.