Results 1 to 11 of 11
  1. #1
    AmejiOrape's Avatar
    Join Date
    Dec 2014
    Gender
    male
    Posts
    184
    Reputation
    27
    Thanks
    99
    My Mood
    Relaxed

    Filtering through a blacklist and a whitelist

    Code:
    TextPacket textPacket = (TextPacket)packet;
                    foreach (string str in NotifierConfig.Default.Whitelist)
                    {
                        if (textPacket.Text.ToLower().Contains(str.ToLower()))
                        {
                            foreach (string strb in NotifierConfig.Default.Blacklist)
                            {
                                if (textPacket.Text.ToLower().Contains(strb.ToLower()))
                                {
                                    textPacket.Send = true;
                                }
    
                                else
                                {
                                    client.SendToClient(PluginUtils.CreateNotification(client.ObjectId, str + " called!"));
                                }
                            }
                        
                        }
                    }
    What I would like this code to do is first look through a given text packet sent for words in a whitelist, and if it has a word/string in there, it must then check for words/strings from a blacklist. If it has a blacklist word, nothing happens. If it does not contain a banned word, it will display a notification saying *word from whitelist* called!

    I had a pretty clear envisioning of how it would work, but it just won't
    But maybe one of you guys are more experienced and can help me.
    Thanks!

  2. #2
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Why would you check for a whitelist word? It would be the same to simply check for a black listed word, and why not censor it.
    Code:
    List<string> words = "This is a testing text.".Split(' ').ToList(); // Get each word.
                List<string> blackList = new List<string>(); // Fill this.
                var bannedWords = from i in blackList where words.Contains(i) select i; // Retrieve only the banned words.
                foreach (string bWord in words) { 
                    if (bannedWords.Contains(bWord)) 
                        words[words.IndexOf(bWord)] = new string('*', bWord.Length); 
                }
    Yes it could have been done nicer but whatever. The idea is that LINQ can be a true ass saver sometimes.

  3. #3
    AmejiOrape's Avatar
    Join Date
    Dec 2014
    Gender
    male
    Posts
    184
    Reputation
    27
    Thanks
    99
    My Mood
    Relaxed
    Quote Originally Posted by ლ(ಠ_ಠლ) View Post
    Why would you check for a whitelist word? It would be the same to simply check for a black listed word, and why not censor it.
    Well, I don't need the blacklist word censored, I just want it to display a notification if the text has a whitelist word and doesn't have a blacklist word. For any other situation, nothing happens.

  4. #4
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Quote Originally Posted by AmejiOrape View Post
    Well, I don't need the blacklist word censored, I just want it to display a notification if the text has a whitelist word and doesn't have a blacklist word. For any other situation, nothing happens.
    Code:
                List<string> words = "This is a testing text.".Split(' ').ToList(); // Get each word.
                List<string> blackList = new List<string>(); // Fill this.
                List<string> whiteList = new List<string>(); // Fill this.
    
                var result = from i in words where !blackLis*****ntains(i) && whiteLis*****ntains(i) select i;
                if(resul*****unt() > 0)
                    // It has a whitelisted word and not a blacklisted one.

  5. #5
    AmejiOrape's Avatar
    Join Date
    Dec 2014
    Gender
    male
    Posts
    184
    Reputation
    27
    Thanks
    99
    My Mood
    Relaxed
    Ummm, that doesn't look very C# to me.
    Or we are just on a much different level of coding. But when I try putting that in my code it just comes up with a lot of redlines. Obviously I need to fit it to the variables that fit my code, but it seems like "From I In Words Where" is more of an english explanation rather than something a computer would follow.


    Duh, we obviously don't have the same references in our files. :P
    I added System.Collections.Generic, gonna test it.

    Okay, but the flaw in this setup is that you can't find which Whitelist word triggered it so that you can call it.
    Last edited by AmejiOrape; 07-17-2015 at 06:12 PM.

  6. #6
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Quote Originally Posted by AmejiOrape View Post
    Ummm, that doesn't look very C# to me.
    Or we are just on a much different level of coding. But when I try putting that in my code it just comes up with a lot of redlines. Obviously I need to fit it to the variables that fit my code, but it seems like "From I In Words Where" is more of an english explanation rather than something a computer would follow.


    Duh, we obviously don't have the same references in our files. :P
    I added System.Collections.Generic, gonna test it.

    Okay, but the flaw in this setup is that you can't find which Whitelist word triggered it so that you can call it.
    Each word is capitalized because I'm a cs so thats why it appeared in red lines. Also please forgive my previous code as it lacks of the correct logic.
    Here is a working one:
    https://pastebin.com/6u1fQQAX
    Last edited by ♪~ ᕕ(ᐛ)ᕗ; 07-18-2015 at 02:08 AM.

  7. #7
    AmejiOrape's Avatar
    Join Date
    Dec 2014
    Gender
    male
    Posts
    184
    Reputation
    27
    Thanks
    99
    My Mood
    Relaxed
    Well, it works now for the most part. It won't call when there's a blacklist word. But now, this happens.

    https://i.imgur.com/ROA1paM.jpg
    Last edited by AmejiOrape; 07-18-2015 at 11:05 AM.

  8. #8
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Quote Originally Posted by AmejiOrape View Post
    Well, it works now for the most part. It won't call when there's a blacklist word. But now, this happens.

    https://i.imgur.com/ROA1paM.jpg
    Do you know how to access a item inside a list? If you want to know ONLY the first word which triggered the function then use "whiteListed[0]" in order to retrieve the first item.
    https://pastebin.com/9eQ67VGN

    Also please learn the basics, I am offering very cheap courses in order to get you started. PM me if you are interested whatsoever.
    Last edited by ♪~ ᕕ(ᐛ)ᕗ; 07-18-2015 at 11:30 AM.

  9. #9
    AmejiOrape's Avatar
    Join Date
    Dec 2014
    Gender
    male
    Posts
    184
    Reputation
    27
    Thanks
    99
    My Mood
    Relaxed
    Ohhh, because it's an array of strings, so you use array notation. Thanks. I think this code might finally be finished

  10. #10
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Quote Originally Posted by AmejiOrape View Post
    Ohhh, because it's an array of strings, so you use array notation. Thanks. I think this code might finally be finished
    No problemo

  11. #11
    Geometrical's Avatar
    Join Date
    Jul 2012
    Gender
    male
    Location
    In the middle of nowhere.
    Posts
    1,034
    Reputation
    331
    Thanks
    10,335
    My Mood
    Chatty
    Here's my go at it:
    Code:
    string input = "This is an input string.";
    string[] blackList = new string[] {"is"};
    for (int i = 0; i < blacklist.Length; i++) {
        if (input.Equals(blackList[i], StringComparison.InvariantCultureIgnoreCase)) {
            //Black listed word found
        }
    }

Similar Threads

  1. Blacklist and Whitelist?
    By xXwhitepandaXx in forum Marketplace Talk
    Replies: 7
    Last Post: 01-07-2014, 10:51 PM
  2. Through the fire and the flames
    By Ed in forum Spammers Corner
    Replies: 1
    Last Post: 11-21-2011, 02:59 AM
  3. Replies: 3
    Last Post: 05-13-2011, 08:49 PM
  4. [Tutorial] gMS V.87 Meso Filter. Filters meso coin, bills and bags [WZ EDIT]
    By jonniiee in forum MapleStory Tutorial & Guides
    Replies: 4
    Last Post: 07-02-2010, 01:07 AM
  5. My Run at Through the Fire and Flames
    By ZuumTec in forum General
    Replies: 9
    Last Post: 01-15-2008, 11:35 PM