· 9 years ago · Aug 23, 2016, 02:24 PM
1package main;
2
3import java.nio.charset.Charset;
4import MyListener;
5import org.pircbotx.Configuration;
6import org.pircbotx.PircBotX;
7
8/**
9 * Basic example class for various features of PircBotX. Heavily documented
10 * to explain what's going on
11 * <p/>
12 * @author Leon Blakey <lord.quackstar at gmail.com>
13 */
14public class PircBotXExample {
15 @SuppressWarnings("deprecation")
16 public static void main(String[] args) {
17 //Setup this bot
18 Configuration configuration = new Configuration.Builder()
19 .setEncoding(Charset.forName("UTF_8"))
20 .setAutoReconnect(true)
21 .setName("loockystwtchbot") //Set the nick of the bot. CHANGE IN YOUR CODE
22 .setLogin("loockystwtch") //login part of hostmask, eg name:login@host
23 .setAutoNickChange(true) //Automatically change nick when the current one is in use
24 .setServer("irc.twitch.tv", 6667)
25 .setServerPassword("oauth:")
26 .addAutoJoinChannel("#Loockystwtch") //Join the official #pircbotx channel
27 .addListener(new MyListener())
28 .buildConfiguration();
29
30 //bot.connect throws various exceptions for failures
31 try {
32 PircBotX bot = new PircBotX(configuration);
33 //Connect to the freenode IRC network
34 bot.startBot();
35 } //In your code you should catch and handle each exception seperately,
36 //but here we just lump them all togeather for simpliciy
37 catch (Exception ex) {
38 ex.printStackTrace();
39 }
40 }
41}