Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. // Define all our included variables
  2. var steam = require('steam');
  3. var winston = require('winston');
  4.  
  5. //These are included node modules that don't require installation via npm
  6. var readline = require('readline');
  7. var fs = require('fs');
  8.  
  9. // Setup readline to read from console. This is used for Steam Guard codes.
  10. var rl = readline.createInterface({
  11. input: process.stdin,
  12. output: process.stdout
  13. });
  14.  
  15. // Setup logging to file and console
  16. var logger = new (winston.Logger)({
  17. transports: [
  18. new (winston.transports.Console)({
  19. colorize: true,
  20. level: 'debug'
  21. }),
  22. new (winston.transports.File)({
  23. level: 'info',
  24. timestamp: true,
  25. filename: 'katjadump.log',
  26. json: false
  27. })
  28. ]
  29. });
  30.  
  31. // Initialize the Steam client
  32. var client = new steam.SteamClient();
  33.  
  34. // Now we can finally start doing stuff! Let's try logging in.
  35. client.logOn({
  36. accountName: username,
  37. password: password
  38. });
  39.  
  40. // After successful login...
  41. client.on('loggedOn', function() {
  42. logger.info('Logged on to Steam');
  43. // Optional: Rename the bot on login.
  44. client.setPersonaName("Katjabot");
  45. // Make sure we're not displaying as online until we're ready
  46. client.setPersonaState(steam.EPersonaState.Offline);
  47. });
  48.  
  49. // If a user adds me...
  50. client.on('friend', function(steamID, relationship) {
  51. if (relationship == steam.EFriendRelationship.RequestRecipient) {
  52. logger.info('[' + steamID + '] Accepted friend request');
  53. client.addFriend(steamID);
  54. }
  55. else if (relationship == steam.EFriendRelationship.None) {
  56. logger.info('[' + steamID + '] Un-friended');
  57. }
  58. });
  59.  
  60. // If a user messages me through Steam...
  61. client.on('friendMsg', function(steamID, message, type) {
  62. if (type == steam.EChatEntryType.ChatMsg) { // Regular chat message
  63. logger.info('[' + steamID + '] MSG: ' + message); // Log it
  64. client.sendMessage(steamID, 'Hello, I\'m Katjabot, a chatbot and your new friend. I can\'t do much at the moment, so I apologise. Have a hug. \*hugs\*');
  65. }
  66. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement