Skip to content

Commit

Permalink
Merge pull request #17 from Fernando-Santana-j/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Fernando-Santana-j authored Aug 9, 2024
2 parents f3e9139 + 4820150 commit 44001a8
Show file tree
Hide file tree
Showing 48 changed files with 1,818 additions and 1,294 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ config
config/mercadoPagoData.json


cart.list
ticket.list
/cart.list
8 changes: 7 additions & 1 deletion Discord/createCartMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ module.exports = async (Discord, client, data) => {
let embed = await DiscordChannel.send(contentEmbend);
}


setTimeout(async()=>{
try {
await DiscordServer.channels.cache.get(data.channelID).delete()
const userD = await client.users.fetch(user)
userD.send(`O seu ultimo carrinho no servidor ${DiscordServer.name} foi expirado!`)
} catch (error) {}
},900000)
} catch (error) {
console.log("MainCartERROR: ",error);
}
Expand Down
47 changes: 15 additions & 32 deletions Discord/createProductMessageEmbend.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path')
let Discord = require('discord.js')
const fs = require('fs');
const sharp = require('sharp');
const functions = require('../functions');

module.exports = async (Discord2, client, data) => {
try {
Expand Down Expand Up @@ -46,37 +47,19 @@ module.exports = async (Discord2, client, data) => {
if (totalEstoque.length <= 0) {
totalEstoque.push(new Discord.StringSelectMenuOptionBuilder().setLabel('Sem estoque').setValue('null').setDefault(true),)
}
let dburl = null
let Newdbres = null
if (produto.backGround) {
const bannerPath = path.join(__dirname, "..", produto.backGround);
let file = await fs.readFileSync(bannerPath);
let buffer = Buffer.from(file, 'binary');
let newBuffer = await sharp(buffer).jpeg().toBuffer()
const attachment = new Discord.AttachmentBuilder(newBuffer, { name: 'test.jpg' });
let dbBannerDiscordServer = await client.guilds.cache.get('1246186853241978911')
let dbBannerDiscordChannel = await dbBannerDiscordServer.channels.cache.get('1253279027662426142')
let dbres = await dbBannerDiscordChannel.send({
files: [attachment]
})
Newdbres = dbres
dburl = await dbres.attachments.first().url
let backGroundLink = ''
let logoLink = ''
if (`logoLink` in produto) {
logoLink = produto.logoLink
}else{
logoLink = produto.productLogo ? functions.discordDB(produto.productLogo,client,Discord) : ``
produto.logoLink = logoLink
}
let dburl2 = null
let Newdbres2 = null
if (produto.productLogo) {
const bannerPath = path.join(__dirname, "..", produto.productLogo);
let file = await fs.readFileSync(bannerPath);
let buffer = Buffer.from(file, 'binary');
let newBuffer = await sharp(buffer).jpeg().toBuffer()
const attachment = new Discord.AttachmentBuilder(newBuffer, { name: 'test.jpg' });
let dbBannerDiscordServer = await client.guilds.cache.get('1246186853241978911')
let dbBannerDiscordChannel = await dbBannerDiscordServer.channels.cache.get('1253279027662426142')
let dbres = await dbBannerDiscordChannel.send({
files: [attachment]
})
Newdbres2 = dbres
dburl2 = await dbres.attachments.first().url
if (`backGroundLink` in produto) {
backGroundLink = produto.backGroundLink
}else{
backGroundLink = produto.backGround ? functions.discordDB(produto.backGround,client,Discord) : ``
produto.backGroundLink = backGroundLink
}
let embed = await DiscordChannel.send({
embeds: [
Expand All @@ -94,8 +77,8 @@ module.exports = async (Discord2, client, data) => {
value: produto.estoque.length.toString(),
inline:true
})
.setThumbnail('personalize' in serverDb && 'iconProduct' in serverDb.personalize ? serverDb.personalize.iconProduct == true ? dburl2 : null : dburl2)
.setImage(dburl)
.setThumbnail('personalize' in serverDb && 'iconProduct' in serverDb.personalize ? serverDb.personalize.iconProduct == true ? logoLink : null : logoLink)
.setImage(backGroundLink)
.setFooter({ text: DiscordServer.name, iconURL: `https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp` })
],
components: [
Expand Down
261 changes: 250 additions & 11 deletions Discord/discordIndex.js

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions Discord/discordRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
const express = require('express');
const router = express.Router();

const stripe = require('stripe')(require('../config/web-config').stripe);
const Discord = require("discord.js");
const db = require('../Firebase/models')
const fs = require('fs');
const functions = require('../functions');
const webConfig = require('../config/web-config');
const sharp = require('sharp');
const botConfig = require('../config/bot-config.js');
const { default: axios } = require("axios");
const client = new Discord.Client({ intents: botConfig.intents })
client.login(botConfig.discordToken)

router.get('/auth/verify/:acesstoken', async (req, res) => {
let param = req.params.acesstoken
if (param) {
try {
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Encoding': 'application/x-www-form-urlencoded'
};
let userResponse = await axios.get('https://discord.com/api/users/@me', {
headers: {
Authorization: `Bearer ${param}`,
...headers
}
}).then((res) => { return res.data })
if (userResponse) {
req.session.uid = userResponse.id
res.redirect('/dashboard')
} else {
res.redirect(webConfig.loginURL)
}
} catch (error) {
res.redirect(webConfig.loginURL)
}
} else {
res.redirect(webConfig.loginURL)
}
})



router.get('/auth/callback', async (req, res) => {
try {
if (req.session.uid) {
res.redirect('/dashboard')
} else {
if (!req.query.code) {
res.redirect('/logout')
} else {
let param = new URLSearchParams({
client_id: webConfig.clientId,
client_secret: webConfig.secret,
grant_type: 'authorization_code',
code: req.query.code,
redirect_uri: webConfig.redirect
})
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Encoding': 'application/x-www-form-urlencoded'
};
const response = await axios.post('https://discord.com/api/oauth2/token', param, { headers }).then((res) => { return res }).catch((err) => {
console.error(err)
})
if (!response) {
res.redirect('/logout')
return
}
let userResponse = await axios.get('https://discord.com/api/users/@me', {
headers: {
Authorization: `Bearer ${response.data.access_token}`,
...headers
}
}).then((res) => { return res.data }).catch((err) => {
console.error(err)
});
await db.create('users', userResponse.id, {
id: userResponse.id,
username: userResponse.username,
profile_pic: userResponse.avatar ? `https://cdn.discordapp.com/avatars/${userResponse.id}/${userResponse.avatar}.png` : 'https://res.cloudinary.com/dgcnfudya/image/upload/v1709143898/gs7ylxx370phif3usyuf.png',
displayName: userResponse.global_name,
email: userResponse.email,
access_token: response.data.access_token
})

req.session.uid = userResponse.id

res.redirect('/dashboard')
}
}
} catch (error) {
res.redirect('/logout')
}
})




router.get('/addbot/:serverID', (req, res) => {
if (!req.params.serverID) {
res.redirect(`/`)
return
}
const guilds = client.guilds.cache;
const isBotInServer = guilds.has(req.params.serverID);
if (isBotInServer) {
res.redirect(`/server/${req.body.serverID}`)
} else {
res.redirect(`https://discord.com/oauth2/authorize?client_id=${webConfig.clientId}&permissions=8&response_type=code&scope=bot+applications.commands+guilds.members.read+applications.commands.permissions.update&redirect_uri=${process.env.DISCORDURI}&guild_id=${req.params.serverID}&disable_guild_select=true`)
}

})



module.exports = router;
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<div align="center" id="top">
<img src="./.github/app.gif" alt="Sdkbot" />

&#xa0;

<!-- <a href="https://sdkbot.netlify.app">Demo</a> -->
</div>

<h1 align="center">Sdkbot</h1>

<p align="center">
<img alt="Github top language" src="https://img.shields.io/github/languages/top/{{YOUR_GITHUB_USERNAME}}/sdkbot?color=56BEB8">

<img alt="Github language count" src="https://img.shields.io/github/languages/count/{{YOUR_GITHUB_USERNAME}}/sdkbot?color=56BEB8">

<img alt="Repository size" src="https://img.shields.io/github/repo-size/{{YOUR_GITHUB_USERNAME}}/sdkbot?color=56BEB8">

<img alt="License" src="https://img.shields.io/github/license/{{YOUR_GITHUB_USERNAME}}/sdkbot?color=56BEB8">

<!-- <img alt="Github issues" src="https://img.shields.io/github/issues/{{YOUR_GITHUB_USERNAME}}/sdkbot?color=56BEB8" /> -->

<!-- <img alt="Github forks" src="https://img.shields.io/github/forks/{{YOUR_GITHUB_USERNAME}}/sdkbot?color=56BEB8" /> -->

<!-- <img alt="Github stars" src="https://img.shields.io/github/stars/{{YOUR_GITHUB_USERNAME}}/sdkbot?color=56BEB8" /> -->
</p>

<!-- Status -->

<!-- <h4 align="center">
🚧 Sdkbot 🚀 Under construction... 🚧
</h4>
<hr> -->

<p align="center">
<a href="#dart-about">About</a> &#xa0; | &#xa0;
<a href="#sparkles-features">Features</a> &#xa0; | &#xa0;
<a href="#rocket-technologies">Technologies</a> &#xa0; | &#xa0;
<a href="#white_check_mark-requirements">Requirements</a> &#xa0; | &#xa0;
<a href="#checkered_flag-starting">Starting</a> &#xa0; | &#xa0;
<a href="#memo-license">License</a> &#xa0; | &#xa0;
<a href="https://github.com/{{YOUR_GITHUB_USERNAME}}" target="_blank">Author</a>
</p>

<br>

## :dart: About ##

Describe your project

## :sparkles: Features ##

:heavy_check_mark: Feature 1;\
:heavy_check_mark: Feature 2;\
:heavy_check_mark: Feature 3;

## :rocket: Technologies ##

The following tools were used in this project:

- [Expo](https://expo.io/)
- [Node.js](https://nodejs.org/en/)
- [React](https://pt-br.reactjs.org/)
- [React Native](https://reactnative.dev/)
- [TypeScript](https://www.typescriptlang.org/)

## :white_check_mark: Requirements ##

Before starting :checkered_flag:, you need to have [Git](https://git-scm.com) and [Node](https://nodejs.org/en/) installed.

## :checkered_flag: Starting ##

```bash
# Clone this project
$ git clone https://github.com/{{YOUR_GITHUB_USERNAME}}/sdkbot

# Access
$ cd sdkbot

# Install dependencies
$ yarn

# Run the project
$ yarn start

# The server will initialize in the <http://localhost:3000>
```

## :memo: License ##

This project is under license from MIT. For more details, see the [LICENSE](LICENSE.md) file.


Made with :heart: by <a href="https://github.com/{{YOUR_GITHUB_USERNAME}}" target="_blank">{{YOUR_NAME}}</a>

&#xa0;

<a href="#top">Back to top</a>
4 changes: 3 additions & 1 deletion config/bot-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ module.exports = {
GatewayIntentBits.AutoModerationConfiguration,
GatewayIntentBits.AutoModerationExecution
],
clientSecret: process.env.CLIENTSECRET
clientSecret: process.env.CLIENTSECRET,
dbServer:'1271518850038366412',
dbChannel:'1271519116196315268'
}
18 changes: 15 additions & 3 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const fs = require('fs');
const stripe = require('stripe')(require('./config/web-config').stripe);
const db = require('./Firebase/models');
const webConfig = require('./config/web-config')
let path = require(`path`);
const botConfig = require('./config/bot-config');

module.exports = {
verifyPermissions: async (user, server, Discord, client) => {
Expand Down Expand Up @@ -128,7 +130,6 @@ module.exports = {
return
}
}

const assinatura = await stripe.subscriptions.retrieve(server.subscription);
if (assinatura) {
const tempoUnixConvert = new Date(assinatura.current_period_end * 1000);
Expand Down Expand Up @@ -163,7 +164,6 @@ module.exports = {
}

} catch (error) {
console.log(error);
res.redirect('/')
}
} else {
Expand All @@ -183,7 +183,6 @@ module.exports = {
...headers
}
}).then((res) => { return res.data }).catch((err) => {
console.error(err)
return { error: true, err: err }
})
if (serverResponse.error) return serverResponse;
Expand Down Expand Up @@ -296,5 +295,18 @@ module.exports = {
const ano = data.getFullYear();
return dia + '/' + mes + '/' + ano;
},
discordDB:async (imagePath,client,Discord)=>{
const bannerPath = path.join(__dirname, imagePath);
let file = await fs.readFileSync(bannerPath);
let buffer = Buffer.from(file, 'binary');
let newBuffer = await sharp(buffer).jpeg().toBuffer()
const attachment = new Discord.AttachmentBuilder(newBuffer, { name: 'test.jpg' });
let dbBannerDiscordServer = await client.guilds.cache.get(botConfig.dbServer)
let dbBannerDiscordChannel = await dbBannerDiscordServer.channels.cache.get(botConfig.dbChannel)
let dbres = await dbBannerDiscordChannel.send({
files: [attachment]
})
return dbres
}

}
Loading

0 comments on commit 44001a8

Please sign in to comment.