Created
April 3, 2016 21:24
-
-
Save ConnorMcF/38ed6ec84de8e5e2a47da684b402b527 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
var Steam = require('steam'); | |
var Cleverbot = require('cleverbot-node'); | |
var cleverbot = new Cleverbot; | |
var steamClient = new Steam.SteamClient(); | |
var steamUser = new Steam.SteamUser(steamClient); | |
var steamFriends = new Steam.SteamFriends(steamClient); | |
var twofa = require('steam-totp'); | |
var uuid = require('node-uuid'); | |
var htmlEscape = require('secure-filters').html; | |
var server = app.listen(7332, function() { | |
console.log('SOCKET ON 7332'); | |
}); | |
var io = require('socket.io')(server); | |
console.log("Connecting to steam..."); | |
steamClient.connect(); | |
steamClient.on('connected', function() { | |
console.log("Connected, logging in..."); | |
var tfa = twofa.generateAuthCode(''); | |
steamUser.logOn({ | |
account_name: '', | |
password: '', | |
two_factor_code: | |
}); | |
}); | |
steamClient.on('logOnResponse', function(logonResp) { | |
if (logonResp.eresult == Steam.EResult.OK) { | |
console.log('Log on!'); | |
steamFriends.setPersonaState(Steam.EPersonaState.Online); | |
steamUser.gamesPlayed({ | |
games_played: [{ game_id: '313740' }] | |
}); | |
console.log(steamFriends.friends) | |
} else { | |
console.log(logonResp); | |
steamClient.disconnect(); | |
} | |
console.log("Done!"); | |
app.listen(7331, function () { | |
console.log('HTTP ON 7331'); | |
}); | |
}); | |
steamFriends.on('message', function(source, message, type, chatter) { | |
// respond to both chat room and private messages | |
console.log(source+': ' + message); | |
if (message == 'help' || message == '!help') { | |
steamFriends.sendMessage(source, 'I\'m a steam bot made by ConnorMcF: http://steamcommunity.com/id/connormcf10', Steam.EChatEntryType.ChatMsg); | |
steamFriends.sendMessage(source, 'I can add other people too! Type "!invite [STEAM 64 ID]" to have the bot add a friend.', Steam.EChatEntryType.ChatMsg); | |
} else if(message == "") { | |
} else { | |
var uid = uuid.v1(); | |
io.emit('message', { uid: uid, message: htmlEscape(message) }); | |
Cleverbot.prepare(function(){ | |
cleverbot.write(message, function (response) { | |
steamFriends.sendMessage(source, response.message, Steam.EChatEntryType.ChatMsg); | |
io.emit('response', { uid: uid, message: htmlEscape(response.message) }); | |
}); | |
}); | |
} | |
}); | |
steamFriends.on('chatInvite', function(chatRoomID, chatRoomName, patronID) { | |
console.log('Got an invite to ' + chatRoomName + ' from ' + steamFriends.personaStates[patronID].player_name); | |
steamFriends.joinChat(chatRoomID); | |
}); | |
steamFriends.on('friend', function(steamID,relation) { | |
if(relation == EFriendRelationship.RequestRecipient) { | |
steamFriends.addFriend(steamID); | |
} | |
}); | |
app.get('/', function (req, res) { | |
res.sendFile(__dirname + '/index.html'); | |
}); | |
io.on('connection', function(socket) { | |
console.log('a user connected'); | |
socket.on('disconnect', function() { | |
console.log('user disconnected'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> | |
<title>Bootstrap 101 Template</title> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> | |
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> | |
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | |
<!--[if lt IE 9]> | |
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> | |
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> | |
<![endif]--> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>BOT Savage Live Feed</h1> | |
<div class="feed"> | |
</div> | |
</div> | |
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<!-- Include all compiled plugins (below), or include individual files as needed --> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> | |
<script src="https://cdn.socket.io/socket.io-1.3.5.js"></script> | |
<script> | |
var socket = io(":7332"); | |
socket.on('message', function(data){ | |
$(".feed").prepend(`<div class="panel panel-default"> | |
<div class="panel-body"> | |
<blockquote> | |
<p>`+ data.message +`</p> | |
</blockquote> | |
<p id="`+ data.uid +`_resp"><b>Waiting for response...</b></p> | |
</div> | |
</div>`).fadeIn(500); | |
}); | |
socket.on('response', function(data){ | |
$("#"+data.uid+"_resp").html(data.message).fadeIn(500); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "sakspri_idle", | |
"version": "1.0.0", | |
"description": "", | |
"main": "app.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"cleverbot-node": "^0.2.1", | |
"express": "^4.13.4", | |
"node-uuid": "^1.4.7", | |
"socket.io": "^1.4.5", | |
"steam": "^1.4.0", | |
"steam-totp": "^1.3.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment