Results 1 to 6 of 6

Thread: perl parsing

  1. #1
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default perl parsing

    i'm making a perl irc bot, and im having trouble parsing this D:

    i need to get 'akwardsaw!~myip PRIVMSG #ethan :s/lol//;' parsed into 2 different variables.. i need 'akwardsaw' in one, and every thing after 'PRIVMSG #ethan :' into an other, and im having lots of troubles with it D:

    what i have to get the message:
    $messge = $in =~ /PRIVMSG $chan \s+(.*)/;

    where $in is the variable that holds the string, and $chan is the channel the bot is in. i suck at regex, and im sure im missing something
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  2. #2
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Alright, heres a tip, irc servers do not allow the characters : ! ~ @ and space in the nick, name(I dont think) and ip.
    idk if perl can be/is oop, but make a class/type/struct called Message. Every time a new message is sent, have a method parse it and create a new Message.

    The line sent sent back from an irc server to the clients looks like
    :noidea`!~noidea`@let.mee.frost.your.flakes PRIVMSG #SRL :testing
    Have it go through the string and have it store the info.
    :noidea`!~noidea`@let.mee.frost.your.flakes PRIVMSG #SRL :testing
    name^....nick^...............ip^.................m sg type^..chan^..msg^

    I think you know a bit of java, so here a crappy example I made

    Code:
    class Message {                   //prevent null showing up in the message
        String original = "", sender = "", name = "", message="", ip = "", channel = "", type = "", originalmessage = "";
        Tokenizer tokens = null;
        String[] words = null, originalwords = null;
        Core utils = new Core();
        ArrayList<String> info = null;
        public int MESSAGE_START_INDEX = 3;
    
        //x x x x x x PRIVMSG channel
        public void parsemessage(String line) {
            //StringTokenizer newtokens = new StringTokenizer();
            info = utils.multisplit(line,  ":|!|~|@| ");
            if (info.size() < 5) return;
            original = line;
            sender = info.get(utils.SENDER_IND);
            name = info.get(utils.NAME_IND);
            ip = info.get(utils.IP_IND);
            type = info.get(utils.MSG_TYPE_IND);
            channel = info.get(utils.CHANNEL_IND);
            for (int i = utils.MESSAGE_IND; info.size() > i; i++) message += info.get(i)+ " ";
            if (message.length() > 0) {
                tokens = new Tokenizer(message);
                words = message.split(" ");
            }
            originalwords = line.split(" ");
            if (originalwords.length > 3) {
                originalmessage += originalwords[MESSAGE_START_INDEX].substring(1);//get rid of the :
                for (int i = MESSAGE_START_INDEX+1; originalwords.length > i; i++) {
                    originalmessage += " "+originalwords[i];
                }
            }
        }
    
        Message(String line) {
            parsemessage(line);
        }
    }
    Last edited by noidea; 06-25-2010 at 03:52 AM.
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  3. #3
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    thanks i'll look into it, try to port over to perl and stuff, but i was hoping for it to be in regex it makes it so much cleaner
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  4. #4
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    thanks i'll look into it, try to port over to perl and stuff, but i was hoping for it to be in regex it makes it so much cleaner
    in java

    String[] info = line.split(":|!|~|@| ");

    but unfortunately that ruins whats after #channel :stuff to say
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  5. #5
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    I feel like this could be much easier..

  6. #6
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by i luffs yeww View Post
    I feel like this could be much easier..
    idk, split helps a lot, but im to lazy atm to add it to the bot

    im torn between that and pos(m//)
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •