示例#1
0
文件: Steam.cs 项目: killowatt/RohBot
        public void Update()
        {
            if (_connectStarted.Elapsed.TotalSeconds > 120)
            {
                if (_bot != null)
                    _bot.Disconnect();
                Status = ConnectionStatus.Disconnected;
            }

            if (Status != ConnectionStatus.Disconnected)
                return;

            _hasConnected = false;
            _connectStarted.Restart();
            Program.Logger.Info("Connecting");

            _bot = new SteamBot(Program.Settings.Username, Program.Settings.Password, Program.Settings.AuthCode);
            _bot.OnConnected += sender =>
            {
                _hasConnected = true;
                _connectStarted.Stop();

                _bot.DisplayName = Program.Settings.PersonaName;
                _bot.PersonaState = EPersonaState.Online;
                Status = ConnectionStatus.Connected;

                Program.Logger.Info("Connected");
            };

            _bot.OnDisconnected += (sender, reason) =>
            {
                if (reason == SteamBotDisconnectReason.SteamGuard)
                    Thread.Sleep(TimeSpan.FromMinutes(2)); // TODO: need a better way of entering steamguard auth

                if (_hasConnected)
                {
                    Program.Logger.InfoFormat("Disconnected {0}", reason);
                    _hasConnected = false;
                }

                Status = ConnectionStatus.Disconnected;
            };

            _bot.OnFriendRequest += (sender, user) => _bot.AddFriend(user.Id);

            _bot.OnPrivateEnter += (sender, chat) =>
            {
                chat.OnMessage += (chatSender, messageSender, message) =>
                    Command.Handle(new CommandTarget(chatSender, messageSender), message, "");
            };

            _bot.OnChatInvite += (sender, chat, @by) =>
            {
                if (chat.Id.IsIndividualAccount)
                    _bot.Join(chat.Id);
            };

            _bot.Connect();
            Status = ConnectionStatus.Connecting;
        }
示例#2
0
        internal SteamGroup(SteamBot bot, SteamID id)
        {
            if (!id.IsClanAccount)
                throw new Exception("SteamClan from non-clan Id");

            Id = id;
            Bot = bot;
            _members = new List<Member>();
        }
示例#3
0
        public void Update()
        {
            if (_connectStarted.Elapsed.TotalSeconds > 120)
            {
                if (_bot != null)
                    _bot.Disconnect();
                Status = ConnectionStatus.Disconnected;
            }

            if (Status != ConnectionStatus.Disconnected)
                return;

            _hasConnected = false;
            _connectStarted.Restart();
            Program.Logger.Info("Connecting");

            _bot = new SteamBot(Program.Settings.Username, Program.Settings.Password);
            _bot.OnConnected += sender =>
            {
                _hasConnected = true;
                _connectStarted.Stop();

                _bot.DisplayName = Program.Settings.PersonaName;
                _bot.PersonaState = EPersonaState.Online;
                Status = ConnectionStatus.Connected;

                Program.Logger.Info("Connected");
            };

            _bot.OnDisconnected += (sender, reason) =>
            {
                if (_hasConnected)
                {
                    Program.Logger.Info("Disconnected");
                    _hasConnected = false;
                }

                Status = ConnectionStatus.Disconnected;
            };

            _bot.OnFriendRequest += (sender, user) => _bot.AddFriend(user.Id);

            _bot.OnPrivateEnter += (sender, chat) =>
            {
                chat.OnMessage += (chatSender, messageSender, message) =>
                    Command.Handle(new CommandTarget(chatSender, messageSender), message, "");
            };

            _bot.OnChatInvite += (sender, chat, @by) =>
            {
                if (chat.Id.IsIndividualAccount)
                    _bot.Join(chat.Id);
            };

            _bot.Connect();
            Status = ConnectionStatus.Connecting;
        }
示例#4
0
        static void Main()
        {
            dynamic account = JsonConvert.DeserializeObject(File.ReadAllText("account.json"));
            var username = (string)account.Username;
            var password = (string)account.Password;
            var authCode = (string)account.AuthCode;

            var bot = new SteamBot(username, password, authCode);
            var chatId = new SteamID(103582791434625334); // FPP

            bot.OnConnected += sender =>
            {
                Console.WriteLine("Connected");

                bot.DisplayName = "Test";
                bot.PersonaState = EPersonaState.Online;

                var chat = bot.Join(chatId);

                chat.OnEnter += steamChat =>
                {
                    Console.WriteLine("Enter");
                    Console.WriteLine(string.Join(", ", chat.Group.Members.Select(m => m.Persona.DisplayName)));
                    chat.Send("Hello!");
                };

                chat.OnLeave += (steamChat, reason) =>
                    Console.WriteLine("Leave " + reason);
            };

            bot.OnDisconnected += (sender, reason) =>
                Console.WriteLine("Disconnected " + reason);

            bot.Connect();

            while (true)
            {
                System.Threading.Thread.Sleep(1);
            }
        }
示例#5
0
 internal SteamPersona(SteamBot bot, SteamID id)
 {
     Bot = bot;
     Id = id;
 }
示例#6
0
文件: Steam.cs 项目: killowatt/RohBot
 public Steam()
 {
     Status = ConnectionStatus.Disconnected;
     _bot = null;
 }