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 # MERCHANTABILITY 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, Boston, MA 02111-1307, USA.
24 package borknet_services
.core
;
28 import borknet_services
.core
.*;
29 import borknet_services
.core
.commands
.*;
32 * The server communication class of the Q IRC Bot.
33 * @author Ozafy - ozafy@borknet.org - http://www.borknet.org
35 public class CoreCommands
37 private HashMap
<String
,Object
> cmds
= new HashMap
<String
,Object
>();
39 private String numeric
= "";
40 private String bot
= "";
41 public CoreCommands(Core C
)
44 numeric
= C
.get_numeric();
45 bot
= C
.get_corenum();
49 // Convert the file object to a URL
50 File dir
= new File(System
.getProperty("user.dir")+File
.separator
+"core"+File
.separator
+"commands"+File
.separator
);
51 URI uri
= dir
.toURI();
52 URL url
= uri
.toURL();
53 urls
= new URL
[]{url
};
54 CmdLoader cl
= new CmdLoader("core/cmds");
55 String
[] commandlist
= cl
.getVars();
56 for(int n
=0; n
<commandlist
.length
; n
++)
58 // Create a new class loader with the directory
59 ClassLoader clsl
= new URLClassLoader(urls
);
61 Class cls
= clsl
.loadClass(commandlist
[n
]);
62 // Create a new instance of the new class
63 cmds
.put(commandlist
[n
].toLowerCase(),cls
.newInstance());
73 public void privmsg(ArrayList
<String
> params
)
75 String source
= params
.get(0);
76 String target
= params
.get(2);
77 String message
= params
.get(3);
78 if(!target
.equals(numeric
) && !target
.equals(numeric
+bot
) && !target
.equalsIgnoreCase(C
.get_nick()+"@"+C
.get_host())) return;
79 CoreDBControl dbc
= C
.get_dbc();
80 User user
= dbc
.getUser(source
);
81 if(!C
.isDeveloper(user
.getAuth()))
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 if(cmds
.containsKey(cmd
))
110 Cmds ccommand
= (Cmds
) cmds
.get(cmd
);
111 ccommand
.parse_help(C
,bot
,source
);
115 C
.cmd_notice(bot
,source
,"This command is either unknown, or you need to be opered up to use it.");
119 if(command
.equals("showcommands"))
121 showCommands(source
);
124 if(command
.startsWith("\1"))
126 if(cmds
.containsKey(command
.replace("\1","")))
128 Cmds ccommand
= (Cmds
) cmds
.get(command
.replace("\1",""));
129 ccommand
.parse_command(C
,bot
,target
,source
,message
);
132 else if(cmds
.containsKey(command
))
134 Cmds ccommand
= (Cmds
) cmds
.get(command
);
135 ccommand
.parse_command(C
,bot
,target
,source
,message
);
139 C
.cmd_notice(bot
,source
,"This command is either unknown, or you need to be opered up to use it.");
140 C
.cmd_notice(bot
,source
,"/msg "+C
.get_nick()+" showcommands");
143 private void showCommands(String username
)
145 C
.cmd_notice(bot
,username
,"The following commands are available to you:");
146 C
.cmd_notice(bot
,username
,"For more information on a specific command, type HELP <command>:");
147 List
<String
> keys
= new ArrayList
<String
>(cmds
.keySet());
148 Collections
.sort(keys
);
149 //Set<String> keys = cmds.keySet();
150 for(String key
: keys
)
152 Cmds ccommand
= (Cmds
) cmds
.get(key
);
153 ccommand
.showcommand(C
,bot
,username
);
155 C
.cmd_notice(bot
,username
,"End of list.");