Advertisement
Guest User

Code +Correct+

a guest
Jan 11th, 2017
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using SteamKit2;
  7. using System.Threading;
  8. using System.IO;
  9. using System.Security.Cryptography;
  10. using ChatterBotAPI;
  11.  
  12. namespace SteamBot
  13. {
  14. class Program
  15. {
  16.  
  17. static SteamClient steamClient;
  18. static CallbackManager manager;
  19. static SteamFriends steamFriends;
  20. static SteamUser steamUser;
  21. static bool isRunning;
  22. static string user, pass;
  23. static string authCode, twoFactorAuth;
  24. static string senderName;
  25. static ChatterBotSession botSession;
  26.  
  27. static void Main(string[] args)
  28. {
  29. if (!File.Exists("chat.txt"))
  30. {
  31. File.Create("chat.txt").Close();
  32. File.WriteAllText("chat.txt", "abc | 123");
  33. }
  34.  
  35. Console.Title = "A bot";
  36. Console.WriteLine("CTRL+C quits the program.");
  37.  
  38. Console.Write("Username: ");
  39. user = Console.ReadLine();
  40.  
  41. Console.Write("Password: ");
  42. pass = Console.ReadLine();
  43. SteamLogIn();
  44. }
  45.  
  46. static void SteamLogIn()
  47. {
  48. steamClient = new SteamClient();
  49.  
  50. manager = new CallbackManager(steamClient);
  51.  
  52. steamUser = steamClient.GetHandler<SteamUser>();
  53.  
  54. steamFriends = steamClient.GetHandler<SteamFriends>();
  55.  
  56. new Callback<SteamClient.ConnectedCallback>(OnConnected, manager);
  57. new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, manager);
  58.  
  59. new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
  60. new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff, manager);
  61.  
  62. new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo, manager);
  63. new Callback<SteamFriends.FriendMsgCallback>(OnChatMessage, manager);
  64.  
  65. new Callback<SteamFriends.FriendsListCallback>(OnFriendsList, manager);
  66.  
  67. new Callback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth, manager);
  68.  
  69.  
  70. isRunning = true;
  71.  
  72. Console.ForegroundColor = ConsoleColor.Cyan;
  73. Console.WriteLine("Connecting to Steam...");
  74.  
  75. steamClient.Connect();
  76.  
  77.  
  78. while (isRunning)
  79. {
  80. manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
  81. }
  82. Console.ReadKey();
  83. }
  84.  
  85. static void OnConnected(SteamClient.ConnectedCallback callback)
  86. {
  87. if (callback.Result != EResult.OK)
  88. {
  89. Console.ForegroundColor = ConsoleColor.Red;
  90. Console.WriteLine("Unable to connect to Steam: {0}", callback.Result);
  91.  
  92. isRunning = false;
  93. return;
  94. }
  95. Console.ForegroundColor = ConsoleColor.Green;
  96. Console.WriteLine("Connected to Steam! Logging in '{0}'...", user);
  97.  
  98. byte[] sentryHash = null;
  99. if (File.Exists("sentry.bin"))
  100. {
  101. byte[] sentryFile = File.ReadAllBytes("sentry.bin");
  102. sentryHash = CryptoHelper.SHAHash(sentryFile);
  103. }
  104.  
  105. steamUser.LogOn(new SteamUser.LogOnDetails
  106. {
  107. Username = user,
  108. Password = pass,
  109.  
  110. AuthCode = authCode,
  111.  
  112. SentryFileHash = sentryHash,
  113. });
  114. }
  115.  
  116. static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
  117. {
  118. if (callback.Result == EResult.AccountLogonDenied)
  119. {
  120. Console.ForegroundColor = ConsoleColor.Red;
  121. Console.WriteLine("FYI : This account is SteamGuard protected.");
  122.  
  123. Console.Write("Please enter the auth code sent to the email at {0}: ", callback.EmailDomain);
  124.  
  125. authCode = Console.ReadLine();
  126.  
  127. return;
  128. }
  129. if (callback.Result != EResult.OK)
  130. {
  131. Console.ForegroundColor = ConsoleColor.DarkRed;
  132. Console.WriteLine("Unable to log in to Steam: {0}\n", callback.Result);
  133. isRunning = false;
  134. return;
  135. }
  136. Console.ForegroundColor = ConsoleColor.Green;
  137. Console.WriteLine("{0} succesfully logged in!", user);
  138. }
  139.  
  140. static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback)
  141. {
  142. Console.WriteLine("Updating sentryfile...");
  143. byte[] sentryHash = CryptoHelper.SHAHash(callback.Data);
  144. File.WriteAllBytes("sentry.bin", callback.Data);
  145. steamUser.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
  146. {
  147. JobID = callback.JobID,
  148. FileName = callback.FileName,
  149. BytesWritten = callback.BytesToWrite,
  150. FileSize = callback.Data.Length,
  151. Offset = callback.Offset,
  152. Result = EResult.OK,
  153. LastError = 0,
  154. OneTimePassword = callback.OneTimePassword,
  155. SentryFileHash = sentryHash,
  156. });
  157. Console.WriteLine("Done!");
  158. }
  159.  
  160. static void OnDisconnected(SteamClient.DisconnectedCallback callback)
  161. {
  162. Console.ForegroundColor = ConsoleColor.Green;
  163. Console.WriteLine("Connecting to steam...", user);
  164.  
  165. steamClient.Connect();
  166. }
  167.  
  168. static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
  169. {
  170. Console.ForegroundColor = ConsoleColor.Red;
  171. Console.WriteLine("Logged off of Steam: {0}", callback.Result);
  172. }
  173.  
  174. static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
  175. {
  176. steamFriends.SetPersonaState(EPersonaState.Online);
  177.  
  178. }
  179. static void OnChatMessage(SteamFriends.FriendMsgCallback callback)
  180. {
  181. if (callback.EntryType == EChatEntryType.ChatMsg)
  182. {
  183.  
  184. var msg = callback.Message.Trim();
  185. var msg2 = msg.Split(' ');
  186. senderName = steamFriends.GetFriendPersonaName(callback.Sender);
  187.  
  188. Console.WriteLine($"[SteamBot] Message received: {senderName}: {callback.Message}");
  189. string[] args;
  190. switch (msg2[0].ToLower())
  191. {
  192. case "Hello":
  193. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Hello");
  194. break;
  195.  
  196. default:
  197. string botReply;
  198. ChatterBotFactory factory = new ChatterBotFactory();
  199. ChatterBot bot = factory.Create(ChatterBotType.CLEVERBOT);
  200. botSession = bot.CreateSession();
  201. try
  202. {
  203. botReply = botSession.Think(callback.Message);
  204. }
  205. catch (Exception)
  206. {
  207. return;
  208. }
  209.  
  210. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, botReply);
  211. Console.WriteLine($"[SteamBot] Responded to {senderName}: {botReply}");
  212.  
  213. break;
  214. }
  215.  
  216. }
  217. }
  218.  
  219. static void OnFriendsList(SteamFriends.FriendsListCallback callback)
  220. {
  221. int friendCount = steamFriends.GetFriendCount();
  222.  
  223. Console.WriteLine($"[SteamBot] Bot has {0} friends", friendCount);
  224.  
  225. for (int x = 0; x < friendCount; x++)
  226. {
  227. SteamID steamIdFriend = steamFriends.GetFriendByIndex(x);
  228.  
  229. Console.WriteLine($"[SteamBot] Friend: {0}", steamIdFriend.Render());
  230. }
  231.  
  232.  
  233. foreach (var friend in callback.FriendList)
  234. {
  235. if (friend.Relationship == EFriendRelationship.RequestRecipient)
  236. {
  237. steamFriends.AddFriend(friend.SteamID);
  238. }
  239. }
  240. }
  241.  
  242. static void OnFriendAdded(SteamFriends.FriendAddedCallback callback)
  243. {
  244. if (callback.Result == EResult.OK)
  245. {
  246. Console.WriteLine($"[SteamBot] {0} added friend.", callback.PersonaName);
  247. steamFriends.SendChatMessage(callback.SteamID, EChatEntryType.ChatMsg, "Thank you for adding me friend.");
  248. }
  249. }
  250.  
  251. public static string[] Separate(int numberOfArguments, string command)
  252. {
  253. string[] separated = new string[4]; // will contain command split by space delimeter
  254.  
  255. int length = command.Length;
  256. int partitionLength = 0;
  257.  
  258. int i = 0;
  259. foreach (char c in command)
  260. {
  261. if (i != numberOfArguments)
  262. {
  263. if (partitionLength > length || numberOfArguments > 5)
  264. { // error handling
  265. separated[0] = "-1";
  266. return separated;
  267. }
  268. else if (c == ' ')
  269. {
  270. separated[i++] = command.Remove(command.IndexOf(c));
  271. command = command.Remove(0, command.IndexOf(c) + 1);
  272. }
  273. partitionLength++;
  274. if (partitionLength == length && i != numberOfArguments)
  275. {
  276. separated[0] = "-1";
  277. return separated;
  278. }
  279. }
  280. else
  281. {
  282. separated[i] = command;
  283. }
  284. }
  285. return separated;
  286. }
  287.  
  288. }
  289. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement