Add Daily Madame on preference

This commit is contained in:
Sebastien 2018-06-06 15:51:59 +02:00
parent 9a00cba123
commit bc4c8245c4
5 changed files with 86 additions and 44 deletions

View File

@ -209,6 +209,23 @@ public class Preference implements Commande {
Message sended = event.getTextChannel().sendMessage(EmbedMessageUtils.buildStandar(eb)).complete(); Message sended = event.getTextChannel().sendMessage(EmbedMessageUtils.buildStandar(eb)).complete();
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start(); new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
break; break;
case "daily_madame":
value = value.replaceAll(" ", "");
if(value.toLowerCase().equals("true") || value.toLowerCase().equals("false")){
boolean result = Boolean.parseBoolean(value);
pref.setDailyMadame(result);
pref = guildPreferenceRepository.save(pref);
EmbedBuilder ebd = new EmbedBuilder().addField(":ok: Ok :ok:","",false).addField("> Daily Madame", "Activate daily madame message\n```java\n" + String.valueOf(value) + "```", false).setColor(Color.green);
Message sendedm = event.getTextChannel().sendMessage(EmbedMessageUtils.buildStandar(ebd)).complete();
new MessageTimeOut(MainBot.messageTimeOut, sendedm, event.getMessage()).start();
}else{
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nWrong value, expect `true` or `false`\n\nMore info with `//help preference`"));
Message sendedm = event.getTextChannel().sendMessage(msg).complete();
new MessageTimeOut(MainBot.messageTimeOut, sendedm, event.getMessage()).start();
}
break;
default: default:
MessageEmbed msg2 = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nUnknown id.\n\nUse `//preference` to see list")); MessageEmbed msg2 = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nUnknown id.\n\nUse `//preference` to see list"));
Message sended2 = event.getTextChannel().sendMessage(msg2).complete(); Message sended2 = event.getTextChannel().sendMessage(msg2).complete();

View File

@ -27,8 +27,11 @@ public class GuildPreferenceEntity {
private String defaultRoleId; private String defaultRoleId;
private boolean dailyMadame;
public GuildPreferenceEntity(String guildId, boolean antiSpam, boolean welcome, String welcomeMessage, String welcomeChanelID, boolean defaultRole, String defaultRoleId) {
public GuildPreferenceEntity(String guildId, boolean antiSpam, boolean welcome, String welcomeMessage, String welcomeChanelID, boolean defaultRole, String defaultRoleId, boolean dailyMadame) {
this.guildId = guildId; this.guildId = guildId;
this.antiSpam = antiSpam; this.antiSpam = antiSpam;
this.welcome = welcome; this.welcome = welcome;
@ -36,13 +39,14 @@ public class GuildPreferenceEntity {
this.welcomeChanelID = welcomeChanelID; this.welcomeChanelID = welcomeChanelID;
this.defaultRole = defaultRole; this.defaultRole = defaultRole;
this.defaultRoleId = defaultRoleId; this.defaultRoleId = defaultRoleId;
this.dailyMadame = dailyMadame;
} }
public GuildPreferenceEntity(){} public GuildPreferenceEntity(){}
public static GuildPreferenceEntity getDefault(Guild guild){ public static GuildPreferenceEntity getDefault(Guild guild){
return new GuildPreferenceEntity(guild.getId(), false, false, "Welcome to this awesome server @name! ", " ", false, " "); return new GuildPreferenceEntity(guild.getId(), false, false, "Welcome to this awesome server @name! ", " ", false, " ", true);
} }
public Integer getId() { public Integer getId() {
@ -108,4 +112,12 @@ public class GuildPreferenceEntity {
public void setDefaultRole(boolean defaultRole) { public void setDefaultRole(boolean defaultRole) {
this.defaultRole = defaultRole; this.defaultRole = defaultRole;
} }
public boolean isDailyMadame() {
return dailyMadame;
}
public void setDailyMadame(boolean dailyMadame) {
this.dailyMadame = dailyMadame;
}
} }

View File

@ -91,13 +91,6 @@ public class Init {
DayListener dayListener = DayListener.getInstance();
dayListener.addListener(new ResetSpam());
dayListener.addListener(new DailyMadame());
dayListener.start();
logger.debug("-----------------FIN INITIALISATION-----------------"); logger.debug("-----------------FIN INITIALISATION-----------------");
@ -115,6 +108,10 @@ public class Init {
static void polish(JDA jda){ static void polish(JDA jda){
CommandLoader.load(); CommandLoader.load();
ApiCommandLoader.load(); ApiCommandLoader.load();
DayListener dayListener = DayListener.getInstance();
dayListener.addListener(new ResetSpam());
dayListener.addListener(new DailyMadame());
dayListener.start();
jda.addEventListener(new BotListener()); jda.addEventListener(new BotListener());
jda.getPresence().setPresence(OnlineStatus.ONLINE, Game.playing("bot.seb6596.ovh")); jda.getPresence().setPresence(OnlineStatus.ONLINE, Game.playing("bot.seb6596.ovh"));

View File

@ -1,13 +1,16 @@
package net.Broken.Tools.DayListener.Listeners; package net.Broken.Tools.DayListener.Listeners;
import net.Broken.Commands.Over18.Madame; import net.Broken.Commands.Over18.Madame;
import net.Broken.DB.Repository.GuildPreferenceRepository;
import net.Broken.MainBot; import net.Broken.MainBot;
import net.Broken.SpringContext;
import net.Broken.Tools.DayListener.NewDayListener; import net.Broken.Tools.DayListener.NewDayListener;
import net.Broken.Tools.Redirection; import net.Broken.Tools.Redirection;
import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.TextChannel; import net.dv8tion.jda.core.entities.TextChannel;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.context.ApplicationContext;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -16,6 +19,14 @@ import java.util.List;
* Daily Listener for DailyMadame * Daily Listener for DailyMadame
*/ */
public class DailyMadame implements NewDayListener{ public class DailyMadame implements NewDayListener{
private GuildPreferenceRepository guildPreferenceRepository;
public DailyMadame() {
ApplicationContext context = SpringContext.getAppContext();
guildPreferenceRepository = (GuildPreferenceRepository) context.getBean("guildPreferenceRepository");
}
private Logger logger = LogManager.getLogger(); private Logger logger = LogManager.getLogger();
@Override @Override
public void onNewDay() { public void onNewDay() {
@ -29,6 +40,7 @@ public class DailyMadame implements NewDayListener{
boolean error=false; boolean error=false;
int errorCp=0; int errorCp=0;
logger.debug(guild.getName()); logger.debug(guild.getName());
if(guildPreferenceRepository.findByGuildId(guild.getId()).get(0).isDailyMadame()){
for(TextChannel iterator : guild.getTextChannels()) for(TextChannel iterator : guild.getTextChannels())
{ {
if(iterator.isNSFW()){ if(iterator.isNSFW()){
@ -67,6 +79,8 @@ public class DailyMadame implements NewDayListener{
else { else {
logger.info("No NSFW chanel found for " + guild.getName() + ", ignoring it!"); logger.info("No NSFW chanel found for " + guild.getName() + ", ignoring it!");
} }
}
} }

View File

@ -117,7 +117,9 @@ public class EmbedMessageUtils {
.addField("> Default Role ID", "Role id for auto move\n```java\n" + guildPref.getDefaultRoleId() + "```Edit: :unlock:\nKey: default_role_id", false) .addField("> Default Role ID", "Role id for auto move\n```java\n" + guildPref.getDefaultRoleId() + "```Edit: :unlock:\nKey: default_role_id", false)
.addField("> Welcome", "Activate welcome message\n```java\n" + String.valueOf(guildPref.isWelcome()) + "```Edit: :unlock:\nKey: welcome", false) .addField("> Welcome", "Activate welcome message\n```java\n" + String.valueOf(guildPref.isWelcome()) + "```Edit: :unlock:\nKey: welcome", false)
.addField("> Welcome chanel ID", "Chane id for welcome message\n```" + guildPref.getWelcomeChanelID() + "```Edit: :unlock:\nKey: welcome_chanel_id", false) .addField("> Welcome chanel ID", "Chane id for welcome message\n```" + guildPref.getWelcomeChanelID() + "```Edit: :unlock:\nKey: welcome_chanel_id", false)
.addField("> Welcome message", "Welcome message (@name for mention)\n```markdown\n" + guildPref.getWelcomeMessage() + "```Edit: :unlock:\nKey: welcome_message", false); .addField("> Welcome message", "Welcome message (@name for mention)\n```markdown\n" + guildPref.getWelcomeMessage() + "```Edit: :unlock:\nKey: welcome_message", false)
.addField("> Daily Madame", "Activate daily madame message\n```java\n" + String.valueOf(guildPref.isWelcome()) + "```Edit: :unlock:\nKey: daily_madame", false);
return buildStandar(messageB); return buildStandar(messageB);
} }