]> jfr.im git - irc/borknet/trunk.git/blame - core/modules/w/Commands.java
git-svn-id: https://svn.code.sf.net/p/borknet-dev-com/code/borknet_services/trunk...
[irc/borknet/trunk.git] / core / modules / w / Commands.java
CommitLineData
dc6da157 1/**\r
2#\r
3# BorkNet Services Core\r
4#\r
5\r
6#\r
7# Copyright (C) 2004 Ozafy - ozafy@borknet.org - http://www.borknet.org\r
8#\r
9# This program is free software; you can redistribute it and/or\r
10# modify it under the terms of the GNU General Public License\r
11# as published by the Free Software Foundation; either version 2\r
12# of the License, or (at your option) any later version.\r
13#\r
14# This program is distributed in the hope that it will be useful,\r
15# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16# MERCHANTABotILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
17# GNU General Public License for more details.\r
18#\r
19# You should have received a copy of the GNU General Public License\r
20# along with this program; if not, write to the Free Software\r
21# Foundation, Inc., 59 Temple Place - Suite 330, Botoston, MA 02111-1307, USA.\r
22#\r
23*/\r
24\r
25/*\r
26This class handles private messages.\r
27\r
28It checks if the message was sent to this bot/server,\r
29then checks if it was help/showcommands or a command\r
30and sends it to the correct class.\r
31*/\r
32\r
33import java.util.*;\r
34import java.net.*;\r
35import java.io.*;\r
36import borknet_services.core.*;\r
37\r
38\r
39/**\r
40 * The server communication class of the Q IRC Botot.\r
41 * @author Ozafy - ozafy@borknet.org - http://www.borknet.org\r
42 */\r
43public class Commands\r
44{\r
45 private ArrayList<Object> cmds = new ArrayList<Object>();\r
46 private ArrayList<String> cmdn = new ArrayList<String>();\r
47 private Core C;\r
48 private W Bot;\r
49 private String numeric = "";\r
50 private String botnum = "";\r
51 public Commands(Core C, W Bot)\r
52 {\r
53 this.C = C;\r
54 this.Bot = Bot;\r
55 numeric = Bot.get_num();\r
56 botnum = Bot.get_corenum();\r
57 cmds = Bot.getCmds();\r
58 cmdn = Bot.getCmdn();\r
59 }\r
60\r
61 public void privmsg(String target, String username, String message)\r
62 {\r
63 if(!target.equals(numeric) && !target.equals(numeric+botnum) && !target.equalsIgnoreCase(Bot.get_nick()+"@"+Bot.get_host())) return;\r
64 String command = "";\r
65 try\r
66 {\r
67 String[] result = message.split("\\s");\r
68 command = result[0].toLowerCase();\r
69 }\r
70 catch(ArrayIndexOutOfBoundsException e)\r
71 {\r
72 command = message.toLowerCase();\r
73 }\r
74 if(command.equals("help"))\r
75 {\r
76 String cmd = "";\r
77 try\r
78 {\r
79 String[] result = message.split("\\s");\r
80 cmd = result[1].toLowerCase();\r
81 }\r
82 catch(ArrayIndexOutOfBoundsException e)\r
83 {\r
84 showCommands(username);\r
85 return;\r
86 }\r
87 int compo = cmdn.indexOf(cmd);\r
88 if(compo > -1)\r
89 {\r
90 Command ccommand = (Command) cmds.get(compo);\r
91 CoreDBControl dbc = C.get_dbc();\r
92 String user[] = dbc.getUserRow(username);\r
93 int lev = 0;\r
94 if(!user[4].equals("0"))\r
95 {\r
96 String auth[] = dbc.getAuthRow(user[4]);\r
97 lev = Integer.parseInt(auth[3]);\r
98 }\r
99 ccommand.parse_help(C,Bot,numeric,botnum,username,lev);\r
100 }\r
101 else\r
102 {\r
103 C.cmd_notice(numeric, botnum,username,"This command is either unknown, or you need to be opered up to use it.");\r
104 }\r
105 return;\r
106 }\r
107 if(command.equals("showcommands"))\r
108 {\r
109 showCommands(username);\r
110 return;\r
111 }\r
112 int compo = cmdn.indexOf(command);\r
113 if(command.startsWith("\1"))\r
114 {\r
115 compo = cmdn.indexOf(command.replace("\1",""));\r
116 }\r
117 if(compo > -1)\r
118 {\r
119 Command ccommand = (Command) cmds.get(compo);\r
120 ccommand.parse_command(C,Bot,numeric,botnum,username,message);\r
121 }\r
122 else\r
123 {\r
124 C.cmd_notice(numeric, botnum,username,"This command is either unknown, or you need to be opered up to use it.");\r
125 C.cmd_notice(numeric, botnum,username,"/msg "+Bot.get_nick()+" showcommands");\r
126 }\r
127 }\r
128 private void showCommands(String username)\r
129 {\r
130 C.cmd_notice(numeric, botnum,username,"The following commands are available to you:");\r
131 CoreDBControl dbc = C.get_dbc();\r
132 String user[] = dbc.getUserRow(username);\r
133 int lev = 0;\r
134 if(!user[4].equals("0"))\r
135 {\r
136 String auth[] = dbc.getAuthRow(user[4]);\r
137 lev = Integer.parseInt(auth[3]);\r
138 }\r
139 for(int n=0; n<cmds.size(); n++)\r
140 {\r
141 Command ccommand = (Command) cmds.get(n);\r
142 ccommand.showcommand(C,Bot,numeric,botnum,username,lev);\r
143 }\r
144 C.cmd_notice(numeric, botnum,username,"End of list.");\r
145 }\r
146}