boozaa 1 year ago
parent
commit
63339d33a3
32 changed files with 980 additions and 0 deletions
  1. 178 0
      AlphaPhase-0.0.1/pom.xml
  2. 132 0
      AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/BugReportCommand.java
  3. 66 0
      AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/MyListener.java
  4. 82 0
      AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/SendMessagesTask.java
  5. 92 0
      AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/UserRoleChangeTask.java
  6. 112 0
      AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/config/AlphaPhaseConfiguration.java
  7. 158 0
      AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/config/MessagesToSendConfiguration.java
  8. 146 0
      AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/messages/PendingMessage.java
  9. BIN
      AlphaPhase-0.0.1/target/AlphaPhase-0.0.1-shaded.jar
  10. 8 0
      AlphaPhase-0.0.1/target/antrun/build-main.xml
  11. 0 0
      AlphaPhase-0.0.1/target/classes/.netbeans_automatic_build
  12. BIN
      AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/BugReportCommand.class
  13. BIN
      AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/MyListener.class
  14. BIN
      AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/SendMessagesTask.class
  15. BIN
      AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/UserRoleChangeTask.class
  16. BIN
      AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/config/AlphaPhaseConfiguration.class
  17. BIN
      AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/config/MessagesToSendConfiguration.class
  18. BIN
      AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/messages/PendingMessage.class
  19. BIN
      AlphaPhase-0.0.1/target/lib/BooCron-0.1.jar
  20. BIN
      AlphaPhase-0.0.1/target/lib/IrcBotX-1.0.jar
  21. BIN
      AlphaPhase-0.0.1/target/lib/YAMLConfiguration-1.0.jar
  22. BIN
      AlphaPhase-0.0.1/target/lib/commons-codec-1.10.jar
  23. BIN
      AlphaPhase-0.0.1/target/lib/commons-lang3-3.4.jar
  24. BIN
      AlphaPhase-0.0.1/target/lib/guava-19.0.jar
  25. BIN
      AlphaPhase-0.0.1/target/lib/log4j-1.2.17.jar
  26. BIN
      AlphaPhase-0.0.1/target/lib/pircbotx-2.0.1.jar
  27. BIN
      AlphaPhase-0.0.1/target/lib/slf4j-api-1.7.13.jar
  28. BIN
      AlphaPhase-0.0.1/target/lib/slf4j-log4j12-1.7.7.jar
  29. 5 0
      AlphaPhase-0.0.1/target/maven-archiver/pom.properties
  30. BIN
      AlphaPhase-0.0.1/target/original-AlphaPhase-0.0.1.jar
  31. 0 0
      AlphaPhase-0.0.1/target/test-classes/.netbeans_automatic_build
  32. 1 0
      README.md

+ 178 - 0
AlphaPhase-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.alphaphase</groupId>
4
    <artifactId>AlphaPhase</artifactId>
5
    <version>0.0.1</version>
6
    <name>AlphaPhase</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>

+ 132 - 0
AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/BugReportCommand.java

@ -0,0 +1,132 @@
1
package fr.waazaa.apps.irc.plugins.alphaphase;
2

													
3
import fr.waazaa.apps.irc.plugins.alphaphase.config.MessagesToSendConfiguration;
4
import fr.waazaa.apps.irc.botx.IrcBotX;
5
import fr.waazaa.apps.irc.botx.command.CommandPlugin;
6
import fr.waazaa.apps.irc.botx.command.CommandScopeEnum;
7
import fr.waazaa.apps.irc.botx.command.IrcCommand;
8
import fr.waazaa.apps.irc.botx.command.help.HelpLine;
9
import fr.waazaa.apps.irc.botx.command.help.HelpMessage;
10
import fr.waazaa.apps.irc.plugins.alphaphase.messages.PendingMessage;
11
import java.util.List;
12
import org.pircbotx.Channel;
13
import org.pircbotx.Colors;
14
import org.pircbotx.User;
15
import java.util.ArrayList;
16
import org.pircbotx.hooks.WaitForQueue;
17
import org.pircbotx.hooks.events.PrivateMessageEvent;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

													
21

													
22
public class BugReportCommand implements CommandPlugin {
23

													
24
    // Le LOGGER
25
    private static final Logger LOGGER = LoggerFactory.getLogger(BugReportCommand.class );
26
    // Variable contenant la commande, exemple: !mycommand devient:
27
    private final String command = "bug report";
28

													
29
    
30
    private List<String> messages = new ArrayList<String>();
31
    
32
    
33
    // Retourne la commande
34
    public String getCommand() {
35
        return this.command;
36
    }
37

													
38
    // Retourne le noeud yml de permission
39
    public String getPermission() {
40
        return "bug.report";
41
    }
42

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

													
48
    // L'aide qui sera retournée au User si il a le noeud yml de permission
49
    public HelpMessage getHelp() {
50
        HelpMessage helps   = new HelpMessage( this.command.toUpperCase() );
51
        HelpLine line       = new HelpLine(
52
            this.getPermission(),
53
            this.command,
54
            "Informer d'un bug trouvé"
55
        );
56
        helps.addLine(line);
57
        return helps;
58
    }
59

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

													
63
        LOGGER.info( "Dans executeCommand() de BugReportCommand" );
64

													
65
        IrcBotX botX            = ircCommand.botX;
66
        List<String> arguments  = ircCommand.arguments;
67
        Channel chan            = ircCommand.chan;
68
        User user               = ircCommand.user;
69
        
70
        user.send().message( "Tu as découvert un bug ?" );
71
        user.send().message( "Merci de bien vouloir m'expliquer ce que tu as fais et "
72
            + "ce que tu attendais comme résultat." );
73
        user.send().message( "Essaye d'être le plus précis possible." );
74
        user.send().message( "J'enregistre tout ce que tu me dis à partir de maintenant,"
75
            + " merci de lancer un " + Colors.BOLD + "stop" + Colors.NORMAL + 
76
            " quand tu auras terminé ton rapport.");
77
        
78
        WaitForQueue queue = new WaitForQueue( botX.getBot() );
79
        while (true) {
80
            
81
            try {
82

													
83
                PrivateMessageEvent currentEvent = queue.waitFor(PrivateMessageEvent.class);
84
                
85
                // On vérifie que ce PrivateMessageEvent vient bien du même User
86
                if( currentEvent.getUser().getNick().equalsIgnoreCase( user.getNick() ) ){
87
                    
88
                    final String message = currentEvent.getMessage();
89
                    
90
                    if( message.equalsIgnoreCase("stop") ){
91
                        user.send().message( Colors.DARK_GREEN + "Merci pour ton retour." );
92
                        
93
                        // On fabrique un seul PendingMessage
94
                        StringBuilder build = new StringBuilder();
95
                        for( String m : messages ){
96
                            build.append( m ).append(" ");
97
                        }
98
                        PendingMessage pendMessage = new PendingMessage( 
99
                            "BUG REPORT",
100
                            user.getNick(),
101
                            build.toString()
102
                        );
103
                        
104
                        // On stocke messages
105
                        new MessagesToSendConfiguration().addMessageTo( "waazaa", pendMessage );
106
                        queue.close();
107
                        return;
108
                    }else{
109
                        
110
                        // On stocke ce message
111
                        messages.add(message);
112
                        
113
                    }
114
                    
115
                }
116

													
117

													
118
            } catch (IllegalArgumentException ex){
119
                user.send().message( 
120
                    Colors.BOLD + Colors.RED + ex.getMessage()
121
                );
122
            } catch (InterruptedException ex) {
123
                user.send().message( 
124
                    Colors.BOLD + Colors.RED + ex.getMessage()
125
                );
126
            }
127
            
128
        }
129
        
130
    }
131

													
132
}

+ 66 - 0
AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/MyListener.java

@ -0,0 +1,66 @@
1
package fr.waazaa.apps.irc.plugins.alphaphase;
2

													
3
import fr.waazaa.apps.irc.plugins.alphaphase.config.AlphaPhaseConfiguration;
4
import fr.waazaa.apps.irc.botx.IrcBotX;
5
import fr.waazaa.apps.irc.botx.config.RoleConfig;
6
import java.util.ArrayList;
7
import java.util.List;
8
import org.pircbotx.User;
9
import org.pircbotx.hooks.ListenerAdapter;
10
import org.pircbotx.hooks.events.JoinEvent;
11
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13

													
14

													
15
public class MyListener extends ListenerAdapter {
16
    
17
    // Le LOGGER
18
    private static final Logger LOGGER = LoggerFactory.getLogger( MyListener.class );
19
    
20
    private boolean started = false;
21
    
22
    private final String ROLE           = "config.permissions.role";
23
    private final String PERMISSIONS    = "config.permissions.permissions";
24
    
25
        
26
    
27
    @Override
28
    public void onJoin(final JoinEvent event ) throws Exception {
29
        
30
        User user = event.getUser();
31
        
32
        if( !this.started ){
33
            
34
            AlphaPhaseConfiguration alphaConfig         = new AlphaPhaseConfiguration();
35
        
36
            // On crée un groupe ALPHA
37
            RoleConfig role         = new RoleConfig( alphaConfig.getString( ROLE ) );
38
            List<String> newPerms   = new ArrayList<String>();
39

													
40
            // Les permissions à donner 
41
            for( String perm : alphaConfig.getStringList( PERMISSIONS ) ){
42
                newPerms.add( perm );
43
            }
44

													
45
            // On vire anciennes permissions
46
            role.removeAllPermissions();
47
            // On ajoute les nouvelles
48
            role.addPermissions( newPerms );
49

													
50
            LOGGER.info( "[ALPHA] Les nouvelles permissions ont pris place à la place des anciennes." );
51

													
52
            // Ajout de la tâche Cron
53
            IrcBotX.cron.addTask( new UserRoleChangeTask() );
54
            LOGGER.info( "[ALPHA] La tâche Cron de modification des UserConfig est lancée." );
55
            IrcBotX.cron.addTask( new SendMessagesTask() );
56
            LOGGER.info( "[ALPHA] La tâche Cron d'envoi de message répondeur est lancée." );
57
            
58
        }
59
        this.started = true;
60
        
61
        
62
        
63
    }
64
    
65
    
66
}

+ 82 - 0
AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/SendMessagesTask.java

@ -0,0 +1,82 @@
1
package fr.waazaa.apps.irc.plugins.alphaphase;
2

													
3
import fr.waazaa.apps.irc.botx.IrcBotX;
4
import fr.waazaa.apps.irc.botx.users.UserManager;
5
import fr.waazaa.apps.irc.plugins.alphaphase.config.MessagesToSendConfiguration;
6
import fr.waazaa.apps.irc.plugins.alphaphase.messages.PendingMessage;
7
import it.sauronsoftware.cron4j.TaskExecutionContext;
8
import java.text.SimpleDateFormat;
9
import java.util.Date;
10
import java.util.List;
11
import java.util.Set;
12
import org.pircbotx.Colors;
13
import org.pircbotx.User;
14
import org.shortrip.boozaa.apps.boocron.cron.CronTask;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

													
18

													
19
public class SendMessagesTask extends CronTask {
20
    
21
    private static final Logger LOGGER = LoggerFactory.getLogger(SendMessagesTask.class );
22
    
23
    
24
    public SendMessagesTask(  ) {
25
        super( "SendMessagesTask", "*/1 * * * *");
26
    }
27
    
28
    
29
    @Override
30
    public void execute(TaskExecutionContext tec) throws RuntimeException {
31
        
32
        LOGGER.info( "[ALPHA] Dans execute() de SendMessagesTask" );
33
        
34
        MessagesToSendConfiguration messagesConfig  = new MessagesToSendConfiguration();
35
        Set<String> targets = messagesConfig.getAllTargets();
36
        
37
        for( String target : targets ){
38
            if( null != UserManager.getUser( target ) ){
39
                
40
                User user = UserManager.getUser( target );
41
                List<PendingMessage> messages = messagesConfig.getMessagesFor(target);
42
                
43
                LOGGER.info( "[ALPHA] Nombre de messages: " + messages.size() );
44
                LOGGER.info( "[ALPHA] User target: " + user.toString() );
45
                LOGGER.info( "[ALPHA] messages: " + messages.toString() );
46
                
47
                for( PendingMessage message :  messages ){
48
                    if( null != message ){
49
                        
50
                        LOGGER.info( "[ALPHA] message: " + message.toString() );
51
                        
52
                        String timeStamp = new SimpleDateFormat("dd.MM.YYYY HH:mm:ss")
53
                            .format(
54
                                new Date( message.getDate() )
55
                            );
56
                        
57
                        user.send().message( 
58
                            Colors.BROWN +
59
                            "[" + message.getType() + "] " 
60
                            + Colors.NORMAL + message.getAuthor() 
61
                            + " -  " + Colors.DARK_GRAY + timeStamp
62
                        );
63
                        user.send().message( 
64
                            Colors.BOLD +
65
                            message.getMessage()
66
                        );
67
                        //messagesConfig.removeMessageFor(target, message); 
68
                        
69
                    }
70
                                       
71
                }
72
                
73
                // On supprime les messages pour cet user
74
                messagesConfig.removeMessagesFor(target);
75
                
76
                
77
            }
78
        }
79
        
80
    }
81
    
82
}

+ 92 - 0
AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/UserRoleChangeTask.java

@ -0,0 +1,92 @@
1
package fr.waazaa.apps.irc.plugins.alphaphase;
2

													
3
import fr.waazaa.apps.irc.plugins.alphaphase.config.MessagesToSendConfiguration;
4
import fr.waazaa.apps.irc.plugins.alphaphase.config.AlphaPhaseConfiguration;
5
import fr.waazaa.apps.irc.botx.IrcBotX;
6
import fr.waazaa.apps.irc.botx.config.IrcConfig;
7
import fr.waazaa.apps.irc.botx.config.UserConfig;
8
import fr.waazaa.apps.irc.botx.users.UserManager;
9
import fr.waazaa.apps.irc.plugins.alphaphase.messages.PendingMessage;
10
import it.sauronsoftware.cron4j.TaskExecutionContext;
11
import java.util.ArrayList;
12
import java.util.List;
13
import org.pircbotx.User;
14
import org.shortrip.boozaa.apps.boocron.cron.CronTask;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

													
18

													
19
public class UserRoleChangeTask extends CronTask {
20
    
21
    private static final Logger LOGGER = LoggerFactory.getLogger(UserRoleChangeTask.class );
22
    private final String ROLE           = "config.permissions.role";
23
    
24
    
25
    
26
    public UserRoleChangeTask() {
27
        super( "UserRoleChangeTask", "*/1 * * * *");
28
    }
29
    
30
    
31
    @Override
32
    public void execute(TaskExecutionContext tec) throws RuntimeException {
33
        
34
        LOGGER.info( "[ALPHA] Dans execute() de UserRoleChangeTask" );
35
        
36
        AlphaPhaseConfiguration alphaConfig         = new AlphaPhaseConfiguration();
37
        MessagesToSendConfiguration messagesConfig  = new MessagesToSendConfiguration();
38
        IrcConfig ircConfig                         = new IrcConfig();
39
        
40
        // Tous les membres REGISTERED doivent passer dans nouveaux groupes
41
        List<UserConfig> allUConfigs = UserManager.getAllUserConfigs();
42
        
43
        for( UserConfig uConf : allUConfigs ){            
44
            
45
            if( uConf.getRole().equalsIgnoreCase( "REGISTERED" )){
46
                
47
                uConf.setRole( alphaConfig.getString(ROLE) );
48
                
49
                List<String> messages = new ArrayList<String>();
50
                messages.add( "Tu as rejoins le groupe d'utilisateur " + alphaConfig.getString( ROLE ) );
51
                messages.add( "Merci de bien vouloir tester les commandes auxquelles tu as droit."
52
                        + " Lances un " + ircConfig.getCommand() + "help pour les connaître." );
53
                messages.add( "Si tu remarques un problème merci de bien vouloir nous en informer "
54
                        + "avec la commande: " + ircConfig.getCommand() + "bug report" );
55

													
56
                // On informe si connecté
57
                if( null != UserManager.getUser( uConf.getNick() ) ){
58

													
59
                    User u = UserManager.getUser( uConf.getNick() );
60
                    for( String str : messages ){
61
                        u.send().message( 
62
                            str 
63
                        );
64
                    }
65

													
66
                }else{
67

													
68
                    // On stocke messages pour sa prochaine connexion
69
                    //  String type, String author, String message
70
                    List<PendingMessage> listPendings = new ArrayList<PendingMessage>();
71
                    
72
                    for( String message : messages ){
73
                       PendingMessage pMess = new PendingMessage (
74
                            "",
75
                            "SYSTEM",
76
                            message
77
                        );
78
                       listPendings.add( pMess );
79
                    }
80
                    
81
                    messagesConfig.addMessagesTo( uConf.getNick(), listPendings );
82

													
83
                }
84
                
85
            }
86
            
87
        }
88
        
89
    }
90
    
91
    
92
}

+ 112 - 0
AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/config/AlphaPhaseConfiguration.java

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

													
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.ArrayList;
6
import java.util.Date;
7
import java.util.List;
8
import org.shortrip.boozaa.libs.yamlconfiguration.InvalidConfigurationException;
9
import org.shortrip.boozaa.libs.yamlconfiguration.serialization.YamlConfiguration;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

													
13

													
14
public class AlphaPhaseConfiguration extends YamlConfiguration {
15
    
16
    private static final Logger LOGGER 	= LoggerFactory.getLogger( AlphaPhaseConfiguration.class );    
17
    private final File source;
18
    
19
    private final String ROLE           = "config.permissions.role";
20
    private final String PERMISSIONS    = "config.permissions.permissions";
21
    private final String TOPIC          = "config.topic.topic";
22
    private final String TOPIC_DATE     = "config.topic.date";
23
    
24
    
25
    
26
    public AlphaPhaseConfiguration(){
27
        this.source = new File( "config" + File.separator + "alpha.yml" );
28
        this.load();
29
    }
30
    
31
    public void load() {
32
        
33
        try {
34
            
35
            if( !this.exists() ){
36
                this.save();
37
            }
38

													
39
            this.load(this.source);
40
            
41
            
42
            if( !this.contains( ROLE )  )
43
                this.set(ROLE, "ALPHA");
44
            
45
            List<String> permissions = new ArrayList<String>();
46
            permissions.add( "user.validate" );
47
            permissions.add( "user.login" );
48
            permissions.add( "user.edit" );
49
            permissions.add( "bug.report" );
50
            
51
            
52
            // On force la mise à jour des permissions
53
            this.set(PERMISSIONS, permissions);
54
            
55
            if( !this.contains( TOPIC )  )
56
                this.set( 
57
                    TOPIC, 
58
                    "ALPHA - " + "Phase de développement en cours: inscription et "
59
                    + "manipulations des comptes utilisateurs" 
60
                );
61
            
62
            if( !this.contains( TOPIC_DATE )  )
63
                this.set( 
64
                    TOPIC_DATE, 
65
                    new Date().getTime()
66
                );
67
            
68
            this.save();
69
            
70
    
71
        } catch (IOException ex) {
72
            LOGGER.error( ex.getMessage() );
73
        } catch (InvalidConfigurationException ex) {
74
            LOGGER.error( ex.getMessage() );
75
        }
76
        
77
    }
78
    
79
    
80
    public void setTopic( String message ){
81
        
82
        this.set(
83
            TOPIC, 
84
            "ALPHA - " + message
85
        );
86
        
87
        this.set(
88
            TOPIC_DATE, 
89
            new Date().getTime()
90
        );
91
        
92
        this.save();
93
        
94
    }
95
    
96
    
97
    
98
    public void save() {
99
        try {
100
            this.save(this.source);
101
        } catch (IOException ex) {
102
            LOGGER.error( ex.getMessage() );
103
        }
104
    }
105
    
106
    
107
    public boolean exists() {
108
        return this.source.exists();
109
    }
110
    
111
    
112
}

+ 158 - 0
AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/config/MessagesToSendConfiguration.java

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

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

													
16

													
17
public class MessagesToSendConfiguration extends YamlConfiguration {
18
    
19
    private static final Logger LOGGER 	= LoggerFactory.getLogger( MessagesToSendConfiguration.class );    
20
    private final File source;
21
    
22
    
23
    public MessagesToSendConfiguration(){
24
        this.source = new File( "config" + File.separator + "alpha-messages.yml" );
25
        this.load();
26
    }
27
    
28
    
29
    public void load() {
30
        
31
        try {
32
            
33
            if( !this.exists() ){
34
                this.save();
35
            }
36

													
37
            this.load(this.source);
38
            
39
            
40
            
41
            
42
            this.save();
43
            
44
    
45
        } catch (IOException ex) {
46
            LOGGER.error( ex.getMessage() );
47
        } catch (InvalidConfigurationException ex) {
48
            LOGGER.error( ex.getMessage() );
49
        }
50
        
51
    }
52
    
53
    public void addMessageTo( String to, PendingMessage message ){
54
        
55
        List<PendingMessage> oldMessages;
56
        if( null != this.getStringList( "messages.to." + to ) ){
57
            oldMessages = (List<PendingMessage>) this.getList("messages.to." + to );            
58
        }else{
59
            oldMessages = new ArrayList<PendingMessage>();            
60
        }
61
        
62
        oldMessages.add( message );
63
        this.set( 
64
            "messages.to." + to, 
65
            oldMessages
66
        );
67
        this.save();
68
        
69
    }
70
    
71
    public void addMessagesTo( String to, List<PendingMessage> messages ){
72
        
73
        List<PendingMessage> oldMessages;
74
        if( null != this.getStringList( "messages.to." + to ) ){
75
            oldMessages = (List<PendingMessage>) this.getList( "messages.to." + to );            
76
        }else{
77
            oldMessages = new ArrayList<PendingMessage>();            
78
        }
79
        
80
        for( PendingMessage message : messages ){
81
            oldMessages.add( message );
82
        }
83
        
84
        this.set( 
85
            "messages.to." + to, 
86
            oldMessages
87
        );
88
        this.save();
89
        
90
    }
91
    
92
    
93
    public Set<String> getAllTargets(){        
94
        return this.getKeys( "messages.to" );        
95
    }
96
    
97
    
98
    public List<PendingMessage> getMessagesFor( String target ){
99
        LOGGER.info( "[ALPHA] Recherche de message en attente pour " + target );
100
        List<PendingMessage> oldMessages = new ArrayList<PendingMessage>();
101
        if( null != this.getList( "messages.to." + target ) ){ 
102
            LOGGER.info( "[ALPHA] La liste n'est pas vide" );           
103
            oldMessages = (List<PendingMessage>) this.getList( "messages.to." + target );            
104
        }
105
        return oldMessages;
106
    }
107
    
108
    
109
    public void removeMessageFor( String target, PendingMessage message ){
110
        
111
        LOGGER.info( "[ALPHA] On veut supprimer un message pour " + target );
112
        List<PendingMessage> oldMessages = (List<PendingMessage>) this.getList( "messages.to." + target );
113
        oldMessages.remove( message );
114
        this.set( 
115
            "messages.to." + target, 
116
            oldMessages
117
        );
118
        this.save();
119
        
120
    }
121
    
122
    
123
    
124
    public void removeMessagesFor( String target ){
125
        
126
        LOGGER.info( "[ALPHA] On veut supprimer tous les messages pour " + target );
127
        this.set( 
128
            "messages.to." + target, 
129
            new ArrayList<PendingMessage>()
130
        );
131
        this.save();
132
        
133
    }
134
    
135
    
136
    
137
    public void save() {
138
        try {
139
            this.save(this.source);
140
        } catch (IOException ex) {
141
            LOGGER.error( ex.getMessage() );
142
        }
143
    }
144
    
145
    
146
    public boolean exists() {
147
        return this.source.exists();
148
    }
149
    
150
    public Set<String> getKeys(String path) {
151
        try {
152
            return this.getConfigurationSection(path).getKeys(false);
153
        } catch (Exception ex) {
154
            return new HashSet<String>();
155
        }
156
    }
157
    
158
}

+ 146 - 0
AlphaPhase-0.0.1/src/main/java/fr/waazaa/apps/irc/plugins/alphaphase/messages/PendingMessage.java

@ -0,0 +1,146 @@
1
package fr.waazaa.apps.irc.plugins.alphaphase.messages;
2

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

													
11

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

													
41
    public Long getDate() {
42
        return date;
43
    }
44
    
45
    public String getType() {
46
        return type;
47
    }
48

													
49
    public String getAuthor() {
50
        return author;
51
    }
52

													
53
    public String getMessage() {
54
        return message;
55
    }
56

													
57
    @Override
58
    public int hashCode() {
59
        int hash = 5;
60
        hash = 17 * hash + (this.type != null ? this.type.hashCode() : 0);
61
        hash = 17 * hash + (this.author != null ? this.author.hashCode() : 0);
62
        hash = 17 * hash + (this.message != null ? this.message.hashCode() : 0);
63
        return hash;
64
    }
65

													
66
    @Override
67
    public boolean equals(Object obj) {
68
        if (this == obj) {
69
            return true;
70
        }
71
        if (obj == null) {
72
            return false;
73
        }
74
        if (getClass() != obj.getClass()) {
75
            return false;
76
        }
77
        final PendingMessage other = (PendingMessage) obj;
78
        if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
79
            return false;
80
        }
81
        if ((this.author == null) ? (other.author != null) : !this.author.equals(other.author)) {
82
            return false;
83
        }
84
        if ((this.message == null) ? (other.message != null) : !this.message.equals(other.message)) {
85
            return false;
86
        }
87
        return true;
88
    }
89

													
90
    @Override
91
    public String toString() {
92
        return "PendingMessage{" + "type=" + type + ", author=" + author + ", message=" + message + ", date=" + date + '}';
93
    }
94
    
95
    
96
    
97

													
98
    @Override
99
    public Map<String, Object> serialize() {
100
        
101
        LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
102
        result.put("TYPE",      this.type );
103
        result.put("AUTHOR",    this.author );
104
        result.put("MESSAGE",   this.message );
105
        result.put("DATE",      this.date );
106
        return result;
107
        
108
    }
109
    
110
    public PendingMessage deserialize(Map<String, Object> args){
111
        
112
        String t    = (String) args.get("TYPE");
113
        
114
        String a    = (String) args.get("AUTHOR");
115
        
116
        String m    = (String)args.get("MESSAGE");
117
        
118
        Long d      = (Long) args.get("DATE");
119
        
120
        LOGGER.info( "type: " + t + ", author: " + a + ", message: " + m );
121
        
122
        PendingMessage pMess    = new PendingMessage( t, a, m);
123
        pMess.date              = d;
124
        return pMess;
125
        
126
    }
127
    
128
    public PendingMessage valueOf(Map<String, Object> args){
129
        
130
        String t    = (String) args.get("TYPE");
131
        
132
        String a    = (String) args.get("AUTHOR");
133
        
134
        String m    = (String)args.get("MESSAGE");
135
        
136
        Long d      = (Long) args.get("DATE");
137
        
138
        LOGGER.info( "type: " + t + ", author: " + a + ", message: " + m );
139
        
140
        PendingMessage pMess    = new PendingMessage( t, a, m);
141
        pMess.date              = d;
142
        return pMess;
143
        
144
    }
145
    
146
}

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


+ 8 - 0
AlphaPhase-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="AlphaPhase*.jar" dir="D:\Workspace\WaaBot\IrcBotX\plugins\"/>
6
  </delete>
7
</target>
8
</project>

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


BIN
AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/BugReportCommand.class


BIN
AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/MyListener.class


BIN
AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/SendMessagesTask.class


BIN
AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/UserRoleChangeTask.class


BIN
AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/config/AlphaPhaseConfiguration.class


BIN
AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/config/MessagesToSendConfiguration.class


BIN
AlphaPhase-0.0.1/target/classes/fr/waazaa/apps/irc/plugins/alphaphase/messages/PendingMessage.class


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


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


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


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


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


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


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


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


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


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


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

@ -0,0 +1,5 @@
1
#Generated by Maven
2
#Wed Apr 10 19:43:52 CEST 2019
3
version=0.0.1
4
groupId=fr.waazaa.apps.irc.plugins.alphaphase
5
artifactId=AlphaPhase

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


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


+ 1 - 0
README.md

@ -3,6 +3,7 @@
3 3
Plugins public développé pour WaaBot.
4 4

													
5 5
Inclut un générateur de source vierge: WaaBotBlankPluginGenerator.jar
6

													
6 7
Jar exécutable et interface simpliste...
7 8

													
8 9
![](https://framapic.org/Fzm7Okity5xT/TrqSBsshHUxm.PNG)