Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using SteamKit2;
- using System.Threading;
- using System.IO;
- using System.Security.Cryptography;
- using ChatterBotAPI;
- namespace SteamBot
- {
- class Program
- {
- static SteamClient steamClient;
- static CallbackManager manager;
- static SteamFriends steamFriends;
- static SteamUser steamUser;
- static bool isRunning;
- static string user, pass;
- static string authCode, twoFactorAuth;
- static string senderName;
- static ChatterBotSession botSession;
- static void Main(string[] args)
- {
- if (!File.Exists("chat.txt"))
- {
- File.Create("chat.txt").Close();
- File.WriteAllText("chat.txt", "abc | 123");
- }
- Console.Title = "A bot";
- Console.WriteLine("CTRL+C quits the program.");
- Console.Write("Username: ");
- user = Console.ReadLine();
- Console.Write("Password: ");
- pass = Console.ReadLine();
- SteamLogIn();
- }
- static void SteamLogIn()
- {
- steamClient = new SteamClient();
- manager = new CallbackManager(steamClient);
- steamUser = steamClient.GetHandler<SteamUser>();
- steamFriends = steamClient.GetHandler<SteamFriends>();
- new Callback<SteamClient.ConnectedCallback>(OnConnected, manager);
- new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, manager);
- new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
- new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff, manager);
- new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo, manager);
- new Callback<SteamFriends.FriendMsgCallback>(OnChatMessage, manager);
- new Callback<SteamFriends.FriendsListCallback>(OnFriendsList, manager);
- new Callback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth, manager);
- isRunning = true;
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("Connecting to Steam...");
- steamClient.Connect();
- while (isRunning)
- {
- manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
- }
- Console.ReadKey();
- }
- static void OnConnected(SteamClient.ConnectedCallback callback)
- {
- if (callback.Result != EResult.OK)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Unable to connect to Steam: {0}", callback.Result);
- isRunning = false;
- return;
- }
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Connected to Steam! Logging in '{0}'...", user);
- byte[] sentryHash = null;
- if (File.Exists("sentry.bin"))
- {
- byte[] sentryFile = File.ReadAllBytes("sentry.bin");
- sentryHash = CryptoHelper.SHAHash(sentryFile);
- }
- steamUser.LogOn(new SteamUser.LogOnDetails
- {
- Username = user,
- Password = pass,
- AuthCode = authCode,
- SentryFileHash = sentryHash,
- });
- }
- static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
- {
- if (callback.Result == EResult.AccountLogonDenied)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("FYI : This account is SteamGuard protected.");
- Console.Write("Please enter the auth code sent to the email at {0}: ", callback.EmailDomain);
- authCode = Console.ReadLine();
- return;
- }
- if (callback.Result != EResult.OK)
- {
- Console.ForegroundColor = ConsoleColor.DarkRed;
- Console.WriteLine("Unable to log in to Steam: {0}\n", callback.Result);
- isRunning = false;
- return;
- }
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("{0} succesfully logged in!", user);
- }
- static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback)
- {
- Console.WriteLine("Updating sentryfile...");
- byte[] sentryHash = CryptoHelper.SHAHash(callback.Data);
- File.WriteAllBytes("sentry.bin", callback.Data);
- steamUser.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
- {
- JobID = callback.JobID,
- FileName = callback.FileName,
- BytesWritten = callback.BytesToWrite,
- FileSize = callback.Data.Length,
- Offset = callback.Offset,
- Result = EResult.OK,
- LastError = 0,
- OneTimePassword = callback.OneTimePassword,
- SentryFileHash = sentryHash,
- });
- Console.WriteLine("Done!");
- }
- static void OnDisconnected(SteamClient.DisconnectedCallback callback)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Connecting to steam...", user);
- steamClient.Connect();
- }
- static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Logged off of Steam: {0}", callback.Result);
- }
- static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
- {
- steamFriends.SetPersonaState(EPersonaState.Online);
- }
- static void OnChatMessage(SteamFriends.FriendMsgCallback callback)
- {
- if (callback.EntryType == EChatEntryType.ChatMsg)
- {
- var msg = callback.Message.Trim();
- var msg2 = msg.Split(' ');
- senderName = steamFriends.GetFriendPersonaName(callback.Sender);
- Console.WriteLine($"[SteamBot] Message received: {senderName}: {callback.Message}");
- string[] args;
- switch (msg2[0].ToLower())
- {
- case "Hello":
- steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Hello");
- break;
- default:
- string botReply;
- ChatterBotFactory factory = new ChatterBotFactory();
- ChatterBot bot = factory.Create(ChatterBotType.CLEVERBOT);
- botSession = bot.CreateSession();
- try
- {
- botReply = botSession.Think(callback.Message);
- }
- catch (Exception)
- {
- return;
- }
- steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, botReply);
- Console.WriteLine($"[SteamBot] Responded to {senderName}: {botReply}");
- break;
- }
- }
- }
- static void OnFriendsList(SteamFriends.FriendsListCallback callback)
- {
- int friendCount = steamFriends.GetFriendCount();
- Console.WriteLine($"[SteamBot] Bot has {0} friends", friendCount);
- for (int x = 0; x < friendCount; x++)
- {
- SteamID steamIdFriend = steamFriends.GetFriendByIndex(x);
- Console.WriteLine($"[SteamBot] Friend: {0}", steamIdFriend.Render());
- }
- foreach (var friend in callback.FriendList)
- {
- if (friend.Relationship == EFriendRelationship.RequestRecipient)
- {
- steamFriends.AddFriend(friend.SteamID);
- }
- }
- }
- static void OnFriendAdded(SteamFriends.FriendAddedCallback callback)
- {
- if (callback.Result == EResult.OK)
- {
- Console.WriteLine($"[SteamBot] {0} added friend.", callback.PersonaName);
- steamFriends.SendChatMessage(callback.SteamID, EChatEntryType.ChatMsg, "Thank you for adding me friend.");
- }
- }
- public static string[] Separate(int numberOfArguments, string command)
- {
- string[] separated = new string[4]; // will contain command split by space delimeter
- int length = command.Length;
- int partitionLength = 0;
- int i = 0;
- foreach (char c in command)
- {
- if (i != numberOfArguments)
- {
- if (partitionLength > length || numberOfArguments > 5)
- { // error handling
- separated[0] = "-1";
- return separated;
- }
- else if (c == ' ')
- {
- separated[i++] = command.Remove(command.IndexOf(c));
- command = command.Remove(0, command.IndexOf(c) + 1);
- }
- partitionLength++;
- if (partitionLength == length && i != numberOfArguments)
- {
- separated[0] = "-1";
- return separated;
- }
- }
- else
- {
- separated[i] = command;
- }
- }
- return separated;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement