Exemple #1
0
        public bool BlockUser(string message)
        {
            SpeechWordHandler speechWordHandler = new SpeechWordHandler();

            string[] messages;

            //First try splitting the message to check whether there is an username available
            try { messages = message.Split(' '); }
            catch { return(false); }

            if (messages.Length > 2)
            {
                return(false);
            }

            string user = messages[1];

            if (speechWordHandler.CheckBlocked(user))
            {
                return(false);
            }

            File.AppendAllLines(speechWordHandler.GetBlockListLocation(), new string[] { "\n", user });
            return(true);
        }
Exemple #2
0
        public bool UnblockUser(string message)
        {
            SpeechWordHandler speechWordHandler = new SpeechWordHandler();

            string[] messages;

            //First try splitting the message to check whether there is an username available
            try { messages = message.Split(' '); }
            catch { return(false); }
            if (messages.Length > 2)
            {
                return(false);
            }

            string user = messages[1];

            //If user is not in blocked list, return.
            if (!speechWordHandler.CheckBlocked(user))
            {
                return(false);
            }
            var lines = File.ReadAllLines(speechWordHandler.GetBlockListLocation());

            //Remove user
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i] == user)
                {
                    lines[i] = lines[i].Replace(user, "");
                    break;
                }
            }
            //firstly, remove WhiteSpace and then replace old file with new file
            var newLines = lines.Where(arg => !string.IsNullOrWhiteSpace(arg));

            File.WriteAllLines(speechWordHandler.GetBlockListLocation(), newLines);
            return(true);
        }
Exemple #3
0
        public TwitchBot()
        {
            //Set up Config Informations
            config           = new Config();
            maxWordLength    = config.GetMaxCharacterLength();
            messageConnector = config.SetMessageConnector();
            antiswear        = config.ReplaceSwearWord();
            voice            = config.SetVoice();
            longMessage      = config.GetLongMessage();

            //Set up Speech Helper
            speechHelper      = new SpeechHelper(voice, 0);
            speechWordHandler = new SpeechWordHandler();
            //Show all available voices to users
            List <string> voices = SpeechHelper.GetAllInstalledVoices();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("All available voices: ");
            Console.ForegroundColor = ConsoleColor.Gray;
            foreach (string s in voices)
            {
                Console.WriteLine(s);
            }
            Console.WriteLine("----------------------------------------------------------------");
            //Set up Twitch Info
            ConnectionCredentials credentials = new ConnectionCredentials(config.GetUsername(), config.GetOAuth());

            client = new TwitchClient();
            client.Initialize(credentials, config.GetChannel());
            client.OnConnected       += OnConnected;
            client.OnJoinedChannel   += OnJoinedChannel;
            client.OnMessageReceived += OnMessageReceived;


            //Log in Twitch
            client.Connect();
        }