try
{
if (command.equals("getfaq"))
{
String name = arguments.trim();
FaqData faq_data = database_faq.getFaq(bot, name);
if (faq_data != null)
{
bot.send(new Privmsg(nick, faq_data.getName()+": "+(faq_data.isRandom() ? "random" : "not random")+": "+faq_data.getAnswer()));
}
else
{
bot.send(new Privmsg(nick, "Faq '"+name+"' couldn't be found."));
}
}
else if (command.equals("randfaq"))
{
FaqData faq_data = database_faq.getRandomFaq(bot);
if (faq_data != null)
{
bot.send(new Privmsg(nick, faq_data.getName()+": "+faq_data.getAnswer()));
}
else
{
bot.send(new Privmsg(nick, "No random faq could be found."));
}
}
else if (command.equals("randfaqon"))
{
String name = arguments.trim();
if (database_faq.setRandom(bot, name, true))
{
bot.send(new Privmsg(nick, "Random retrieval has been enabled for faq '"+name+"'."));
}
else
{
bot.send(new Privmsg(nick, "Faq '"+name+"' couldn't be found."));
}
}
else if (command.equals("randfaqoff"))
{
String name = arguments.trim();
if (database_faq.setRandom(bot, name, false))
{
bot.send(new Privmsg(nick, "Random retrieval has been disabled for faq '"+name+"'."));
}
else
{
bot.send(new Privmsg(nick, "Faq '"+name+"' couldn't be found."));
}
}
else if (command.equals("addfaq"))
{
int first_colon_index = arguments.indexOf(":");
if (-1 == first_colon_index)
{
bot.send(new Privmsg(nick, "Invalid syntax '!"+command+" "+arguments+"'"));
return;
}
else
{
int second_colon_index = arguments.indexOf(":", first_colon_index+1);
String name = null;
String answer = null;
boolean random = false;
if (second_colon_index != -1)
{
String random_string = arguments.substring(first_colon_index+1, second_colon_index).trim();
if (1 == random_string.length())
{
if ('1' == random_string.charAt(0))
{
random = true;
answer = arguments.substring(second_colon_index+1).trim();
}
else if ('0' == random_string.charAt(0))
{
random = false;
answer = arguments.substring(second_colon_index+1).trim();
}
else
{
bot.send(new Privmsg(nick, "Invalid syntax '!"+command+" "+arguments+"'"));
return;
}
}
}
name = arguments.substring(0, first_colon_index).trim();
if (null == answer)
{
answer = arguments.substring(first_colon_index+1).trim();
}
try
{
FaqData faq_data = new FaqData(name, answer);
faq_data.setRandom(random);
database_faq.addFaq(bot, faq_data);
bot.send(new Privmsg(nick, "Added faq '"+name+"'"));
}
catch (FaqManagerException e)
{
try
{
if (database_faq.getFaq(bot, name) != null)
{
bot.send(new Privmsg(nick, "Faq '"+name+"' already exists, delete it first to update it."));
}
}
catch (FaqManagerException e2)
{
e.fillInStackTrace();
throw e;
}
}
}
}
else if (command.equals("delfaq"))
{
String name = arguments.trim();
if (database_faq.removeFaq(bot, arguments))
{
bot.send(new Privmsg(nick, "Removed faq '"+name+"'"));
}
else
{
bot.send(new Privmsg(nick, "Faq '"+name+"' couldn't be found."));
}
}
else if (command.equals("editfaq"))
{
int first_colon_index = arguments.indexOf(":");
if (-1 == first_colon_index)
{
bot.send(new Privmsg(nick, "Invalid syntax '!"+command+" "+arguments+"'"));
return;
}
else
{
String name = null;
String answer = null;
name = arguments.substring(0, first_colon_index).trim();
answer = arguments.substring(first_colon_index+1).trim();
FaqData faq_data = database_faq.getFaq(bot, name);
if (null == faq_data)
{
bot.send(new Privmsg(nick, "Faq '"+name+"' doesn't exist."));
}
else
{
faq_data.setName(name);
faq_data.setAnswer(answer);
if (database_faq.editFaq(faq_data))
{
bot.send(new Privmsg(nick, "Edited faq '"+name+"'"));
}
else