Hello,
I am using PircBotX to create a irc bot, but I am having an issue creating a dynamic command system. I am using MySQL to store information into a database, and it works fine. I also have no problem reading from the database so please do not even consider that it is the database.
public void onMessage(MessageEvent<PircBotX> event) throws Exception { String[] args = event.getMessage().split(" "); if(event.getMessage().startsWith("!peacebot command add")) { MySQL mysql = new MySQL(); mysql.connect("127.0.0.1", "root", "", "peacebot"); mysql.Query("INSERT INTO `peacebot`.`peacebot_command` (`command_id`, `command_channel`, `command_trigger`, `command_message`) VALUES (NULL, '" + event.getChannel().getName().replace("#", "") + "', '" + args[3] + "', '" + event.getMessage().substring(22).replaceAll(args[3], "") + "');"); mysql.disconnect(); /**for(int i = 0; i < args.length; i++) { List<String> list = new ArrayList<String>(); for (String s : args) { list.add(s); } System.out.println(list); Iterator<String> itr = list.iterator(); while(itr.hasNext()){ System.out.println(itr.next()); } }**/ } }
I already know what the problem is, but I do not know how to fix it. The problem is that the argument[3] has a space in it, but it will not erase the space no matter what I do.
Example:
1399576848536 <<<:mretech!mretech@mretech.tmi.twitch.tv PRIVMSG #mretech :!peacebot command add !test test 1399576850794 <<<:mretech!mretech@mretech.tmi.twitch.tv PRIVMSG #mretech :!test 1399576850818 >>>PRIVMSG #mretech : test