Advertisement
Guest User

blarg

a guest
Mar 19th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 34.75 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 System.Xml;
  7. using System.Xml.Linq;
  8. using System.Net;
  9. using System.Windows.Forms;
  10. using System.Data;
  11. using SteamKit2;
  12. using System.IO;
  13. using System.Threading;
  14.  
  15. namespace _1703_Bot
  16. {
  17.     class Program
  18.     {
  19.         static bool is_running = false;
  20.         static string user_name, pass;
  21.         static string auth_code;
  22.  
  23.         static int request_cooldown = 10000;
  24.         static bool request_cooldown_bool = false;
  25.  
  26.         static string[] usage_array;
  27.         static int usage_command_broadcast = 0;
  28.         static int usage_command_friends = 0;
  29.         static int usage_command_help = 0;
  30.         static int usage_command_notorious = 0;
  31.         static int usage_command_online = 0;
  32.         static int usage_command_pester = 0;
  33.         static int usage_command_send = 0;
  34.         static int usage_command_vsa = 0;
  35.  
  36.         static SteamClient steam_client;
  37.         static CallbackManager callback_manager;
  38.         static SteamUser steam_user;
  39.         static SteamFriends steam_friends;
  40.  
  41.         static void Main(string[] args)
  42.         {
  43.             //Application.EnableVisualStyles();
  44.             //Application.SetCompatibleTextRenderingDefault(false);
  45.             //Application.Run(new Bot_Windows_Form());
  46.  
  47.             var usage_list = new List<string>();
  48.             var usage_file = new FileStream("command_usage.dat", FileMode.Open, FileAccess.ReadWrite);
  49.             using (var usage_stream = new StreamReader(usage_file, Encoding.Default))
  50.             {
  51.                 string line;
  52.                 while ((line = usage_stream.ReadLine()) != null)
  53.                 {
  54.                     usage_list.Add(line);
  55.                 }
  56.             }
  57.             usage_array = usage_list.ToArray();
  58.             Console.Write(usage_array);
  59.  
  60.             if (!File.Exists("chat.txt"))
  61.             {
  62.                 File.Create("chat.txt").Close();
  63.                 File.WriteAllText("chat.txt", "Hello | <MSG> Hello. Use '!help' to view commands.");
  64.             }
  65.             if (!File.Exists("admin.txt"))
  66.             {
  67.                 File.Create("admin.txt").Close();
  68.                 File.WriteAllText("admin.txt", "76561198053054477");
  69.             }
  70.  
  71.             Console.Title = "1703 Bot Console";
  72.             Console.Write("Username: ");
  73.             user_name = Console.ReadLine();
  74.             Console.Write("Password: ");
  75.             pass = Console.ReadLine();
  76.  
  77.             SteamLogIn();
  78.         }
  79.  
  80.         static void SteamLogIn()
  81.         {
  82.             steam_client = new SteamClient();
  83.             callback_manager = new CallbackManager(steam_client);
  84.             steam_user = steam_client.GetHandler<SteamUser>();
  85.             steam_friends = steam_client.GetHandler<SteamFriends>();
  86.  
  87.             callback_manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
  88.             callback_manager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
  89.             callback_manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
  90.             callback_manager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff);
  91.             callback_manager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo);
  92.             callback_manager.Subscribe<SteamFriends.FriendMsgCallback>(OnChatMessage);
  93.             callback_manager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendsList);
  94.             callback_manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
  95.  
  96.             is_running = true;
  97.  
  98.             Console.Write("Connecting to Steam...");
  99.             steam_client.Connect();
  100.  
  101.             while (is_running)
  102.             {
  103.                 callback_manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
  104.             }
  105.             Console.ReadKey();
  106.         }
  107.  
  108.         static void OnConnected(SteamClient.ConnectedCallback callback)
  109.         {
  110.             if (callback.Result != EResult.OK)
  111.             {
  112.                 Console.WriteLine("Unable to connect to Steam: {0}", callback.Result);
  113.                 is_running = false;
  114.                 return;
  115.             }
  116.             Console.WriteLine("Connected to Steam! Logging in '{0}'", callback.Result);
  117.  
  118.             byte[] sentry_hash = null;
  119.             if (File.Exists("sentry.bin"))
  120.             {
  121.                 byte[] sentry_file = File.ReadAllBytes("sentry.bin");
  122.                 sentry_hash = CryptoHelper.SHAHash(sentry_file);
  123.             }
  124.  
  125.             steam_user.LogOn(new SteamUser.LogOnDetails
  126.             {
  127.                 Username = user_name,
  128.                 Password = pass,
  129.                 AuthCode = auth_code,
  130.                 SentryFileHash = sentry_hash,
  131.             });
  132.         }
  133.  
  134.         static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
  135.         {
  136.             if (callback.Result == EResult.AccountLogonDenied)
  137.             {
  138.                 Console.WriteLine("This account is SteamGuard protected.");
  139.                 Console.WriteLine("Please enter the authorization code sent ot the email at {0}: ", callback.EmailDomain);
  140.                 auth_code = Console.ReadLine();
  141.                 return;
  142.             }
  143.  
  144.             if (callback.Result != EResult.OK)
  145.             {
  146.                 Console.WriteLine("Unable to log in to Steam: {0}\n", callback.Result);
  147.                 is_running = false;
  148.                 return;
  149.             }
  150.             Console.WriteLine("{0} Successfully Logged in to Steam!", user_name);
  151.         }
  152.  
  153.         static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback)
  154.         {
  155.             Console.WriteLine("Updating Sentryfile...");
  156.             byte[] sentry_hash = CryptoHelper.SHAHash(callback.Data);
  157.             File.WriteAllBytes("sentry.bin", callback.Data);
  158.             steam_user.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
  159.             {
  160.                 JobID = callback.JobID,
  161.                 FileName = callback.FileName,
  162.                 BytesWritten = callback.BytesToWrite,
  163.                 FileSize = callback.Data.Length,
  164.                 Offset = callback.Offset,
  165.                 Result = EResult.OK,
  166.                 LastError = 0,
  167.                 OneTimePassword = callback.OneTimePassword,
  168.                 SentryFileHash = sentry_hash,
  169.             });
  170.             Console.WriteLine("Done!");
  171.         }
  172.  
  173.         static void OnDisconnected(SteamClient.DisconnectedCallback callback)
  174.         {
  175.             Console.WriteLine("\n{0} Disconnected from Steam, reconnecting...\n", user_name);
  176.             Thread.Sleep(TimeSpan.FromSeconds(5));
  177.             steam_client.Connect();
  178.         }
  179.  
  180.         static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
  181.         {
  182.             Console.WriteLine("Logged off of Steam: {0}", callback.Result);
  183.         }
  184.  
  185.         static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
  186.         {
  187.             steam_friends.SetPersonaState(EPersonaState.Online);
  188.         }
  189.  
  190.         static void OnFriendsList(SteamFriends.FriendsListCallback callback)
  191.         {
  192.             Thread.Sleep(2500);
  193.             foreach (var friend in callback.FriendList)
  194.             {
  195.                 if (friend.Relationship == EFriendRelationship.RequestRecipient)
  196.                 {
  197.                     steam_friends.AddFriend(friend.SteamID);
  198.                     Thread.Sleep(500);
  199.                     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.");
  200.                 }
  201.             }
  202.         }
  203.  
  204.         static void OnChatMessage(SteamFriends.FriendMsgCallback callback)
  205.         {
  206.             string[] args;
  207.             if (callback.EntryType == EChatEntryType.ChatMsg)
  208.             {
  209.                 if (callback.Message.Length > 1)
  210.                 {
  211.                     if (callback.Message.Remove(1) == "!")
  212.                     {
  213.                         string command = callback.Message;
  214.  
  215.                         if (callback.Message.Contains(" "))
  216.                         {
  217.                             command = callback.Message.Remove(callback.Message.IndexOf(' '));
  218.                         }
  219.  
  220.                         switch (command)
  221.                         {
  222.                             #region send
  223.                             case "!send":
  224.                                 if (!isBotAdmin(callback.Sender))
  225.                                     break;
  226.  
  227.                                 args = seperate(2, ' ', callback.Message);
  228.                                 Console.WriteLine("!send '" + args[1] + "' '" + args[2] + "'Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
  229.                                 if (args[0] == "-1")
  230.                                 {
  231.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<ERROR> Incorrect Syntax. Use '!send [friend] [message]'.");
  232.                                     return;
  233.                                 }
  234.                                 for (int i = 0; i < steam_friends.GetFriendCount(); i++)
  235.                                 {
  236.                                     SteamID friend = steam_friends.GetFriendByIndex(i);
  237.                                     if (steam_friends.GetFriendPersonaName(friend).ToLower().Contains(args[1].ToLower()))
  238.                                     {
  239.                                         steam_friends.SendChatMessage(friend, EChatEntryType.ChatMsg, "<MSG> " + args[2]);
  240.                                     }
  241.                                 }
  242.                                 break;
  243.                             #endregion
  244.                             #region broadcast
  245.                             case "!broadcast":
  246.                                 if (!isBotAdmin(callback.Sender))
  247.                                     break;
  248.  
  249.                                 args = seperate(1, ' ', callback.Message);
  250.                                 Console.WriteLine("!broadcast '" + args[1] + "' Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
  251.                                 if (args[0] == "-1")
  252.                                 {
  253.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<ERROR> Inccorect syntax. Use '!broadcast [message]'.");
  254.                                 }
  255.                                 for (int i = 0; i < steam_friends.GetFriendCount(); i++)
  256.                                 {
  257.                                     SteamID friend = steam_friends.GetFriendByIndex(i);
  258.                                     if (friend > 0)
  259.                                     {
  260.                                         steam_friends.SendChatMessage(friend, EChatEntryType.ChatMsg, "<BROADCAST> " + args[1]);
  261.                                     }
  262.                                 }
  263.                                 break;
  264.                             #endregion
  265.                             #region friends
  266.                             case "!friends":
  267.                                 Console.WriteLine("!friends Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
  268.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> List of bot friends: ");
  269.                                 for (int i = 0; i < steam_friends.GetFriendCount(); i++)
  270.                                 {
  271.                                     SteamID friend = steam_friends.GetFriendByIndex(i);
  272.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> Friend: " + steam_friends.GetFriendPersonaName(friend) + " State: " + steam_friends.GetFriendPersonaState(friend));
  273.                                 }
  274.                                 break;
  275.                             #endregion
  276.                             #region help
  277.                             case "!help":
  278.                                 Console.Write("!help Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
  279.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> List of User Commands:");
  280.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> '!help' : Lists all Available Commands");
  281.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> '!friends' : Lists all the friends of the 1703 Bot");
  282.                                 if (!isBotAdmin(callback.Sender))
  283.                                 {
  284.                                     break;
  285.                                 }
  286.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> List of Admin Commands:");
  287.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> '!broadcast [message]' : Broadcasts a message to all 1703 Bot Friends");
  288.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> '!send [friend] [message]' : sends a message to specified 1703 Bot Friend");
  289.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> '!pester [friend] [message] [message ammount]' : sends a message to a specified 1703 Bot Friend a specified number of times");
  290.                                 break;
  291.                             #endregion
  292.                             #region pester
  293.                             //case "!pester":
  294.                             //    int counter = 0;
  295.                             //    if (!isBotAdmin(callback.Sender))
  296.                             //        break;
  297.                             //    args = seperate(3, ' ', callback.Message);
  298.                             //    Console.WriteLine("!pester '" + args[1] + "' '" + args[2] + "'Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
  299.                             //    if (args[0] == "-1")
  300.                             //    {
  301.                             //        steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<ERROR> Incorrect Syntax. Use '!pester [friend] [message'.");
  302.                             //        return;
  303.                             //    }
  304.                             //    for (int i = 0; i < steam_friends.GetFriendCount(); i++)
  305.                             //    {
  306.                             //        SteamID friend = steam_friends.GetFriendByIndex(i);
  307.                             //        if (steam_friends.GetFriendPersonaName(friend).ToLower().Contains(args[1].ToLower()))
  308.                             //        {
  309.                             //            while (counter < int.Parse(args[3]))
  310.                             //            {
  311.                             //                steam_friends.SendChatMessage(friend, EChatEntryType.ChatMsg, "<MSG> " + args[2]);
  312.                             //                counter++;
  313.                             //            }
  314.                             //        }
  315.                             //    }
  316.                             //    break;
  317.                             #endregion
  318.                             #region online
  319.                             case "!online":
  320.                                 Console.WriteLine("!online Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
  321.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> List of all Online Members");
  322.                                 if (request_cooldown_bool == true)
  323.                                 {
  324.                                     Console.WriteLine("Waiting For Global Census Cooldown: 5s");
  325.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Waiting For Global Census Cooldown: " + request_cooldown + " ms");
  326.                                     System.Threading.Thread.Sleep(request_cooldown);
  327.                                     request_cooldown_bool = false;
  328.                                 }
  329.                                 WebClient web_client = new System.Net.WebClient();
  330.                                 Console.WriteLine("Downloading member_list.xml...");
  331.                                 web_client.DownloadFile("http://census.daybreakgames.com/s:17034223270/xml/get/ps2:v2/outfit_member/?outfit_id=37530159341123962&c:limit=100&c:resolve=online_status&c:show=character_id&c:resolve=character_name", "member_list.xml");
  332.                                 XmlDocument doc = new XmlDocument();
  333.                                 doc.Load("member_list.xml");
  334.                                 XmlNodeList member_nodes = doc.GetElementsByTagName("outfit_member");
  335.                                 foreach (XmlNode member_node in member_nodes)
  336.                                 {
  337.                                     XmlAttribute character_id = member_node.Attributes["character_id"];
  338.                                     XmlAttribute online_status = member_node.Attributes["online_status"];
  339.                                     XmlNode character_name_node = member_node["character"];
  340.                                     string character_name_string = character_name_node.InnerXml;
  341.                                     string remove_1 = ("<name first=");
  342.                                     character_name_string = character_name_string.Replace(remove_1, "");
  343.                                     string[] character_name_string_temp = character_name_string.Split(' ');
  344.                                     character_name_string_temp[1] = ("");
  345.                                     character_name_string_temp[2] = ("");
  346.                                     character_name_string = string.Join("", character_name_string_temp);
  347.                                     int online_status_true = System.Convert.ToInt32(online_status.Value);
  348.                                     if (online_status_true > 0)
  349.                                     {
  350.                                         Console.WriteLine("Character_ID: " + character_id.Value);
  351.                                         Console.WriteLine("Character_Name: " + character_name_string);
  352.                                         Console.WriteLine("Online_Status: " + online_status.Value);
  353.                                         Console.WriteLine("");
  354.                                         steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Character ID: " + character_id.Value);
  355.                                         steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Character Name: " + character_name_string);
  356.                                         steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Online Status: " + online_status.Value);
  357.                                     }
  358.                                 }
  359.                                 if (request_cooldown_bool == false)
  360.                                 {
  361.                                     request_cooldown_bool = true;
  362.                                 }
  363.                                 break;
  364.                             #endregion
  365.                             #region notorious
  366.                             case "!notorious":
  367.                                 Console.WriteLine("!notorious Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
  368.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> List of all Online Members of Notorious");
  369.                                 if (request_cooldown_bool == true)
  370.                                 {
  371.                                     Console.WriteLine("Waiting For Global Census Cooldown: 5s");
  372.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Waiting For Global Census Cooldown: " + request_cooldown + " ms");
  373.                                     System.Threading.Thread.Sleep(request_cooldown);
  374.                                     request_cooldown_bool = false;
  375.                                 }
  376.                                 WebClient web_client_notorious = new System.Net.WebClient();
  377.                                 Console.WriteLine("Downloading notorious_member_list.xml...");
  378.                                 web_client_notorious.DownloadFile("http://census.daybreakgames.com/s:17034223270/xml/get/ps2:v2/outfit_member/?outfit_id=37509488620602103&c:limit=100&c:resolve=online_status&c:show=character_id&c:resolve=character_name", "notorious_member_list.xml");
  379.                                 XmlDocument doc_notorious = new XmlDocument();
  380.                                 doc_notorious.Load("notorious_member_list.xml");
  381.                                 XmlNodeList member_nodes_notorious = doc_notorious.GetElementsByTagName("outfit_member");
  382.                                 foreach (XmlNode member_node in member_nodes_notorious)
  383.                                 {
  384.                                     XmlAttribute character_id = member_node.Attributes["character_id"];
  385.                                     XmlAttribute online_status = member_node.Attributes["online_status"];
  386.                                     XmlNode character_name_node = member_node["character"];
  387.                                     string character_name_string = character_name_node.InnerXml;
  388.                                     string remove_1 = ("<name first=");
  389.                                     character_name_string = character_name_string.Replace(remove_1, "");
  390.                                     string[] character_name_string_temp = character_name_string.Split(' ');
  391.                                     character_name_string_temp[1] = ("");
  392.                                     character_name_string_temp[2] = ("");
  393.                                     character_name_string = string.Join("", character_name_string_temp);
  394.                                     int online_status_true = System.Convert.ToInt32(online_status.Value);
  395.                                     if (online_status_true > 0)
  396.                                     {
  397.                                         Console.WriteLine("Character_ID: " + character_id.Value);
  398.                                         Console.WriteLine("Character_Name: " + character_name_string);
  399.                                         Console.WriteLine("Online_Status: " + online_status.Value);
  400.                                         Console.WriteLine("");
  401.                                         steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Character ID: " + character_id.Value);
  402.                                         steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Character Name: " + character_name_string);
  403.                                         steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Online Status: " + online_status.Value);
  404.                                     }
  405.                                 }
  406.                                 if (request_cooldown_bool == false)
  407.                                 {
  408.                                     request_cooldown_bool = true;
  409.                                 }
  410.                                 break;
  411.                             #endregion
  412.                             #region vsa
  413.                             case "!vsa":
  414.                                 Console.WriteLine("!vsa Command Recieved: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
  415.                                 steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "<INFO> List of all Online Members of VSA");
  416.                                 if (request_cooldown_bool == true)
  417.                                 {
  418.                                     Console.WriteLine("Waiting For Global Census Cooldown: 5s");
  419.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Waiting For Global Census Cooldown: " + request_cooldown + " ms");
  420.                                     System.Threading.Thread.Sleep(request_cooldown);
  421.                                     request_cooldown_bool = false;
  422.                                 }
  423.                                 WebClient web_client_vsa = new System.Net.WebClient();
  424.                                 Console.WriteLine("Downloading member_list.xml...");
  425.                                 web_client_vsa.DownloadFile("http://census.daybreakgames.com/s:17034223270/xml/get/ps2:v2/outfit_member/?outfit_id=37510145262230990&c:limit=500&c:resolve=online_status&c:show=character_id&c:resolve=character_name", "vsa_member_list.xml");
  426.                                 XmlDocument doc_vsa = new XmlDocument();
  427.                                 doc_vsa.Load("member_list.xml");
  428.                                 XmlNodeList member_nodes_vsa = doc_vsa.GetElementsByTagName("outfit_member");
  429.                                 foreach (XmlNode member_node in member_nodes_vsa)
  430.                                 {
  431.                                     XmlAttribute character_id = member_node.Attributes["character_id"];
  432.                                     XmlAttribute online_status = member_node.Attributes["online_status"];
  433.                                     XmlNode character_name_node = member_node["character"];
  434.                                     string character_name_string = character_name_node.InnerXml;
  435.                                     string remove_1 = ("<name first=");
  436.                                     character_name_string = character_name_string.Replace(remove_1, "");
  437.                                     string[] character_name_string_temp = character_name_string.Split(' ');
  438.                                     character_name_string_temp[1] = ("");
  439.                                     character_name_string_temp[2] = ("");
  440.                                     character_name_string = string.Join("", character_name_string_temp);
  441.                                     int online_status_true = System.Convert.ToInt32(online_status.Value);
  442.                                     if (online_status_true > 0)
  443.                                     {
  444.                                         if (character_id.Value == "5428010917263970257")
  445.                                         {
  446.                                             Console.WriteLine("Character_ID: " + character_id.Value);
  447.                                             Console.WriteLine("Character_Name: " + character_name_string);
  448.                                             Console.WriteLine("Online_Status: " + online_status.Value);
  449.                                             Console.WriteLine("");
  450.                                             steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Character ID: " + character_id.Value);
  451.                                             steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Character Name: " + character_name_string);
  452.                                             steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Online Status: " + online_status.Value);
  453.                                         }
  454.                                     }
  455.                                 }
  456.                                 if (request_cooldown_bool == false)
  457.                                 {
  458.                                     request_cooldown_bool = true;
  459.                                 }
  460.                                 break;
  461.                             #endregion
  462.                             #region olookup
  463.                             case "!olookup":
  464.                                 break;
  465.                             #endregion
  466.                             #region gendesc
  467.                             case "!gendesc":
  468.                                 if (!isBotAdmin(callback.Sender))
  469.                                     break;
  470.  
  471.                                 args = seperate(2, ' ', callback.Message);
  472.                                 Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ") + "!gendesc '" + args[1] + "' '" + args[2] + "' command recieved from user '" + steam_friends.GetFriendPersonaName(callback.Sender) + "'.");
  473.                                 if (args[0] == "-1")
  474.                                 {
  475.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "[ERROR] Incorrect syntax. Use '!gendesc [color] [description]'.");
  476.                                     break;
  477.                                 }
  478.  
  479.                                 else if (args[2].Length > 24)
  480.                                 {
  481.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "[ERROR] Description is too long to fit squad listing, maximum of 24 characters.");
  482.                                     break;
  483.                                 }
  484.  
  485.                                 else if (args[1] == "red")
  486.                                 {
  487.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "[INFO] <font color=\"#FF5555\">" + args[2] + "</font>");
  488.                                     break;
  489.                                 }
  490.  
  491.                                 else if (args[1] == "blue")
  492.                                 {
  493.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "[INFO] <font color=\"#55FFFF\">" + args[2] + "</font>");
  494.                                     break;
  495.                                 }
  496.                                 else if (args[1] == "green")
  497.                                 {
  498.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "[INFO] <font color=\"#55FF55\">" + args[2] + "</font>");
  499.                                     break;
  500.                                 }
  501.  
  502.                                 else if (args[1] == "yellow")
  503.                                 {
  504.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "[INFO] <font color=\"#FFFF55\">" + args[2] + "</font>");
  505.                                     break;
  506.                                 }
  507.                                 else if (args[1] == "purple")
  508.                                 {
  509.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "[INFO] <font color=\"#FF55FF\">" + args[2] + "</font>");
  510.                                     break;
  511.                                 }
  512.                                 else if (args[1] == "orange")
  513.                                 {
  514.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "[INFO] <font color=\"#FFAA00\">" + args[2] + "</font>");
  515.                                     break;
  516.                                 }
  517.                                 else
  518.                                 {
  519.                                     steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "[ERROR] Color '" + args[1] + "' is not supported. Available colors: red, orange, yellow, green, blue, purple; examples: http://imgur.com/a/91SpM");
  520.                                 }
  521.                                 break;
  522.                                 #endregion
  523.  
  524.                         }
  525.                     }
  526.                 }
  527.                 string rLine;
  528.                 string trimmed = callback.Message;
  529.                 char[] trim = { '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', ']', '{', '}', '\\', '|', ';', ':', '"', '\'', ',', '<', '.', '>', '/', '?' };
  530.                 for (int i = 0; i < 30; i++)
  531.                 {
  532.                     trimmed = trimmed.Replace(trim[i].ToString(), "");
  533.                 }
  534.  
  535.                 StreamReader stream_reader = new StreamReader("chat.txt");
  536.  
  537.                 while ((rLine = stream_reader.ReadLine()) != null)
  538.                 {
  539.                     string text = rLine.Remove(rLine.IndexOf('|') - 1);
  540.                     string response = rLine.Remove(0, rLine.IndexOf('|') + 2);
  541.  
  542.                     if (callback.Message.Contains(text))
  543.                     {
  544.                         Console.WriteLine("Chat reply Sent: User: " + steam_friends.GetFriendPersonaName(callback.Sender));
  545.                         steam_friends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, response);
  546.                         stream_reader.Close();
  547.                         return;
  548.                     }
  549.                 }
  550.             }
  551.         }
  552.  
  553.         public static bool isBotAdmin(SteamID sid)
  554.         {
  555.             string[] lines = null;
  556.             try
  557.             {
  558.                 lines = File.ReadAllLines("admin.txt");
  559.                 foreach (string i in lines)
  560.                 {
  561.                     if (sid.ConvertToUInt64() == Convert.ToUInt64(i))
  562.                     {
  563.                         return true;
  564.                     }
  565.                 }
  566.                 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)");
  567.                 Console.WriteLine(steam_friends.GetFriendPersonaName(sid) + " attemted to use an administrator command while not an administrator.");
  568.                 return false;
  569.             }
  570.  
  571.             catch (Exception e)
  572.             {
  573.                 Console.WriteLine(e.Message);
  574.                 return false;
  575.             }
  576.         }
  577.  
  578.         public static string[] seperate(int number, char seperator, string thestring)
  579.         {
  580.             string[] returned = new string[4];
  581.             int i = 0;
  582.             int error = 0;
  583.             int length = thestring.Length;
  584.  
  585.             foreach (char c in thestring)
  586.             {
  587.                 if (i != number)
  588.                 {
  589.                     if (error > length || number > 5)
  590.                     {
  591.                         returned[0] = "-1";
  592.                         return returned;
  593.                     }
  594.                     else if (c == seperator)
  595.                     {
  596.                         returned[i] = thestring.Remove(thestring.IndexOf(c));
  597.                         thestring = thestring.Remove(0, thestring.IndexOf(c) + 1);
  598.                         i++;
  599.                     }
  600.                     error++;
  601.                     if (error == length && i != number)
  602.                     {
  603.                         returned[0] = "-1";
  604.                         return returned;
  605.                     }
  606.                 }
  607.                 else
  608.                 {
  609.                     returned[i] = thestring;
  610.                 }
  611.             }
  612.             return returned;
  613.         }
  614.     }
  615. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement