Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const SteamEncryption = require("./steamencryption.js");
- const SteamIDConvert = require("steamidconvert")();
- const CountryCodes = require("country-data").countries;
- const entities = require('html-entities').AllHtmlEntities;
- const Discord = require("discord.js");
- const request = require("request");
- const MySQL = require("mysql");
- const AdminServ = {};
- AdminServ.bot = new Discord.Client();
- var sf_jar = request.jar();
- function numberWithCommas(x)
- {
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
- }
- function escapeRegExp(str)
- {
- return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
- }
- AdminServ.channels = {};
- AdminServ.channels.general = "general";
- AdminServ.facepunch_url = "1515567";
- AdminServ.forums_channel = "general";
- AdminServ.forums_interval = 10000;
- AdminServ.username = "richard_tanner";
- AdminServ.password = "richXg#88500";
- AdminServ.botsecret = "MzA4MzY0OTAyMDMxMDMyMzMx.C-gkew.-UgkTie-IzLjh26aAlhdRpf9XaI";
- AdminServ.useragent = "Tom the Bot";
- AdminServ.userGame = "dasdsad"
- AdminServ.prefix = "!"
- AdminServ.database = MySQL.createConnection(
- {
- host : "localhost",
- user : "gmodsto.re",
- database: "gmodsto.re",
- });
- AdminServ.escape_markdown = function(str, escape) {
- var r = new RegExp(escapeRegExp(escape),"g");
- return str.replace(r,escape.replace(/(.)/g,"\\$1"));
- };
- AdminServ.api = function(path,shortcut,cb) {
- request.get({url:"https://gmodstore.com/api/" + path,headers:{"User-Agent":AdminServ.useragent},jar:sf_jar},function(err,httpobj,body) {
- if (err) {console.log(err);return;}
- body = JSON.parse(body);
- if (shortcut) {
- cb(body[shortcut]);
- } else {
- cb(body);
- }
- });
- };
- AdminServ.script = function(message,id) {
- AdminServ.api("scripts/info/" + id,"script",function(data) {
- var msg = "";
- msg += "**" + AdminServ.escape_markdown(data.name,"**") + "**";
- AdminServ.api("scripts/reviews/" + id,"reviews",function(r_data) {
- var total = 0;
- for(var i=0;i < r_data.length;i++) {
- total += Number(r_data[i].review_rating);
- }
- if (total != 0) {
- total = total / r_data.length;
- }
- var stars = "";
- if (total > 4.5) {
- stars = "★★★★★";
- } else if (total > 4) {
- stars = "★★★★☆";
- } else if (total > 3) {
- stars = "★★★☆☆";
- } else if (total > 2) {
- stars = "★★☆☆☆";
- } else if (total > 1) {
- stars = "★☆☆☆☆";
- } else if (total == 0) {
- stars = "☆☆☆☆☆";
- }
- msg += "\n(" + +total.toFixed(2) + " - " + stars + ")";
- msg += "\n\nBy " + data.author_name + " (" + SteamIDConvert.convertToText(data.author_steam64) + ")";
- var price = data.price_discount;
- if (price == "0.00") {
- price = data.price;
- }
- request.get({url:"https://gmodstore.com/scripts/view/" + id,headers:{"User-Agent":AdminServ.useragent},jar:sf_jar},function(err,httpobj,body) {
- if (err) {console.log(err);return;}
- var sales = /<strong>(\d+)<\/strong> sales/.exec(body)[1];
- msg += "\n\nViews: " + numberWithCommas(data.views);
- msg += "\nPrice: $" + price;
- msg += "\nSales: " + numberWithCommas(Number(sales));
- message.channel.sendMessage(msg);
- });
- });
- });
- };
- AdminServ.job = function(message,id) {
- request.get({url:"https://gmodstore.com/jobs/view/" + id,headers:{"User-Agent":AdminServ.useragent},jar:sf_jar},function(err,httpobj,body) {
- if (err) {console.log(err);return;}
- var title = /<div class="row">\n<div class="col-md-12">\n<h1>(.*?)<\/h1>\n<\/div>\n<\/div>/.exec(body);
- var budget = /<tr>\n<td>Budget<\/td>\n<td>\$(.*?)<\/td>\n<\/tr>/.exec(body);
- var user = /<h2><a href="\/users\/view\/(\d+)"><i class="fa fa-.*?"><\/i><span style=""> (.*?) <span class="reputation".*?>(.*?)<\/span>/.exec(body);
- var doing = /<div class="alert alert-success" role="alert">\nThis job is being done by someone else, but you can still apply for it\n<\/div>/.exec(body);
- var done = /<div class="alert alert-success" role="alert">\nThis job has been done by someone else, you can no longer apply for it\n<\/div>/.exec(body);
- var license = /<div class="well license-header">\nThis job is using the "<a href=".*?">(.*?)<\/a>" license.\n<\/div>/.exec(body);
- var apps = /<span.*?><strong>(\d+)<\/strong> applications<\/span>/.exec(body);
- var views = /<tr>\n<td>Views<\/td>\n<td>(\d+)<\/td>\n<\/tr>/.exec(body);
- if (title && budget && license && apps && views) {
- var msg = "";
- msg += "**" + AdminServ.escape_markdown(title[1],"**") + "**";
- if (doing) {
- msg += " (In progress)";
- } else if (done) {
- msg += " (Done)";
- }
- if (user) {
- msg += "\n\nBy: " + user[2] + " (" + SteamIDConvert.convertToText(user[1]) + ") [" + user[3] + " rep]";
- }
- msg += "\n\nBudget: $" + budget[1];
- msg += "\n\nApplications: " + apps[1];
- msg += "\n\nViews: " + numberWithCommas(views[1]);
- msg += "\nLicense: " + license[1];
- message.channel.sendMessage(msg);
- }
- });
- };
- AdminServ.shortlink = function(message,link) {
- AdminServ.database.query("SELECT `clicks`,`steamid64` FROM `links` WHERE `id`=" + AdminServ.database.escape(link),function(err,link_rows) {
- if (err) {console.log(err);return;}
- if (link_rows.length == 1) {
- AdminServ.database.query("SELECT `steamtable`,`lastupdated` FROM `users` WHERE `steamid64`=" + AdminServ.database.escape(link_rows[0].steamid64),function(err,user_rows) {
- if (err) {console.log(err);return;}
- var name = SteamIDConvert.convertToText(link_rows[0].steamid64);
- if (user_rows.length == 1) {
- if (user_rows[0].steamtable == "null" || user_rows[0].steamtable == null) {
- }
- var steamtable = JSON.parse(user_rows[0].steamtable);
- name = steamtable.personaname;
- }
- message.channel.sendMessage("That link was created by **" + AdminServ.escape_markdown(name,"**") + "** and has been clicked " + link_rows[0].clicks + " times.");
- });
- }
- });
- };
- var usergroups = [
- "User",
- "Developer",
- "Staff",
- "Administrator",
- ];
- var days = [
- "Mon",
- "Tue",
- "Wed",
- "Thu",
- "Fri",
- "Sat",
- "Sun",
- ];
- var months = [
- "Jan",
- "Feb",
- "Mar",
- "Apr",
- "May",
- "Jun",
- "Jul",
- "Aug",
- "Sep",
- "Oct",
- "Nov",
- "Dec",
- ];
- AdminServ.user = function(message,steamid64) {
- AdminServ.api("users/search/steam64/" + steamid64,"user",function(data) {
- var msg = "";
- msg += "https://" + data.avatar.replace(/_full.jpg$/,"_medium.jpg") + "\n\n";
- msg += "**" + AdminServ.escape_markdown(data.name,"**") + "** (" + SteamIDConvert.convertToText(steamid64) + ") (" + usergroups[Number(data.usergroup)] + ")";
- if (CountryCodes[data.country_code]) {
- msg += "\n\nFrom " + CountryCodes[data.country_code].name;
- }
- if (Number(data.scripts_rep) > 0) {
- msg += "\n\nScript Reputation: " + numberWithCommas(data.scripts_rep);
- }
- if (Number(data.jobs_rep) > 0) {
- msg += "\nJob Reputation: " + numberWithCommas(data.jobs_rep);
- }
- AdminServ.api("users/banned/" + steamid64,"bans",function(data) {
- // need to do
- message.channel.sendMessage(msg);
- });
- });
- };
- AdminServ.forums = function() {
- function check() {
- request.get({url:"https://gmodstore.com/community/",headers:{"User-Agent":AdminServ.useragent},jar:sf_jar},function(err,httpobj,body) {
- if (err) {console.log(err);return;}
- var r = /(?:<div class="forum-category-header">\n<span>(.*?)<\/span>[\s\S]*?)?<a href="\/community\/boards\/[\s\S]*?">(?!\n)([\s\S]*?)(?!\n)<\/a>[\s\S]*?<td class="forum-category-lastpost">[\s\S]*?<a href="(\/community\/threads\/.*?\/post-(.*?)(?:#post-.*?)?)" class="forum-category-lastpost-title">([\s\S]*?)<\/a>\n<div class="forum-category-lastpost-meta">\n<a href="\/users\/view\/(.*?)">(.*?)<\/a>[\s\S]*?<date>.*?>(.*?)</g;
- var latest_posts_n = body.match(r);
- if (latest_posts_n) {
- latest_posts_n = latest_posts_n.length;
- var latest_posts = [];
- var latest_posts_r;
- for(var i=0;i < latest_posts_n;i++) {
- latest_posts_r = r.exec(body);
- latest_posts.push(latest_posts_r);
- delete latest_posts[latest_posts.length - 1].input;
- delete latest_posts[latest_posts.length - 1].index;
- delete latest_posts[latest_posts.length - 1][0];
- }
- var cur_forum;
- for(i=0;i < latest_posts.length;i++) {
- var board;
- var url;
- var id;
- var thread;
- var user;
- var username;
- var time;
- if (latest_posts[i][1]) {
- cur_forum = entities.decode(latest_posts[i][1]);
- }
- board = entities.decode(latest_posts[i][2]);
- url = entities.decode(latest_posts[i][3]);
- id = entities.decode(latest_posts[i][4]);
- thread = entities.decode(latest_posts[i][5]);
- user = entities.decode(latest_posts[i][6]);
- username = entities.decode(latest_posts[i][7]);
- time = entities.decode(latest_posts[i][8]);
- if (thread == "") continue;
- if (cur_forum == "The BotAdminServ Of The Forums") continue;
- AdminServ.database.query("SELECT `id` FROM `bot_forums` WHERE `board`=? AND `forum`=?",[board,cur_forum],(function(cur_forum,board,url,id,thread,user,username,time) {
- return function(err,rows) {
- if (err) {console.log(err);return;}
- if (rows.length == 0) {
- //AdminServ.database.query("INSERT INTO `bot_forums` (`forum`,`board`,`id`) VALUES(?,?,?)",[cur_forum,board,id]);
- } else if (rows[0].id != id) {
- AdminServ.channels.community.sendMessage("```\n" + cur_forum + " -> " + board + " -> " + thread + " • " + time + "\n\n" + username + " • " + SteamIDConvert.convertToText(user) + "\n```\nhttps://scriptfodder.com" + url);
- //AdminServ.database.query("UPDATE `bot_forums` SET `id`=? WHERE `forum`=? AND `board`=?",[id,cur_forum,board]);
- }
- };
- })(cur_forum,board,url,id,thread,user,username,time));
- }
- }
- });
- request.get({url:"https://facepunch.com/showthread.php?t=" + AdminServ.facepunch_url + "&page=200",headers:{"User-Agent":AdminServ.useragent}},function(err,httpobj,body) {
- if (err) {console.log(err);return;}
- var posts = /<span class="date" title=".*?">(.*?)<\/span>[\s\S]*?<a name="post(\d+)".*? Post #(\d+)[\s\S]*?<div class="userinfo user_(\d+).*?>[\s\S]*?<a class="username.*">(.*?)<\/span><\/a>/g;
- if (posts) {
- var latest_posts_n = body.match(posts);
- if (latest_posts_n) {
- latest_posts_n = latest_posts_n.length;
- var latest_posts = [];
- var latest_posts_r;
- for(var i=0;i < latest_posts_n;i++) {
- latest_posts_r = posts.exec(body);
- latest_posts.push(latest_posts_r);
- delete latest_posts[latest_posts.length - 1].input;
- delete latest_posts[latest_posts.length - 1].index;
- delete latest_posts[latest_posts.length - 1][0];
- }
- latest_posts = latest_posts[latest_posts.length - 1];
- var time = latest_posts[1];
- var global_post_id = latest_posts[2];
- var thread_post_id = latest_posts[3];
- var user_id = latest_posts[4];
- var username = latest_posts[5];
- AdminServ.database.query("SELECT `id` FROM `bot_forums` WHERE `board`='Facepunch' AND `forum`='Facepunch'",function(err,rows) {
- if (err) {console.log(err);return;}
- if (rows.length == 0) {
- AdminServ.database.query("INSERT INTO `bot_forums` (`forum`,`board`,`id`) VALUES('Facepunch','Facepunch',?)",[thread_post_id]);
- } else if (rows[0].id != thread_post_id) {
- AdminServ.channels.community.sendMessage("```\nFacepunch Thread • " + time + "\n\n" + username + " (#" + user_id + ")\n```\nhttps://facepunch.com/showthread.php?t=" + AdminServ.facepunch_url + "&p=" + global_post_id + "&viewfull=1#post" + global_post_id);
- AdminServ.database.query("UPDATE `bot_forums` SET `id`=? WHERE `forum`='Facepunch' AND `board`='Facepunch'",[thread_post_id]);
- }
- });
- }
- }
- });
- }
- setInterval(check,AdminServ.forums_interval);
- check();
- };
- AdminServ.bot.on("userUpdate",function(oldUser,newUser) {
- //AdminServ.database.query("INSERT INTO `bot_discordids` (`id`,`username`,`nickname`) VALUES(?,?,?) ON DUPLICATE KEY UPDATE `id`=?, `username`=?, `nickname`=?",[newUser.id,newUser.username,newUser.nickname,newUser.id,newUser.username,newUser.nickname]);
- });
- AdminServ.bot.on("message",message => {
- if (message.author.id == AdminServ.bot.user.id) {return;}
- //AdminServ.database.query("INSERT INTO `bot_discordlog` (`channel`,`discord`,`datetime`,`message`) VALUES(?,?,CURRENT_TIMESTAMP,?)",[message.channel.name,message.author.id,message.content]);
- var script = /gmodstore\.com\/scripts\/view\/(\d+)/g;
- var user = /gmodstore\.com\/users\/view\/(\d+)/g;
- var job = /gmodstore\.com\/jobs\/view\/(\d+)/g;
- var usrsearch = /search\/(\d+)/g;
- var shortlink = /https?:\/\/gmodsto\.re\/([a-zA-Z0-9-$%^*(),'\";:\|#@~`=_]+)/g;
- var matches = 0;
- if (message.content.match(script)) {
- if (message.content.match(script).length == 1) {
- matches += 1;
- }
- }
- if (message.content.match(usrsearch)) {
- if (message.content.match(usrsearch).length == 1) {
- matches += 1;
- }
- }
- if (message.content.match(user)) {
- if (message.content.match(user).length == 1) {
- matches += 1;
- }
- }
- if (message.content.match(job)) {
- if (message.content.match(job).length == 1) {
- matches += 1;
- }
- }
- if (message.content.match(shortlink)) {
- if (message.content.match(shortlink).length == 1) {
- matches += 1;
- }
- }
- if (matches > 1 || matches == 0) {
- return;
- }
- script = script.exec(message.content);
- if (script) {
- AdminServ.script(message,script[1]);
- }
- user = user.exec(message.content);
- if (user) {
- AdminServ.user(message,user[1]);
- }
- usrsearch = usrsearch.exec(message.content);
- if (usrsearch) {
- AdminServ.channels.general.sendMessage(" Yup");
- }
- job = job.exec(message.content);
- if (job) {
- AdminServ.job(message,job[1]);
- }
- shortlink = shortlink.exec(message.content);
- if (shortlink) {
- AdminServ.shortlink(message,shortlink[1]);
- }
- });
- AdminServ.bot.on("guildMemberAdd",function(_,member) {
- member.sendMessage("Welcome to the GModStore Discord. Please read the #welcome channel.\n\nTo link your GModStore profile to the Discord (which will also grant you with the Developer role if you're a developer), type `.link <GModStore profile URL>` and instructions will follow.\nType `.help` to see the commands you can use on me.");
- member = member.user;
- AdminServ.channels.general.sendMessage(member.toString() + " has joined the Discord.");
- });
- AdminServ.bot.on("guildMemberRemove",function(_,member) {
- member = member.user;
- AdminServ.channels.general.sendMessage(member.toString() + " has left the Discord.");
- });
- AdminServ.bot.on("ready",function() {
- AdminServ.bot.user.setGame("JSBot");
- AdminServ.guild = AdminServ.bot.guilds.array();
- for (var i=0;i < AdminServ.guild.length;i++) {
- if (AdminServ.guild[i].id == "191312474954268672") {
- AdminServ.guild = AdminServ.guild[i];
- AdminServ.users = AdminServ.guild.members.array();
- for (var i=0;i < AdminServ.users.length;i++) {
- //AdminServ.database.query("INSERT INTO `bot_discordids` (`id`,`username`,`nickname`) VALUES(?,?,?) ON DUPLICATE KEY UPDATE `id`=?, `username`=?, `nickname`=?",[AdminServ.users[i].id,AdminServ.users[i].user.username,AdminServ.users[i].nickname || AdminServ.users[i].user.username,AdminServ.users[i].id,AdminServ.users[i].user.username,AdminServ.users[i].nickname || AdminServ.users[i].user.username]);
- }
- }
- }
- var jar = request.jar();
- var channels = AdminServ.bot.channels.array();
- for (var i=0;i < channels.length;i++) {
- if (channels[i].type == "text") {
- AdminServ.channels[channels[i].name] = channels[i];
- }
- }
- //AdminServ.channels.general.sendMessage("Hello, I am AdminServ -- Connection established.");
- });
- AdminServ.bot.on("message", (message) => {
- let prefix = "!";
- if (message.content.startsWith( prefix + "ping")) {
- message.channel.sendMessage("pong! your mom");
- }
- });
- AdminServ.bot.login(AdminServ.botsecret);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement