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 SteamKit2.Internal;
- using SteamKit2.GC;
- namespace SteamChatBot
- {
- class Program
- {
- static SteamClient steamClient;
- static CallbackManager manager;
- static SteamUser steamUser;
- static SteamFriends friends;
- static SteamTrading trading;
- static bool isRunning = false;
- static SteamID owner = Put your 64bit steamID here;
- static SteamID[] admins = { And here those of your friends, 012345678910111213 }; // That table isn't really useful yet
- static SteamID[] friendL = { };
- static System.IO.StreamWriter logFile = new System.IO.StreamWriter(@"log.txt");
- static void Main()
- {
- log("Bot starting up ..");
- Console.Title = "Andromedan";
- SteamLogin();
- }
- static void SteamLogin()
- {
- steamClient = new SteamClient();
- steamUser = steamClient.GetHandler<SteamUser>();
- friends = steamClient.GetHandler<SteamFriends>();
- trading = steamClient.GetHandler<SteamTrading>();
- manager = new CallbackManager(steamClient);
- new Callback<SteamClient.ConnectedCallback>(OnConnected, manager);
- new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
- new Callback<SteamFriends.FriendsListCallback>(OnFriendList, manager);
- new Callback<SteamFriends.FriendMsgCallback>(OnFriendMsg, manager);
- new Callback<SteamTrading.TradeProposedCallback>(OnTradeProposal, manager);
- new Callback<SteamUser.AccountInfoCallback>(OnAccountInfoReceived, manager);
- isRunning = true;
- steamClient.Connect();
- while (isRunning)
- {
- manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
- }
- Console.ReadKey();
- }
- static void log(string tx, int type = 0)
- {
- //type 0 = nothing, type 1 = error, type 2 = succes, type 3 = notice
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("PREFIX | ");
- logFile.Write("PREFIX | ");
- Console.ResetColor();
- string logLine = DateTime.Now.ToString("HH:mm tt") + "| " + tx + "\n";
- if (type == 1)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- }
- else if (type == 2)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- }
- else if (type == 3)
- {
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- }
- Console.Write(logLine);
- Console.ResetColor();
- logFile.Write(logLine);
- logFile.Flush();
- }
- static Boolean isAdmin(SteamID profileID)
- {
- foreach (SteamID ad in admins)
- {
- if (profileID == ad)
- {
- return true;
- }
- }
- return false;
- }
- static void noticeOwner(int type)
- {
- log(("Operator told for type " + type + " event."), 3);
- if (type == 1)
- {
- friends.SendChatMessage(owner, EChatEntryType.ChatMsg, "NAUT | Initialized, and succesfuly connected to Steam.");
- }
- else if (type == 2)
- {
- friends.SendChatMessage(owner, EChatEntryType.ChatMsg, "NAUT | Stoping the process ..");
- }
- else if (type == 3)
- {
- friends.SendChatMessage(owner, EChatEntryType.ChatMsg, "NAUT | Rebooting ..");
- }
- }
- static void reboot()
- {
- noticeOwner(3);
- Main();
- return;
- }
- static void OnAccountInfoReceived(SteamUser.AccountInfoCallback callback)
- {
- log("Steam account data received from Steam.");
- }
- static void OnFriendList(SteamFriends.FriendsListCallback callback)
- {
- System.Threading.Thread.Sleep(1000);
- foreach (var fr in callback.FriendList)
- {
- if (fr.Relationship == EFriendRelationship.RequestInitiator)
- {
- friends.AddFriend(fr.SteamID);
- System.Threading.Thread.Sleep(1000);
- friends.SendChatMessage(fr.SteamID, EChatEntryType.ChatMsg, "Hi. I am a Trading bot.");
- }
- }
- int i = 0;
- foreach (var fri in callback.FriendList)
- {
- friendL[i] = fri.SteamID;
- i++;
- }
- log("New friend list received from Steam.");
- }
- static void OnFriendMsg(SteamFriends.FriendMsgCallback callback)
- {
- if (callback.EntryType == EChatEntryType.ChatMsg)
- {
- Console.WriteLine("/ /");
- }
- }
- static void OnConnected(SteamClient.ConnectedCallback callback)
- {
- if (callback.Result != EResult.OK)
- {
- log(("Impossible to connect ! Error: " + callback.Result), 1);
- isRunning = false;
- return;
- }
- log("Connected to Steam network !", 2);
- log("Connecting to the main account ..");
- steamUser.LogOn(new SteamUser.LogOnDetails
- {
- Username = "Steam account username", //For now you'll have to disable Steam Guard for it to connect.
- Password = "Steam account password"
- });
- }
- static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
- {
- if (callback.Result == EResult.AccountLogonDenied)
- {
- log("Error; The account's protected by Steam Guard.", 1);
- return;
- }
- if (callback.Result != EResult.OK)
- {
- log(("Error; Impossible to connect: " + callback.Result), 1);
- isRunning = false;
- return;
- }
- log(("Connecté avec succes: " + callback.Result), 2);
- foreach(var adm in admins){
- //friends.SendChatMessage(adm, EChatEntryType.ChatMsg, "NAUT | Initialized. You're registered as administrator.");
- }
- friends.SetPersonaName("BOT | Andromedan");
- friends.SetPersonaState(EPersonaState.Online);
- noticeOwner(1);
- Console.WriteLine("You can enter the command :lcmd, and so obtain a list of all available commands.");
- while (1 == 1){
- string comd = Console.ReadLine();
- log("Command entered by operator | " + comd + ".");
- if (comd == ":halt")
- {
- noticeOwner(2);
- System.Threading.Thread.Sleep(1000);
- log("Turning off ..");
- Environment.Exit(0);
- }
- else if (comd == ":reboot")
- {
- reboot();
- }
- else if (comd == ":broadcast")
- {
- Console.WriteLine("Enter a message to broadcast."); //It doesn't really work yet ..
- string msg = Console.ReadLine();
- foreach (var fID in friendL){
- friends.SendChatMessage(fID, EChatEntryType.ChatMsg, msg);
- }
- }
- else if (comd == ":lcmd")
- {
- Console.WriteLine("These are the available commands ..\n");
- Console.WriteLine(":halt turns off the bot.\n");
- Console.WriteLine(":reboot reboots the bot.\n");
- Console.WriteLine(":broadcast broadcasts a message through chat to every persons on the friend list.");
- }
- }
- }
- static void OnTradeProposal(SteamTrading.TradeProposedCallback callback)
- {
- log(("Trade offer received. Trade mate's SteamID: " + callback.OtherClient + ", Name: " + callback.OtherName + ". Trade ID: " + callback.TradeID + "."), 3);
- trading.RespondToTrade(callback.TradeID, true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement