Browse Source

first commit

boozaa 1 year ago
commit
f815f68928
31 changed files with 874 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 178 0
      Repondeur-0.0.1/pom.xml
  3. 175 0
      Repondeur-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/repondeur/PendingMessage.java
  4. 223 0
      Repondeur-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/repondeur/RepondeurCommand.java
  5. 37 0
      Repondeur-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/repondeur/RepondeurListener.java
  6. 166 0
      Repondeur-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/repondeur/config/MessageConfig.java
  7. 81 0
      Repondeur-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/repondeur/crontasks/SendMessageTask.java
  8. BIN
      Repondeur-0.0.1/target/Repondeur-0.0.1-shaded.jar
  9. 8 0
      Repondeur-0.0.1/target/antrun/build-main.xml
  10. 0 0
      Repondeur-0.0.1/target/classes/.netbeans_automatic_build
  11. BIN
      Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/PendingMessage.class
  12. BIN
      Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/RepondeurCommand$1.class
  13. BIN
      Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/RepondeurCommand$ActionTo.class
  14. BIN
      Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/RepondeurCommand.class
  15. BIN
      Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/RepondeurListener.class
  16. BIN
      Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/config/MessageConfig.class
  17. BIN
      Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/crontasks/SendMessageTask.class
  18. BIN
      Repondeur-0.0.1/target/lib/BooCron-0.1.jar
  19. BIN
      Repondeur-0.0.1/target/lib/IrcBotX-1.0.jar
  20. BIN
      Repondeur-0.0.1/target/lib/YAMLConfiguration-1.0.jar
  21. BIN
      Repondeur-0.0.1/target/lib/commons-codec-1.10.jar
  22. BIN
      Repondeur-0.0.1/target/lib/commons-lang3-3.4.jar
  23. BIN
      Repondeur-0.0.1/target/lib/guava-19.0.jar
  24. BIN
      Repondeur-0.0.1/target/lib/log4j-1.2.17.jar
  25. BIN
      Repondeur-0.0.1/target/lib/pircbotx-2.0.1.jar
  26. BIN
      Repondeur-0.0.1/target/lib/slf4j-api-1.7.13.jar
  27. BIN
      Repondeur-0.0.1/target/lib/slf4j-log4j12-1.7.7.jar
  28. 5 0
      Repondeur-0.0.1/target/maven-archiver/pom.properties
  29. BIN
      Repondeur-0.0.1/target/original-Repondeur-0.0.1.jar
  30. 0 0
      Repondeur-0.0.1/target/test-classes/.netbeans_automatic_build
  31. BIN
      WaaBotBlankPluginGenerator.jar

+ 1 - 0
.gitignore

@ -0,0 +1 @@
1
AlphaPhase-0.0.1/

+ 178 - 0
Repondeur-0.0.1/pom.xml

@ -0,0 +1,178 @@
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <groupId>fr.waazaa.apps.irc.plugins.repondeur</groupId>
4
    <artifactId>Repondeur</artifactId>
5
    <version>0.0.1</version>
6
    <name>Repondeur</name>
7
    <repositories>
8
        <repository>
9
            <id>maven-central</id>
10
            <url>http://repo.maven.apache.org/maven2</url>
11
        </repository>
12
        <repository>
13
            <id>local-repo</id>
14
            <url>http://192.168.0.32:8080/repository</url>
15
        </repository>
16
    </repositories>
17
    <properties>
18
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19
    </properties>
20
    <build>
21
        <plugins>
22

													
23
            <!-- On nettoie le dossier de sortie des anciennes versions du jar -->
24
            <plugin>
25
                <groupId>org.apache.maven.plugins</groupId>
26
                <artifactId>maven-antrun-plugin</artifactId>
27
                <version>1.7</version>
28
                <executions>
29
                    <execution>
30
                        <phase>test</phase>
31
                        <goals>
32
                            <goal>run</goal>
33
                        </goals>
34
                        <configuration>
35
                            <target>
36
                                <delete>
37
                                    <fileset dir="D:\Workspace\WaaBot\IrcBotX\plugins\" includes="${project.artifactId}*.jar" />
38
                                </delete>
39
                            </target>
40
                        </configuration>
41
                    </execution>
42
                </executions>
43
            </plugin>
44

													
45
            <!-- On définie pour quelle version java on a normé -->
46
            <plugin>
47
                <groupId>org.apache.maven.plugins</groupId>
48
                <artifactId>maven-compiler-plugin</artifactId>
49
                <version>2.0.2</version>
50
                <configuration>
51
                    <source>1.5</source>
52
                    <target>1.5</target>
53
                </configuration>
54
            </plugin>
55

													
56
            <!-- On précise le dossier de sortie du jar compilé -->
57
            <plugin>
58
                <groupId>org.apache.maven.plugins</groupId>
59
                <artifactId>maven-jar-plugin</artifactId>
60
                <configuration>
61
                    <outputDirectory>D:\Workspace\WaaBot\IrcBotX\plugins\</outputDirectory>
62
                </configuration>
63
            </plugin>
64
            <!-- On précise qu'on veut charger les libs -->
65
            <plugin>
66
                <artifactId>maven-dependency-plugin</artifactId>
67
                <executions>
68
                    <execution>
69
                        <phase>install</phase>
70
                        <goals>
71
                            <goal>copy-dependencies</goal>
72
                        </goals>
73
                        <configuration>
74
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
75
                        </configuration>
76
                    </execution>
77
                </executions>
78
            </plugin>
79

													
80
            <!-- On inclut les dépendances -->
81
            <plugin>
82
                <groupId>org.apache.maven.plugins</groupId>
83
                <artifactId>maven-shade-plugin</artifactId>
84
                <executions>
85
                    <execution>
86
                        <phase>package</phase>
87
                        <goals>
88
                            <goal>shade</goal>
89
                        </goals>
90
                    </execution>
91
                </executions>
92
                <configuration>
93
                    <finalName>${project.artifactId}-${project.version}</finalName>
94
                </configuration>
95
            </plugin>
96

													
97
        </plugins>
98

													
99
        <resources>
100
            <resource>
101
                <directory>src/main/resources</directory>
102
            </resource>
103
        </resources>
104
    </build>
105

													
106
    <dependencies>
107
        <dependency>
108
            <groupId>fr.waazaa.apps.irc.botx</groupId>
109
            <artifactId>IrcBotX</artifactId>
110
            <version>1.0</version>
111
            <type>jar</type>
112
            <scope>provided</scope>
113
        </dependency>
114
        <dependency>
115
            <groupId>com.google.guava</groupId>
116
            <artifactId>guava</artifactId>
117
            <version>19.0</version>
118
            <type>jar</type>
119
            <scope>provided</scope>
120
        </dependency>
121
        <dependency>
122
            <groupId>log4j</groupId>
123
            <artifactId>log4j</artifactId>
124
            <version>1.2.17</version>
125
            <type>jar</type>
126
            <scope>provided</scope>
127
        </dependency>
128
        <dependency>
129
            <groupId>org.slf4j</groupId>
130
            <artifactId>slf4j-api</artifactId>
131
            <version>1.7.13</version>
132
            <type>jar</type>
133
            <scope>provided</scope>
134
        </dependency>
135
        <dependency>
136
            <groupId>org.slf4j</groupId>
137
            <artifactId>slf4j-log4j12</artifactId>
138
            <version>1.7.7</version>
139
            <type>jar</type>
140
            <scope>provided</scope>
141
        </dependency>
142
        <dependency>
143
            <groupId>commons-codec</groupId>
144
            <artifactId>commons-codec</artifactId>
145
            <version>1.10</version>
146
            <type>jar</type>
147
            <scope>provided</scope>
148
        </dependency>
149
        <dependency>
150
            <groupId>org.apache.commons</groupId>
151
            <artifactId>commons-lang3</artifactId>
152
            <version>3.4</version>
153
            <type>jar</type>
154
            <scope>provided</scope>
155
        </dependency>
156
        <dependency>
157
            <groupId>org.pircbotx</groupId>
158
            <artifactId>pircbotx</artifactId>
159
            <version>2.0.1</version>
160
            <type>jar</type>
161
            <scope>provided</scope>
162
        </dependency>
163
        <dependency>
164
            <groupId>org.shortrip.boozaa.libs.yamlconfiguration</groupId>
165
            <artifactId>YAMLConfiguration</artifactId>
166
            <version>1.0</version>
167
            <type>jar</type>
168
            <scope>provided</scope>
169
        </dependency>
170
        <dependency>
171
            <groupId>org.shortrip.boozaa.apps.BooCron</groupId>
172
            <artifactId>BooCron</artifactId>
173
            <version>0.1</version>
174
            <type>jar</type>
175
            <scope>provided</scope>
176
        </dependency>
177
    </dependencies>
178
</project>

+ 175 - 0
Repondeur-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/repondeur/PendingMessage.java

@ -0,0 +1,175 @@
1
package fr.waazaa.apps.irc.plugins.repondeur;
2

													
3

													
4
import java.text.SimpleDateFormat;
5
import java.util.Date;
6
import java.util.LinkedHashMap;
7
import java.util.Map;
8
import org.shortrip.boozaa.libs.yamlconfiguration.ConfigurationSerializable;
9
import org.shortrip.boozaa.libs.yamlconfiguration.ConfigurationSerialization;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

													
13

													
14
public class PendingMessage implements ConfigurationSerializable {
15
    
16
    private static final Logger LOGGER = LoggerFactory.getLogger(PendingMessage.class );
17
    private String type;
18
    private String target;
19
    private String author;
20
    private String message;
21
    private Long date;
22
    
23
    public PendingMessage(){
24
        ConfigurationSerialization.registerClass(PendingMessage.class);        
25
    }
26
    
27
    public PendingMessage( String type, String author, String target, String message ){
28
        
29
        this.type       = type;
30
        this.author     = author;
31
        this.target     = target;
32
        this.message    = message;
33
        this.date       = new Date().getTime();
34
        ConfigurationSerialization.registerClass(PendingMessage.class);
35
    }
36
    
37
    
38
    public PendingMessage( Map<String, Object> args ){        
39
        this.type       = (String) args.get("TYPE");
40
        this.author     = (String) args.get("AUTHOR");
41
        this.target     = (String) args.get("TARGET");
42
        this.message    = (String) args.get("MESSAGE");
43
        this.date       = (Long) args.get("DATE");
44
        ConfigurationSerialization.registerClass(PendingMessage.class);        
45
    }
46
    
47

													
48
    public String getDate() {
49
        return new SimpleDateFormat("dd.MM.YYYY HH:mm:ss")
50
        .format(
51
            new Date( this.date )
52
        );
53
    }
54
    
55
    public String getType() {
56
        return type;
57
    }
58

													
59
    public String getTarget() {
60
        return target;
61
    }
62

													
63
    public String getAuthor() {
64
        return author;
65
    }
66

													
67
    public String getMessage() {
68
        return message;
69
    }
70

													
71
    public void setType(String type) {
72
        this.type = type.toUpperCase();
73
    }
74

													
75
    public void setTarget(String target) {
76
        this.target = target;
77
    }
78

													
79
    public void setAuthor(String author) {
80
        this.author = author;
81
    }
82

													
83
    public void setMessage(String message) {
84
        this.message = message;
85
    }
86

													
87
    public void setDate() {        
88
        this.date = new Date().getTime();
89
    }
90

													
91
    
92
    
93
    @Override
94
    public int hashCode() {
95
        int hash = 5;
96
        hash = 43 * hash + (this.type != null ? this.type.hashCode() : 0);
97
        hash = 43 * hash + (this.target != null ? this.target.hashCode() : 0);
98
        hash = 43 * hash + (this.author != null ? this.author.hashCode() : 0);
99
        hash = 43 * hash + (this.message != null ? this.message.hashCode() : 0);
100
        hash = 43 * hash + (this.date != null ? this.date.hashCode() : 0);
101
        return hash;
102
    }
103

													
104
    @Override
105
    public boolean equals(Object obj) {
106
        if (this == obj) {
107
            return true;
108
        }
109
        if (obj == null) {
110
            return false;
111
        }
112
        if (getClass() != obj.getClass()) {
113
            return false;
114
        }
115
        final PendingMessage other = (PendingMessage) obj;
116
        if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
117
            return false;
118
        }
119
        if ((this.target == null) ? (other.target != null) : !this.target.equals(other.target)) {
120
            return false;
121
        }
122
        if ((this.author == null) ? (other.author != null) : !this.author.equals(other.author)) {
123
            return false;
124
        }
125
        if ((this.message == null) ? (other.message != null) : !this.message.equals(other.message)) {
126
            return false;
127
        }
128
        if (this.date != other.date && (this.date == null || !this.date.equals(other.date))) {
129
            return false;
130
        }
131
        return true;
132
    }
133

													
134
    @Override
135
    public String toString() {
136
        return "PendingMessage{" + "type=" + type + ", target=" + target + ", author=" + author + ", message=" + message + ", date=" + date + '}';
137
    }
138

													
139
    
140
    
141
    
142
    
143
    
144
    
145

													
146
    @Override
147
    public Map<String, Object> serialize() {
148
        
149
        LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
150
        result.put("TYPE",      this.type );
151
        result.put("AUTHOR",    this.author );
152
        result.put("TARGET",    this.target );
153
        result.put("MESSAGE",   this.message );
154
        result.put("DATE",      this.date );
155
        return result;
156
        
157
    }
158
    
159
    public PendingMessage deserialize(Map<String, Object> args){
160
        
161
        PendingMessage pMess    = new PendingMessage( args );
162
        pMess.date              = (Long) args.get("DATE");
163
        return pMess;
164
        
165
    }
166
    
167
    public PendingMessage valueOf(Map<String, Object> args){
168
        
169
        PendingMessage pMess    = new PendingMessage( args );
170
        pMess.date              = (Long) args.get("DATE");
171
        return pMess;
172
        
173
    }
174
    
175
}

+ 223 - 0
Repondeur-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/repondeur/RepondeurCommand.java

@ -0,0 +1,223 @@
1
package fr.waazaa.apps.irc.plugins.repondeur;
2

													
3
import fr.waazaa.apps.irc.botx.IrcBotX;
4
import fr.waazaa.apps.irc.botx.command.CommandPlugin;
5
import fr.waazaa.apps.irc.botx.command.CommandScopeEnum;
6
import fr.waazaa.apps.irc.botx.command.IrcCommand;
7
import fr.waazaa.apps.irc.botx.command.help.HelpLine;
8
import fr.waazaa.apps.irc.botx.command.help.HelpMessage;
9
import org.pircbotx.Colors;
10
import org.pircbotx.User;
11
import com.google.common.base.Preconditions;
12
import fr.waazaa.apps.irc.botx.users.UserManager;
13
import fr.waazaa.apps.irc.plugins.repondeur.config.MessageConfig;
14
import java.util.Set;
15
import org.pircbotx.hooks.WaitForQueue;
16
import org.pircbotx.hooks.events.PrivateMessageEvent;
17
import org.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
19

													
20

													
21
public class RepondeurCommand implements CommandPlugin {
22

													
23
    // Le LOGGER
24
    private static final Logger LOGGER = LoggerFactory.getLogger(RepondeurCommand.class );
25
    // Variable contenant la commande, exemple: !mycommand devient:
26
    private final String command = "repondeur";
27
    
28
    
29
    private ActionTo actionTo = ActionTo.START;
30

													
31
    // Retourne la commande
32
    public String getCommand() {
33
        return this.command;
34
    }
35

													
36
    // Retourne le noeud yml de permission
37
    public String getPermission() {
38
        return "repondeur";
39
    }
40

													
41
    // PRIVATE si la commande doit être lancée en mp autrement PUBLIC
42
    public CommandScopeEnum getScope() {
43
        return CommandScopeEnum.PRIVATE;
44
    }
45

													
46
    // L'aide qui sera retournée au User si il a le noeud yml de permission
47
    public HelpMessage getHelp() {
48
        HelpMessage helps   = new HelpMessage( this.command.toUpperCase() );
49
        HelpLine line       = new HelpLine(
50
            this.getPermission(),
51
            this.command,
52
            "Laisser des messages ou lire les votres"
53
        );
54
        helps.addLine(line);
55
        return helps;
56
    }
57

													
58
    // Votre logique d'execution, un User a lancé votre commande et a la bonne permission
59
    public void executeCommand(IrcCommand ircCommand) throws IllegalArgumentException {
60

													
61
        LOGGER.info( "Dans executeCommand() de RepondeurCommand" );
62

													
63
        IrcBotX botX            = ircCommand.botX;
64
        User user               = ircCommand.user;
65

													
66
        // On demande le destinataire
67
        this.askDestinataire(user);
68
        
69
        MessageConfig mConfig   = new MessageConfig();
70
        PendingMessage pMess    = new PendingMessage();
71
        
72
        WaitForQueue queue = new WaitForQueue( botX.getBot() );
73
        while (true) {
74
            
75
            try {
76

													
77
                PrivateMessageEvent currentEvent = queue.waitFor(PrivateMessageEvent.class);
78
                
79
                // On vérifie que ce PrivateMessageEvent vient bien du même User
80
                if( currentEvent.getUser().getNick().equalsIgnoreCase( user.getNick() ) ){
81
                    
82
                    final String message    = currentEvent.getMessage();
83
                    
84
                    switch( this.actionTo ){
85
                        
86
                        case ASK_TARGET:
87
                            
88
                            // Vérification saisie
89
                            Set<User> connectedUsers = UserManager.getAllConnectedUsers();
90
                            boolean targetIsEligible = true;
91
                            for( User u : connectedUsers ){
92
                                if( u.getNick().equalsIgnoreCase( message ) )
93
                                    targetIsEligible = false;
94
                            }
95
                            Preconditions.checkArgument( 
96
                                targetIsEligible,
97
                                "Le destinataire de ton message est connecté actuellement."
98
                                + " Je t'invite à le pm directement, merci."
99
                            );
100
                            
101
                            // Le destinataire n'est pas connecté alors on va stocker
102
                            pMess.setTarget( message );
103
                            pMess.setType( "message" );
104
                            pMess.setAuthor( user.getNick() );
105
                            pMess.setDate();
106
                            
107
                            this.askMessage(user);
108
                            
109
                            
110
                            break;
111
                            
112
                        case ASK_MESSAGE:
113
                            
114
                            pMess.setMessage(message);                            
115
                            // On stocke
116
                            mConfig.addMessageTo(pMess);
117
                            // On envoit message ok
118
                            this.sendSuccess(user);
119
                            
120
                            // On sort
121
                            this.actionTo = ActionTo.START;
122
                            queue.close();
123
                            return;
124
                              
125
                        default:
126
                            
127
                            break;
128
                        
129
                        
130
                    }
131
                    
132
                    
133
                    
134
                }
135

													
136

													
137

													
138

													
139
            } catch (IllegalArgumentException ex){
140
                user.send().message( 
141
                    Colors.BOLD + Colors.RED + ex.getMessage()
142
                );
143
            } catch (InterruptedException ex) {
144
                user.send().message( 
145
                    Colors.BOLD + Colors.RED + ex.getMessage()
146
                );
147
            }
148
            
149
        }
150
        
151
    }
152
    
153
    
154
    private void askDestinataire( User user ){
155
        
156
        this.actionTo = ActionTo.ASK_TARGET;
157
        user.send().message( 
158
            Colors.BOLD  + "A qui souhaites tu envoyer un message ?"
159
        );
160
        
161
    }
162
    
163
    
164
    private void askMessage( User user ){
165
        
166
        this.actionTo = ActionTo.ASK_MESSAGE;
167
        user.send().message( 
168
            Colors.BOLD  + "Quel message envoyer ?"
169
        );
170
        
171
    }
172
    
173
    private void sendSuccess( User user ){
174
        
175
        this.actionTo = ActionTo.ASK_MESSAGE;
176
        user.send().message( 
177
            Colors.DARK_GREEN  + "Message stocké avec succès. Il sera distribué "
178
            + "au destinataire quand il se connectera."
179
        );
180
        
181
    }
182
    
183
    
184
    private boolean isInteger(String s) {
185
        return isInteger(s,10);
186
    }
187

													
188
    private boolean isInteger(String s, int radix) {
189
        if(s.isEmpty()) return false;
190
        for(int i = 0; i < s.length(); i++) {
191
            if(i == 0 && s.charAt(i) == '-') {
192
                if(s.length() == 1) return false;
193
                else continue;
194
            }
195
            if(Character.digit(s.charAt(i),radix) < 0) return false;
196
        }
197
        return true;
198
    }
199
    
200
    
201
    
202
    public enum ActionTo {
203
    
204
        START("start"),        
205
        ASK_TARGET("ask_target"),        
206
        ASK_MESSAGE("ask_message");
207

													
208
        private String name = "";
209

													
210
        //Constructeur
211
        ActionTo(String name){
212
          this.name = name;
213
        }
214

													
215
        @Override
216
        public String toString(){
217
          return name;
218
        }
219

													
220
    }
221
    
222

													
223
}

+ 37 - 0
Repondeur-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/repondeur/RepondeurListener.java

@ -0,0 +1,37 @@
1
package fr.waazaa.apps.irc.plugins.repondeur;
2

													
3
import fr.waazaa.apps.irc.botx.IrcBotX;
4
import fr.waazaa.apps.irc.plugins.repondeur.crontasks.SendMessageTask;
5
import org.pircbotx.hooks.ListenerAdapter;
6
import org.pircbotx.hooks.events.JoinEvent;
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

													
10

													
11
public class RepondeurListener extends ListenerAdapter {
12
    
13
     // Le LOGGER
14
    private static final Logger LOGGER = LoggerFactory.getLogger(RepondeurListener.class );
15
    
16
    private boolean started = false;
17
    
18
    
19
    
20
    @Override
21
    public void onJoin(final JoinEvent event ) throws Exception {
22
        
23
        
24
        if( !this.started ){
25
            
26
            // On donne les CronTask
27
            IrcBotX.cron.addTask( new SendMessageTask() );
28
            LOGGER.info( "La tâche Cron d'envoi de PendingMessage est lancée." );
29
            
30
        }
31
        this.started = true;
32
        
33
        
34
    }
35
    
36
    
37
}

+ 166 - 0
Repondeur-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/repondeur/config/MessageConfig.java

@ -0,0 +1,166 @@
1
package fr.waazaa.apps.irc.plugins.repondeur.config;
2

													
3
import fr.waazaa.apps.irc.plugins.repondeur.PendingMessage;
4
import java.io.File;
5
import java.io.IOException;
6
import java.util.ArrayList;
7
import java.util.HashMap;
8
import java.util.HashSet;
9
import java.util.List;
10
import java.util.Map;
11
import java.util.Set;
12
import org.pircbotx.User;
13
import org.shortrip.boozaa.libs.yamlconfiguration.InvalidConfigurationException;
14
import org.shortrip.boozaa.libs.yamlconfiguration.serialization.YamlConfiguration;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

													
18

													
19
public class MessageConfig extends YamlConfiguration {
20
    
21
    private static final Logger LOGGER 	= LoggerFactory.getLogger( MessageConfig.class );    
22
    private final File source;
23
    
24
    
25
    private final String MESSAGE_TO = "messages.to";
26
    
27
    
28
    public MessageConfig(){
29
        String path = "plugins" + File.separator + "Repondeur" + File.separator;
30
        if( !new File( path  ).exists() )
31
            new File( path ).mkdirs();
32
            
33
        this.source = new File( path + File.separator + "messages.yml" );
34
        this.load();
35
    }
36
    
37
    
38
    public void load() {
39
        
40
        try {
41
            
42
            if( !this.exists() ){
43
                this.save();
44
            }
45

													
46
            this.load(this.source);
47
            
48
            
49
            
50
            
51
            this.save();
52
            
53
    
54
        } catch (IOException ex) {
55
            LOGGER.error( ex.getMessage() );
56
        } catch (InvalidConfigurationException ex) {
57
            LOGGER.error( ex.getMessage() );
58
        }
59
        
60
    }
61
    
62
    
63
    
64
    public void addMessageTo( PendingMessage pMess ){
65
        
66
        LOGGER.info( "addMessageTo pour target: " + pMess.getTarget() );
67
        
68
        if( !this.hasMessageTo(pMess) ){
69
            
70
            List<PendingMessage> list = (List<PendingMessage>) this.getList( 
71
                MESSAGE_TO + "." + pMess.getTarget()
72
            );
73
            if( null == list ){
74
                list = new ArrayList<PendingMessage>();
75
            }
76
            list.add(pMess);
77
            this.set( MESSAGE_TO + "." + pMess.getTarget(), list );
78
            this.save();
79
            
80
        }            
81
        
82
    }
83
        
84
    
85
    public List<PendingMessage> getMessagesFor( String target ){
86
        
87
        return (List<PendingMessage>) this.getList( 
88
            MESSAGE_TO + "." + target
89
        );
90
        
91
    }
92
    
93
    
94
    public List<PendingMessage> getMessagesFor( User target ){
95
        
96
        return (List<PendingMessage>) this.getList( 
97
            MESSAGE_TO + "." + target.getNick()
98
        );
99
        
100
    }
101
    
102
    
103
    public void removeMessageFor( PendingMessage pMess ){
104
        
105
        List<PendingMessage> list = (List<PendingMessage>) this.getList( 
106
            MESSAGE_TO + "." + pMess.getTarget()
107
        );
108
        list.remove(pMess);
109
        this.set( MESSAGE_TO + "." + pMess.getTarget(), list );
110
        
111
    }
112
    
113
    
114
    public void removeMessagesFor( String target ){
115
        
116
        this.set( MESSAGE_TO + "." + target, new ArrayList<PendingMessage>() );
117
        this.save();
118
        
119
    }
120
    
121
    
122
    public void removeMessagesFor( User target ){
123
        
124
        this.set( MESSAGE_TO + "." + target.getNick(), new ArrayList<PendingMessage>() );
125
        this.save();
126
        
127
    }
128
    
129
    
130
    private boolean hasMessageTo( PendingMessage pMess ){
131
        
132
        List<PendingMessage> list = (List<PendingMessage>) this.getList( 
133
            MESSAGE_TO + "." + pMess.getTarget()
134
        );
135
        if( null == list ){
136
            return false;
137
        }else{
138
            return list.contains( pMess ); 
139
        }
140
        
141
    }
142
    
143
    
144
    public Set<String> getKeys(String path) {
145
        try {
146
            return this.getConfigurationSection(path).getKeys(false);
147
        } catch (Exception ex) {
148
            return new HashSet<String>();
149
        }
150
    }
151
    
152
    
153
    public void save() {
154
        try {
155
            this.save(this.source);
156
        } catch (IOException ex) {
157
            LOGGER.error( ex.getMessage() );
158
        }
159
    }
160
    
161
    
162
    public boolean exists() {
163
        return this.source.exists();
164
    }
165
    
166
}

+ 81 - 0
Repondeur-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/repondeur/crontasks/SendMessageTask.java

@ -0,0 +1,81 @@
1
package fr.waazaa.apps.irc.plugins.repondeur.crontasks;
2

													
3
import fr.waazaa.apps.irc.botx.users.UserManager;
4
import fr.waazaa.apps.irc.plugins.repondeur.PendingMessage;
5
import fr.waazaa.apps.irc.plugins.repondeur.config.MessageConfig;
6
import it.sauronsoftware.cron4j.TaskExecutionContext;
7
import java.util.ArrayList;
8
import java.util.List;
9
import java.util.Set;
10
import org.pircbotx.Colors;
11
import org.pircbotx.User;
12
import org.shortrip.boozaa.apps.boocron.cron.CronTask;
13

													
14

													
15
public class SendMessageTask extends CronTask {
16
    
17
    public SendMessageTask() {
18
        super( "SendMessageTask", "*/1 * * * *" );
19
    }
20
    
21
    
22
    @Override
23
    public void execute(TaskExecutionContext tec) throws RuntimeException {
24
        
25
        // On récupère le MessageConfig
26
        MessageConfig mConfig = new MessageConfig();
27
        
28
        // On va boucler pour voir si un destinataire est co lui envoyer ses messages
29
        Set<User> users = UserManager.getAllConnectedUsers();
30
        
31
        List<PendingMessage> pMessSent = new ArrayList<PendingMessage>();
32
        
33
        for( User user : users ){
34
            
35
            List<PendingMessage> originalMessages = mConfig.getMessagesFor( user );            
36
            
37
            
38
            if( (null != originalMessages) && originalMessages.size() > 0 ){
39
                
40
                // Le user en questione est connecté, on lui envoit les messages
41
                for( PendingMessage pMess : originalMessages ){
42
                    
43
                    this.sendPendingMessageTo( pMess, user );
44
                    // On vire ce PendingMessage
45
                    pMessSent.add(pMess);
46
                    //mConfig.removeMessageFor(pMess);
47
                    
48
                }
49
                
50
            }
51
            
52
        }
53
            
54
        // Sauvegarde des suppressions/modifications
55
        for( PendingMessage pM : pMessSent ){
56
            mConfig.removeMessageFor(pM);
57
        }
58
        mConfig.save();
59
        
60
    }
61
    
62
    
63
    
64
    private void sendPendingMessageTo( PendingMessage message, User user ){
65
        
66
        user.send().message( 
67
            Colors.BROWN +
68
            "[" + message.getType() + "] " 
69
            + Colors.NORMAL + message.getAuthor() 
70
            + " -  " + Colors.DARK_GRAY + message.getDate()
71
        );
72
        user.send().message( 
73
            Colors.BOLD +
74
            message.getMessage()
75
        );
76
        
77
    }
78
    
79
    
80
    
81
}

BIN
Repondeur-0.0.1/target/Repondeur-0.0.1-shaded.jar


+ 8 - 0
Repondeur-0.0.1/target/antrun/build-main.xml

@ -0,0 +1,8 @@
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<project name="maven-antrun-" default="main"  >
3
<target name="main">
4
  <delete>
5
    <fileset includes="Repondeur*.jar" dir="D:\Workspace\WaaBot\IrcBotX\plugins\"/>
6
  </delete>
7
</target>
8
</project>

+ 0 - 0
Repondeur-0.0.1/target/classes/.netbeans_automatic_build


BIN
Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/PendingMessage.class


BIN
Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/RepondeurCommand$1.class


BIN
Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/RepondeurCommand$ActionTo.class


BIN
Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/RepondeurCommand.class


BIN
Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/RepondeurListener.class


BIN
Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/config/MessageConfig.class


BIN
Repondeur-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/repondeur/crontasks/SendMessageTask.class


BIN
Repondeur-0.0.1/target/lib/BooCron-0.1.jar


BIN
Repondeur-0.0.1/target/lib/IrcBotX-1.0.jar


BIN
Repondeur-0.0.1/target/lib/YAMLConfiguration-1.0.jar


BIN
Repondeur-0.0.1/target/lib/commons-codec-1.10.jar


BIN
Repondeur-0.0.1/target/lib/commons-lang3-3.4.jar


BIN
Repondeur-0.0.1/target/lib/guava-19.0.jar


BIN
Repondeur-0.0.1/target/lib/log4j-1.2.17.jar


BIN
Repondeur-0.0.1/target/lib/pircbotx-2.0.1.jar


BIN
Repondeur-0.0.1/target/lib/slf4j-api-1.7.13.jar


BIN
Repondeur-0.0.1/target/lib/slf4j-log4j12-1.7.7.jar


+ 5 - 0
Repondeur-0.0.1/target/maven-archiver/pom.properties

@ -0,0 +1,5 @@
1
#Generated by Maven
2
#Thu Apr 11 13:43:23 CEST 2019
3
version=0.0.1
4
groupId=fr.waazaa.apps.irc.plugins.repondeur
5
artifactId=Repondeur

BIN
Repondeur-0.0.1/target/original-Repondeur-0.0.1.jar


+ 0 - 0
Repondeur-0.0.1/target/test-classes/.netbeans_automatic_build


BIN
WaaBotBlankPluginGenerator.jar