3 # BorkNet Services Core
7 # Copyright (C) 2004 Ozafy - ozafy@borknet.org - http://www.borknet.org
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.
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.
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.
27 import borknet_services
.core
.*;
31 * The server communication class of the Q IRC Botot.
32 * @author Ozafy - ozafy@borknet.org - http://www.borknet.org
36 private ArrayList
<Object
> cmds
= new ArrayList
<Object
>();
37 private ArrayList
<String
> cmdn
= new ArrayList
<String
>();
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
)
51 numeric
= Bot
.get_num();
52 botnum
= Bot
.get_corenum();
55 rules
= Bot
.getRules();
56 network
= C
.get_net();
57 spamwords
= new Spamwords(C
);
60 public void privmsg(ArrayList
<String
> params
)
62 String source
= params
.get(0);
63 String target
= params
.get(2);
64 String message
= params
.get(3);
65 if(target
.startsWith("#"))
67 if(dbc
.SchanExists(target
) && !dbc
.isService(source
))
69 User user
= dbc
.getUser(source
);
70 if(!user
.getOperator())
72 String f
= dbc
.getChanFlags(target
);
75 spamscan(source
, message
);
77 else if(f
.equals("i"))
79 C
.cmd_dis(source
, "You are violating "+network
+" rules. Please read "+rules
+". ID: "+dbc
.getID());
84 if(!target
.equals(numeric
) && !target
.equals(numeric
+botnum
) && !target
.equalsIgnoreCase(Bot
.get_nick()+"@"+Bot
.get_host())) return;
88 String
[] result
= message
.split("\\s");
89 command
= result
[0].toLowerCase();
91 catch(ArrayIndexOutOfBoundsException e
)
93 command
= message
.toLowerCase();
95 if(command
.equals("help"))
100 String
[] result
= message
.split("\\s");
101 cmd
= result
[1].toLowerCase();
103 catch(ArrayIndexOutOfBoundsException e
)
105 showCommands(source
);
108 int compo
= cmdn
.indexOf(cmd
);
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());
118 C
.cmd_notice(numeric
, botnum
,source
,"This command is either unknown, or you need to be opered up to use it.");
122 if(command
.equals("showcommands"))
124 showCommands(source
);
127 int compo
= cmdn
.indexOf(command
);
128 if(command
.startsWith("\1"))
130 compo
= cmdn
.indexOf(command
.replace("\1",""));
134 Command ccommand
= (Command
) cmds
.get(compo
);
135 ccommand
.parse_command(C
,Bot
,numeric
,botnum
,source
,message
);
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");
143 private void showCommands(String source
)
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
++)
150 Command ccommand
= (Command
) cmds
.get(n
);
151 ccommand
.showcommand(C
,Bot
,numeric
,botnum
,source
,user
.getOperator());
153 C
.cmd_notice(numeric
, botnum
,source
,"End of list.");
155 private void spamscan(String source
, String msg
)
157 dbc
.addPoints(source
, Bot
.getSpamtext());
158 if(msg
.contains("#"))
160 if(msg
.indexOf("#",msg
.indexOf("#")) > -1)
162 String chans
[] = msg
.split("\\s");
163 for (String chan
: chans
)
165 if(chan
.startsWith("#") && dbc
.chanExists(chan
))
167 dbc
.addPoints(source
, Bot
.getSpamchan());
173 String chan
= msg
.substring(msg
.indexOf("#"));
174 if(chan
.contains(" "))
176 chan
= chan
.substring(chan
.indexOf("#"),chan
.indexOf(" ",chan
.indexOf("#")));
178 if(dbc
.chanExists(chan
))
180 dbc
.addPoints(source
, Bot
.getSpamchan());
184 if(msg
.contains("http://") || msg
.contains("www."))
186 dbc
.addPoints(source
, Bot
.getSpamweb());
188 if(dbc
.repeat(source
,msg
))
190 dbc
.addPoints(source
, Bot
.getSpamrepeat());
192 dbc
.addPoints(source
, spamwords
.getPoints(msg
));
193 dbc
.setMsg(source
,msg
);
194 if(dbc
.getPoints(source
) >= Bot
.getSpamwarning())
196 C
.cmd_notice(numeric
, botnum
,source
, "You are violating "+network
+" rules. Please read "+rules
+" and cease your abuse.");
198 if(dbc
.getPoints(source
) >= Bot
.getSpamkill())
200 C
.cmd_dis(source
, "You are violating "+network
+" rules. Please read "+rules
+". ID: "+dbc
.getID());