bugs fixed

pull/6/head
Vyacheslav N. Boyko 2018-03-27 16:43:42 +03:00
parent fd06b97800
commit 94b0f62e82
19 changed files with 56 additions and 33 deletions

View File

@ -5,7 +5,7 @@ After=network.target
[Service]
User=bvn13
WorkingDirectory=/srv/jircbot
ExecStart=/usr/bin/java -jar /srv/jircbot/jircbot-1.1.8.jar
ExecStart=/usr/bin/java -jar /srv/jircbot/jircbot-1.2.1.jar
SuccessExitStatus=143
[Install]

View File

@ -6,7 +6,7 @@
<groupId>ru.bvn13</groupId>
<artifactId>jircbot</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<packaging>jar</packaging>

View File

@ -153,6 +153,9 @@ public class JircBot extends ListenerAdapter {
}
public static String extractServer(String s) {
String d[] = s.split("[\\.]");
return ""+d[d.length-2]+"."+d[d.length-1];
}
}

View File

@ -13,10 +13,13 @@ import javax.persistence.UniqueConstraint;
* Created by bvn13 on 31.01.2018.
*/
@Entity
@Table(name = "channel_settings", uniqueConstraints = {@UniqueConstraint(columnNames = {"channelName"}, name = "uniq_channel_settings_channel_name")})
@Table(name = "channel_settings", uniqueConstraints = {@UniqueConstraint(columnNames = {"serverHost", "channelName"}, name = "uniq_channel_settings_server_host_channel_name")})
@Getter @Setter
public class ChannelSettings extends BaseModel {
@Column(nullable = false, columnDefinition = "VARCHAR(255) DEFAULT ''")
private String serverHost;
@Column(nullable = false)
private String channelName;

View File

@ -7,5 +7,5 @@ import ru.bvn13.jircbot.database.entities.ChannelSettings;
* Created by bvn13 on 01.02.2018.
*/
public interface ChannelSettingsRepository extends JpaRepository<ChannelSettings, Long> {
ChannelSettings getFirstByChannelName(String channelName);
ChannelSettings getFirstByServerHostAndChannelName(String serverHost, String channelName);
}

View File

@ -14,19 +14,21 @@ public class ChannelSettingsService {
@Autowired
private ChannelSettingsRepository channelSettingsRepository;
public ChannelSettings getChannelSettings(String channelName) {
ChannelSettings settings = channelSettingsRepository.getFirstByChannelName(channelName);
public ChannelSettings getChannelSettings(String serverHost, String channelName) {
ChannelSettings settings = channelSettingsRepository.getFirstByServerHostAndChannelName(serverHost, channelName);
if (settings == null) {
settings = new ChannelSettings();
settings.setServerHost(serverHost);
settings.setChannelName(channelName);
}
return settings;
}
public void creaateChannelSettings(String channelName) {
ChannelSettings settings = channelSettingsRepository.getFirstByChannelName(channelName);
public void creaateChannelSettings(String serverHost, String channelName) {
ChannelSettings settings = channelSettingsRepository.getFirstByServerHostAndChannelName(serverHost, channelName);
if (settings == null) {
settings = new ChannelSettings();
settings.setServerHost(serverHost);
settings.setChannelName(channelName);
channelSettingsRepository.save(settings);
}

View File

@ -5,6 +5,7 @@ import org.pircbotx.hooks.events.PrivateMessageEvent;
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.config.JircBotConfiguration;
import ru.bvn13.jircbot.database.entities.ChannelSettings;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
@ -29,7 +30,7 @@ public class AdminListener extends ImprovedListenerAdapter {
@Override
public void onJoin(JoinEvent event) throws Exception {
if (event.getChannel().getName().startsWith("#")) {
channelSettingsService.creaateChannelSettings(event.getChannel().getName());
channelSettingsService.creaateChannelSettings(JircBot.extractServer(event.getUser().getServer()), event.getChannel().getName());
}
}
@ -74,8 +75,8 @@ public class AdminListener extends ImprovedListenerAdapter {
event.getBot().sendRaw().rawLine(command); event.respondPrivateMessage("done"); break;
case "set" :
try {
String args[] = commands[1].split(" ", 3); // set, channel, mode/hello-message
changeSettings(args[1], args[0], args[2]);
String args[] = commands[1].split(" ", 4); // set, server, channel, mode/hello-message
changeSettings(JircBot.extractServer(args[1]), args[2], args[0], args[3]);
event.respondPrivateMessage("done");
} catch (Exception e) {
event.respondPrivateMessage(e.getMessage());
@ -105,9 +106,11 @@ public class AdminListener extends ImprovedListenerAdapter {
return false;
}
private void changeSettings(String channelName, String set, String modeStr) {
private void changeSettings(String serverHost, String channelName, String set, String modeStr) {
if (set.equals("hello-message") || set.equals("hello-msg")) {
ChannelSettings settings = channelSettingsService.getChannelSettings(channelName);
ChannelSettings settings = channelSettingsService.getChannelSettings(serverHost, channelName);
settings.setOnJoinMessage(modeStr);
channelSettingsService.save(settings);
} else {
@ -116,7 +119,7 @@ public class AdminListener extends ImprovedListenerAdapter {
}
Boolean mode = modeStr.equals("on");
ChannelSettings settings = channelSettingsService.getChannelSettings(channelName);
ChannelSettings settings = channelSettingsService.getChannelSettings(serverHost, channelName);
switch (set.toLowerCase()) {
case "autorejoin":

View File

@ -8,6 +8,7 @@ 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.listeners.advices.AdviceEngine;
@ -26,7 +27,7 @@ public class AutoRejoinListener extends ImprovedListenerAdapter {
@Override
public void onKick(KickEvent event) throws Exception {
if (!channelSettingsService.getChannelSettings(event.getChannel().getName()).getAutoRejoinEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), event.getChannel().getName()).getAutoRejoinEnabled()) {
return;
}
@ -41,7 +42,7 @@ public class AutoRejoinListener extends ImprovedListenerAdapter {
@Override
public void onJoin(JoinEvent event) throws Exception {
if (!channelSettingsService.getChannelSettings(event.getChannel().getName()).getAutoRejoinEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), event.getChannel().getName()).getAutoRejoinEnabled()) {
return;
}

View File

@ -10,6 +10,7 @@ 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 java.io.BufferedReader;
@ -32,7 +33,7 @@ public class BashOrgListener extends ImprovedListenerAdapter {
@Override
public void onGenericMessage(final GenericMessageEvent event) throws Exception {
if (!channelSettingsService.getChannelSettings(getChannelName(event)).getBashOrgEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), getChannelName(event)).getBashOrgEnabled()) {
return;
}

View File

@ -6,6 +6,7 @@ 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.entities.DeferredMessage;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
import ru.bvn13.jircbot.database.services.DeferredMessageService;
@ -33,7 +34,7 @@ public class DeferredMessagesListener extends ImprovedListenerAdapter {
@Override
public void onGenericMessage(final GenericMessageEvent event) throws Exception {
if (!channelSettingsService.getChannelSettings(getChannelName(event)).getDeferredMessagesEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), getChannelName(event)).getDeferredMessagesEnabled()) {
return;
}

View File

@ -8,6 +8,7 @@ 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.services.InternetAccessor;
@ -34,7 +35,7 @@ public class GoogleSearchListener extends ImprovedListenerAdapter {
@Override
public void onGenericMessage(final GenericMessageEvent event) throws Exception {
if (!channelSettingsService.getChannelSettings(this.getChannelName(event)).getGoogleSearchEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), this.getChannelName(event)).getGoogleSearchEnabled()) {
return;
}

View File

@ -4,6 +4,7 @@ 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.entities.GrammarCorrection;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
import ru.bvn13.jircbot.database.services.GrammarCorrectionService;
@ -36,7 +37,7 @@ public class GrammarCorrectorListener extends ImprovedListenerAdapter {
@Override
public void onGenericMessage(final GenericMessageEvent event) throws Exception {
if (!channelSettingsService.getChannelSettings(this.getChannelName(event)).getGrammarCorrectionEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), this.getChannelName(event)).getGrammarCorrectionEnabled()) {
return;
}

View File

@ -6,6 +6,7 @@ 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;
@ -21,7 +22,7 @@ public class HelloOnJoinListener extends ImprovedListenerAdapter {
@Override
public void onJoin(final JoinEvent event) throws Exception {
ChannelSettings channelSettings = channelSettingsService.getChannelSettings(getChannelName(event));
ChannelSettings channelSettings = channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), getChannelName(event));
if (!channelSettings.getHelloOnJoinEnabled()) {
return;

View File

@ -6,6 +6,7 @@ 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.services.InternetAccessor;
@ -40,7 +41,7 @@ public class LinkPreviewListener extends ImprovedListenerAdapter {
@Override
public void onGenericMessage(final GenericMessageEvent event) throws Exception {
if (!channelSettingsService.getChannelSettings(getChannelName(event)).getLinkPreviewEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), getChannelName(event)).getLinkPreviewEnabled()) {
return;
}

View File

@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
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.IrcMessage;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
import ru.bvn13.jircbot.database.services.IrcMessageService;
@ -32,11 +33,11 @@ public class LoggerListener extends ImprovedListenerAdapter {
public boolean isEnabled(Event event) throws Exception {
return channelSettingsService.getChannelSettings(getChannelName(event)).getLoggingEnabled();
return channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), getChannelName(event)).getLoggingEnabled();
}
public boolean isEnabled(String channelName) throws Exception {
return channelSettingsService.getChannelSettings(channelName).getLoggingEnabled();
public boolean isEnabled(String serverName, String channelName) throws Exception {
return channelSettingsService.getChannelSettings(serverName, channelName).getLoggingEnabled();
}
// @Override
@ -71,7 +72,7 @@ public class LoggerListener extends ImprovedListenerAdapter {
for (String channelName : onlineUsers.keySet()) {
Set<String> users = onlineUsers.get(channelName);
if (users.contains(event.getUser().getNick().toLowerCase())) {
if (isEnabled(channelName)) {
if (isEnabled(JircBot.extractServer(event.getBot().getUserBot().getServer()), channelName)) {
log(event.getBot().getServerHostname(), channelName, "User " + event.getUser().getNick() + " quit (" + event.getReason() + ")");
users.remove(event.getUser().getNick().toLowerCase());
}
@ -101,7 +102,7 @@ public class LoggerListener extends ImprovedListenerAdapter {
for (String channelName : onlineUsers.keySet()) {
Set<String> users = onlineUsers.get(channelName);
if (users.contains(event.getUser().getNick().toLowerCase())) {
if (isEnabled(channelName)) {
if (isEnabled(JircBot.extractServer(event.getBot().getUserBot().getServer()), channelName)) {
log(event.getBot().getServerHostname(), channelName,"User "+event.getOldNick()+" is now known as "+event.getNewNick());
users.remove(event.getUser().getNick().toLowerCase());
}
@ -129,7 +130,7 @@ public class LoggerListener extends ImprovedListenerAdapter {
@Override
public void onOutput(OutputEvent event) throws Exception {
if (!isEnabled(event.getLineParsed().get(1))) return;
if (!isEnabled(JircBot.extractServer(event.getBot().getUserBot().getServer()), event.getLineParsed().get(1))) return;
switch (event.getLineParsed().get(0)) {
case "PRIVMSG" :
case "NOTICE" :

View File

@ -7,6 +7,7 @@ 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 java.util.HashMap;
@ -29,7 +30,7 @@ public class RegexCheckerListener extends ImprovedListenerAdapter {
//TODO: rework with FSM
if (!channelSettingsService.getChannelSettings(getChannelName(event)).getRegexCheckerEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), getChannelName(event)).getRegexCheckerEnabled()) {
return;
}

View File

@ -11,6 +11,7 @@ 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 java.io.BufferedReader;
@ -33,7 +34,7 @@ public class AdviceListener extends ImprovedListenerAdapter {
@Override
public void onGenericMessage(final GenericMessageEvent event) throws Exception {
if (!channelSettingsService.getChannelSettings(getChannelName(event)).getAdvicesEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), getChannelName(event)).getAdvicesEnabled()) {
return;
}

View File

@ -5,6 +5,7 @@ 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 java.util.HashMap;
@ -22,7 +23,7 @@ public class CalculatorListener extends ImprovedListenerAdapter {
@Override
public void onGenericMessage(final GenericMessageEvent event) throws Exception {
if (!channelSettingsService.getChannelSettings(getChannelName(event)).getCalculatorEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), getChannelName(event)).getCalculatorEnabled()) {
return;
}

View File

@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.bvn13.fsm.Exceptions.FSMException;
import ru.bvn13.jircbot.bot.ImprovedListenerAdapter;
import ru.bvn13.jircbot.bot.JircBot;
import ru.bvn13.jircbot.database.services.ChannelSettingsService;
import java.util.HashMap;
@ -26,7 +27,7 @@ public class QuizListener extends ImprovedListenerAdapter {
@Override
public void onGenericMessage(final GenericMessageEvent event) throws Exception {
if (!channelSettingsService.getChannelSettings(getChannelName(event)).getQuizEnabled()) {
if (!channelSettingsService.getChannelSettings(JircBot.extractServer(event.getBot().getUserBot().getServer()), getChannelName(event)).getQuizEnabled()) {
return;
}