Skip to content

Instantly share code, notes, and snippets.

@Laurian
Created March 28, 2010 15:12
Show Gist options
  • Save Laurian/346797 to your computer and use it in GitHub Desktop.
Save Laurian/346797 to your computer and use it in GitHub Desktop.
/*
*
*/
package com.namebound.cenobot;
import com.namebound.yeti.representation.RdfRepresentation;
import com.namebound.yeti.resource.Resource;
import com.namebound.yeti.resource.Store;
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jibble.pircbot.PircBot;
import org.ontoware.rdf2go.exception.ModelRuntimeException;
/**
*
* @author Laurian Gridinoc
*/
public class CenoBot extends PircBot {
public static final String rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
public static final String dc = "http://purl.org/dc/elements/1.1/";
public static final String sioc = "http://rdfs.org/sioc/ns#";
public static final String rdfs = "http://www.w3.org/2000/01/rdf-schema#";
private static DateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
private static DateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
private String server;
private Resource fourStore;
private Store talisStore;
public CenoBot(String name, String server, String fourStore, String talisStore, String user, String pass) {
this.server = server;
this.fourStore = new Resource(fourStore);
try {
this.talisStore = new Store(talisStore, user, pass);
} catch (URISyntaxException ex) {
Logger.getLogger(CenoBot.class.getName()).log(Level.SEVERE, null, ex);
}
this.setName(name);
}
@Override
public void onMessage(String channel, String sender, String login, String hostname, String message) {
if (message.equalsIgnoreCase("time")) {
String time = new java.util.Date().toString();
sendMessage(channel, sender + ": the time is now " + time);
}
RdfRepresentation msg = new RdfRepresentation();
Date now = new Date();
String date = iso8601Format.format(now);
String day = dayFormat.format(now);
//sample
//<rdf:Description rdf:about="http://api.talis.com/stores/talis-irc/items/1209725038.72">
Resource subject = new Resource("http://purl.org/net/cenobot/" + UUID.randomUUID().toString());
//sample
//<rdfs:seeAlso rdf:resource="http://n2.talis.com/irc/2008-05-02#10:43:58"/>
msg.addStatement(subject, new Resource(rdfs + "seeAlso"), new Resource(
"http://purl.org/net/cenobot/" + channel.substring(1) + "/" + date.replace('T', '#')));
//sample
//<j.0:hasContainer rdf:resource="irc://irc.freenode.net/#talis"/>
msg.addStatement(subject, new Resource(sioc + "hasContainer"),
"irc://" + server + "/" + channel);
//sample
//<j.0:content>talis not found.</j.0:content>
msg.addStatement(subject, new Resource(sioc + "content"), message);
//sample
//<dc:source>#talis</dc:source>
msg.addStatement(subject, new Resource(dc + "source"), channel);
//sample
//<dc:date>2008-05-02T10:43:58Z</dc:date>
msg.addStatement(subject, new Resource(dc + "date"), date);
//sample
//<dc:creator>robot_monkey</dc:creator>
msg.addStatement(subject, new Resource(dc + "creator"), sender);
try {
msg.model().writeTo(System.out);
} catch (IOException ex) {
Logger.getLogger(CenoBot.class.getName()).log(Level.SEVERE, null, ex);
} catch (ModelRuntimeException ex) {
Logger.getLogger(CenoBot.class.getName()).log(Level.SEVERE, null, ex);
}
//post to talis
talisStore.meta.post(msg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment