Commits

Fuco committed d989a6d

+ Added removeUser method for user dao
+ Added merge admin command
- Removed description from youtube videos

Comments (0)

Files changed (5)

src/cz/dasnet/dasik/Dasik.java

 package cz.dasnet.dasik;
 
 import cz.dasnet.dasik.dao.LearnDaoImpl;
+import java.io.UnsupportedEncodingException;
 import java.util.Set;
 import cz.dasnet.dasik.dao.UserDao;
 import org.springframework.jdbc.datasource.DriverManagerDataSource;
         log.info("Bot created");
     }
 
-    public static void main(String[] args) throws ConfigException {
+    public static void main(String[] args) throws ConfigException, UnsupportedEncodingException {
         Dasik bot = new Dasik();
 
         bot.setName(bot.getConfig().getProperty("irc.name", "DASik"));
         bot.setLogin(bot.getConfig().getProperty("irc.name", "DASik"));
         bot.setFinger(bot.getConfig().getProperty("irc.name", "DASik"));
         bot.setAutoNickChange(true);
-        //bot.setVerbose(true);
+        bot.setVerbose(true);
+        bot.setEncoding("UTF-8");
 
         try {
+            //bot.startIdentServer();
             bot.connect(bot.getConfig().getProperty("irc.server", "irc.quakenet.org"),
                     bot.getConfig().getPropertyInt("irc.port", 6667));
         } catch (IrcException ex) {

src/cz/dasnet/dasik/dao/UserDao.java

 
     void updateUser(User user);
 
+    void removeUser(User user);
+
     int getUserCount();
 
     void invalidateUser(String mask);

src/cz/dasnet/dasik/dao/UserDaoImpl.java

         update(sql, userParameters);
         invalidateUser(user.getMask());
     }
+
+    public void removeUser(User user) {
+        String sql = "DELETE FROM users WHERE id = ?";
+        update(sql, user.getId());
+        invalidateUser(user.getMask());
+    }
 }

src/cz/dasnet/dasik/plugin/AdminCommand.java

  */
 package cz.dasnet.dasik.plugin;
 
+import java.util.List;
 import cz.dasnet.dasik.Dasik;
 import cz.dasnet.dasik.config.ConfigException;
 import cz.dasnet.dasik.entities.User;
 import org.apache.log4j.Logger;
+import static cz.dasnet.dasik.util.CollectionUtils.newArrayList;
 
 /**
  * Class implementing basic admin commands like join/part/quit and so on.
                 User u = bot.getUserDao().find(mask);
                 if (u == null) {
                     bot.send(channel, "User not found");
+                    return;
                 }
 
-                bot.send(channel, "User " + u.getMask() + ": Access: " + u.getAccess());
+                String nick = bot.maskToNick(mask) != null ? " (" + bot.maskToNick(mask) + ")" : "";
+                bot.send(channel, "[User " + u.getMask() + nick + "] Access: " + u.getAccess()
+                        + " | Total words: " + u.getWords() + " | Today's words: " + u.getWordsDaily());
+            } else if ("merge".equals(command) && token.length >= 3) {
+                String mask = bot.nickToMask(token[1]);
+                if (mask == null) {
+                    mask = token[1];
+                }
+
+                User u = bot.getUserDao().find(mask);
+                if (u == null) {
+                    bot.send(channel, "User " + mask + " not found");
+                    return;
+                }
+
+                List<User> users = newArrayList();
+                for (int i = 2; i < token.length; i++) {
+                    String mmask = bot.nickToMask(token[i]);
+                    if (mmask == null) {
+                        mmask = token[i];
+                    }
+                    User uu = bot.getUserDao().find(mmask);
+                    if (uu != null) {
+                        users.add(uu);
+                    }
+                }
+
+                for (User uu : users) {
+                    u.incWords(uu.getWords());
+                    u.setWordsDaily(Math.max(u.getWordsDaily(), uu.getWordsDaily()));
+                    u.setAccess(Math.max(u.getAccess(), uu.getAccess()));
+                }
+
+                for (User uu : users) {
+                    bot.getUserDao().removeUser(uu);
+                }
+
+                bot.getUserDao().updateUser(u);
+                String nick = bot.maskToNick(mask) != null ? " (" + bot.maskToNick(mask) + ")" : "";
+                bot.send(channel, "*** The merging is complete ***");
+                bot.send(channel, "[User " + u.getMask() + nick + "] Access: " + u.getAccess()
+                        + " | Total words: " + u.getWords() + " | Today's words: " + u.getWordsDaily());
             }
         }
     }

src/cz/dasnet/dasik/plugin/URLInfo.java

                 bot.send(channel, "Title: " + shorten(title, 200) + " [" + addMagSeparator(views, ",")
                         + " views; Rating: " + addMagSeparator(likes, ",") + "/"
                         + addMagSeparator(dislikes, ",") + "; Length: " + toMS(dur) + "]");
-                bot.send(channel, "Description: " + shorten(desc, 300));
+                //bot.send(channel, "Description: " + shorten(desc, 300));
             } catch (DocumentException ex) {
             } catch (MalformedURLException ex) {
             }