Advertisement
Guest User

SoA Steam Trading Bot

a guest
Aug 3rd, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 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 SteamKit2.Internal;
  8. using SteamKit2.GC;
  9.  
  10. namespace SteamChatBot
  11. {
  12. class Program
  13. {
  14. static SteamClient steamClient;
  15. static CallbackManager manager;
  16. static SteamUser steamUser;
  17. static SteamFriends friends;
  18. static SteamTrading trading;
  19. static bool isRunning = false;
  20. static SteamID owner = Put your 64bit steamID here;
  21.  
  22. static SteamID[] admins = { And here those of your friends, 012345678910111213 }; // That table isn't really useful yet
  23. static SteamID[] friendL = { };
  24.  
  25. static System.IO.StreamWriter logFile = new System.IO.StreamWriter(@"log.txt");
  26.  
  27. static void Main()
  28. {
  29. log("Bot starting up ..");
  30. Console.Title = "Andromedan";
  31. SteamLogin();
  32. }
  33.  
  34. static void SteamLogin()
  35. {
  36. steamClient = new SteamClient();
  37. steamUser = steamClient.GetHandler<SteamUser>();
  38. friends = steamClient.GetHandler<SteamFriends>();
  39. trading = steamClient.GetHandler<SteamTrading>();
  40.  
  41. manager = new CallbackManager(steamClient);
  42.  
  43. new Callback<SteamClient.ConnectedCallback>(OnConnected, manager);
  44. new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
  45.  
  46. new Callback<SteamFriends.FriendsListCallback>(OnFriendList, manager);
  47. new Callback<SteamFriends.FriendMsgCallback>(OnFriendMsg, manager);
  48.  
  49. new Callback<SteamTrading.TradeProposedCallback>(OnTradeProposal, manager);
  50. new Callback<SteamUser.AccountInfoCallback>(OnAccountInfoReceived, manager);
  51.  
  52.  
  53. isRunning = true;
  54.  
  55. steamClient.Connect();
  56.  
  57. while (isRunning)
  58. {
  59. manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
  60. }
  61. Console.ReadKey();
  62. }
  63.  
  64. static void log(string tx, int type = 0)
  65. {
  66. //type 0 = nothing, type 1 = error, type 2 = succes, type 3 = notice
  67. Console.ForegroundColor = ConsoleColor.Cyan;
  68. Console.Write("PREFIX | ");
  69. logFile.Write("PREFIX | ");
  70. Console.ResetColor();
  71. string logLine = DateTime.Now.ToString("HH:mm tt") + "| " + tx + "\n";
  72.  
  73. if (type == 1)
  74. {
  75. Console.ForegroundColor = ConsoleColor.Red;
  76. }
  77. else if (type == 2)
  78. {
  79. Console.ForegroundColor = ConsoleColor.Green;
  80. }
  81. else if (type == 3)
  82. {
  83. Console.ForegroundColor = ConsoleColor.DarkYellow;
  84. }
  85.  
  86. Console.Write(logLine);
  87. Console.ResetColor();
  88. logFile.Write(logLine);
  89. logFile.Flush();
  90. }
  91.  
  92. static Boolean isAdmin(SteamID profileID)
  93. {
  94. foreach (SteamID ad in admins)
  95. {
  96. if (profileID == ad)
  97. {
  98. return true;
  99. }
  100. }
  101. return false;
  102. }
  103.  
  104. static void noticeOwner(int type)
  105. {
  106. log(("Operator told for type " + type + " event."), 3);
  107. if (type == 1)
  108. {
  109. friends.SendChatMessage(owner, EChatEntryType.ChatMsg, "NAUT | Initialized, and succesfuly connected to Steam.");
  110. }
  111. else if (type == 2)
  112. {
  113. friends.SendChatMessage(owner, EChatEntryType.ChatMsg, "NAUT | Stoping the process ..");
  114. }
  115. else if (type == 3)
  116. {
  117. friends.SendChatMessage(owner, EChatEntryType.ChatMsg, "NAUT | Rebooting ..");
  118. }
  119.  
  120. }
  121.  
  122. static void reboot()
  123. {
  124. noticeOwner(3);
  125. Main();
  126. return;
  127. }
  128.  
  129. static void OnAccountInfoReceived(SteamUser.AccountInfoCallback callback)
  130. {
  131. log("Steam account data received from Steam.");
  132.  
  133. }
  134.  
  135. static void OnFriendList(SteamFriends.FriendsListCallback callback)
  136. {
  137. System.Threading.Thread.Sleep(1000);
  138. foreach (var fr in callback.FriendList)
  139. {
  140.  
  141. if (fr.Relationship == EFriendRelationship.RequestInitiator)
  142. {
  143. friends.AddFriend(fr.SteamID);
  144. System.Threading.Thread.Sleep(1000);
  145. friends.SendChatMessage(fr.SteamID, EChatEntryType.ChatMsg, "Hi. I am a Trading bot.");
  146. }
  147. }
  148.  
  149. int i = 0;
  150. foreach (var fri in callback.FriendList)
  151. {
  152. friendL[i] = fri.SteamID;
  153. i++;
  154. }
  155. log("New friend list received from Steam.");
  156.  
  157. }
  158.  
  159. static void OnFriendMsg(SteamFriends.FriendMsgCallback callback)
  160. {
  161. if (callback.EntryType == EChatEntryType.ChatMsg)
  162. {
  163. Console.WriteLine("/ /");
  164. }
  165. }
  166.  
  167. static void OnConnected(SteamClient.ConnectedCallback callback)
  168. {
  169. if (callback.Result != EResult.OK)
  170. {
  171. log(("Impossible to connect ! Error: " + callback.Result), 1);
  172. isRunning = false;
  173. return;
  174. }
  175. log("Connected to Steam network !", 2);
  176. log("Connecting to the main account ..");
  177.  
  178. steamUser.LogOn(new SteamUser.LogOnDetails
  179. {
  180. Username = "Steam account username", //For now you'll have to disable Steam Guard for it to connect.
  181. Password = "Steam account password"
  182. });
  183. }
  184.  
  185. static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
  186. {
  187. if (callback.Result == EResult.AccountLogonDenied)
  188. {
  189. log("Error; The account's protected by Steam Guard.", 1);
  190. return;
  191. }
  192. if (callback.Result != EResult.OK)
  193. {
  194. log(("Error; Impossible to connect: " + callback.Result), 1);
  195. isRunning = false;
  196. return;
  197. }
  198. log(("Connecté avec succes: " + callback.Result), 2);
  199.  
  200. foreach(var adm in admins){
  201. //friends.SendChatMessage(adm, EChatEntryType.ChatMsg, "NAUT | Initialized. You're registered as administrator.");
  202. }
  203.  
  204. friends.SetPersonaName("BOT | Andromedan");
  205. friends.SetPersonaState(EPersonaState.Online);
  206. noticeOwner(1);
  207.  
  208. Console.WriteLine("You can enter the command :lcmd, and so obtain a list of all available commands.");
  209.  
  210. while (1 == 1){
  211. string comd = Console.ReadLine();
  212. log("Command entered by operator | " + comd + ".");
  213. if (comd == ":halt")
  214. {
  215. noticeOwner(2);
  216. System.Threading.Thread.Sleep(1000);
  217. log("Turning off ..");
  218. Environment.Exit(0);
  219. }
  220. else if (comd == ":reboot")
  221. {
  222. reboot();
  223. }
  224. else if (comd == ":broadcast")
  225. {
  226. Console.WriteLine("Enter a message to broadcast."); //It doesn't really work yet ..
  227. string msg = Console.ReadLine();
  228.  
  229. foreach (var fID in friendL){
  230. friends.SendChatMessage(fID, EChatEntryType.ChatMsg, msg);
  231. }
  232.  
  233. }
  234. else if (comd == ":lcmd")
  235. {
  236. Console.WriteLine("These are the available commands ..\n");
  237. Console.WriteLine(":halt turns off the bot.\n");
  238. Console.WriteLine(":reboot reboots the bot.\n");
  239. Console.WriteLine(":broadcast broadcasts a message through chat to every persons on the friend list.");
  240. }
  241.  
  242. }
  243.  
  244.  
  245. }
  246.  
  247. static void OnTradeProposal(SteamTrading.TradeProposedCallback callback)
  248. {
  249. log(("Trade offer received. Trade mate's SteamID: " + callback.OtherClient + ", Name: " + callback.OtherName + ". Trade ID: " + callback.TradeID + "."), 3);
  250. trading.RespondToTrade(callback.TradeID, true);
  251. }
  252.  
  253. }
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement