Esempio n. 1
0
        public virtual async Task SendMessageImmediateAsync(string message)
        {
            try
            {
                _client.SendMessage(_serverDTO.Username.Trim().ToLower(), message);

                await FireMessageServerChatEventAsync(this, new MessageServerChatEventArgs
                {
                    Message = new MessageServerChat
                    {
                        Bot         = _bot,
                        ChatColor   = TwitchNETUtils.GetHexCode(_botChatColor),
                        MessageText = message,
                        MessageType = MessageType.Sent,
                        Server      = this,
                        User        = _bot.BotDTO.UserDTO,
                        Id          = Guid.NewGuid(),
                        Timestamp   = DateTime.UtcNow
                    }
                });
            }
            catch (Exception ex)
            {
                await FireErrorEventAsync(this, new ErrorMessageServerChatEventArgs
                {
                    Bot                   = _bot,
                    ChatColor             = CurrentBotChatColorHex,
                    Exception             = ex,
                    Message               = message,
                    ErrorMessageEventType = ErrorMessageEventType.Sending,
                    ErrorMessageSendType  = ErrorMessageSendType.Immediate
                });
            }
        }
Esempio n. 2
0
        protected virtual void OnChatColorChanged(object sender, OnChatColorChangedArgs args)
        {
            if (args.Channel.Trim().ToLower() == _serverDTO.Username.Trim().ToLower())
            {
                _isWaitingForColorChange = false;

                Task.Run(async() =>
                {
                    await FireServerChatColorChangeEventAsync(sender, new ServerChatColorChangeEventArgs
                    {
                        Bot          = _bot,
                        HexColorCode = TwitchNETUtils.GetHexCode(_botChatColor),
                        Server       = this,
                        ServerChatColorChangeEventType = ServerChatColorChangeEventType.Confirmed
                    });
                });
            }
        }
Esempio n. 3
0
 public virtual void SendCommand(IServer server, string message, ChatColorPresets chatColor)
 {
     SendCommand(server, message, TwitchNETUtils.GetHexCode(chatColor));
 }
Esempio n. 4
0
        public virtual void OnTimerTick()
        {
            if (_isWaitingForColorChange)
            {
                return;
            }

            if (_messagesQueued.TryPeek(out var message))
            {
                if (TwitchNETUtils.GetChatColor(message.ChatColor) != _botChatColor)
                {
                    Task.Run(async() =>
                    {
                        try
                        {
                            // Change the chat color
                            _botChatColor = TwitchNETUtils.GetChatColor(message.ChatColor);
                            ChangeChatColorExt.ChangeChatColor(_client,
                                                               _client.JoinedChannels.FirstOrDefault(s => s.Channel.Trim().ToLower() == _serverDTO.Username.Trim().ToLower()),
                                                               _botChatColor);

                            await FireServerChatColorChangeEventAsync(this, new ServerChatColorChangeEventArgs
                            {
                                Bot          = _bot,
                                HexColorCode = TwitchNETUtils.GetHexCode(_botChatColor),
                                Server       = this,
                                ServerChatColorChangeEventType = ServerChatColorChangeEventType.Initiated
                            });
                        }
                        catch (Exception ex)
                        {
                            await FireErrorEventAsync(this, new ErrorBotServerColorChangeEventArgs
                            {
                                Bot       = _bot,
                                Exception = ex,
                                HexCode   = TwitchNETUtils.GetHexCode(_botChatColor),
                                Server    = this
                            });
                        }
                    });
                }
                else
                {
                    if (_messagesQueued.TryDequeue(out message))
                    {
                        Task.Run(async() =>
                        {
                            switch (message)
                            {
                            case IMessageServerChat e:
                                try
                                {
                                    _client.SendMessage(_serverDTO.Username.Trim().ToLower(), message.MessageText);

                                    await FireMessageServerChatEventAsync(this, new MessageServerChatEventArgs
                                    {
                                        Message = e
                                    });
                                }
                                catch (Exception ex)
                                {
                                    await FireErrorEventAsync(this, new ErrorMessageServerChatEventArgs
                                    {
                                        Bot                   = _bot,
                                        ChatColor             = TwitchNETUtils.GetHexCode(_botChatColor),
                                        ErrorMessageEventType = ErrorMessageEventType.Sending,
                                        ErrorMessageSendType  = ErrorMessageSendType.QueuedSent,
                                        Exception             = ex,
                                        Message               = message.MessageText
                                    });
                                }
                                break;

                            case IMessageServerCommand e:
                                try
                                {
                                    _client.SendMessage(_serverDTO.Username.Trim().ToLower(), $"/me {message.MessageText}");

                                    await FireMessageServerCommandEventAsync(this, new MessageServerCommandEventArgs
                                    {
                                        Message = e
                                    });
                                }
                                catch (Exception ex)
                                {
                                    await FireErrorEventAsync(this, new ErrorMessageServerCommandEventArgs
                                    {
                                        Bot                   = _bot,
                                        ChatColor             = TwitchNETUtils.GetHexCode(_botChatColor),
                                        ErrorMessageEventType = ErrorMessageEventType.Sending,
                                        ErrorMessageSendType  = ErrorMessageSendType.QueuedSent,
                                        Exception             = ex,
                                        Message               = message.MessageText
                                    });
                                }
                                break;

                            default:
                                break;
                            }
                        });
                    }
                }
            }
        }