Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Move from notify blacklist to announcement mute role #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions src/main/java/com/almightyalpaca/discord/jdabutler/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.filter.ThresholdFilter;
import com.almightyalpaca.discord.jdabutler.commands.Dispatcher;
import com.almightyalpaca.discord.jdabutler.commands.commands.NotifyCommand;
import com.almightyalpaca.discord.jdabutler.config.Config;
import com.almightyalpaca.discord.jdabutler.config.ConfigFactory;
import com.almightyalpaca.discord.jdabutler.config.exception.KeyNotFoundException;
Expand Down Expand Up @@ -50,38 +49,18 @@ public class Bot

public static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor(MiscUtils.newThreadFactory("main-executor"));

public static Guild getGuildJda()
{
return Bot.jda.getGuildById("125227483518861312");
}

public static Role getRoleBots()
{
return Bot.getGuildJda().getRoleById("125616720156033024");
}

public static Role getRoleStaff()
{
return Bot.getGuildJda().getRoleById("169481978268090369");
}

public static boolean isAdmin(final User user)
{
final Member member = Bot.getGuildJda().getMember(user);
return member != null && member.getRoles().contains(Bot.getRoleStaff());
}

public static Role getRoleHelper()
{
return Bot.getGuildJda().getRoleById("183963327033114624");
final Member member = EntityLookup.getGuildJda().getMember(user);
return member != null && member.getRoles().contains(EntityLookup.getRoleStaff());
}

public static boolean isHelper(final User user)
{
if(isAdmin(user))
return true;
final Member member = Bot.getGuildJda().getMember(user);
return member != null && member.getRoles().contains(Bot.getRoleHelper());
final Member member = EntityLookup.getGuildJda().getMember(user);
return member != null && member.getRoles().contains(EntityLookup.getRoleHelper());
}

public static void main(final String[] args) throws JsonIOException, JsonSyntaxException, WrongTypeException, KeyNotFoundException, IOException, LoginException, IllegalArgumentException, InterruptedException, SecurityException
Expand Down Expand Up @@ -136,8 +115,6 @@ public static void main(final String[] args) throws JsonIOException, JsonSyntaxE
root.addAppender(appender);
}

NotifyCommand.reloadBlacklist(null);

EXECUTOR.submit(() ->
{
VersionCheckerRegistry.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.almightyalpaca.discord.jdabutler;

import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Role;

public class EntityLookup
{

/*
JDA Guild
*/
public static final long GUILD_JDA_ID = 125227483518861312L;
public static Guild getGuildJda()
{
return Bot.jda.getGuildById(GUILD_JDA_ID);
}

//ROLES
public static final long ROLE_BOTS_ID = 125616720156033024L;
public static Role getRoleBots()
{
return getGuildJda().getRoleById(ROLE_BOTS_ID);
}

public static final long ROLE_STAFF_ID = 169481978268090369L;
public static Role getRoleStaff()
{
return getGuildJda().getRoleById(ROLE_STAFF_ID);
}

public static final long ROLE_HELPERS_ID = 183963327033114624L;
public static Role getRoleHelper()
{
return getGuildJda().getRoleById(ROLE_HELPERS_ID);
}

//todo
public static final long ROLE_ANNOUNCEMUTE_ID = -1L;
public static Role getRoleAnnounceMute()
{
return getGuildJda().getRoleById(ROLE_ANNOUNCEMUTE_ID);
}


/*
DAPI Guild
*/
public static final long GUILD_DAPI_ID = 81384788765712384L;

//CHANNELS/CATEGORIES
public static final long CHANNEL_DAPI_JDA_ID = 381889648827301889L;
public static final long CATEGORY_DAPI_TESTING_ID = 356505966201798656L;


/*
USERS
*/
public static final long MAIN_BUTLER_ID = 189074312974696448L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public void onGuildMemberJoin(final GuildMemberJoinEvent event)
if(user.isBot())
{
final AuditableRestAction<Void> action = guild.getController()
.addSingleRoleToMember(member, Bot.getRoleBots()).reason("Auto Role");
final String message = String.format("Added %#s (%d) to %s", user, user.getIdLong(), Bot.getRoleBots().getName());
.addSingleRoleToMember(member, EntityLookup.getRoleBots()).reason("Auto Role");
final String message = String.format("Added %#s (%d) to %s", user, user.getIdLong(), EntityLookup.getRoleBots().getName());
action.queue(
v -> Bot.LOG.info(message),
ex -> Bot.LOG.error("Could not add User {} to role {}", user.getName(), Bot.getRoleBots().getName(), ex)
ex -> Bot.LOG.error("Could not add User {} to role {}", user.getName(), EntityLookup.getRoleBots().getName(), ex)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.almightyalpaca.discord.jdabutler.commands;

import com.almightyalpaca.discord.jdabutler.Bot;
import com.almightyalpaca.discord.jdabutler.EntityLookup;
import com.almightyalpaca.discord.jdabutler.commands.commands.*;
import com.almightyalpaca.discord.jdabutler.commands.commands.moderation.SoftbanCommand;
import com.almightyalpaca.discord.jdabutler.util.MiscUtils;
Expand Down Expand Up @@ -78,9 +79,9 @@ public void onGuildMessageReceived(final GuildMessageReceivedEvent event)

final TextChannel channel = event.getChannel();

if (channel.getGuild().getIdLong() == 81384788765712384L // if DAPI
&& !(channel.getIdLong() == 381889648827301889L // and not #java_jda
|| (channel.getParent() != null && channel.getParent().getIdLong() == 356505966201798656L))) // or not testing category
if (channel.getGuild().getIdLong() == EntityLookup.GUILD_DAPI_ID // if DAPI
&& !(channel.getIdLong() == EntityLookup.CHANNEL_DAPI_JDA_ID // and not #java_jda
|| (channel.getParent() != null && channel.getParent().getIdLong() == EntityLookup.CATEGORY_DAPI_TESTING_ID))) // and not testing category
return; // ignore message

if (message.toLowerCase().startsWith(prefix.toLowerCase()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.almightyalpaca.discord.jdabutler.commands.commands;

import com.almightyalpaca.discord.jdabutler.Bot;
import com.almightyalpaca.discord.jdabutler.EntityLookup;
import com.almightyalpaca.discord.jdabutler.util.EmbedUtil;
import com.almightyalpaca.discord.jdabutler.commands.Command;
import com.almightyalpaca.discord.jdabutler.util.MiscUtils;
Expand All @@ -26,7 +27,7 @@ public class AnnouncementCommand extends Command
@Override
public void dispatch(final User sender, final TextChannel channel, final Message message, final String content, final GuildMessageReceivedEvent event)
{
if(!channel.getGuild().equals(Bot.getGuildJda()))
if(!channel.getGuild().equals(EntityLookup.getGuildJda()))
{
this.sendFailed(message);
return;
Expand Down
Loading