1. Fuco
  2. DASik

Commits

Fuco  committed e118705

+ added reconnect handler
* fixed unix startup script

  • Participants
  • Parent commits a30e0c5
  • Branches default

Comments (0)

Files changed (7)

File dasik.sh

View file
  • Ignore whitespace
 #!/bin/bash
 
 cp="lib/log4j-1.2.16.jar"
-cp="${cp};lib/dom4j-2.0.0-ALPHA-2.jar"
-cp="${cp};lib/jaxen-1.1.3.jar"
-cp="${cp};lib/pircbot.jar"
-cp="${cp};lib/mysql-connector-java-5.1.6-bin.jar"
-cp="${cp};lib/org.springframework.transaction-3.1.0.M1.jar"
-cp="${cp};lib/org.springframework.jdbc-3.1.0.M1.jar"
-cp="${cp};lib/org.springframework.core-3.1.0.M1.jar"
-cp="${cp};lib/org.springframework.beans-3.1.0.M1.jar"
-cp="${cp};lib/commons-logging-1.1.1.jar"
-cp="${cp};lib/groovy-all-1.8.0.jar"
-cp="${cp};build/classes"
+cp="${cp}:lib/dom4j-2.0.0-ALPHA-2.jar"
+cp="${cp}:lib/jaxen-1.1.3.jar"
+cp="${cp}:lib/pircbot.jar"
+cp="${cp}:lib/mysql-connector-java-5.1.6-bin.jar"
+cp="${cp}:lib/org.springframework.transaction-3.1.0.M1.jar"
+cp="${cp}:lib/org.springframework.jdbc-3.1.0.M1.jar"
+cp="${cp}:lib/org.springframework.core-3.1.0.M1.jar"
+cp="${cp}:lib/org.springframework.beans-3.1.0.M1.jar"
+cp="${cp}:lib/commons-logging-1.1.1.jar"
+cp="${cp}:lib/groovy-all-1.8.0.jar"
+cp="${cp}:build/classes"
 
 java -cp $cp -Djava.security.manager -Djava.security.policy=dasik.policy cz.dasnet.dasik.Dasik

File src/cz/dasnet/dasik/Dasik.java

View file
  • Ignore whitespace
         }
     }
 
+    @Override
+    public void onDisconnect() {
+        while (!isConnected()) {
+            try {
+                Thread.sleep(10000);
+                reconnect();
+            } catch (Exception ex) {
+                log.error("An error occured while reconnecting", ex);
+            }
+        }
+    }
+
     private void auth() {
         String target = config.getProperty("irc.auth.service");
         String msg = config.getProperty("irc.auth.message");

File src/cz/dasnet/dasik/dao/LearnDaoImpl.java

View file
  • Ignore whitespace
             Learn l = queryForObject(sql, learnRowMapper, trigger, type);
             return l;
         } catch (DataAccessException ex) {
-            log.error("Learn with trigger " + trigger + " of type " + type + " not found", ex);
+            //log.error("Learn with trigger " + trigger + " of type " + type + " not found", ex);
             return null;
         }
     }
             List<Learn> l = query(sql, learnRowMapper, trigger + "%", type);
             return l;
         } catch (DataAccessException ex) {
-            log.error("Learn with trigger " + trigger + " of type " + type + " not found", ex);
+            //log.error("Learn with trigger " + trigger + " of type " + type + " not found", ex);
             return null;
         }
     }

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

View file
  • Ignore whitespace
             cacheUser(u);
             return u;
         } catch (DataAccessException ex) {
-            log.error("User with id " + id + " not found", ex);
+            //log.error("User with id " + id + " not found", ex);
             return null;
         }
     }
             cacheUser(u);
             return u;
         } catch (DataAccessException ex) {
-            log.error("User with mask " + mask + " not found", ex);
+            //log.error("User with mask " + mask + " not found", ex);
             return null;
         }
     }

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

View file
  • Ignore whitespace
 
 import cz.dasnet.dasik.Dasik;
 import cz.dasnet.dasik.config.ConfigException;
+import cz.dasnet.dasik.entities.User;
 import org.apache.log4j.Logger;
 
 /**
                 }
             } else if ("auth".equals(command)) {
                 bot.send(channel, bot.nickToAuth(token[1]));
+            } else if ("whois".equals(command) && token.length >= 2) {
+                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 not found");
+                }
+
+                bot.send(channel, "User " + u.getMask() + ": Access: " + u.getAccess());
             }
         }
     }

File src/cz/dasnet/dasik/plugin/LearnPlugin.java

View file
  • Ignore whitespace
 import cz.dasnet.dasik.Dasik;
 import cz.dasnet.dasik.entities.Learn;
 import cz.dasnet.dasik.entities.User;
+import java.security.AccessControlException;
 import java.util.List;
 import org.apache.log4j.Logger;
 import static cz.dasnet.dasik.util.StringUtils.longestCommonPrefix;
             try {
                 value = shell.evaluate(source);
             } catch (CompilationFailedException ex) {
+                value = ex.getClass().getName() + ": " + ex.getMessage().replaceAll("\\s+", " ");
                 log.error("Learn trigger compilation failed", ex);
+            } catch (AccessControlException ex) {
+                value = ex.getClass().getName() + ": " + ex.getMessage().replaceAll("\\s+", " ");
+                log.error("Access denied", ex);
             }
 
             return value.toString();

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

View file
  • Ignore whitespace
                 String dislikes = ratingNode.valueOf("@numDislikes");
                 String dur = durNode.valueOf("@seconds");
 
-                bot.describe(channel, "Title: " + shorten(title, 200) + " [" + addMagSeparator(views, ",")
+                bot.send(channel, "Title: " + shorten(title, 200) + " [" + addMagSeparator(views, ",")
                         + " views; Rating: " + addMagSeparator(likes, ",") + "/"
                         + addMagSeparator(dislikes, ",") + "; Length: " + toMS(dur) + "]");
-                bot.describe(channel, "Description: " + shorten(desc, 300));
+                bot.send(channel, "Description: " + shorten(desc, 300));
             } catch (DocumentException ex) {
             } catch (MalformedURLException ex) {
             }