]>
Commit | Line | Data |
---|---|---|
431b229b LP |
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 | # MERCHANTABILITY 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, Boston, MA 02111-1307, USA. | |
22 | # | |
23 | */ | |
24 | import java.io.*; | |
25 | import java.util.*; | |
26 | import java.text.*; | |
27 | import java.util.regex.*; | |
28 | import borknet_services.core.*; | |
29 | ||
30 | /** | |
31 | * Class to load configuration files. | |
32 | * @author Ozafy - ozafy@borknet.org - http://www.borknet.org | |
33 | */ | |
34 | public class Chanflags implements Command | |
35 | { | |
36 | /** | |
37 | * Constructs a Loader | |
38 | * @param debug If we're running in debug. | |
39 | */ | |
40 | public Chanflags() | |
41 | { | |
42 | } | |
43 | ||
44 | public void parse_command(Core C, S Bot, String numeric, String botnum, String username, String params) | |
45 | { | |
46 | DBControl dbc = Bot.getDBC(); | |
47 | if(dbc.getUser(username).getOperator()) | |
48 | { | |
49 | String[] result = params.split("\\s"); | |
50 | try | |
51 | { | |
52 | //get some info from what the user asks | |
53 | String channel = result[1]; | |
54 | String flags = result[2]; | |
55 | if(flags.length() > 1) | |
56 | { | |
57 | C.cmd_notice(numeric, botnum, username, "You can only set one flag."); | |
58 | return; | |
59 | } | |
60 | //need to check they don't remove the a flag | |
61 | Pattern pat = Pattern.compile("[^din]"); | |
62 | Matcher m = pat.matcher(flags); | |
63 | StringBuffer sb = new StringBuffer(); | |
64 | boolean nok = m.find(); | |
65 | while(nok) | |
66 | { | |
67 | m.appendReplacement(sb, ""); | |
68 | nok = m.find(); | |
69 | } | |
70 | m.appendTail(sb); | |
71 | flags = sb.toString(); | |
72 | //he has access | |
73 | if(flags.length() < 1) | |
74 | { | |
75 | C.cmd_notice(numeric, botnum, username, "Invalid flag."); | |
76 | return; | |
77 | } | |
78 | if(dbc.setChanFlags(channel,flags)) | |
79 | { | |
80 | if(flags.equals("i")) | |
81 | { | |
82 | C.cmd_privmsg(numeric, botnum, channel, "Instagib is now enabled so please refrain from talking."); | |
83 | } | |
84 | else if(flags.equals("n")) | |
85 | { | |
86 | C.cmd_privmsg(numeric, botnum, channel, "Scanning normally."); | |
87 | } | |
88 | else if(flags.equals("d")) | |
89 | { | |
90 | C.cmd_privmsg(numeric, botnum, channel, "Deaf mode is now enabled, spam away!"); | |
91 | } | |
92 | C.cmd_notice(numeric, botnum, username, "Done."); | |
93 | } | |
94 | else | |
95 | { | |
96 | C.cmd_notice(numeric, botnum, username, "Can't find that channel!"); | |
97 | } | |
98 | return; | |
99 | } | |
100 | //he asked to see the flags, or asked nothing | |
101 | catch(ArrayIndexOutOfBoundsException e) | |
102 | { | |
103 | try | |
104 | { | |
105 | //get the channel | |
106 | String channel = result[1]; | |
107 | //check which channel | |
108 | String flags = dbc.getChanFlags(channel); | |
109 | if(flags.equals("0")) | |
110 | { | |
111 | C.cmd_notice(numeric, botnum, username, "Can't find that channel!"); | |
112 | return; | |
113 | } | |
114 | //it does, return the flags set | |
115 | else | |
116 | { | |
117 | C.cmd_notice(numeric, botnum, username, "Current channel flags are: +" + flags); | |
118 | return; | |
119 | } | |
120 | } | |
121 | //he asked nothing | |
122 | catch(ArrayIndexOutOfBoundsException f) | |
123 | { | |
124 | C.cmd_notice(numeric, botnum, username, "/msg " + Bot.get_nick() + " chanflags <#channel> [flag]"); | |
125 | C.cmd_notice(numeric, botnum, username, "Possible flags are:"); | |
126 | C.cmd_notice(numeric, botnum, username, "d: Deaf."); | |
127 | C.cmd_notice(numeric, botnum, username, "i: Instagib."); | |
128 | C.cmd_notice(numeric, botnum, username, "n: Normal."); | |
129 | return; | |
130 | } | |
131 | } | |
132 | } | |
133 | else | |
134 | { | |
135 | C.cmd_notice(numeric, botnum, username, "This command is either unknown, or you need to be opered up to use it."); | |
136 | return; | |
137 | } | |
138 | } | |
139 | ||
140 | public void parse_help(Core C, S Bot, String numeric, String botnum, String username, boolean operator) | |
141 | { | |
142 | if(operator) | |
143 | { | |
144 | C.cmd_notice(numeric, botnum, username, "/msg " + Bot.get_nick() + " chanflags <#channel> [flag]"); | |
145 | C.cmd_notice(numeric, botnum, username, "Possible flags are:"); | |
146 | C.cmd_notice(numeric, botnum, username, "d: Deaf."); | |
147 | C.cmd_notice(numeric, botnum, username, "i: Instagib."); | |
148 | C.cmd_notice(numeric, botnum, username, "n: Normal."); | |
149 | } | |
150 | else | |
151 | { | |
152 | C.cmd_notice(numeric, botnum, username, "This command is either unknown, or you need to be opered up to use it."); | |
153 | return; | |
154 | } | |
155 | } | |
156 | public void showcommand(Core C, S Bot, String numeric, String botnum, String username, boolean operator) | |
157 | { | |
158 | if(operator) | |
159 | { | |
160 | C.cmd_notice(numeric, botnum, username, "CHANFLAGS Will change/display a channel's flags."); | |
161 | } | |
162 | } | |
163 | } |