-
Notifications
You must be signed in to change notification settings - Fork 1
/
ZatchBotMain.java
110 lines (97 loc) · 5.01 KB
/
ZatchBotMain.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*A Simple IRC bot that uses PIRC
Copyright (C) 2014
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
//Created by Sapein
//Zatchbot v 1.0
import java.io.*;
import org.jibble.pircbot.*;
public class ZatchBotMain {
static String Server; //This will be replaced by what is inputed in the Config upon start. This is the IRC server
static String Channel; //This will be replaced by what is inputted in the Channel Line upon Start. These are the channels to Auto-Connect to.
private static String configVersion = "1.0";
public static void main(String[] arg) throws Exception {
//Begin Config Creation Code
String conVersion;
File file = new File("Config.txt"); //sets the file name
// NOTE: That the defaults set here are to prevent the bot from erroring out upon start-up, your changes will not be overwritten.
if (!file.exists()) { //checks to see if it exists, if not it writes this
file.createNewFile(); //creates the file
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("Config Version: " + configVersion+ "\r\n");
bw.write(" =--Connection--=" +"\r\n");
bw.write("--IRC Server--" + "\r\n"); //puts this on the first line of the file
bw.write("irc.rizon.net" + "\r\n"); //puts this on the second line of the file
bw.write("--Channels--" + "\r\n"); //puts this on the third line of the file
bw.write("== To add Multiple Channels use a comma(,) inbetween with no spaces ==" + "\r\n"); //puts this on the fourth line of the file
bw.write("#chat" + "\r\n"); //puts this on the fifth line of the file
bw.write(" ==--IRC Bot--==" + "\r\n"); //creates the sixth line of the file
bw.write("--Toggle Hostname Verification for Ops--" + "\r\n"); //puts this on the Seventh line of the file
bw.write("false " + "\r\n"); //makes Hostname Verification False by default
bw.write("--Toggle Nick Verification for Ops--" + "\r\n"); //puts this on the Ninth line of the file
bw.write("true " + "\r\n"); //Sets the Nick verification to true
bw.write("--Bot Name--" +"\r\n"); //puts this on the Eleventh line of the file
bw.write("Zatch" + "\r\n"); //puts this on the twelfth line of the file
bw.write("--Master--" + "\r\n"); //puts this on the thirteenth line of the file
bw.write("Chanku" + "\r\n"); //puts this on the fourteenth line of the file
bw.write("--Op Nicks--" + "\r\n"); //puts this on the fifteenth line of the file
bw.write("\r\n"); //generates a blank space
bw.write("--Op Hostnames" + "\r\n"); //puts this on the Seventeenth line of the file
bw.write("\r\n"); //generates blank space on the Eighteenth line of the file
bw.write("--Toggle Logs" +"\r\n");
bw.write("false" + "\r\n");
bw.write("--Logs Location--" + "\r\n");
bw.write("\r\n");
bw.close(); //closes the writer.
}
//End Config Creation Code
//Begin Config Access Code
BufferedReader saveFile= new BufferedReader(new FileReader("Config.txt"));
// Get the integer value from the String.
conVersion = saveFile.readLine();
if(!conVersion.startsWith("Config Version")){
saveFile.readLine();
Server = saveFile.readLine();
saveFile.readLine();
saveFile.readLine();
Channel = saveFile.readLine();
// Not needed, but read blank line at the bottom.
saveFile.close();
}else{
saveFile.readLine();
saveFile.readLine();
Server = saveFile.readLine();
saveFile.readLine();
saveFile.readLine();
Channel = saveFile.readLine();
// Not needed, but read blank line at the bottom.
saveFile.close();
}
String[] Channels = Channel.split(",");
//End Config Access Code
ZatchBot bot = new ZatchBot(); // this starts your bot
bot.setVerbose(true); // enable debugging, useful during programming
bot.connect(Server); //Connect to the Server(The Server Variable is called here)
for(int ChannelAmount = 0; ChannelAmount < Channels.length; ++ChannelAmount) { //This makes sure that all Channels listed are joined as we stored it in a variable earlier.
bot.joinChannel(Channels[ChannelAmount]); //Actually Joins the channels.
}
}
/*
* This is mainly designed to return the config version. This may be deprecated in the future and is only really used
* for getting the configVersion Variable.
*/
public static String getConfigVersion(){
return configVersion;
}
}