]> jfr.im git - irc/rizon/bncbot.git/commitdiff
Add staff note origin/milos/bncrecheck
authorMilos <redacted>
Sat, 24 Oct 2015 12:54:22 +0000 (14:54 +0200)
committerMilos <redacted>
Thu, 12 Nov 2015 14:16:12 +0000 (15:16 +0100)
database.sql
src/net/rizon/bncbot/CommandManager.java
src/net/rizon/bncbot/UserDB.java
src/net/rizon/bncbot/commands/BncInfoCmd.java
src/net/rizon/bncbot/commands/BncNoteCmd.java [new file with mode: 0644]
strings.en.properties

index 5a2fe7e139ddb43d2f347bfeb0988e6e9567dddd..7f187f6506ce97e81de2c3804b45fb458e23c231 100644 (file)
@@ -197,6 +197,7 @@ CREATE TABLE `bncbot_users` (
   `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
@@ -251,4 +252,4 @@ CREATE TABLE `bncbot_users` (
 /*!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
index 66a63e830d8e7da2fecfef8b43be504b18639d54..eccf03177840269adf2f5f2af63122858c627b85 100644 (file)
@@ -43,6 +43,7 @@ public final class CommandManager {
 \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
index 0043b1231df08417a2e1bfcce91c82e7ccfee508..6a53e5bdfdff08ebc8c11ae67b4a42ea915b1dd0 100644 (file)
@@ -199,6 +199,20 @@ public final class UserDB implements Iterable<UserDB.UserEntry> {
                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
@@ -438,7 +452,7 @@ public final class UserDB implements Iterable<UserDB.UserEntry> {
        }\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
@@ -472,7 +486,8 @@ public final class UserDB implements Iterable<UserDB.UserEntry> {
                                                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
@@ -624,6 +639,7 @@ public final class UserDB implements Iterable<UserDB.UserEntry> {
                private Date actionTime;\r
 \r
                private String actionReason;\r
+               private String note;\r
 \r
                private String bncServerAbbr;\r
 \r
@@ -643,6 +659,7 @@ public final class UserDB implements Iterable<UserDB.UserEntry> {
                        this.actionTime = null;\r
 \r
                        this.actionReason = null;\r
+                       this.note = null;\r
 \r
                        this.bncServerAbbr = serverAbbr;\r
 \r
@@ -689,6 +706,10 @@ public final class UserDB implements Iterable<UserDB.UserEntry> {
                        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
@@ -736,6 +757,14 @@ public final class UserDB implements Iterable<UserDB.UserEntry> {
                        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
@@ -754,6 +783,7 @@ public final class UserDB implements Iterable<UserDB.UserEntry> {
                                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
index 4b62063f0250bb9681d3ac990a1add80f77e1abf..7d96d8f4977e9ceb40685fe53d8fe324413c62af 100644 (file)
@@ -71,6 +71,8 @@ public class BncInfoCmd extends AbstractSimpleCommand {
                                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
diff --git a/src/net/rizon/bncbot/commands/BncNoteCmd.java b/src/net/rizon/bncbot/commands/BncNoteCmd.java
new file mode 100644 (file)
index 0000000..9b666d6
--- /dev/null
@@ -0,0 +1,51 @@
+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"));
+            }
+        }
+    }
+
+}
index 83c51a6c4dd119cbeab4c195ce62210ca6cb3b90..03a9f821698baa3783b93a11665ded7af280d5ab 100644 (file)
@@ -79,6 +79,8 @@ adminDeleted = deleted
 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
@@ -106,6 +108,7 @@ adminInfo5None = Last action: none
 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