Advertisement
Guest User

Untitled

a guest
May 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. const dis = require('discord.js');
  2. const bot = new dis.Client();
  3. const fs = require('fs')
  4. const readline = require('readline');
  5. const {google} = require('googleapis');
  6. const SCOPES = ['https://www.googleapis.com/auth/drive'];
  7. const TOKEN_PATH = 'token.json';
  8. let auth = ''
  9. fs.readFile('credentials.json', (err, content) => {
  10. if (err) return console.log('Error loading client secret file:', err);
  11. // Authorize a client with credentials, then call the Google Sheets API.
  12. authorize(JSON.parse(content),fetchAuth);
  13. });
  14.  
  15. function fetchAuth(authc){
  16. auth=authc
  17. }
  18.  
  19. function authorize(credentials, callback) {
  20. const {client_secret, client_id, redirect_uris} = credentials.installed;
  21. const oAuth2Client = new google.auth.OAuth2(
  22. client_id, client_secret, redirect_uris[0]);
  23.  
  24. fs.readFile(TOKEN_PATH, (err, token) => {
  25. if (err) return getNewToken(oAuth2Client, callback);
  26. oAuth2Client.setCredentials(JSON.parse(token));
  27. callback(oAuth2Client);
  28. });
  29. }
  30.  
  31. function getNewToken(oAuth2Client, callback) {
  32. const authUrl = oAuth2Client.generateAuthUrl({
  33. access_type: 'offline',
  34. scope: SCOPES,
  35. });
  36. console.log('Authorize this app by visiting this url:', authUrl);
  37. const rl = readline.createInterface({
  38. input: process.stdin,
  39. output: process.stdout,
  40. });
  41. rl.question('Enter the code from that page here: ', (code) => {
  42. rl.close();
  43. oAuth2Client.getToken(code, (err, token) => {
  44. if (err) return console.error('Error while trying to retrieve access token', err);
  45. oAuth2Client.setCredentials(token);
  46. fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => {
  47. if (err) return console.error(err);
  48. console.log('Token stored to', TOKEN_PATH);
  49. });
  50. callback(oAuth2Client);
  51. });
  52. });
  53. }
  54.  
  55. let ServerChannel = bot.channels.get('379245458461163532');
  56. let prefix = '.';
  57. bot.on('ready',() => {
  58. bot.user.setActivity(`with ${prefix} prefix.`);
  59. });
  60.  
  61. bot.on('message',(msg) =>{
  62. if(msg.content.startsWith(prefix)){
  63. let command = msg.content.substr(1);
  64. command = command.split(' '); // spliting
  65. if(command[0] === 'prefix'){
  66. prefix = command[1];
  67. msg.channel.send(`Prefix has been changed to ${prefix}`);
  68. bot.user.setActivity(`with ${prefix} prefix.`);
  69. } else if(command[0] === 'script'){
  70. const sheets = google.sheets({version: 'v4', auth});
  71. var request = {
  72. spreadsheetId:'1SXOqxmJiX_U9LDEn4uPa8Wp-DTBceq8rR5ymA_csmoU',
  73. range:'Sheet1!A1:A1',
  74. valueInputOption:'',
  75. resource:{
  76. range:'A1',
  77. values:[
  78. [command[1]]
  79. ]
  80. }
  81. };
  82. sheets.spreadsheets.values.update(request, function(err, response) {
  83. if (err) {
  84. msg.channel.send(`An error occured while updating the Google Sheet, ${err}`);
  85. return;
  86. } else{
  87. msg.channel.send('Successfully updated the Google sheet, expecting the roblox server to get this message.');
  88. };
  89. });
  90. };
  91. };
  92. });
  93.  
  94. bot.login('something');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement