`bnc_action_by_hostmask` varchar(255) DEFAULT NULL COMMENT 'The hostmask of the user that performed the last action this BNC request.',\r
`bnc_action_time` timestamp NULL DEFAULT NULL COMMENT 'The last time an action was performed on this BNC request.',\r
`bnc_action_reason` text COMMENT 'An optional reason for why the action was performed. Usually used only if bnc_state > 1.',\r
+ `bnc_note` text COMMENT 'An optional note for user.',\r
`bnc_server_id` int(9) unsigned NOT NULL DEFAULT '1' COMMENT 'The ID of the server the user exists on.',\r
PRIMARY KEY (`bnc_user_id`),\r
KEY `bnc_server_id` (`bnc_server_id`),\r
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\r
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\r
\r
--- Dump completed on 2014-10-20 19:26:32
\ No newline at end of file
+-- Dump completed on 2014-10-20 19:26:32\r
\r
handlers.put(".bncinfo", new BncInfoCmd());\r
handlers.put(".bi", handlers.get(".bncinfo"));\r
+ handlers.put(".bncnote", new BncNoteCmd());\r
handlers.put(".bncfind", new BncFindCmd());\r
handlers.put(".bncuserstats", new BncStatsCmd());\r
handlers.put(".bncsearch", handlers.get(".bncfind"));\r
return true;\r
}\r
\r
+ public boolean setNote(UserEntry ue, String notingUser, String note) {\r
+ if (ue == null)\r
+ return false;\r
+\r
+ ue.setNote(notingUser, note);\r
+ if (note != null)\r
+ this.logEvent("BNC note for user '%s' (id %s) was added by %s: %s", ue.getNick(), ue.getId(), notingUser, note);\r
+ else\r
+ this.logEvent("BNC note for user '%s' (id %s) was deleted by %s", ue.getNick(), ue.getId(), notingUser);\r
+ this.saveData();\r
+\r
+ return true;\r
+ }\r
+\r
public boolean addBlacklist(String mask) throws IllegalArgumentException {\r
if (!mask.contains("!") || !mask.contains("@"))\r
throw new IllegalArgumentException("Invalid parameter: mask. Invalid hostmask.");\r
}\r
\r
public void saveData(boolean now) {\r
- String query = "REPLACE INTO `bncbot_users` VALUES (?,?,?,?,?,?,?,?,?,?);";\r
+ String query = "REPLACE INTO `bncbot_users` VALUES (?,?,?,?,?,?,?,?,?,?,?);";\r
String blQuery = "REPLACE INTO `bncbot_bl` VALUES (?,?);";\r
String bncLookupQuery = "SELECT `server_id`, `server_abbr` FROM `bncbot_bncs` ORDER BY `server_id` ASC;";\r
long saveStart = System.currentTimeMillis();\r
ps.setString(7, ue.getActionByHostmask());\r
ps.setTimestamp(8, (ue.getState() != UserEntry.UserState.NotProcessed) ? new Timestamp(ue.getActionTime().getTime()) : null);\r
ps.setString(9, ue.getActionReason());\r
- ps.setInt(10, bncLookupTable.get(ue.getBncServerAbbr().toLowerCase()));\r
+ ps.setString(10, ue.getNote());\r
+ ps.setInt(11, bncLookupTable.get(ue.getBncServerAbbr().toLowerCase()));\r
\r
ps.addBatch();\r
\r
private Date actionTime;\r
\r
private String actionReason;\r
+ private String note;\r
\r
private String bncServerAbbr;\r
\r
this.actionTime = null;\r
\r
this.actionReason = null;\r
+ this.note = null;\r
\r
this.bncServerAbbr = serverAbbr;\r
\r
return (this.state != UserState.NotProcessed && this.state != UserState.Approved) ? this.actionReason : null;\r
}\r
\r
+ public String getNote() {\r
+ return this.note;\r
+ }\r
+\r
public String getBncServerAbbr() {\r
return this.bncServerAbbr;\r
}\r
this.modified = true;\r
}\r
\r
+ private void setNote(String user, String note) {\r
+ if (note != null)\r
+ note = user.split("!")[0] + ": " + note;\r
+ this.note = note;\r
+\r
+ this.modified = true;\r
+ }\r
+\r
private boolean isModified() {\r
return this.modified;\r
}\r
ue.actionTime = (ue.getState() != UserState.NotProcessed) ? new Date(rs.getTimestamp("bnc_action_time").getTime()) : null;\r
\r
ue.actionReason = rs.getString("bnc_action_reason");\r
+ ue.note = rs.getString("bnc_note");\r
\r
ue.modified = false;\r
\r
bot.privmsg(bot.getAdminChannel(), bot.getString("adminInfo6Detached", connEvent.getEntryTime(),\r
Helpers.unixTimeToDaysSince(connEvent.getEntryTime().getTime()), connEvent.wasLastClient() ? " (all clients gone)" : ""));\r
}\r
+ if (ue.getNote() != null)\r
+ bot.privmsg(bot.getAdminChannel(), bot.getString("adminInfo7", ue.getNote()));\r
} else {\r
bot.privmsg(bot.getAdminChannel(), bot.getString("adminNoMatch"));\r
}\r
--- /dev/null
+package net.rizon.bncbot.commands;
+
+import net.rizon.bncbot.AbstractSimpleCommand;
+import net.rizon.bncbot.UserDB;
+
+public class BncNoteCmd extends AbstractSimpleCommand {
+ @Override
+ public boolean prepare(String line) {
+ super.prepare(line);
+
+ // We want the message to look like this:
+ // :nick!ident@host PRIVMSG #adminchan :command arg reason+++++
+ // 0 1 2 3 4 5..6..7....
+ return args[2].equalsIgnoreCase(bot.getAdminChannel()) && args.length >= 5;
+ }
+
+ @Override
+ public void run() {
+ String[] values = args[4].split(",");
+ String note;
+
+ if (args.length < 6)
+ note = null;
+ else
+ note = argsv[5];
+
+ for (String value : values) {
+ // Try as a nick.
+ UserDB.UserEntry ue = bot.database.findUser(value);
+ if (ue == null) {
+ // Try as a integer.
+ try {
+ int intValue = Integer.parseInt(value);
+ ue = bot.database.findUser(intValue);
+ } catch (NumberFormatException e) {
+ ue = null; // Oh well. :/
+ }
+ }
+ if (ue != null) {
+ bot.database.setNote(ue, args[0].substring(1), note);
+ if (note != null)
+ bot.privmsg(bot.getAdminChannel(), bot.getString("adminNoteSet"));
+ else
+ bot.privmsg(bot.getAdminChannel(), bot.getString("adminNoteDel"));
+ } else {
+ bot.privmsg(bot.getAdminChannel(), bot.getString("adminNoMatch"));
+ }
+ }
+ }
+
+}
adminSuspended = suspended\r
adminUnsuspended = unsuspended\r
adminMoved = moved\r
+adminNoteSet = Note has been set.\r
+adminNoteDel = Note has been deleted.\r
# Message template for an already processed request.\r
adminAlreadyProcessed = That application has already been processed.\r
adminAlreadyProcessedDetail = Application ID <%1$s> has already been processed.\r
adminInfo6Active = Last seen: currently attached\r
adminInfo6Detached = Last seen: detached at %1$s (%2$s days ago)%3$s\r
adminInfo6Never = Last seen: never\r
+adminInfo7 = Note by %1$s\r
# Search info line\r
adminQueryMatch = %1$s users matched your query string '%2$s':\r
# Real IP line\r