]> jfr.im git - irc/Ozafy/borknet_p10_irc_services.git/blob - core/modules/s/Commands.java
First commit
[irc/Ozafy/borknet_p10_irc_services.git] / core / modules / s / Commands.java
1 /**
2 #
3 # BorkNet Services Core
4 #
5
6 #
7 # Copyright (C) 2004 Ozafy - ozafy@borknet.org - http://www.borknet.org
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABotILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Botoston, MA 02111-1307, USA.
22 #
23 */
24 import java.util.*;
25 import java.net.*;
26 import java.io.*;
27 import borknet_services.core.*;
28
29
30 /**
31 * The server communication class of the Q IRC Botot.
32 * @author Ozafy - ozafy@borknet.org - http://www.borknet.org
33 */
34 public class Commands
35 {
36 private ArrayList<Object> cmds = new ArrayList<Object>();
37 private ArrayList<String> cmdn = new ArrayList<String>();
38 private Core C;
39 private S Bot;
40 private DBControl dbc;
41 private String numeric = "";
42 private String botnum = "";
43 private String network = "";
44 private String rules = "";
45 private Spamwords spamwords;
46 public Commands(Core C, S Bot)
47 {
48 this.C = C;
49 this.Bot = Bot;
50 dbc = Bot.getDBC();
51 numeric = Bot.get_num();
52 botnum = Bot.get_corenum();
53 cmds = Bot.getCmds();
54 cmdn = Bot.getCmdn();
55 rules = Bot.getRules();
56 network = C.get_net();
57 spamwords = new Spamwords(C);
58 }
59
60 public void privmsg(ArrayList<String> params)
61 {
62 String source = params.get(0);
63 String target = params.get(2);
64 String message = params.get(3);
65 if(target.startsWith("#"))
66 {
67 if(dbc.SchanExists(target) && !dbc.isService(source))
68 {
69 User user = dbc.getUser(source);
70 if(!user.getOperator())
71 {
72 String f = dbc.getChanFlags(target);
73 if(f.equals("n"))
74 {
75 spamscan(source, message);
76 }
77 else if(f.equals("i"))
78 {
79 C.cmd_dis(source, "You are violating "+network+" rules. Please read "+rules+". ID: "+dbc.getID());
80 }
81 }
82 }
83 }
84 if(!target.equals(numeric) && !target.equals(numeric+botnum) && !target.equalsIgnoreCase(Bot.get_nick()+"@"+Bot.get_host())) return;
85 String command = "";
86 try
87 {
88 String[] result = message.split("\\s");
89 command = result[0].toLowerCase();
90 }
91 catch(ArrayIndexOutOfBoundsException e)
92 {
93 command = message.toLowerCase();
94 }
95 if(command.equals("help"))
96 {
97 String cmd = "";
98 try
99 {
100 String[] result = message.split("\\s");
101 cmd = result[1].toLowerCase();
102 }
103 catch(ArrayIndexOutOfBoundsException e)
104 {
105 showCommands(source);
106 return;
107 }
108 int compo = cmdn.indexOf(cmd);
109 if(compo > -1)
110 {
111 Command ccommand = (Command) cmds.get(compo);
112 CoreDBControl dbc = C.get_dbc();
113 User user = dbc.getUser(source);
114 ccommand.parse_help(C,Bot,numeric,botnum,source,user.getOperator());
115 }
116 else
117 {
118 C.cmd_notice(numeric, botnum,source,"This command is either unknown, or you need to be opered up to use it.");
119 }
120 return;
121 }
122 if(command.equals("showcommands"))
123 {
124 showCommands(source);
125 return;
126 }
127 int compo = cmdn.indexOf(command);
128 if(command.startsWith("\1"))
129 {
130 compo = cmdn.indexOf(command.replace("\1",""));
131 }
132 if(compo > -1)
133 {
134 Command ccommand = (Command) cmds.get(compo);
135 ccommand.parse_command(C,Bot,numeric,botnum,source,message);
136 }
137 else
138 {
139 C.cmd_notice(numeric, botnum,source,"This command is either unknown, or you need to be opered up to use it.");
140 C.cmd_notice(numeric, botnum,source,"/msg "+Bot.get_nick()+" showcommands");
141 }
142 }
143 private void showCommands(String source)
144 {
145 C.cmd_notice(numeric, botnum,source,"The following commands are available to you:");
146 CoreDBControl dbc = C.get_dbc();
147 User user = dbc.getUser(source);
148 for(int n=0; n<cmds.size(); n++)
149 {
150 Command ccommand = (Command) cmds.get(n);
151 ccommand.showcommand(C,Bot,numeric,botnum,source,user.getOperator());
152 }
153 C.cmd_notice(numeric, botnum,source,"End of list.");
154 }
155 private void spamscan(String source, String msg)
156 {
157 dbc.addPoints(source, Bot.getSpamtext());
158 if(msg.contains("#"))
159 {
160 if(msg.indexOf("#",msg.indexOf("#")) > -1)
161 {
162 String chans[] = msg.split("\\s");
163 for (String chan : chans)
164 {
165 if(chan.startsWith("#") && dbc.chanExists(chan))
166 {
167 dbc.addPoints(source, Bot.getSpamchan());
168 }
169 }
170 }
171 else
172 {
173 String chan = msg.substring(msg.indexOf("#"));
174 if(chan.contains(" "))
175 {
176 chan = chan.substring(chan.indexOf("#"),chan.indexOf(" ",chan.indexOf("#")));
177 }
178 if(dbc.chanExists(chan))
179 {
180 dbc.addPoints(source, Bot.getSpamchan());
181 }
182 }
183 }
184 if(msg.contains("http://") || msg.contains("www."))
185 {
186 dbc.addPoints(source, Bot.getSpamweb());
187 }
188 if(dbc.repeat(source,msg))
189 {
190 dbc.addPoints(source, Bot.getSpamrepeat());
191 }
192 dbc.addPoints(source, spamwords.getPoints(msg));
193 dbc.setMsg(source,msg);
194 if(dbc.getPoints(source) >= Bot.getSpamwarning())
195 {
196 C.cmd_notice(numeric, botnum,source, "You are violating "+network+" rules. Please read "+rules+" and cease your abuse.");
197 }
198 if(dbc.getPoints(source) >= Bot.getSpamkill())
199 {
200 C.cmd_dis(source, "You are violating "+network+" rules. Please read "+rules+". ID: "+dbc.getID());
201 }
202 }
203 }