Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import org.jibble.pircbot.PircBot;
- import org.jibble.pircbot.IrcException;
- import org.jsoup.Jsoup;
- public class InfoBot extends PircBot {
- protected final Pattern urlPattern;
- public InfoBot() throws IOException, IrcException {
- this.urlPattern = Pattern.compile("(https?://[^\\s]+)");
- this.setName("TestBot");
- this.setVerbose(true);
- this.connect("irc.efnet.nl");
- this.joinChannel("#test");
- }
- public void onMessage(final String channel, final String sender, final String login, final String hostname, final String message) {
- final Matcher matcher = this.urlPattern.matcher(message);
- while (matcher.find()) {
- final String url = matcher.group();
- try {
- final String title = Jsoup.connect(url).get().select("title").first().text();
- this.sendMessage(channel, title);
- } catch (final IOException e) {
- System.out.println("Could not fetch URL: " + url);
- }
- }
- }
- public static void main(final String[] args) throws IOException, IrcException {
- final InfoBot infoBot = new InfoBot();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement