Skip to content

Commit

Permalink
More cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
EazyFTW committed Oct 3, 2020
1 parent 80d3c2d commit 376009c
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class PreorderCommand extends CommandModule {

Expand Down Expand Up @@ -102,10 +103,9 @@ public String obfuscateTransactionId(String transactionId) {
if(transactionId.equals("NONE") || transactionId.equals("something")) return "Unknown";
StringBuilder sb = new StringBuilder(transactionId);

StringBuilder length = new StringBuilder();
for(int i = 0; i < (int)(transactionId.length() / 1.5d); i++) length.append("\\*");
String length = IntStream.range(0, (int) (transactionId.length() / 1.5d)).mapToObj(i -> "\\*").collect(Collectors.joining());

sb.replace(0, (int)(transactionId.length() / 1.5d), length.toString());
sb.replace(0, (int)(transactionId.length() / 1.5d), length);
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ protected Query<Role> newQuery() {
return bot.getRoles("Staff");
}
};
private final DefinedQuery<TextChannel> STAFF_CHANNEL = new DefinedQuery<TextChannel>() {
@Override
protected Query<TextChannel> newQuery() {
return bot.getChannels("staff-chat");
}
};

public UserCheckCommand(TechDiscordBot bot) { super(bot); }

Expand All @@ -45,7 +39,7 @@ protected Query<TextChannel> newQuery() {
public DefinedQuery<Role> getRestrictedRoles() { return STAFF_ROLE; }

@Override
public DefinedQuery<TextChannel> getRestrictedChannels() { return STAFF_CHANNEL; }
public DefinedQuery<TextChannel> getRestrictedChannels() { return null; }

@Override
public CommandCategory getCategory() { return CommandCategory.ADMIN; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void onCommand(TextChannel channel, Message message, Member member, Strin
new TechEmbedBuilder("Wiki Help").setText("**Wiki Command Args**\n\n`!wiki` - *If in a plugin support channel, shows that Wiki, otherwise shows your owned plugin's wikis.*\n`!wiki -a` - *Shows all wikis.*\n`wiki -m` - *Shows your wikis if in a plugin support channel.*").send(channel);
return;
}

if(Plugin.isPluginChannel(channel)) {
if(args.length == 0) {
showCurrentChannel(channel);
Expand Down Expand Up @@ -72,6 +73,7 @@ public void showCurrentChannel(TextChannel channel) {
new TechEmbedBuilder("Wikis").error().setText(plugin.getEmoji().getAsMention() + " " + plugin.getRoleName() + " unfortunately does not have a wiki!").sendTemporary(channel, 10);
return;
}

new TechEmbedBuilder("Wikis").setText("*Showing the wiki of the support channel you're in.*\n\n" + plugin.getEmoji().getAsMention() + " " + plugin.getWiki() + "\n\nFor more info please execute the command `wiki help`.").send(channel);
}
}
Expand All @@ -80,20 +82,27 @@ public void showYourPlugins(Member member, TextChannel channel) {
boolean apiIsUp = TechDiscordBot.getSpigotAPI().isAvailable();
List<Plugin> plugins = Plugin.allWithWiki();
if(apiIsUp) plugins = Plugin.fromUser(member).stream().filter(Plugin::hasWiki).collect(Collectors.toList());

StringBuilder sb = new StringBuilder();
if(!apiIsUp) sb.append(TechDiscordBot.getBot().getEmotes("offline").first().getAsMention()).append(" **The API is not online, showing all plugins with a wiki.**\n\n");
if(apiIsUp) sb.append("*Showing all wikis of the plugins you own!*\n\n");
if(plugins.isEmpty()) sb.append("**You do not own of any of Tech's plugins, showing all wikis!**\n\n");
if(plugins.isEmpty()) plugins = Plugin.allWithWiki();
if(!apiIsUp)
sb.append(TechDiscordBot.getBot().getEmotes("offline").first().getAsMention()).append(" **The API is not online, showing all plugins with a wiki.**\n\n");
if(apiIsUp)
sb.append("*Showing all wikis of the plugins you own!*\n\n");
if(plugins.isEmpty())
sb.append("**You do not own of any of Tech's plugins, showing all wikis!**\n\n");
if(plugins.isEmpty())
plugins = Plugin.allWithWiki();

plugins.forEach(p -> sb.append(p.getEmoji().getAsMention()).append(" ").append(p.getWiki()).append("\n"));
new TechEmbedBuilder("Wikis").setText(sb.toString().substring(0, sb.toString().length() - 1)).send(channel);
new TechEmbedBuilder("Wikis").setText(sb.substring(0, sb.toString().length() - 1)).send(channel);
}

public void showAll(TextChannel channel) {
List<Plugin> plugins = Plugin.allWithWiki();
StringBuilder sb = new StringBuilder();
sb.append("*Showing all wikis!*\n\n");

plugins.forEach(p -> sb.append(p.getEmoji().getAsMention()).append(" ").append(p.getWiki()).append("\n"));
new TechEmbedBuilder("Wikis").setText(sb.toString().substring(0, sb.toString().length() - 1)).send(channel);
new TechEmbedBuilder("Wikis").setText(sb.substring(0, sb.toString().length() - 1)).send(channel);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.TechsCode.TechDiscordBot.module.modules;

import me.TechsCode.SpigotAPI.client.objects.Resource;
import me.TechsCode.SpigotAPI.client.objects.Review;
import me.TechsCode.SpigotAPI.client.objects.Update;
import me.TechsCode.TechDiscordBot.TechDiscordBot;
Expand Down Expand Up @@ -41,14 +40,15 @@ public void onEnable() {
TechDiscordBot.getSpigotAPI().getReviews().getStream().forEach(x -> announcedIds.add(x.getId()));
TechDiscordBot.getSpigotAPI().getUpdates().getStream().forEach(x -> announcedIds.add(x.getId()));
}
for(Resource resource : TechDiscordBot.getSpigotAPI().getResources().get()) {

Arrays.stream(TechDiscordBot.getSpigotAPI().getResources().get()).forEach(resource -> {
Plugin plugin = Plugin.fromId(resource.getId());
if(plugin == null) continue;
if (plugin == null) return;
Review[] newReviews = resource.getReviews().getStream().filter(x -> !announcedIds.contains(x.getId())).toArray(Review[]::new);
Update[] newUpdates = resource.getUpdates().getStream().filter(x -> !announcedIds.contains(x.getId())).toArray(Update[]::new);
Arrays.stream(newReviews).forEach(review -> printReview(plugin, review));
Arrays.stream(newUpdates).forEach(update -> printUpdate(plugin, update));
}
});
}
}).start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ protected Query<TextChannel> newQuery() {
}
};

private HashMap<String, Message> cachedMessages = new HashMap<>();
private final HashMap<String, Message> cachedMessages = new HashMap<>();

private final DefinedQuery<Role> STAFF_ROLE = new DefinedQuery<Role>() {
@Override
protected Query newQuery() {
protected Query<Role> newQuery() {
return bot.getRoles("Staff");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public EventsModule(TechDiscordBot bot) {
}

@Override
public void onEnable() {

}
public void onEnable() {}

@SubscribeEvent
public void memberJoin(GuildMemberJoinEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,21 @@ public void onChat(GuildMessageReceivedEvent e) {
SongodaPurchase purchase = TechDiscordBot.getSongodaPurchases().stream()
.filter(p -> p.getEmail() != null && p.getEmail().equals(e.getMessage().getContentDisplay())).findFirst().orElse(null);

email = purchase.getEmail();
username = purchase.getUsername();

lastInstructions = new TechEmbedBuilder("Transfer to SpigotMC from Songoda (" + e.getAuthor().getName() + ")")
.setText("We've detected that you've bought " + plugins + " using your linked discord account.\n\nCould you please provide your Spigot Username?")
.send(TRANSFER_CHANNEL.query().first());
if(purchase != null) {
email = purchase.getEmail();
username = purchase.getUsername();

lastInstructions = new TechEmbedBuilder("Transfer to SpigotMC from Songoda (" + e.getAuthor().getName() + ")")
.setText("We've detected that you've bought " + plugins + " using your linked discord account.\n\nCould you please provide your Spigot Username?")
.send(TRANSFER_CHANNEL.query().first());
}
}
}
}

public void sendTransferRequest(String songodaEmail, String songodaUsername, String spigotUsername, Member member) {
member.getGuild().addRoleToMember(member, member.getGuild().getRolesByName("Requested-Transfer", true).get(0)).queue();

new TechEmbedBuilder("Songoda Transfer Request")
.setText("Request by " + member.getAsMention() + "\n\nPlugins - " + plugins + "\nSpigot Username - " + spigotUsername + "\n\nSongoda Email - " + (songodaEmail == null ? "N/A" : songodaEmail) + "\nSongoda Username - " + (songodaUsername == null ? "N/A" : songodaUsername))
.send(TRANSFER_STAFF_CHANNEL.query().first());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public void triggerMessage(TextChannel channel, Member member) {
if (messages.containsValue(member.getId())) return;
TextChannel verificationChannel = bot.getChannel("695493411117072425");


TechEmbedBuilder teb = new TechEmbedBuilder().setText("Hello, " + member.getAsMention() + "! I've detected that you might be trying to get help in this channel! Please verify in " + verificationChannel.getAsMention() + " in order to get help, thanks!\n\n*If you are not trying to get help, you can delete this message by reacting to it!*")
.error();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public void startTimeout(String userId) {
} catch (InterruptedException e) {
e.printStackTrace();
}

if(this.selectionUserId == null || userId == null) return;
if(this.selectionUserId.equals(userId) && isSelection) {
new TechEmbedBuilder("Ticket - Error")
Expand Down Expand Up @@ -284,8 +285,9 @@ public void onReactionAdd(MessageReactionAddEvent e) {
sendIssueInstructions(e.getMember());
} else {
String ezMention = TechDiscordBot.getJDA().getUserById("130340486920667136").getAsMention();

new TechEmbedBuilder("Ticket Creation - Error")
.setText("This shouldn't be happening. Contact " + ezMention + " (EazyFTW#0001) immediately!")
.setText("This shouldn't be happening. Contact " + ezMention + " (ItsEazy#0001) immediately!")
.error()
.sendTemporary(channel, 10);
isSelection = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class VerificationModule extends Module {
};

private TextChannel channel;
private Message lastInstructions, apiNotAvailable;
private Message lastInstructions;

private List<String> verificationQueue;

Expand All @@ -43,7 +43,6 @@ public void onEnable() {
channel = VERIFICATION_CHANNEL.query().first();

lastInstructions = null;
//apiNotAvailable = null;
verificationQueue = new ArrayList<>();

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Expand All @@ -60,6 +59,7 @@ public void onDisable() {

public void sendInstructions() {
if(lastInstructions != null) lastInstructions.delete().complete();

TechEmbedBuilder howItWorksMessage = new TechEmbedBuilder("How It Works").setText("Type your SpigotMC Username in this Chat to verify.\n\nVerification not working? Feel free to contact a staff member in <#311178000026566658>.");
lastInstructions = howItWorksMessage.send(channel);
}
Expand Down Expand Up @@ -134,9 +134,11 @@ public void onMessage(GuildMessageReceivedEvent e) {
.setText(e.getAuthor().getName() + " has successfully verified their SpigotMC Account!")
.setThumbnail(avatarUrl)
.send(channel);

sendInstructions();
verificationQueue.remove(e.getAuthor().getId());
TechDiscordBot.getStorage().createVerification(userId, e.getAuthor().getId());

new TechEmbedBuilder("Verification Complete!")
.setText("You've been successfully verified!\n\nHere are your purchased plugins: " + Plugin.getMembersPluginsinEmojis(e.getMember()) + "\n\n*Your roles will be updated automatically from now on!*")
.setThumbnail(avatarUrl)
Expand Down

0 comments on commit 376009c

Please sign in to comment.