diff --git a/docs/doc.html b/docs/doc.html
new file mode 100644
index 0000000..e236cd1
--- /dev/null
+++ b/docs/doc.html
@@ -0,0 +1,428 @@
+
+
+
+
+
+ JIrcBot documentation
+
+
+
+JIrcBot documentation
+
+view project sources at GitHub repo
+
+
+
+
+
+
MODULE: AdminListener
+
+
+ Admin commands of the bot
Must be send in private dialog
You must be the owner of the bot (config.json) and your nick must be registered and verified at server
+
+
+
+
COMMANDS:
+
+
+
+ -
+
+
+ cmd
+
+
+
+ Description: send RAW command to server (be careful with that shit!)
+
+
+ Example: ?cmd [ANY COMMAND WITH PARAMS]
+
+
+
+ -
+
+
+ join
+
+
+
+ Description: joins given channel on current server
+
+
+ Example: ?join [#CHANNEL_NAME]
+
+
+
+ -
+
+
+ kick
+
+
+
+ Description: kick user from channel
+
+
+ Example: ?kick [#CHANNEL_NAME] [YOUR_HOSTILE_NICK]
+
+
+
+ -
+
+
+ leave
+
+
+
+ Description: joins given channel on current server
+
+
+ Example: ?leave [#CHANNEL_NAME]
+
+
+
+ -
+
+
+ op|deop
+
+
+
+ Description: give / take away OP user status
+
+
+ Example: ?op [#CHANNEL_NAME] [YOUR_FRIEND_NICK]
?deop [#CHANNEL_NAME] [YOUR_HOSTILE_NICK]
+
+
+
+ -
+
+
+ privmsg
+
+
+
+ Description: send private message
+
+
+ Example: ?privmsg [YOUR_FRIEND_NICK]
+
+
+
+ -
+
+
+ restart
+
+
+
+ Description: trying to restart the bot on current server
+
+
+ Example: ?restart
+
+
+
+ -
+
+
+ set
+
+
+
+ Description: set ON|OFF any of bot opportunity for channel
Opportunities:
autorejoin | auto-rejoin - auto rejoin channel on kicking
bash | bashorg - bach.org quoting
deferredmessages | deferred-messages | tell - saving and delivering deferred messages
gs | googlesearch | google-search - search in Google
grammar | grammarcorrection | grammar-correction - grammar checker (does not work in current version)
hello | helloonjoin | hello-on-join - sending your phrase on user joins
links | linkpreview | links-preview - sending titles of web pages by given URL
logging | log - logging for channel
regex | regexp | regexchecker | regexpchecker | regex-checker | regexp-checker - regular expression checker
advice | advices - give yor friend advices
calc | calculator - calculator
quiz - quiz
+
+
+ Example: ?set [#CHANNEL_NAME] [OPPORTUNITY] [ON|OFF]
+
+
+
+
+
+
+
+
+
+
+
MODULE: BashOrgListener
+
+
+ Send bash.org quotes in channel on your request
+
+
+
+
COMMANDS:
+
+
+
+ -
+
+
+ bash
+
+
+
+ Description: Send random quote from bash.org to channel
+
+
+ Example: ?bash
+
+
+
+
+
+
+
+
+
+
+
MODULE: DeferredMessagesListener
+
+
+ This module is like answerphone - it stores your speech to any opponent into bot's database and when your opponent becomes online (joins channel and starts to speak) the bot notice him/her with your deferred messages.
+
+
+
+
COMMANDS:
+
+
+
+ -
+
+
+ forget
+
+
+
+ Description: If you do not want to read all messages deferred to you this command tells the bot do not disturb you this time
+
+
+ Example: ?forget
+
+
+
+ -
+
+
+ read
+
+
+
+ Description: Let the bot send you all the messages deferred to you this time in private dialogue
+
+
+ Example: ?read
+
+
+
+ -
+
+
+ tell
+
+
+
+ Description: Let the bot keep in mind your message to any opponent
+
+
+ Example: ?tell [YOUR_FRIEND] [YOUR MESSAGE]
+
+
+
+
+
+
+
+
+
+
+
MODULE: GoogleSearchListener
+
+
+ Make a search in Google for you
+
+
+
+
COMMANDS:
+
+
+
+ -
+
+
+ gs
+
+
+
+ Description: Search it
+
+
+ Example: ?gs [WHAT YOU WANT TO SEARCH]
+
+
+
+
+
+
+
+
+
+
+
MODULE: HelloOnJoinListener
+
+
+ The bot greets everyone joining the channel
You can set the greeting text using Admin module
+
+
+
+
COMMANDS:
+
+
+
+
+
+
+
+
+
+
+
MODULE: LinkPreviewListener
+
+
+ With this module enabled into Admin module the bot will send the title of every URL found in messages posted in channel
+
+
+
+
COMMANDS:
+
+
+
+
+
+
+
+
+
+
+
MODULE: LoggerListener
+
+
+ This module logs all the messages into database for being able to observe in Web
+
+
+
+
COMMANDS:
+
+
+
+
+
+
+
+
+
+
+
MODULE: PingPongListener
+
+
+ Try to play ping-pong if you not aware of is the bot here
+
+
+
+
COMMANDS:
+
+
+
+ -
+
+
+ ping
+
+
+
+ Description: Returns pong
+
+
+ Example: ?ping
+
+
+
+
+
+
+
+
+
+
+
MODULE: RegexCheckerListener
+
+
+
+
+
+
+
COMMANDS:
+
+
+
+ -
+
+
+ regex
+
+
+
+ Description: Checks if given message with given regular expression
+
+
+ Example: ?regex
+
+
+
+
+
+
+
+
+
+
+
MODULE: StatisticsListener
+
+
+
+
+
+
+
COMMANDS:
+
+
+
+ -
+
+
+ stats
+
+
+
+ Description: Provides statistics for channel
+
+
+ Example: ?stats [D(ay)|M(onth)|Y(ear)|A(ll)] [ALL]
+
+
+
+
+
+
+
+
+
+
+
+ (c) bvn13
+ powered with PircBotX
+
+
+
+
\ No newline at end of file
diff --git a/jircbot.iml b/jircbot.iml
index c014a2c..408f1bd 100644
--- a/jircbot.iml
+++ b/jircbot.iml
@@ -34,73 +34,73 @@
-
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
+
-
+
-
-
-
-
+
+
+
+
-
-
+
+
-
@@ -108,8 +108,8 @@
-
-
+
+
diff --git a/pom.xml b/pom.xml
index a53d74b..c1df553 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,13 +6,13 @@
ru.bvn13
jircbot
- 2.0.7
+ 2.0.8
jar
org.springframework.boot
spring-boot-starter-parent
- 2.0.0.RELEASE
+ 2.0.6.RELEASE
@@ -24,10 +24,6 @@
2.1
- 2.0.0.RELEASE
- 5.0.4.RELEASE
- 5.2.14.Final
-
UTF-8
UTF-8
1.8
@@ -78,7 +74,10 @@
spring-boot-starter-thymeleaf
-
+
+ org.springframework.boot
+ spring-boot-devtools
+
@@ -88,12 +87,10 @@
com.zaxxer
HikariCP
- 2.7.6
org.hibernate
hibernate-entitymanager
- ${hibernate.version}
org.springframework
@@ -114,7 +111,6 @@
org.hibernate
hibernate-spatial
- 5.1.0.Final
diff --git a/src/main/java/ru/bvn13/jircbot/documentation/DescriptionProvided.java b/src/main/java/ru/bvn13/jircbot/documentation/DescriptionProvided.java
new file mode 100644
index 0000000..ec72912
--- /dev/null
+++ b/src/main/java/ru/bvn13/jircbot/documentation/DescriptionProvided.java
@@ -0,0 +1,13 @@
+package ru.bvn13.jircbot.documentation;
+
+/**
+ * Created by bvn13 on 28.10.2018.
+ */
+public interface DescriptionProvided {
+
+ ListenerDescription getDescription();
+ default void registerDescription(DocumentationProvider documentationProvider) {
+ documentationProvider.register(this);
+ }
+
+}
diff --git a/src/main/java/ru/bvn13/jircbot/documentation/DocumentationProvider.java b/src/main/java/ru/bvn13/jircbot/documentation/DocumentationProvider.java
new file mode 100644
index 0000000..bccf681
--- /dev/null
+++ b/src/main/java/ru/bvn13/jircbot/documentation/DocumentationProvider.java
@@ -0,0 +1,34 @@
+package ru.bvn13.jircbot.documentation;
+
+import javafx.collections.transformation.SortedList;
+import lombok.Getter;
+import org.modelmapper.internal.util.Lists;
+import org.springframework.stereotype.Component;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * Created by bvn13 on 28.10.2018.
+ */
+@Component
+public class DocumentationProvider {
+
+ @Getter
+ private Map descriptors = new HashMap<>();
+
+ public void register(DescriptionProvided descriptionProvided) {
+ descriptors.put(descriptionProvided.getDescription().getModuleName(), descriptionProvided);
+ }
+
+ public List getModuleNames() {
+ List names = Lists.from(descriptors.keySet().iterator());
+ names.sort(String.CASE_INSENSITIVE_ORDER);
+ return names;
+ }
+
+ public DescriptionProvided getModuleDescriptor(String moduleName) {
+ return descriptors.getOrDefault(moduleName, null);
+ }
+
+}
diff --git a/src/main/java/ru/bvn13/jircbot/documentation/ListenerDescription.java b/src/main/java/ru/bvn13/jircbot/documentation/ListenerDescription.java
new file mode 100644
index 0000000..305909d
--- /dev/null
+++ b/src/main/java/ru/bvn13/jircbot/documentation/ListenerDescription.java
@@ -0,0 +1,67 @@
+package ru.bvn13.jircbot.documentation;
+
+import lombok.Builder;
+import lombok.Getter;
+import org.modelmapper.internal.util.Lists;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by bvn13 on 28.10.2018.
+ */
+public class ListenerDescription {
+
+ @Builder
+ public static class CommandDescription {
+
+ @Getter
+ private String command = "";
+ @Getter
+ private String description = "";
+ @Getter
+ private String example = "";
+
+ }
+
+ @Getter
+ private String moduleName = "";
+ @Getter
+ private String moduleDescription = "";
+
+ private Map commandsDescription = new HashMap<>();
+
+
+ private ListenerDescription() {}
+
+ public static ListenerDescription create() {
+ return new ListenerDescription();
+ }
+
+ public ListenerDescription setModuleName(String moduleName) {
+ this.moduleName = moduleName;
+ return this;
+ }
+
+ public ListenerDescription setModuleDescription(String moduleDescription) {
+ this.moduleDescription = moduleDescription;
+ return this;
+ }
+
+ public ListenerDescription addCommand(CommandDescription description) {
+ commandsDescription.put(description.getCommand(), description);
+ return this;
+ }
+
+ public List getCommandNames() {
+ List names = Lists.from(commandsDescription.keySet().iterator());
+ names.sort(String.CASE_INSENSITIVE_ORDER);
+ return names;
+ }
+
+ public CommandDescription getCommandDescription(String command) {
+ return commandsDescription.getOrDefault(command, null);
+ }
+
+}
diff --git a/src/main/java/ru/bvn13/jircbot/listeners/AdminListener.java b/src/main/java/ru/bvn13/jircbot/listeners/AdminListener.java
index c8bce0a..a3b5998 100644
--- a/src/main/java/ru/bvn13/jircbot/listeners/AdminListener.java
+++ b/src/main/java/ru/bvn13/jircbot/listeners/AdminListener.java
@@ -3,7 +3,6 @@ package ru.bvn13.jircbot.listeners;
import org.pircbotx.hooks.events.JoinEvent;
import org.pircbotx.hooks.events.MessageEvent;
import org.pircbotx.hooks.events.PrivateMessageEvent;
-import org.pircbotx.hooks.types.GenericEvent;
import org.pircbotx.hooks.types.GenericMessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -14,15 +13,20 @@ import ru.bvn13.jircbot.bot.JircBot;
import ru.bvn13.jircbot.config.JircBotConfiguration;
import ru.bvn13.jircbot.database.entities.ChannelSettings;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
+import ru.bvn13.jircbot.documentation.DescriptionProvided;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+import ru.bvn13.jircbot.documentation.ListenerDescription;
import ru.bvn13.jircbot.model.Config;
import java.util.concurrent.atomic.AtomicReference;
+import static ru.bvn13.jircbot.documentation.ListenerDescription.CommandDescription;
+
/**
* Created by bvn13 on 27.03.2018.
*/
@Component
-public class AdminListener extends ImprovedListenerAdapter {
+public class AdminListener extends ImprovedListenerAdapter implements DescriptionProvided {
private static final Logger logger = LoggerFactory.getLogger(AdminListener.class);
@@ -34,6 +38,81 @@ public class AdminListener extends ImprovedListenerAdapter {
@Autowired
private ChannelSettingsService channelSettingsService;
+ @Autowired
+ public AdminListener(DocumentationProvider documentationProvider) {
+ this.registerDescription(documentationProvider);
+ }
+
+ @Override
+ public ListenerDescription getDescription() {
+ return ListenerDescription.create()
+ .setModuleName("AdminListener")
+ .setModuleDescription("Admin commands of the bot\nMust be send in private dialog\nYou must be the owner of the bot (config.json) and your nick must be registered and verified at server")
+ .addCommand(CommandDescription.builder()
+ .command("join")
+ .description("joins given channel on current server")
+ .example("?join [#CHANNEL_NAME]")
+ .build()
+ )
+ .addCommand(CommandDescription.builder()
+ .command("leave")
+ .description("joins given channel on current server")
+ .example("?leave [#CHANNEL_NAME]")
+ .build()
+ )
+ .addCommand(CommandDescription.builder()
+ .command("restart")
+ .description("trying to restart the bot on current server")
+ .example("?restart")
+ .build()
+ )
+ .addCommand(CommandDescription.builder()
+ .command("privmsg")
+ .description("send private message")
+ .example("?privmsg [YOUR_FRIEND_NICK]")
+ .build()
+ )
+ .addCommand(CommandDescription.builder()
+ .command("cmd")
+ .description("send RAW command to server (be careful with that shit!)")
+ .example("?cmd [ANY COMMAND WITH PARAMS]")
+ .build()
+ )
+ .addCommand(CommandDescription.builder()
+ .command("op|deop")
+ .description("give / take away OP user status")
+ .example("?op [#CHANNEL_NAME] [YOUR_FRIEND_NICK]\n?deop [#CHANNEL_NAME] [YOUR_HOSTILE_NICK]")
+ .build()
+ )
+ .addCommand(CommandDescription.builder()
+ .command("kick")
+ .description("kick user from channel")
+ .example("?kick [#CHANNEL_NAME] [YOUR_HOSTILE_NICK]")
+ .build()
+ )
+ .addCommand(CommandDescription.builder()
+ .command("set")
+ .description("set ON|OFF any of bot opportunity for channel\n\n"+
+ "Opportunities: \n\n"+
+ "autorejoin | auto-rejoin - auto rejoin channel on kicking\n"+
+ "bash | bashorg - bach.org quoting\n"+
+ "deferredmessages | deferred-messages | tell - saving and delivering deferred messages\n"+
+ "gs | googlesearch | google-search - search in Google\n"+
+ "grammar | grammarcorrection | grammar-correction - grammar checker (does not work in current version)\n"+
+ "hello | helloonjoin | hello-on-join - sending your phrase on user joins\n"+
+ "links | linkpreview | links-preview - sending titles of web pages by given URL\n"+
+ "logging | log - logging for channel\n"+
+ "regex | regexp | regexchecker | regexpchecker | regex-checker | regexp-checker - regular expression checker\n"+
+ "advice | advices - give yor friend advices\n"+
+ "calc | calculator - calculator\n"+
+ "quiz - quiz\n")
+ .example("?set [#CHANNEL_NAME] [OPPORTUNITY] [ON|OFF]")
+ .build()
+ )
+ ;
+ }
+
+
@Override
public void onJoin(JoinEvent event) throws Exception {
if (event.getChannel().getName().startsWith("#")) {
@@ -48,8 +127,6 @@ public class AdminListener extends ImprovedListenerAdapter {
}
}
-
-
@Override
public void onMessage(MessageEvent event) throws Exception {
Config config = getBotConfig(event);
@@ -247,8 +324,8 @@ public class AdminListener extends ImprovedListenerAdapter {
case "bashorg":
settings.setBashOrgEnabled(mode);
break;
- case "defferedmessages":
- case "deffered-messages":
+ case "deferredmessages":
+ case "deferred-messages":
case "tell" :
settings.setDeferredMessagesEnabled(mode);
break;
@@ -302,4 +379,5 @@ public class AdminListener extends ImprovedListenerAdapter {
channelSettingsService.save(settings);
}
}
+
}
diff --git a/src/main/java/ru/bvn13/jircbot/listeners/BashOrgListener.java b/src/main/java/ru/bvn13/jircbot/listeners/BashOrgListener.java
index f636e23..a831d38 100644
--- a/src/main/java/ru/bvn13/jircbot/listeners/BashOrgListener.java
+++ b/src/main/java/ru/bvn13/jircbot/listeners/BashOrgListener.java
@@ -4,25 +4,28 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
-import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.MessageEvent;
-import org.pircbotx.hooks.types.GenericMessageEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.bvn13.jircbot.bot.ImprovedListenerAdapter;
import ru.bvn13.jircbot.bot.JircBot;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
+import ru.bvn13.jircbot.documentation.DescriptionProvided;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+import ru.bvn13.jircbot.documentation.ListenerDescription;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
+import static ru.bvn13.jircbot.documentation.ListenerDescription.CommandDescription;
+
/**
* Created by bvn13 on 26.01.2018.
*/
@Component
-public class BashOrgListener extends ImprovedListenerAdapter {
+public class BashOrgListener extends ImprovedListenerAdapter implements DescriptionProvided {
private static final String COMMAND = "?bash";
private static final String USER_AGENT = "Mozilla/5.0";
@@ -30,6 +33,24 @@ public class BashOrgListener extends ImprovedListenerAdapter {
@Autowired
private ChannelSettingsService channelSettingsService;
+ @Autowired
+ public BashOrgListener(DocumentationProvider documentationProvider) {
+ this.registerDescription(documentationProvider);
+ }
+
+ @Override
+ public ListenerDescription getDescription() {
+ return ListenerDescription.create()
+ .setModuleName("BashOrgListener")
+ .setModuleDescription("Send bash.org quotes in channel on your request")
+ .addCommand(CommandDescription.builder()
+ .command("bash")
+ .description("Send random quote from bash.org to channel")
+ .example("?bash")
+ .build()
+ );
+ }
+
@Override
public void onMessage(final MessageEvent event) throws Exception {
@@ -79,7 +100,7 @@ public class BashOrgListener extends ImprovedListenerAdapter {
int responseCode = con.getResponseCode();
if (responseCode != 200) {
- throw new Exception("Не удалось получить цитату!");
+ throw new Exception("Could not get a random quote!");
}
String response = getDataFromConnection(con);
@@ -87,7 +108,7 @@ public class BashOrgListener extends ImprovedListenerAdapter {
Elements quotes = doc.select(".quote .text");
if (quotes.size() == 0) {
- throw new Exception("Не получено ни одной цитаты!");
+ throw new Exception("Nothing was received from bash.org!");
}
Element quote = quotes.get(0);
diff --git a/src/main/java/ru/bvn13/jircbot/listeners/DeferredMessagesListener.java b/src/main/java/ru/bvn13/jircbot/listeners/DeferredMessagesListener.java
index 553ff2e..6b00154 100644
--- a/src/main/java/ru/bvn13/jircbot/listeners/DeferredMessagesListener.java
+++ b/src/main/java/ru/bvn13/jircbot/listeners/DeferredMessagesListener.java
@@ -11,15 +11,20 @@ import ru.bvn13.jircbot.bot.JircBot;
import ru.bvn13.jircbot.database.entities.DeferredMessage;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
import ru.bvn13.jircbot.database.services.DeferredMessageService;
+import ru.bvn13.jircbot.documentation.DescriptionProvided;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+import ru.bvn13.jircbot.documentation.ListenerDescription;
import java.text.SimpleDateFormat;
import java.util.List;
+import static ru.bvn13.jircbot.documentation.ListenerDescription.CommandDescription;
+
/**
* Created by bvn13 on 31.01.2018.
*/
@Component
-public class DeferredMessagesListener extends ImprovedListenerAdapter {
+public class DeferredMessagesListener extends ImprovedListenerAdapter implements DescriptionProvided {
private static final String COMMAND = "?tell";
private static final String COMMAND_FORGET = "?forget";
@@ -33,6 +38,37 @@ public class DeferredMessagesListener extends ImprovedListenerAdapter {
@Autowired
private DeferredMessageService deferredMessageService;
+ @Autowired
+ public DeferredMessagesListener(DocumentationProvider documentationProvider) {
+ registerDescription(documentationProvider);
+ }
+
+ @Override
+ public ListenerDescription getDescription() {
+ return ListenerDescription.create()
+ .setModuleName("DeferredMessagesListener")
+ .setModuleDescription("This module is like answerphone - it stores your speech to any opponent into bot's database and when your opponent becomes online (joins channel and starts to speak) the bot notice him/her with your deferred messages.")
+ .addCommand(CommandDescription.builder()
+ .command("tell")
+ .description("Let the bot keep in mind your message to any opponent")
+ .example("?tell [YOUR_FRIEND] [YOUR MESSAGE]")
+ .build()
+ )
+ .addCommand(CommandDescription.builder()
+ .command("forget")
+ .description("If you do not want to read all messages deferred to you this command tells the bot do not disturb you this time")
+ .example("?forget")
+ .build()
+ )
+ .addCommand(CommandDescription.builder()
+ .command("read")
+ .description("Let the bot send you all the messages deferred to you this time in private dialogue")
+ .example("?read")
+ .build()
+ )
+ ;
+ }
+
@Override
public void onMessage(final MessageEvent event) throws Exception {
diff --git a/src/main/java/ru/bvn13/jircbot/listeners/GoogleSearchListener.java b/src/main/java/ru/bvn13/jircbot/listeners/GoogleSearchListener.java
index 2652a1a..4583e06 100644
--- a/src/main/java/ru/bvn13/jircbot/listeners/GoogleSearchListener.java
+++ b/src/main/java/ru/bvn13/jircbot/listeners/GoogleSearchListener.java
@@ -11,6 +11,9 @@ import org.springframework.stereotype.Component;
import ru.bvn13.jircbot.bot.ImprovedListenerAdapter;
import ru.bvn13.jircbot.bot.JircBot;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
+import ru.bvn13.jircbot.documentation.DescriptionProvided;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+import ru.bvn13.jircbot.documentation.ListenerDescription;
import ru.bvn13.jircbot.services.InternetAccessor;
import java.io.UnsupportedEncodingException;
@@ -18,11 +21,14 @@ import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;
+import static ru.bvn13.jircbot.documentation.ListenerDescription.CommandDescription;
+
+
/**
* Created by bvn13 on 06.02.2018.
*/
@Component
-public class GoogleSearchListener extends ImprovedListenerAdapter {
+public class GoogleSearchListener extends ImprovedListenerAdapter implements DescriptionProvided {
private static final String COMMAND = "?gs";
@@ -32,6 +38,24 @@ public class GoogleSearchListener extends ImprovedListenerAdapter {
@Autowired
private ChannelSettingsService channelSettingsService;
+ @Autowired
+ public GoogleSearchListener(DocumentationProvider documentationProvider) {
+ this.registerDescription(documentationProvider);
+ }
+
+ @Override
+ public ListenerDescription getDescription() {
+ return ListenerDescription.create()
+ .setModuleName("GoogleSearchListener")
+ .setModuleDescription("Make a search in Google for you")
+ .addCommand(CommandDescription.builder()
+ .command("gs")
+ .description("Search it")
+ .example("?gs [WHAT YOU WANT TO SEARCH]")
+ .build()
+ );
+ }
+
@Override
public void onMessage(final MessageEvent event) throws Exception {
@@ -91,5 +115,4 @@ public class GoogleSearchListener extends ImprovedListenerAdapter {
return String.format("%s / %s / %s", URLDecoder.decode(destinationUrl, "utf-8"), linkTitle, description);
}
-
}
diff --git a/src/main/java/ru/bvn13/jircbot/listeners/HelloOnJoinListener.java b/src/main/java/ru/bvn13/jircbot/listeners/HelloOnJoinListener.java
index e6f3ac0..4d6ab70 100644
--- a/src/main/java/ru/bvn13/jircbot/listeners/HelloOnJoinListener.java
+++ b/src/main/java/ru/bvn13/jircbot/listeners/HelloOnJoinListener.java
@@ -1,20 +1,24 @@
package ru.bvn13.jircbot.listeners;
-import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.JoinEvent;
-import org.pircbotx.hooks.events.MessageEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.bvn13.jircbot.bot.ImprovedListenerAdapter;
import ru.bvn13.jircbot.bot.JircBot;
import ru.bvn13.jircbot.database.entities.ChannelSettings;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
+import ru.bvn13.jircbot.documentation.DescriptionProvided;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+import ru.bvn13.jircbot.documentation.ListenerDescription;
+
+import static ru.bvn13.jircbot.documentation.ListenerDescription.CommandDescription;
+
/**
* Created by bvn13 on 25.01.2018.
*/
@Component
-public class HelloOnJoinListener extends ImprovedListenerAdapter {
+public class HelloOnJoinListener extends ImprovedListenerAdapter implements DescriptionProvided {
@Autowired
private ChannelSettingsService channelSettingsService;
@@ -35,9 +39,22 @@ public class HelloOnJoinListener extends ImprovedListenerAdapter {
if (channelSettings.getOnJoinMessage() != null && !channelSettings.getOnJoinMessage().isEmpty()) {
event.respond(channelSettings.getOnJoinMessage().replace("%nick%", event.getUser().getNick()));
} else {
- event.respond("Привет, " + event.getUser().getNick() + "!");
+ event.respond("Welcome, " + event.getUser().getNick() + "!");
}
}
+ @Autowired
+ public HelloOnJoinListener(DocumentationProvider documentationProvider) {
+ registerDescription(documentationProvider);
+ }
+
+ @Override
+ public ListenerDescription getDescription() {
+ return ListenerDescription.create()
+ .setModuleName("HelloOnJoinListener")
+ .setModuleDescription("The bot greets everyone joining the channel\n"+
+ "You can set the greeting text using Admin module")
+ ;
+ }
}
diff --git a/src/main/java/ru/bvn13/jircbot/listeners/LinkPreviewListener.java b/src/main/java/ru/bvn13/jircbot/listeners/LinkPreviewListener.java
index 4ecd31e..6dd30b2 100644
--- a/src/main/java/ru/bvn13/jircbot/listeners/LinkPreviewListener.java
+++ b/src/main/java/ru/bvn13/jircbot/listeners/LinkPreviewListener.java
@@ -1,34 +1,29 @@
package ru.bvn13.jircbot.listeners;
-import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.MessageEvent;
-import org.pircbotx.hooks.types.GenericMessageEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.bvn13.jircbot.bot.ImprovedListenerAdapter;
import ru.bvn13.jircbot.bot.JircBot;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
+import ru.bvn13.jircbot.documentation.DescriptionProvided;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+import ru.bvn13.jircbot.documentation.ListenerDescription;
import ru.bvn13.jircbot.services.InternetAccessor;
import java.io.*;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
-import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import static java.lang.System.out;
+import static ru.bvn13.jircbot.documentation.ListenerDescription.CommandDescription;
/**
* Created by bvn13 on 23.01.2018.
*/
@Component
-public class LinkPreviewListener extends ImprovedListenerAdapter {
+public class LinkPreviewListener extends ImprovedListenerAdapter implements DescriptionProvided {
@Autowired
private InternetAccessor internetAccessor;
@@ -38,6 +33,20 @@ public class LinkPreviewListener extends ImprovedListenerAdapter {
@Autowired
private ChannelSettingsService channelSettingsService;
+ @Autowired
+ public LinkPreviewListener(DocumentationProvider documentationProvider) {
+ registerDescription(documentationProvider);
+ }
+
+ @Override
+ public ListenerDescription getDescription() {
+ return ListenerDescription.create()
+ .setModuleName("LinkPreviewListener")
+ .setModuleDescription("With this module enabled into Admin module the bot will send the title of every URL found in messages posted in channel")
+ ;
+ }
+
+
@Override
public void onMessage(final MessageEvent event) throws Exception {
diff --git a/src/main/java/ru/bvn13/jircbot/listeners/LoggerListener.java b/src/main/java/ru/bvn13/jircbot/listeners/LoggerListener.java
index 2365958..40b0eaa 100644
--- a/src/main/java/ru/bvn13/jircbot/listeners/LoggerListener.java
+++ b/src/main/java/ru/bvn13/jircbot/listeners/LoggerListener.java
@@ -2,8 +2,6 @@ package ru.bvn13.jircbot.listeners;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.events.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.bvn13.jircbot.bot.ImprovedListenerAdapter;
@@ -11,14 +9,20 @@ import ru.bvn13.jircbot.bot.JircBot;
import ru.bvn13.jircbot.database.entities.IrcMessage;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
import ru.bvn13.jircbot.database.services.IrcMessageService;
+import ru.bvn13.jircbot.documentation.DescriptionProvided;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+import ru.bvn13.jircbot.documentation.ListenerDescription;
import java.util.*;
+import static ru.bvn13.jircbot.documentation.ListenerDescription.CommandDescription;
+
+
/**
* Created by bvn13 on 10.03.2018.
*/
@Component
-public class LoggerListener extends ImprovedListenerAdapter {
+public class LoggerListener extends ImprovedListenerAdapter implements DescriptionProvided {
@Autowired
@@ -29,7 +33,18 @@ public class LoggerListener extends ImprovedListenerAdapter {
private Map> onlineUsers = new HashMap<>();
+ @Autowired
+ public LoggerListener(DocumentationProvider documentationProvider) {
+ registerDescription(documentationProvider);
+ }
+ @Override
+ public ListenerDescription getDescription() {
+ return ListenerDescription.create()
+ .setModuleName("LoggerListener")
+ .setModuleDescription("This module logs all the messages into database for being able to observe in Web")
+ ;
+ }
public boolean isEnabled(Event event) throws Exception {
diff --git a/src/main/java/ru/bvn13/jircbot/listeners/PingPongListener.java b/src/main/java/ru/bvn13/jircbot/listeners/PingPongListener.java
index 2a8001c..1377552 100644
--- a/src/main/java/ru/bvn13/jircbot/listeners/PingPongListener.java
+++ b/src/main/java/ru/bvn13/jircbot/listeners/PingPongListener.java
@@ -2,11 +2,16 @@ package ru.bvn13.jircbot.listeners;
import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.MessageEvent;
-import org.pircbotx.hooks.types.GenericMessageEvent;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import ru.bvn13.jircbot.documentation.DescriptionProvided;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+import ru.bvn13.jircbot.documentation.ListenerDescription;
+
+import static ru.bvn13.jircbot.documentation.ListenerDescription.CommandDescription;
@Component
-public class PingPongListener extends ListenerAdapter {
+public class PingPongListener extends ListenerAdapter implements DescriptionProvided {
private static final String COMMAND = "?ping";
@@ -25,4 +30,22 @@ public class PingPongListener extends ListenerAdapter {
}
+ @Autowired
+ public PingPongListener(DocumentationProvider documentationProvider) {
+ registerDescription(documentationProvider);
+ }
+
+ @Override
+ public ListenerDescription getDescription() {
+ return ListenerDescription.create()
+ .setModuleName("PingPongListener")
+ .setModuleDescription("Try to play ping-pong if you not aware of is the bot here")
+ .addCommand(CommandDescription.builder()
+ .command("ping")
+ .description("Returns pong")
+ .example("?ping")
+ .build()
+ );
+ }
+
}
diff --git a/src/main/java/ru/bvn13/jircbot/listeners/RegexCheckerListener.java b/src/main/java/ru/bvn13/jircbot/listeners/RegexCheckerListener.java
index b2a137a..97dbd36 100644
--- a/src/main/java/ru/bvn13/jircbot/listeners/RegexCheckerListener.java
+++ b/src/main/java/ru/bvn13/jircbot/listeners/RegexCheckerListener.java
@@ -1,22 +1,26 @@
package ru.bvn13.jircbot.listeners;
-import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.WaitForQueue;
import org.pircbotx.hooks.events.MessageEvent;
-import org.pircbotx.hooks.types.GenericMessageEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.bvn13.jircbot.bot.ImprovedListenerAdapter;
import ru.bvn13.jircbot.bot.JircBot;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
+import ru.bvn13.jircbot.documentation.DescriptionProvided;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+import ru.bvn13.jircbot.documentation.ListenerDescription;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import static ru.bvn13.jircbot.documentation.ListenerDescription.CommandDescription;
+
+
@Component
-public class RegexCheckerListener extends ImprovedListenerAdapter {
+public class RegexCheckerListener extends ImprovedListenerAdapter implements DescriptionProvided {
private static final String COMMAND = "?regex ";
@@ -25,6 +29,24 @@ public class RegexCheckerListener extends ImprovedListenerAdapter {
@Autowired
private ChannelSettingsService channelSettingsService;
+ @Autowired
+ public RegexCheckerListener(DocumentationProvider documentationProvider) {
+ registerDescription(documentationProvider);
+ }
+
+ @Override
+ public ListenerDescription getDescription() {
+ return ListenerDescription.create()
+ .setModuleName("RegexCheckerListener")
+ .setModuleDescription("")
+ .addCommand(CommandDescription.builder()
+ .command("regex")
+ .description("Checks if given message with given regular expression")
+ .example("?regex")
+ .build()
+ );
+ }
+
@Override
public void onMessage(final MessageEvent event) throws Exception {
diff --git a/src/main/java/ru/bvn13/jircbot/listeners/StatisticsListener.java b/src/main/java/ru/bvn13/jircbot/listeners/StatisticsListener.java
index 9f86f7a..334f9b0 100644
--- a/src/main/java/ru/bvn13/jircbot/listeners/StatisticsListener.java
+++ b/src/main/java/ru/bvn13/jircbot/listeners/StatisticsListener.java
@@ -4,21 +4,25 @@ import org.pircbotx.hooks.events.MessageEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.bvn13.jircbot.bot.ImprovedListenerAdapter;
-import ru.bvn13.jircbot.bot.JircBot;
import ru.bvn13.jircbot.database.entities.dto.StatisticsDTO;
import ru.bvn13.jircbot.database.services.IrcMessageService;
+import ru.bvn13.jircbot.documentation.DescriptionProvided;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+import ru.bvn13.jircbot.documentation.ListenerDescription;
import ru.bvn13.jircbot.utilities.DateTimeUtility;
-import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
+import static ru.bvn13.jircbot.documentation.ListenerDescription.CommandDescription;
+
+
/**
* Created by bvn13 on 11.04.2018.
*/
@Component
-public class StatisticsListener extends ImprovedListenerAdapter {
+public class StatisticsListener extends ImprovedListenerAdapter implements DescriptionProvided {
private static final String COMMAND = "?stats";
@@ -30,6 +34,24 @@ public class StatisticsListener extends ImprovedListenerAdapter {
@Autowired
private IrcMessageService ircMessageService;
+ @Autowired
+ public StatisticsListener(DocumentationProvider documentationProvider) {
+ registerDescription(documentationProvider);
+ }
+
+ @Override
+ public ListenerDescription getDescription() {
+ return ListenerDescription.create()
+ .setModuleName("StatisticsListener")
+ .setModuleDescription("")
+ .addCommand(CommandDescription.builder()
+ .command("stats")
+ .description("Provides statistics for channel")
+ .example("?stats [D(ay)|M(onth)|Y(ear)|A(ll)] [ALL]")
+ .build()
+ );
+ }
+
@Override
public void onMessage(MessageEvent event) throws Exception {
diff --git a/src/main/java/ru/bvn13/jircbot/web/controllers/DocumentationController.java b/src/main/java/ru/bvn13/jircbot/web/controllers/DocumentationController.java
new file mode 100644
index 0000000..9dbcedd
--- /dev/null
+++ b/src/main/java/ru/bvn13/jircbot/web/controllers/DocumentationController.java
@@ -0,0 +1,29 @@
+package ru.bvn13.jircbot.web.controllers;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import ru.bvn13.jircbot.documentation.DocumentationProvider;
+
+/**
+ * Created by bvn13 on 28.10.2018.
+ */
+@Controller
+@RequestMapping("/docs")
+public class DocumentationController {
+
+ @Autowired
+ private DocumentationProvider documentationProvider;
+
+ @GetMapping
+ public String get(Model model) {
+
+ model.addAttribute("modules", documentationProvider.getModuleNames());
+ model.addAttribute("descriptions", documentationProvider.getDescriptors());
+
+ return "documentation";
+ }
+
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 4da54c3..a22c91b 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -32,4 +32,6 @@ spring.jpa.show-sql=false
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
-
+#hot restart
+#spring.devtools.restart.additional-paths=resources/
+spring.devtools.restart.additional-exclude=templates/**
diff --git a/src/main/resources/templates/documentation.html b/src/main/resources/templates/documentation.html
new file mode 100644
index 0000000..eac9ac7
--- /dev/null
+++ b/src/main/resources/templates/documentation.html
@@ -0,0 +1,56 @@
+
+
+
+
+ JIrcBot documentation
+
+
+
+JIrcBot documentation
+
+view project sources at GitHub repo
+
+
+
+
+
+
MODULE:
+
+
+
+
+
+
+
COMMANDS:
+
+
+
+ -
+
+
+
+
+
+
+ Description:
+
+
+ Example:
+
+
+
+
+
+
+
+
+
+
+
+ (c) bvn13
+ powered with PircBotX
+
+
+
+
\ No newline at end of file