]> jfr.im git - irc/borknet/trunk.git/blame - core/modules/q/Settopic.java
git-svn-id: https://svn.code.sf.net/p/borknet-dev-com/code/borknet_services/trunk...
[irc/borknet/trunk.git] / core / modules / q / Settopic.java
CommitLineData
b1d4498c 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# MERCHANTABILITY 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, Boston, MA 02111-1307, USA.\r
22#\r
b1d4498c 23*/\r
24import java.io.*;\r
25import java.util.*;\r
26import java.text.*;\r
27import java.util.regex.*;\r
28import borknet_services.core.*;\r
29\r
30/**\r
31 * Class to load configuration files.\r
32 * @author Ozafy - ozafy@borknet.org - http://www.borknet.org\r
33 */\r
34public class Settopic implements Command\r
35{\r
36 /**\r
37 * Constructs a Loader\r
38 * @param debug If we're running in debug.\r
39 */\r
40 public Settopic()\r
41 {\r
42 }\r
43\r
44 public void parse_command(Core C, Q Bot, DBControl dbc, String numeric, String botnum, String target, String username, String params)\r
45 {\r
46 String[] result = params.split("\\s");\r
47 try\r
48 {\r
49 //get the channel\r
8263f119 50 String chan = result[1];\r
b1d4498c 51 // xD\r
8263f119 52 if(!chan.startsWith("#")) throw new ArrayIndexOutOfBoundsException();\r
b1d4498c 53 //temp topic\r
54 String topic = "";\r
55 //get the channel\r
8263f119 56 String channel[] = dbc.getChanRow(chan);\r
57 if(channel[0].equals("0"))\r
b1d4498c 58 {\r
59 C.cmd_notice(numeric, botnum, username, "Can't find that channel!");\r
60 return;\r
61 }\r
62 //it does\r
63 else\r
64 {\r
65 String user[] = dbc.getUserRow(username);\r
66 //get access string\r
8263f119 67 String acc = get_access(user[4], chan,dbc);\r
b19c02f5 68 if(acc.contains("t") || acc.contains("n") || acc.contains("m") || user[5].equals("1"))\r
b1d4498c 69 {\r
70 //we have to set a new topic\r
71 if(result.length>2)\r
72 {\r
73 for(int p=2;p<result.length;p++)\r
74 {\r
75 topic += result[p] + " ";\r
76 }\r
8263f119 77 if(topic.trim().length() > 250)\r
78 {\r
79 topic = topic.substring(0,250);\r
80 }\r
81 //save it\r
82 dbc.setChanField(chan,4,topic);\r
b1d4498c 83 }\r
8263f119 84 //we have to reset the stored topic\r
b1d4498c 85 else\r
86 {\r
8263f119 87 topic = channel[4];\r
b1d4498c 88 }\r
8263f119 89 C.cmd_topic(numeric, botnum, chan, topic);\r
b1d4498c 90 C.cmd_notice(numeric, botnum, username, "Done.");\r
91 return;\r
92 }\r
93 //no access\r
94 else\r
95 {\r
96 C.cmd_notice(numeric, botnum, username, "You don't have +t flag on that channel.");\r
97 }\r
98 return;\r
99 }\r
100 }\r
101 catch(ArrayIndexOutOfBoundsException e)\r
102 {\r
103 C.cmd_notice(numeric, botnum, username, "/msg " + Bot.get_nick() + " settopic <#channel> [topic]");\r
104 return;\r
105 }\r
106 }\r
107\r
108 public void parse_help(Core C, Q Bot, String numeric, String botnum, String username, int lev)\r
109 {\r
110 if(lev > 0)\r
111 {\r
112 C.cmd_notice(numeric, botnum, username, "/msg " + Bot.get_nick() + " settopic <#channel> [topic]");\r
8263f119 113 C.cmd_notice(numeric, botnum, username, "Sets the topic on a channel. If no topic is set, the stored topic will be reset.");\r
b1d4498c 114 C.cmd_notice(numeric, botnum, username, "eg: /msg " + Bot.get_nick() + " settopic #BorkNet Welcome to the BorkNet channel.");\r
115 }\r
116 else\r
117 {\r
118 C.cmd_notice(numeric, botnum, username, "This command is either unknown, or you need to be opered up to use it.");\r
119 }\r
120 }\r
121 public void showcommand(Core C, Q Bot, String numeric, String botnum, String username, int lev)\r
122 {\r
123 if(lev > 0)\r
124 {\r
cb67c259 125 C.cmd_notice(numeric, botnum, username, "SETTOPIC Sets the topic on a channel.");\r
b1d4498c 126 }\r
127 }\r
128\r
129 /**\r
130 * Get an authnick's access on a channel\r
131 * @param nick user's authnick\r
132 * @param chan channel to get access from\r
133 *\r
134 * @return the user's access flags\r
135 */\r
136 public String get_access(String nick , String chan, DBControl dbc)\r
137 {\r
138 String access[] = dbc.getAccRow(nick, chan);\r
139 return access[2];\r
140 }\r
141}