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.IO;
- using System.Threading;
- namespace _1703_Bot
- {
- class Program
- {
- static bool is_running = false;
- static string user_name, pass;
- static string auth_code;
- static SteamClient steam_client;
- static CallbackManager callback_manager;
- static SteamUser steam_user;
- static SteamFriends steam_friends;
- static void Main(string[] args)
- {
- if (!File.Exists("chat.txt"))
- {
- File.Create("chat.txt").Close();
- File.WriteAllText("chat.txt", "Hello | <MSG> Hello. Use '!help' to view commands.");
- }
- if (!File.Exists("admin.txt"))
- {
- File.Create("admin.txt").Close();
- File.WriteAllText("admin.txt", "76561198053054477");
- }
- Console.Title = "1703 Bot Console";
- Console.Write("Username: ");
- user_name = Console.ReadLine();
- Console.Write("Password: ");
- pass = Console.ReadLine();
- SteamLogIn();
- }
- static void SteamLogIn()
- {
- steam_client = new SteamClient();
- callback_manager = new CallbackManager(steam_client);
- steam_user = steam_client.GetHandler<SteamUser>();
- steam_friends = steam_client.GetHandler<SteamFriends>();
- callback_manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
- callback_manager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
- callback_manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
- callback_manager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff);
- callback_manager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo);
- callback_manager.Subscribe<SteamFriends.FriendMsgCallback>(OnChatMessage);
- callback_manager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendsList);
- callback_manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
- is_running = true;
- Console.Write("Connecting to Steam...");
- steam_client.Connect();
- while (is_running)
- {
- callback_manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
- }
- Console.ReadKey();
- }
- static void OnConnected(SteamClient.ConnectedCallback callback)
- {
- if (callback.Result != EResult.OK)
- {
- Console.WriteLine("Unable to connect to Steam: {0}", callback.Result);
- is_running = false;
- return;
- }
- Console.WriteLine("Connected to Steam! Logging in '{0}'", callback.Result);
- byte[] sentry_hash = null;
- if (File.Exists("sentry.bin"))
- {
- byte[] sentry_file = File.ReadAllBytes("sentry.bin");
- sentry_hash = CryptoHelper.SHAHash(sentry_file);
- }
- steam_user.LogOn(new SteamUser.LogOnDetails
- {
- Username = user_name,
- Password = pass,
- AuthCode = auth_code,
- SentryFileHash = sentry_hash,
- });
- }
- static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
- {
- if (callback.Result == EResult.AccountLogonDenied)
- {
- Console.WriteLine("This account is SteamGuard protected.");
- Console.WriteLine("Please enter the authorization code sent ot the email at {0}: ", callback.EmailDomain);
- auth_code = Console.ReadLine();
- return;
- }
- if (callback.Result != EResult.OK)
- {
- Console.WriteLine("Unable to log in to Steam: {0}\n", callback.Result);
- is_running = false;
- return;
- }
- Console.WriteLine("{0} Successfully Logged in to Steam!", user_name);
- }
- static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback)
- {
- Console.WriteLine("Updating Sentryfile...");
- byte[] sentry_hash = CryptoHelper.SHAHash(callback.Data);
- File.WriteAllBytes("sentry.bin", callback.Data);
- steam_user.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 = sentry_hash,
- });
- Console.WriteLine("Done!");
- }
- static void OnDisconnected(SteamClient.DisconnectedCallback callback)
- {
- Console.WriteLine("\n{0} Disconnected from Steam, reconnecting...\n", user_name);
- Thread.Sleep(TimeSpan.FromSeconds(5));
- steam_client.Connect();
- }
- static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
- {
- Console.WriteLine("Logged off of Steam: {0}", callback.Result);
- }
- static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
- {
- steam_friends.SetPersonaState(EPersonaState.Online);
- }
- static void OnFriendsList(SteamFriends.FriendsListCallback callback)
- {
- Thread.Sleep(2500);
- foreach (var friend in callback.FriendList)
- {
- if (friend.Relationship == EFriendRelationship.RequestRecipient)
- {
- steam_friends.AddFriend(friend.SteamID);
- Thread.Sleep(500);
- steam_friends.SendChatMessage(friend.SteamID, EChatEntryType.ChatMsg, "<MSG> hello, I am 1703 bot. I will notify you of any 1703 outfit events. Use '!help' to view my commands.");
- }
- }
- }
- static void OnChatMessage(SteamFriends.FriendMsgCallback callback)
- {
- string[] args;
- if (callback.EntryType == EChatEntryType.ChatMsg)
- {
- if (callback.Message.Length > 1)
- {
- if (callback.Message.Remove(1) == "!")
- {
- string command = callback.Message;
- if (callback.Message.Contains(" "))
- {
- command = callback.Message.Remove(callback.Message.IndexOf(' '));
- }
- switch (command)
- {
- #region send
- case "!send":
- if (!isBotAdmin(callback.Sender))
- break;
- args = seperate(2, ' ', callback.Message);
- Console.WriteLine("!send '" + args[1] + "' '" + args[2] + "'Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
- if (args[0] == "-1")
- {
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<ERROR> Incorrect Syntax. Use '!send [friend] [message]'.");
- return;
- }
- for (int i = 0; i < steam_friends.GetFriendCount(); i++)
- {
- SteamID friend = steam_friends.GetFriendByIndex(i);
- if (steam_friends.GetFriendPersonaName(friend).ToLower().Contains(args[1].ToLower()))
- {
- steam_friends.SendChatMessage(friend, EChatEntryType.ChatMsg, "<MSG> " + args[2]);
- }
- }
- break;
- #endregion
- #region broadcast
- case "!broadcast":
- if (!isBotAdmin(callback.Sender))
- break;
- args = seperate(1, ' ', callback.Message);
- Console.WriteLine("!broadcast '" + args[1] + "' Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
- if (args[0] == "-1")
- {
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<ERROR> Inccorect syntax. Use '!broadcast [message]'.");
- }
- for (int i = 0; i < steam_friends.GetFriendCount(); i++)
- {
- SteamID friend = steam_friends.GetFriendByIndex(i);
- if (friend > 0)
- {
- steam_friends.SendChatMessage(friend, EChatEntryType.ChatMsg, "<BROADCAST> " + args[1]);
- }
- }
- break;
- #endregion
- #region friends
- case "!friends":
- Console.WriteLine("!friends Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> List of bot friends: ");
- for (int i = 0; i < steam_friends.GetFriendCount(); i++)
- {
- SteamID friend = steam_friends.GetFriendByIndex(i);
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> Friend: " + steam_friends.GetFriendPersonaName(friend) + " State: " + steam_friends.GetFriendPersonaState(friend));
- }
- break;
- #endregion
- #region help
- case "!help":
- Console.Write("!help Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> List of User Commands:");
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> '!help' : Lists all Available Commands");
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> '!friends' : Lists all the friends of the 1703 Bot");
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> List of Admin Commands:");
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> '!broadcast [message]' : Broadcasts a message to all 1703 Bot Friends");
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> 'send [friend] [message]' : sends a message to specified 1703 Bot Friend");
- break;
- #endregion
- }
- }
- }
- string rLine;
- string trimmed = callback.Message;
- char[] trim = { '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', ']', '{', '}', '\\', '|', ';', ':', '"', '\'', ',', '<', '.', '>', '/', '?' };
- for (int i = 0; i < 30; i++)
- {
- trimmed = trimmed.Replace(trim[i].ToString(), "");
- }
- StreamReader stream_reader = new StreamReader("chat.txt");
- while ((rLine = stream_reader.ReadLine()) != null)
- {
- string text = rLine.Remove(rLine.IndexOf('|') - 1);
- string response = rLine.Remove(0, rLine.IndexOf('|') + 2);
- if (callback.Message.Contains(text))
- {
- Console.WriteLine("Cat reply Sent: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
- steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, response);
- stream_reader.Close();
- return;
- }
- }
- }
- }
- public static bool isBotAdmin(SteamID sid)
- {
- string[] lines = null;
- try
- {
- lines = File.ReadAllLines("admin.txt");
- foreach (string i in lines)
- {
- if (sid.ConvertToUInt64() == Convert.ToUInt64(i))
- {
- return true;
- }
- }
- steam_friends.SendChatMessage(sid, EChatEntryType.ChatMsg, "<ERROR> You do not have sufficient permission to use that command. If this is an error, and you are an admin, please contact D3i (Dei) or Infilze (Koolbade)");
- Console.WriteLine(steam_friends.GetFriendPersonaName(sid) + " attemted to use an administrator command while not an administrator.");
- return false;
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- return false;
- }
- }
- public static string[] seperate(int number, char seperator, string thestring)
- {
- string[] returned = new string[4];
- int i = 0;
- int error = 0;
- int length = thestring.Length;
- foreach (char c in thestring)
- {
- if (i != number)
- {
- if (error > length || number > 5)
- {
- returned[0] = "-1";
- return returned;
- }
- else if (c == seperator)
- {
- returned[i] = thestring.Remove(thestring.IndexOf(c));
- thestring = thestring.Remove(0, thestring.IndexOf(c) + 1);
- i++;
- }
- error++;
- if (error == length && i != number)
- {
- returned[0] = "-1";
- return returned;
- }
- }
- else
- {
- returned[i] = thestring;
- }
- }
- return returned;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement