コード例 #1
0
ファイル: SteamRoom.cs プロジェクト: mdkozlowski/RohBot
        private void HandleLeave(SteamChat chat, SteamPersona user, SteamChatLeaveReason reason, SteamPersona sourceUser)
        {
            _lastMessage.Restart();

            var message = user.DisplayName;

            switch (reason)
            {
            case SteamChatLeaveReason.Left:
                message += " left chat.";
                break;

            case SteamChatLeaveReason.Disconnected:
                message += " disconnected.";
                break;

            case SteamChatLeaveReason.Kicked:
                message += string.Format(" was kicked by {0}.", sourceUser.DisplayName);
                break;

            case SteamChatLeaveReason.Banned:
                message += string.Format(" was banned by {0}.", sourceUser.DisplayName);
                break;
            }

            var by   = sourceUser != null ? sourceUser.DisplayName : "";
            var byId = sourceUser != null?sourceUser.Id.ConvertToUInt64().ToString("D") : "0";

            var byType = sourceUser != null ? "Steam" : "";

            var line = new StateLine(Util.GetCurrentTimestamp(), RoomInfo.ShortName, reason.ToString(), user.DisplayName, user.Id.ConvertToUInt64().ToString("D"), "Steam", by, byId, byType, message);

            SendLine(line);
        }
コード例 #2
0
ファイル: SteamRoom.cs プロジェクト: shadobaker/RohBot
        public void Disconnect()
        {
            if (Chat == null)
            {
                return;
            }

            Chat.Leave(SteamChatLeaveReason.Left);
            Chat = null;
        }
コード例 #3
0
ファイル: SteamRoom.cs プロジェクト: mdkozlowski/RohBot
        public override void Leave()
        {
            if (Chat != null)
            {
                Chat.Leave(SteamChatLeaveReason.Left);
                Chat = null;
            }

            base.Leave();
        }
コード例 #4
0
ファイル: SteamRoom.cs プロジェクト: mdkozlowski/RohBot
        private void HandleEnter(SteamChat chat, SteamPersona user)
        {
            _lastMessage.Restart();

            var message = user.DisplayName + " entered chat.";

            var line = new StateLine(Util.GetCurrentTimestamp(), RoomInfo.ShortName, "Enter", user.DisplayName, user.Id.ConvertToUInt64().ToString("D"), "Steam", "", "0", "", message);

            SendLine(line);
        }
コード例 #5
0
ファイル: SteamRoom.cs プロジェクト: mdkozlowski/RohBot
        public override void Update()
        {
            if (!IsActive)
            {
                if (Chat != null)
                {
                    Chat.Leave(SteamChatLeaveReason.Left);
                }

                return;
            }

            if (Chat != null && _lastMessage.Elapsed >= TimeSpan.FromMinutes(30))
            {
                Program.Logger.Info("Rejoining " + RoomInfo.ShortName);
                _lastMessage.Restart();
                Chat.Leave(SteamChatLeaveReason.Disconnected);
                return;
            }

            if (Program.Steam.Status != Steam.ConnectionStatus.Connected || Chat != null)
            {
                return;
            }

            _hasConnected = false;
            Chat          = Program.Steam.Bot.Join(SteamId);

            Chat.OnEnter += sender =>
            {
                _hasConnected = true;
                Program.Logger.Info("Entered " + RoomInfo.ShortName);
                SendPersistentSysMessage("Connected to Steam.");
            };

            Chat.OnLeave += (sender, reason) =>
            {
                if (_hasConnected)
                {
                    _hasConnected = false;
                    Program.Logger.Info("Left " + RoomInfo.ShortName + ": " + reason);
                    SendPersistentSysMessage("Lost connection to Steam.");
                }

                Chat = null;
            };

            Chat.OnMessage   += HandleMessage;
            Chat.OnUserEnter += HandleEnter;
            Chat.OnUserLeave += HandleLeave;
        }
コード例 #6
0
ファイル: SteamRoom.cs プロジェクト: shadobaker/RohBot
        private void HandleMessage(SteamChat chat, SteamPersona user, string message)
        {
            _lastMessage.Restart();

            var senderName = user.DisplayName;
            var senderId   = user.Id.ConvertToUInt64().ToString("D");
            var inGame     = user.Playing != null && user.Playing.ToUInt64() != 0;

            var line = new ChatLine(Util.GetCurrentTimestamp(), RoomInfo.ShortName, "Steam", senderName, senderId, "", message, inGame);

            SendLine(line);

            Command.Handle(new CommandTarget(this, user), message, "~");
        }
コード例 #7
0
ファイル: Command.cs プロジェクト: shadobaker/RohBot
 // For Steam private messages
 public CommandTarget(SteamChat steamChat, SteamPersona sender)
 {
     PrivateChat = steamChat;
     Persona     = sender;
 }
コード例 #8
0
ファイル: Steam.cs プロジェクト: shadobaker/RohBot
 private void BotPrivateEnter(SteamBot sender, SteamChat chat)
 {
     chat.OnMessage += (chatSender, messageSender, message) =>
                       Command.Handle(new CommandTarget(chatSender, messageSender), message, "");
 }