Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //todo:
- // discordBot receives SteamID and logs in database as dID : sID
- // app checks desired channel's dIDs against sIDs
- // if sID is known, log all competitive played maps
- // if Majority of maps are the same; display score as setgame
- const fs = require('fs');
- const config = require('./config.json');
- const DataPath = './database.json'
- const SteamUser = require('steam-user');
- const SteamTotp = require('steam-totp');
- const Discord = require('discord.js');
- const sClient = new SteamUser(); //Initialize Steam
- const dClient = new Discord.Client(); //Initialize Discord
- const sAdmin = config.sAdmin
- const dAdmin = config.dAdmin
- const sLogOnOptions = {
- accountName: config.sUser,
- password: config.sPass
- //twoFactorCode: Steam-Totp.generateAuthCode(config.sSecret)
- };
- sClient.logOn(sLogOnOptions);
- sClient.on('loggedOn', () => {
- console.log('Steam Online and ready.');
- sClient.setPersona(SteamUser.Steam.EPersonaState.Online, 'RuleBot');
- //sClient.gamesPlayed('with your mom.');
- });
- dClient.on('ready',() => {
- console.log("Discord Online and ready.")
- });
- //sEvent Handling
- sClient.on('friendRelationship', (steamid, relationship) => {
- //if bot receives add request
- if (relationship === 2){
- sClient.addFriend(steamid);
- sClient.chatMessage(steamid, 'Fuck you. I would have blocked you if my programming permitted. I mean-- Thanks for adding me!');
- sClient.chatMessage(steamid, 'Send <!r connect> to me on Discord to get your connection command.')
- console.log('New Friend: ' + steamid)
- } else {
- // if ()
- };
- });
- var friendsLoaded = false
- sClient.on('friendPersonasLoaded', (x,y,z) => {
- friendsLoaded = true
- console.log('Friends Loaded:' + friendsLoaded);
- //console.log(sClient.users);
- });
- //event handling
- dClient.on("guildDelete", guild => {
- console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
- });
- dClient.on("guildCreate", guild => {
- console.log(`I have been added to: ${guild.name} (id: ${guild.id})`);
- });
- dClient.on('guildMemberAdd', (member) => {
- console.log('User has joined: '+ member.user.username);
- });
- //Message handling
- var prefix = '!r'
- sClient.on('friendMessage', (steamid, message) => {
- if (steamid === sAdmin) {
- console.log(message)
- };
- if (!message.startsWith(prefix)) return;
- console.log('Steam command received');
- var args = message.split(' ').slice(1);
- var argresult = args.join(' ');
- if (args[0] === 'add') {
- sClient.addFriend(args[1]);
- console.log('Attempting to add ' + args[1]);
- } else
- if (args[0] === 'id') {
- sClient.chatMessage(steamid, sClient.users[steamid].player_name + ', your ID is: ' + String(steamid))
- } else
- if (args[0] === 'getpersona') {
- let rPresence = sClient.users[steamid].rich_presence
- let parsedPresence = {}
- for (var i in rPresence) {
- let newKey = rPresence[i].key
- let newVal = rPresence[i].value
- parsedPresence[newKey] = newVal
- };
- if (!args[1]) {
- console.log(sClient.users[steamid]);
- } else
- sClient.chatMessage(steamid, parsedPresence[args[1]]);
- } else
- if (args[0] === 'getinfo') {
- sClient.chatMessage(steamid, sClient.users[args[1]].player_name)
- console.log(sClient.users[args[1]]);
- } else
- if (args[0] === 'connect') {
- sClient.chatMessage(steamid, 'Send the following command to my Discord: \n !r connect ' +steamid);
- };
- }); //end of SMessage Handler
- dClient.on('message', message => {
- if (!message.content.startsWith(prefix)) return;
- console.log('dCommand: ' + message);
- var args = message.content.split(' ').slice(1);
- var argresult = args.join(' ');
- if (message.author.bot) return;
- if (args[0] === 'ping') {
- message.channel.send(dClient.ping + ' ms');
- } else
- if (args[0] === 'setgame'){
- args.shift()
- argresult = args.join(' ');
- console.log(argresult)
- if (!argresult) argresult = null;
- dClient.user.setActivity(argresult);
- sClient.gamesPlayed(argresult);
- } else
- if (args[0] === 'setstatus'){
- args.shift()
- argresult = args.join(' ');
- if (!argresult) argresult = 'online';
- dClient.user.setStatus(argresult)
- .then(console.log);
- } else
- if (args[0] === 'add'){
- let steamFriendLink = 'steam://friends/add/' + config.sBotID
- message.channel.send(steamFriendLink + '\nPlease add me on steam.');
- } else
- if (args[0] === 'test') {
- message.channel.send('fuck you');
- //console.log(message.author.id);
- } else
- if (args[0] === 'getSteam') {
- let steamid = args[1]
- //message.channel.send(sClient.users.steamid.player_name);
- //sClient.chatMessage(steamid, 'test');
- //console.log(sClient.users);
- } else
- if (args[0] === 'connect') {
- if (!args[1]) {
- message.author.send('Usage: !r connect <Steam ID>');
- } else {
- //paste start
- fs.readFile(DataPath, 'utf8', function readFileCallback(err, data){
- if (err){
- console.log(err);
- } else {
- var IDObj = {};
- var IDJson = JSON.stringify(IDObj, null, 2);
- let dID = [message.author.id]
- let sID = parseInt(args[1],10);
- IDObj = JSON.parse(data); //now it an object
- //IDObj.table.push({[dID] : sID}); //add some data
- if (IDObj.dID) console.log('already exists!');
- //IDObj.table.push({[dID] : sID}); //add some data
- IDObj[dID] = sID
- IDJson = JSON.stringify(IDObj, null, 2); //convert it back to json
- fs.writeFile(DataPath, IDJson, 'utf8', (err) => { // write it back
- if (err) {console.error(err)
- message.author.send('An error occured. Pass this along to Rules and call him an asshole for me.\n' + err);
- } else {
- message.author.send('Successfully connected your Discord ID to your Steam ID');
- console.log('Added '+ dID +' : ' + sID + ' to the database.');
- //console.log('Added ' + [dID] + ':' + [steamid] + ' to the database.');
- };
- });
- }});
- };
- //paste end
- };
- });
- var IDObj = {};
- var interval = setInterval( function() {
- //console.log('Interval Works.');
- // let tarChannel = '425444453973622808' // lounge
- //let tarChannel = '447469258180526090' /CSGO
- //let tarChannel = '422438345256337414' //general chat
- let tarChannel = '444699651313238041' //general ayylmao voice
- let membersInVoice = dClient.channels.get(tarChannel).members.map(m=>m.user.id); //Lounge Chan
- let usernamesInVoice = dClient.channels.get(tarChannel).members.map(m=>m.user.username); //Lounge Chan
- if (friendsLoaded) {
- if (!membersInVoice[0]) {
- console.log('No users currently in desired channel.')
- } else {
- // console.log(membersInVoice);
- // console.log(usernamesInVoice);
- //var IDObj = {};
- fs.readFile(DataPath, 'utf8', function readFileCallback(err, data) {
- if (err) {
- console.log(err);
- } else {
- //console.log(data);
- IDObj = JSON.parse(data);
- //console.log(IDObj);
- };
- });
- //console.log(IDObj);
- //console.log(JSON.stringify(IDObj));
- var knownUsers = {};
- for (var i in membersInVoice) {
- var dID = String(membersInVoice[i]);
- var sID = undefined
- //console.log(JSON.stringify(IDObj));
- //console.log(IDObj[membersInVoice[i]]);
- if (IDObj[String(dID)]) {
- sID = IDObj[String(dID)]
- //console.log('SteamID:' + sID);
- let dUser = dClient.users.get(dID).username
- //console.log('DiscID:' + dUser);
- let allSteamUsers = sClient.users
- let sUser = allSteamUsers[sID].player_name
- //console.log('sUser:' + sUser);
- let rPresence = sClient.users[sID].rich_presence
- var parsedPresence = {}
- for (var i in rPresence) {
- let newKey = rPresence[i].key
- let newVal = rPresence[i].value
- parsedPresence[newKey] = newVal
- };
- let currentPlay = parsedPresence.status
- //console.log(parsedPresence);
- console.log(dUser + ' | ' + sUser + ' | ' + currentPlay);
- parsedPresence = {}
- } else {
- };
- };
- }; //if members are in voice close
- }; //if friendsloaded close
- }, 6 * 1000); //run every 6 seconds
- dClient.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement