Jump to content



Photo
- - - - -

#casiocalc Irc Channel's Widget Is Live


  • Please log in to reply
100 replies to this topic

#41 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 30 May 2012 - 06:58 PM

I think this would be a good idea also :)


NOOOOOOOO

I'd rather strip smilies from messages than have them be displayed graphically.

#42 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 30 May 2012 - 07:55 PM

I disagree. I like graphical smilies. We could make it an option though.

#43 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 30 May 2012 - 09:22 PM

OPTION

#44 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 03 June 2012 - 02:14 PM

Things went a bit screwy in my life in the week after that, and I've yet to find time to get that all done; if you could put the prefixes here, I should be able to have them implemented soon.


The prefixes should be "JOINED:", "LEFT:" and "CHANGEDNICK:"

about smiles, I generally don't like their graphical form that much either, I add that at the end of the todo list.

#45 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 13 August 2012 - 11:26 PM

Forty-Two:

Could you replace the join and leave messages by :


"joined the channel"
"left the channel"

Note that there is also a big typo in the current leave message.

#46 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 15 August 2012 - 03:42 PM

2072: why the leave message as well? (It seems that that post was cut off...)

Related: http://www.cemetech....opic.php?t=7670

#47 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 15 August 2012 - 07:36 PM

indeed it had been cut off, I edited it back. Another IPB bug I presume, whatever....

#48 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 15 August 2012 - 08:34 PM

indeed it had been cut off, I edited it back. Another IPB bug I presume, whatever....


Yes, that will be fairly trivial. Ofc, here is the original comment for the code:

//This is all to play with 2072's mind (and it's also good for 'reducing' code size)

:P

#49 MicroPro

MicroPro

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 640 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    Casio ClassPad 300

Posted 17 August 2012 - 07:55 AM

indeed it had been cut off, I edited it back. Another IPB bug I presume, whatever....

Just posted to say it's something with the chat widget, encoding, etc. Whenever you copy text from chat widget there are some zero (0x00) characters together with your text. Try copy-pasting text from it into a hex editor.

#50 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 17 August 2012 - 10:05 PM

yes these are the hyphenation characters actually, browsers are supposed to remove them when using the clipboard but it doesn't work...

#51 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 25 August 2012 - 10:06 PM

Yes, that will be fairly trivial. Ofc, here is the original comment for the code:

//This is all to play with 2072's mind (and it's also good for 'reducing' code size)

:P


Since the typo and grammar issue were hurting my eyes, I've made an internal fix to automatically replace the messages with proper ones :)
I also added an about link pointing to this thread.

#52 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 26 August 2012 - 12:25 AM

I noticed the about link. Also, thanks for fixing grammar/spelling errors.

#53 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 02 November 2012 - 01:07 AM

New topics and posts notification should be working now!

Edited by Forty-Two, 02 November 2012 - 02:32 AM.
Fixed unreadable colors :P


#54 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 02 November 2012 - 01:27 AM

Cool! :)

#55 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 02 November 2012 - 02:15 AM

Notifications are using shorter URIs now :)

#56 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 02 November 2012 - 01:20 PM

Are you using a url shortening service or is it your own?

#57 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 02 November 2012 - 02:00 PM

it's just a redirection using a rewrite rule in .htaccess:


RewriteEngine On
RewriteBase /
RewriteCond  %{REQUEST_URI} ^/p[0-9]+$
RewriteRule [0-9]+ http://community.casiocalc.org/?act=findpost&pid=$0 [R=301,L]

RewriteCond %{REQUEST_URI} ^/t[0-9]+$
RewriteRule [0-9]+ http://community.casiocalc.org/topic/$0- [R=301,L]


#58 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 02 November 2012 - 02:05 PM

Oh, ok, very good.

Good to know we are not relying on other servers. :)

Is a bot handling the post notifications, or is it server side?

#59 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 02 November 2012 - 02:22 PM

it uses the same system than the one used when someone "enters the room" or when someone posts a message using the chat widget. So this is server side :)

#60 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 02 November 2012 - 02:49 PM

Wow, that's really good. Because some other sites use a bot to get the information from an RSS feed, and periodically, those bots will go down (particularly with omnimaga). So this is good because the post notifier will only go down if the site goes down, right?

#61 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1565 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 03 November 2012 - 11:52 AM

yes but users may experience a delay when answering to posts if Forty-Two's bot fails to respond, In that case the notification is not lost but queued.

#62 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 03 November 2012 - 02:17 PM

But the onsite widget would still show the notifications, right?

#63 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 03 November 2012 - 03:47 PM

But the onsite widget would still show the notifications, right?


Yes, since it is updated via the php.

#64 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 03 November 2012 - 03:51 PM

I wonder if the people in charge of #prizm on efnet would want our post notifications, since they get notifications of cemetech posts including the word "prizm".

#65 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 18 December 2012 - 06:43 PM

Could the name highlighter not be case-sensitive?

#66 Anonymouse

Anonymouse

    Casio Addict

  • Members
  • PipPipPip
  • 58 posts
  • Gender:Male

  • Calculators:
    CASIO Graph 75

Posted 26 December 2012 - 11:47 PM

Where's the bot gone?

#67 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 27 December 2012 - 01:21 AM

Where's the bot gone?


I have the same question. I PM'd forty about it but have not received a reply yet.

@Forty: maybe you could give me a copy of ucfbot to run if and when ucfbot goes down?

#68 Casimo

Casimo

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 641 posts
  • Gender:Not Telling

Posted 29 December 2012 - 10:24 AM

I really like this widget :greengrin: .
But I also think that a tab 'Who is active?' would be better than 'Casimo left the Channel' or 'Casimo joined the channel' because you can't see whether Casimo is now active or whether he visited the site for 5h.

#69 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 01 January 2013 - 03:47 PM

There is a list of users active in the past 30 minutes at the bottom of the current page. At the moment, the protocol does not allow transfer of a list of users, so it will not show users active in irc.

Where's the bot gone?


Juju's paypal payments were delayed due to christmas, and his host took down his site. It should be up within the next few days.

#70 MicroPro

MicroPro

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 640 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    Casio ClassPad 300

Posted 06 January 2013 - 01:13 PM

Feature Request: Clickable user names for users that use the widget (not using IRC clients), which links to their profile page.

Useful for getting familiar with new users. (And an alternative way to view your own profile :) )

#71 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 06 January 2013 - 10:37 PM

Feature Request: Clickable user names for users that use the widget (not using IRC clients), which links to their profile page.

Useful for getting familiar with new users. (And an alternative way to view your own profile :) )


Yes, yes, yes please :)

#72 Anonymouse

Anonymouse

    Casio Addict

  • Members
  • PipPipPip
  • 58 posts
  • Gender:Male

  • Calculators:
    CASIO Graph 75

Posted 18 January 2013 - 09:10 PM

Will whoever was originally hosting the bot ever come back? I don't want to run it forever.

#73 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 18 January 2013 - 10:20 PM

I believe the server is up. I will see about restarting it.

I will have my own server running it within the next week.

#74 Casimo

Casimo

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 641 posts
  • Gender:Not Telling

Posted 26 January 2013 - 09:23 AM

The widget/bot is down again.

#75 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 26 January 2013 - 09:59 PM

I am aware and working on it.

#76 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 27 January 2013 - 05:39 PM

I have reorganized the bot's intenal coding. This should make it easier to add modules (be prepared to see some modules in the next few months). To demonstrate how this will al work, I will show the method calls for each end of the bot.

Lets start with someone saying something in irc.

<Forty-Two> ohai

The bot's onMessage method is called by the PircBot library

@Override
    public void onMessage(String channel, String sender, String login, String hostname, String message) {

        if(!(talkChannel.equals(channel))) return;  //If it's not in the channel we are talking in, return
        if(sender.equals(getName())) return;  //If it's us, return
        manager.handleSay(sender, message);  //Call the manager's handle say method
        logger.trace(">>> ["+sender+"] "+message)  //Log the message

    }

This in turn passes the message on to the manager.

public void handleSay(String user, String message) {

        for(MessageHandler handler:handlers){  //Iterate over all handlers

            handler.handleSay(user, message);  //Call the handleSay method of them

        }

    }

For our example, we will only look at the ClientMessageHandler's handleSay method, but note that other handlers hcan be loaded as well.

public void handleSay(String user, String message)

        addMessage(user, message, Common.SAY);  //Add the message to the queue

    }

This adds the message to the queue of messages to be sent to the server on the casiocalc side.

private void addMessage(String user, String message, int type){

        long time= System.currentTimeMillis();  //Get the time; this is necessary for the protocol
        JSONObject object= new JSONObject();  //This is what we use to wrap the message in

        try{

            object.put("time", time);  //First put the current time
            object.put("user", Common.escape(user));  //Then put the user doing the action.  In this case, "Forty-Two"
            object.put("message", Common.escape(message));  //Put the message "ohai"
            object.put("type", type);  //Put the type of message: 0 for errors (never used at my end, but still part of the protocol), 1 for messages (When someone says something), 2 for channel events (Someone joins or parts the channel), and 3 for actions (the /me command)

            synchronized(lock){  //Make sure we are the only thread accssing the queue
                queue.add(object.toString());  //Add the object
            }
            logger.trace("Added the message \""+object.toString()+"\" to the queue");  //Lg it

        }
        catch(JSONException e){  //error handling

            logger.warn("Unable to format the message into JSON: "+e.getMessage());
            return;

        }

    }

Every second, the flush method is called, which sends messages in the queue (if any) to the casiocalc server.

private void flush(){

        if(queue.isEmpty()) return;  //Don't even bother if the queue is empty
        logger.debug("Flushing messages");
        synchronized (lock){  //Make sure no one else touches the queue while we're using it

            String messageDigest= Common.getHash(queue);  //Get digest in hex
            String random= Common.randomString();  //Get a random string to use for security
            String key= random+Common.SALT+messageDigest;  //Put these all together
            String outDigest= Common.toHex(Common.getMessageDigest().digest(key.getBytes()));  //Compute the digest to send
            HttpURLConnection connection;

            try{

                URL url= new URL("http://api.casiocalc.org/CasioIRCEventReceiver.php?AuthChallengeRandom="+random+"&AuthChallengeKey="+outDigest);  //The authentication parameters are passed in the url, similar to the GET method
                connection = (HttpURLConnection) url.openConnection(); //Set the 
                connection.setDoOutput(true);  //No idea >.>
                connection.setDoInput(true);  //Gonna have to refresh my knowledge of the api
                connection.setRequestMethod("POST");  //This is so we can stick stuff in the body, like when you fill out a form

                PrintStream out= new PrintStream(connection.getOutputStream());  //Open a stream to the output
                for (String line : queue) { //For every line in the queue...

                    out.println(line);  //...print it

                }
                out.close();  //Close the output stream once were done with it
            }
            //Handle them errors
            catch(MalformedURLException e){

                log("Malformed URL: "+e.getMessage());
                return;

            }
            catch(ProtocolException e){

                log("Error in Protocol: "+e.getMessage());
                return;

            }
            catch(IOException e){

                log("I/O Error: "+e.getMessage());
                return;

            }

            try{
                //This is where we check for errors when we authenticated

                BufferedReader in= new BufferedReader(new InputStreamReader(connection.getInputStream()));  //Get a stream
                for(String line= in.readLine(); line!=null; line= in.readLine()){  //Read off the output so we can log it

                    logger.trace("RESP: "+line);

                }

                switch(connection.getResponseCode()){

                    case HttpURLConnection.HTTP_OK: break;  //It worked!
                    case HttpURLConnection.HTTP_BAD_REQUEST: log("Malformed data"); return;  //This is the response if the json is wrong
                    case HttpURLConnection.HTTP_UNAUTHORIZED: log("Unable to authenticate"); return;  //This is what happens if we get the auth wrong (Oh noes!)

                }

            }
            //More error handling
            catch(MalformedURLException e){

                log("Malformed URL: "+e.getMessage());

            }
            catch(ProtocolException e){

                log("Error in Protocol: "+e.getMessage());

            }
            catch(IOException e){

                log("I/O Error: "+e.getMessage());

            }
            finally{

                queue.clear();  //Make sure the queue gets cleared

            }

        }

The casiocalc side then updates a file with the stuff that goes into chat, and the widget on the page updates itself from that. The next post will have a message going the other way.
  • MicroPro likes this

#77 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 27 January 2013 - 05:58 PM

Now for when someone says something in the widget.

<Forty-Two> ohai

The widget forwards the message to the server, which in turn sends it to the bot. The bot runs a server which recieves the messages from casiocalc. This is based on the server included with java in the com.su.net.httpserver package.

public void handle(HttpExchange exchange) throws IOException {

        logger.trace("Recieved request from "+exchange.getRemoteAddress().getHostName());

        if(!(exchange.getRequestMethod().equals("POST"))){  //If the request was not post, return an error

            sendError(exchange, "Bad method: "+exchange.getRequestMethod(), HttpURLConnection.HTTP_BAD_METHOD);
            return;

        }

        BufferedReader body= new BufferedReader(new InputStreamReader(exchange.getRequestBody()));  //Create a new bufferedreader that updates the MessageDigest

        LinkedList<String> buffer= new LinkedList<String>();  //Read the lines into a buffer
        for(String line= body.readLine(); line!=null; line= body.readLine()) {

            buffer.add(line);
            logger.trace("RECV: "+line);

        }

        Headers headers= exchange.getRequestHeaders();  //Get the headers
        String random= headers.getFirst("AuthChallengeRandom");
        String inDigest= headers.getFirst("AuthChallengeKey");

        String messageDigest= Common.getHash(buffer);  //Compute our message digest
        String key= random+Common.SALT+messageDigest;  //Add everything togather
        String outDigest= Common.toHex(Common.getMessageDigest().digest(key.getBytes()));  //This should match the digest that the casiocalc server sent us


        logger.trace("Input Digest: "+inDigest+" Random: "+random+" Message Digest: "+messageDigest+" Computed Digest: "+outDigest);

        if(!(outDigest.equals(inDigest))){  //If they're not equal, complain

            sendError(exchange, "Invalid digest: "+inDigest, HttpURLConnection.HTTP_UNAUTHORIZED);
            return;

        }

        for(String line: buffer){  //Parse each line from the server

            try {

                JSONObject json = new JSONObject(line);  //Create a new object for each line

                String user= json.getString("user");  //Get the user ("Forty-Two")
                String message= json.getString("message");  //The message ("ohai")
                int type= json.getInt("type");  //And the message type (1); we ignore the time parameter, though it is still passed

                switch(type){  //Switch for message types and pass it on to the bot (actually the BotManager)
                    case 0: bot.error(message); break;
                    case 1: bot.say(user, message); break;  //Evals to true
                    case 2: bot.channel(user, message); break;
                    case 3: bot.action(user, message); break;
                    default: logger.debug("Invalid message type: "+type); break;
                }

            } catch (JSONException e) {
                logger.debug("Unable to parse line from server: "+line);
            }

        }

        exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0);  //Wrap it up
        exchange.close();  //Close it when we're done

    }

The server calls the apropriate method of the BotManager, in our case the say() method

/**
     * Sends a message from a user in the form of<br />
     * <pre>[user] message</pre>
     * @param user The user to send from
     * @param message The message to send
     */
    public void say(String user, String message){

        bot.say(user, message);

    }

As you can see, the BotManager does not do anything but forward the message on to the bot. This is to keep the components' jobs separated: the bot only interfaces with irc, and the manager controls who talks to the bot (and also handles the handlers [see above])

public void say(String user, String message){

        logger.trace(">>> ["+user+"] "+message);
        sendMessage("["+user+"] "+message);  //Calls the sendMessage method, which overloads the super's sendMessage method

    }

private void sendMessage(String message){

        if(!(isConnected())) chatReconnect();  //If we aren't connected, reconnect
        if(!(Common.hasString(getChannels(), talkChannel))) joinChannel(talkChannel);  //If we aren't in the channel, join it
        sendMessage(talkChannel, message);  //Send the message to the channel

    }

The message is then passed on to the PircBot library where it is sent to the irc channel.

#78 Forty-Two

Forty-Two

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 528 posts
  • Gender:Male
  • Location:Well, The sign says "You are here"...

  • Calculators:
    Casio fx-CG10 Prizm
    Casio fx-9860GII
    TI-84+ SE

Posted 02 February 2013 - 04:08 PM

UcfBot is back up!

There had been a small problem with the line ending (stupid windows), but that got fixed. Expect to see more new features as we transition to the next version.

#79 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 02 February 2013 - 11:21 PM

Awesome!

Window$--

#80 Casimo

Casimo

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 641 posts
  • Gender:Not Telling

Posted 08 February 2013 - 04:29 PM

It seems like UcfBot has got a problem: You can only send and read data transfered by the bot.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users