Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js");
- const config = require("./config.json");
- const sqlite3 = require('sqlite3').verbose();
- const fetch = require("node-fetch");
- var Rcon = require('simple-rcon');
- const sdb = new sqlite3.Database('./users.sqlite');
- let db = new sqlite3.Database('../Data/Servers/Server1/ShooterGame/Binaries/Win64/ArkApi/Plugins/NewPlayerProtection/NewPlayerProtection.db', (err) => {
- if (err) {
- console.error(err.message);
- }
- console.log('Connected to the database.');
- });
- const client = new Discord.Client();
- client.on("ready", () => {
- sdb.run('PRAGMA journal_mode = WAL;');
- sdb.run('PRAGMA synchronous = 1;');
- const intervalID = setInterval(activityFunc, 20000);
- function activityFunc() {
- fetch("https://ark-servers.net/api/?object=servers&element=detail&key=0XukpeqlSzFGmNzVwQ6tybgHEjUxVCMGaej")
- .then(r => r.json())
- .then(j => {
- client.channels.get("523463160917655552").send("` Online Players: " + j.players + "`");
- client.channels.get("523463160917655552").send("` Max Players: " + j.maxplayers + "`");
- client.channels.get("523463160917655552").send("` Is server online: " + j.is_online + "`");
- if (j.is_online == 1) {
- client.user.setActivity(j.players + "/" + j.maxplayers);
- }else{
- client.user.setActivity("Offline");
- }
- });
- }
- console.log("Bot connected sucessfully.");
- client.channels.get("523463160917655552").send("`Bot startup correctly`");
- client.channels.get("523463160917655552").send("`Connected to db`");
- client.channels.get("523463160917655552").send("`Debug info will be posted below:`");
- });
- // Set the prefix
- client.on("message", async message => {
- // Exit and stop if the prefix is not there or if user is a bot
- if (!message.content.startsWith(config.prefix) || message.author.bot) return;
- const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
- const command = args.shift().toLowerCase();
- if (message.content.startsWith(config.prefix + "broadcast")) {
- let text = args.join(" ");
- if (text == 0) {
- message.channel.send("Arguments can't be empty");
- }else{
- var client = new Rcon({
- host: '149.202.45.160',
- port: '27020',
- password: 'defiant'
- }).exec('ServerChat ' + text).connect();
- message.channel.send("`Message has been sent: " + text + "`");
- }
- }
- if (command === "store") {
- const embed = new Discord.RichEmbed()
- .setTitle("Store")
- .setDescription("You can buy an item with the command `buy <name>`")
- .setAuthor(message.author.username, message.author.avatarURL)
- .setColor(0x0000FF);
- embed.addField("Artifact 5", "id: art5");
- return message.channel.send({embed});
- }
- if (command === "buy") {
- let argument = args.join(" ");
- if (argument == "art5") {
- var client = new Rcon({
- host: '149.202.45.160',
- port: '27020',
- password: 'defiant'
- }).exec("gfi Blueprint'/Game/PrimalEarth/CoreBlueprints/Items/Artifacts/PrimalItemArtifact_05.PrimalItemArtifact_05' 1 0 0").connect();
- message.channel.send("`Item has been sent to you!`");
- }else{
- message.channel.send("This item is not on the shop.");
- }
- }
- if (command === "register") {
- const aid = message.author.id;
- const consult = sdb.prepare("SELECT id FROM users WHERE discordid = ?").get(aid);
- console.log(aid);
- console.log(consult.id);
- if (consult == undefined) {
- message.channel.send("Test");
- }else{
- var id = `${message.guild.id}-${message.author.id}`;
- var user = message.author.username;
- var discordid = message.author.id;
- var steamid = 0;
- const set = sdb.prepare("INSERT OR REPLACE INTO users (id, user, discordid, steamid) VALUES (?, ?, ?, ?)").run(id, user, discordid, steamid);
- message.channel.send("Make sure to link your steamid to your discord account by using `!linksteamid` ");
- }
- }
- if (command === "linksteamid") {
- let steamid = args.join(" ");
- const aid = message.author.id;
- const consult = sdb.prepare("SELECT id FROM users WHERE discordid = ?").run(aid);
- if (!consult) {
- message.channel.send("You are not registered, make sure to user `!register` first.");
- }else{
- const setSteamId = sdb.prepare("UPDATE users SET steamid = ? WHERE discordid = ?").run(steamid, aid);
- message.channel.send("You have now linked your steamid: " + steamid + " to this discord user!");
- }
- }
- if (command === "protected") {
- //Access DB
- let sql = `SELECT DISTINCT SteamId steamid FROM players
- WHERE Is_New_Player = 0
- ORDER BY SteamId`;
- db.all(sql, [], (err, rows) => {
- if (err) {
- throw err;
- }
- rows.forEach((row) => {
- return message.channel.send(row.steamid);
- });
- });
- }
- });
- client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement