Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const dis = require('discord.js');
- const bot = new dis.Client();
- const fs = require('fs')
- const readline = require('readline');
- const {google} = require('googleapis');
- const SCOPES = ['https://www.googleapis.com/auth/drive'];
- const TOKEN_PATH = 'token.json';
- let auth = ''
- fs.readFile('credentials.json', (err, content) => {
- if (err) return console.log('Error loading client secret file:', err);
- // Authorize a client with credentials, then call the Google Sheets API.
- authorize(JSON.parse(content),fetchAuth);
- });
- function fetchAuth(authc){
- auth=authc
- }
- function authorize(credentials, callback) {
- const {client_secret, client_id, redirect_uris} = credentials.installed;
- const oAuth2Client = new google.auth.OAuth2(
- client_id, client_secret, redirect_uris[0]);
- fs.readFile(TOKEN_PATH, (err, token) => {
- if (err) return getNewToken(oAuth2Client, callback);
- oAuth2Client.setCredentials(JSON.parse(token));
- callback(oAuth2Client);
- });
- }
- function getNewToken(oAuth2Client, callback) {
- const authUrl = oAuth2Client.generateAuthUrl({
- access_type: 'offline',
- scope: SCOPES,
- });
- console.log('Authorize this app by visiting this url:', authUrl);
- const rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout,
- });
- rl.question('Enter the code from that page here: ', (code) => {
- rl.close();
- oAuth2Client.getToken(code, (err, token) => {
- if (err) return console.error('Error while trying to retrieve access token', err);
- oAuth2Client.setCredentials(token);
- fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => {
- if (err) return console.error(err);
- console.log('Token stored to', TOKEN_PATH);
- });
- callback(oAuth2Client);
- });
- });
- }
- let ServerChannel = bot.channels.get('379245458461163532');
- let prefix = '.';
- bot.on('ready',() => {
- bot.user.setActivity(`with ${prefix} prefix.`);
- });
- bot.on('message',(msg) =>{
- if(msg.content.startsWith(prefix)){
- let command = msg.content.substr(1);
- command = command.split(' '); // spliting
- if(command[0] === 'prefix'){
- prefix = command[1];
- msg.channel.send(`Prefix has been changed to ${prefix}`);
- bot.user.setActivity(`with ${prefix} prefix.`);
- } else if(command[0] === 'script'){
- const sheets = google.sheets({version: 'v4', auth});
- var request = {
- spreadsheetId:'1SXOqxmJiX_U9LDEn4uPa8Wp-DTBceq8rR5ymA_csmoU',
- range:'Sheet1!A1:A1',
- valueInputOption:'',
- resource:{
- range:'A1',
- values:[
- [command[1]]
- ]
- }
- };
- sheets.spreadsheets.values.update(request, function(err, response) {
- if (err) {
- msg.channel.send(`An error occured while updating the Google Sheet, ${err}`);
- return;
- } else{
- msg.channel.send('Successfully updated the Google sheet, expecting the roblox server to get this message.');
- };
- });
- };
- };
- });
- bot.login('something');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement