Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const config = require("./config.json");
  3. const sqlite3 = require('sqlite3').verbose();
  4. const fetch = require("node-fetch");
  5. var Rcon = require('simple-rcon');
  6. const sdb = new sqlite3.Database('./users.sqlite');
  7.  
  8. let db = new sqlite3.Database('../Data/Servers/Server1/ShooterGame/Binaries/Win64/ArkApi/Plugins/NewPlayerProtection/NewPlayerProtection.db', (err) => {
  9.   if (err) {
  10.     console.error(err.message);
  11.   }
  12.   console.log('Connected to the database.');
  13. });
  14.  
  15. const client = new Discord.Client();
  16.  
  17.  
  18. client.on("ready", () => {
  19.  
  20.         sdb.run('PRAGMA journal_mode = WAL;');
  21.         sdb.run('PRAGMA synchronous = 1;');
  22.        
  23.        
  24.         const intervalID = setInterval(activityFunc, 20000);
  25.        
  26.         function activityFunc() {
  27.         fetch("https://ark-servers.net/api/?object=servers&element=detail&key=0XukpeqlSzFGmNzVwQ6tybgHEjUxVCMGaej")
  28.         .then(r => r.json())
  29.         .then(j => {
  30.         client.channels.get("523463160917655552").send("` Online Players: " + j.players + "`");
  31.             client.channels.get("523463160917655552").send("` Max Players: " + j.maxplayers + "`");
  32.         client.channels.get("523463160917655552").send("` Is server online: " + j.is_online + "`");
  33.                    
  34.                     if (j.is_online == 1) {
  35.                    
  36.             client.user.setActivity(j.players + "/" + j.maxplayers);
  37.            
  38.                     }else{
  39.                    
  40.             client.user.setActivity("Offline");
  41.                    
  42.                     }
  43.            
  44.             });
  45.         }  
  46.  
  47.     console.log("Bot connected sucessfully.");
  48.     client.channels.get("523463160917655552").send("`Bot startup correctly`");
  49.     client.channels.get("523463160917655552").send("`Connected to db`");
  50.     client.channels.get("523463160917655552").send("`Debug info will be posted below:`");
  51. });
  52.  
  53.  
  54.  
  55.  
  56. // Set the prefix
  57. client.on("message", async message => {
  58.   // Exit and stop if the prefix is not there or if user is a bot
  59.     if (!message.content.startsWith(config.prefix) || message.author.bot) return;
  60.     const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  61.     const command = args.shift().toLowerCase();
  62.    
  63.     if (message.content.startsWith(config.prefix + "broadcast")) {
  64.    
  65.         let text = args.join(" ");
  66.        
  67.         if (text == 0) {
  68.             message.channel.send("Arguments can't be empty");
  69.         }else{
  70.  
  71.         var client = new Rcon({
  72.           host: '149.202.45.160',
  73.           port: '27020',
  74.           password: 'defiant'
  75.         }).exec('ServerChat ' + text).connect();
  76.        
  77.             message.channel.send("`Message has been sent: " + text + "`");
  78.     }
  79.     }
  80.        
  81.        
  82.    
  83.     if (command === "store") {
  84.        
  85.             const embed = new Discord.RichEmbed()
  86.               .setTitle("Store")
  87.               .setDescription("You can buy an item with the command `buy <name>`")
  88.               .setAuthor(message.author.username, message.author.avatarURL)
  89.               .setColor(0x0000FF);
  90.             embed.addField("Artifact 5", "id: art5");
  91.                
  92.                 return message.channel.send({embed});
  93.        
  94.     }
  95.    
  96.     if (command === "buy") {
  97.        
  98.         let argument = args.join(" ");
  99.        
  100.         if (argument == "art5") {
  101.                
  102.         var client = new Rcon({
  103.           host: '149.202.45.160',
  104.           port: '27020',
  105.           password: 'defiant'
  106.         }).exec("gfi Blueprint'/Game/PrimalEarth/CoreBlueprints/Items/Artifacts/PrimalItemArtifact_05.PrimalItemArtifact_05' 1 0 0").connect();
  107.        
  108.             message.channel.send("`Item has been sent to you!`");
  109.                
  110.         }else{
  111.        
  112.             message.channel.send("This item is not on the shop.");
  113.        
  114.         }
  115.        
  116.     }
  117.    
  118.         if (command === "register") {
  119.            
  120.             const aid = message.author.id;
  121.            
  122.             const consult = sdb.prepare("SELECT id FROM users WHERE discordid = ?").get(aid);
  123.            
  124.             console.log(aid);
  125.             console.log(consult.id);
  126.            
  127.             if (consult == undefined) {
  128.                
  129.                 message.channel.send("Test");
  130.                
  131.             }else{
  132.                
  133.                 var id = `${message.guild.id}-${message.author.id}`;
  134.                 var user = message.author.username;
  135.                 var discordid = message.author.id;
  136.                 var steamid = 0;
  137.                 const set = sdb.prepare("INSERT OR REPLACE INTO users (id, user, discordid, steamid) VALUES (?, ?, ?, ?)").run(id, user, discordid, steamid);
  138.                 message.channel.send("Make sure to link your steamid to your discord account by using `!linksteamid` ");
  139.                
  140.             }
  141.            
  142.         }
  143.    
  144.    
  145.         if (command === "linksteamid") {
  146.        
  147.             let steamid = args.join(" ");
  148.            
  149.             const aid = message.author.id;
  150.            
  151.             const consult = sdb.prepare("SELECT id FROM users WHERE discordid = ?").run(aid);
  152.            
  153.             if (!consult) {
  154.            
  155.                 message.channel.send("You are not registered, make sure to user `!register` first.");
  156.            
  157.             }else{
  158.                
  159.                 const setSteamId = sdb.prepare("UPDATE users SET steamid = ? WHERE discordid = ?").run(steamid, aid);
  160.                 message.channel.send("You have now linked your steamid: " + steamid + " to this discord user!");
  161.                
  162.             }
  163.        
  164.         }
  165.    
  166.   if (command === "protected") {
  167.    
  168.             //Access DB
  169.             let sql = `SELECT DISTINCT SteamId steamid FROM players
  170.                         WHERE Is_New_Player = 0
  171.                        ORDER BY SteamId`;
  172.  
  173.  
  174.             db.all(sql, [], (err, rows) => {
  175.               if (err) {
  176.                 throw err;
  177.               }
  178.              
  179.              
  180.               rows.forEach((row) => {
  181.                 return message.channel.send(row.steamid);
  182.               });
  183.              
  184.             });
  185.  
  186.   }
  187. });
  188.  
  189. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement