-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from Ree6-Applications/feature/reddit-notifier
Reddit post Notifier.
- Loading branch information
Showing
7 changed files
with
423 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/main/java/de/presti/ree6/commands/impl/community/RedditNotifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package de.presti.ree6.commands.impl.community; | ||
|
||
import de.presti.ree6.commands.Category; | ||
import de.presti.ree6.commands.CommandEvent; | ||
import de.presti.ree6.commands.interfaces.Command; | ||
import de.presti.ree6.commands.interfaces.ICommand; | ||
import de.presti.ree6.main.Main; | ||
import net.dv8tion.jda.api.Permission; | ||
import net.dv8tion.jda.api.entities.TextChannel; | ||
import net.dv8tion.jda.api.interactions.commands.build.CommandData; | ||
|
||
/** | ||
* A Command to activate Reddit Notifications. | ||
*/ | ||
@Command(name = "redditnotifier", description = "Manage your Reddit-Notifier!", category = Category.COMMUNITY) | ||
public class RedditNotifier implements ICommand { | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public void onPerform(CommandEvent commandEvent) { | ||
if (!commandEvent.getGuild().getSelfMember().hasPermission(Permission.MANAGE_WEBHOOKS)) { | ||
Main.getInstance().getCommandManager().sendMessage("I need the permission `Manage Webhooks` to use this command!", commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
} | ||
|
||
if (commandEvent.isSlashCommand()) { | ||
Main.getInstance().getCommandManager().sendMessage("This Command doesn't support slash commands yet.", commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
return; | ||
} | ||
|
||
if(commandEvent.getArguments().length == 1) { | ||
if(commandEvent.getArguments()[0].equalsIgnoreCase("list")) { | ||
StringBuilder end = new StringBuilder("```\n"); | ||
|
||
for(String users : Main.getInstance().getSqlConnector().getSqlWorker().getAllSubreddits(commandEvent.getGuild().getId())) { | ||
end.append(users).append("\n"); | ||
} | ||
|
||
end.append("```"); | ||
|
||
Main.getInstance().getCommandManager().sendMessage(end.toString(), 10, commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
|
||
} else { | ||
Main.getInstance().getCommandManager().sendMessage("Please use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "redditnotifier list/add/remove", 5, commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
} | ||
} else if(commandEvent.getArguments().length == 3) { | ||
|
||
if (commandEvent.getMessage().getMentions().getChannels(TextChannel.class).isEmpty()) { | ||
Main.getInstance().getCommandManager().sendMessage("Please use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "redditnotifier add/remove Subreddit #Channel", 5, commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
return; | ||
} | ||
|
||
String name = commandEvent.getArguments()[1]; | ||
if (commandEvent.getArguments()[0].equalsIgnoreCase("add")) { | ||
commandEvent.getMessage().getMentions().getChannels(TextChannel.class).get(0).createWebhook("Ree6-RedditNotifier-" + name).queue(w -> Main.getInstance().getSqlConnector().getSqlWorker().addRedditWebhook(commandEvent.getGuild().getId(), w.getId(), w.getToken(), name)); | ||
Main.getInstance().getCommandManager().sendMessage("A Reddit Notifier has been created for the Subreddit " + name + "!", 5, commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
|
||
if (!Main.getInstance().getNotifier().isSubredditRegistered(name)) { | ||
Main.getInstance().getNotifier().registerSubreddit(name); | ||
} | ||
} else if (commandEvent.getArguments()[0].equalsIgnoreCase("remove")) { | ||
Main.getInstance().getCommandManager().sendMessage("Please use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "redditnotifier remove Subreddit", 5, commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
} else { | ||
Main.getInstance().getCommandManager().sendMessage("Please use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "redditnotifier add Subreddit #Channel", 5, commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
} | ||
} else if(commandEvent.getArguments().length == 2) { | ||
String name = commandEvent.getArguments()[1]; | ||
if(commandEvent.getArguments()[0].equalsIgnoreCase("remove")) { | ||
Main.getInstance().getSqlConnector().getSqlWorker().removeRedditWebhook(commandEvent.getGuild().getId(), name); | ||
Main.getInstance().getCommandManager().sendMessage("A Reddit Notifier has been removed from the Subreddit " + name + "!", 5, commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
|
||
if (Main.getInstance().getNotifier().isSubredditRegistered(name)) { | ||
Main.getInstance().getNotifier().unregisterSubreddit(name); | ||
} | ||
} else if (commandEvent.getArguments()[0].equalsIgnoreCase("add")) { | ||
Main.getInstance().getCommandManager().sendMessage("Please use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "redditnotifier add Subreddit #Channel", 5, commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
} else { | ||
Main.getInstance().getCommandManager().sendMessage("Please use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "redditnotifier remove Subreddit", 5, commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
} | ||
} else { | ||
Main.getInstance().getCommandManager().sendMessage("Please use " + Main.getInstance().getSqlConnector().getSqlWorker().getSetting(commandEvent.getGuild().getId(), "chatprefix").getStringValue() + "redditnotifier list/add/remove", 5, commandEvent.getChannel(), commandEvent.getInteractionHook()); | ||
} | ||
Main.getInstance().getCommandManager().deleteMessage(commandEvent.getMessage(), commandEvent.getInteractionHook()); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public CommandData getCommandData() { | ||
return null; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
@Override | ||
public String[] getAlias() { | ||
return new String[] { "yt", "ytnotifier" }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/de/presti/ree6/sql/entities/webhook/WebhookReddit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.presti.ree6.sql.entities.webhook; | ||
|
||
import de.presti.ree6.sql.base.annotations.Property; | ||
import de.presti.ree6.sql.base.annotations.Table; | ||
|
||
/** | ||
* SQL Entity for the Reddit-Webhooks. | ||
*/ | ||
@Table(name = "RedditNotify") | ||
public class WebhookReddit extends Webhook { | ||
|
||
/** | ||
* Name of the Channel. | ||
*/ | ||
@Property(name = "subreddit") | ||
private String subreddit; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public WebhookReddit() { | ||
} | ||
|
||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param guildId The guild ID. | ||
* @param subreddit The name of the Subreddit. | ||
* @param channelId The channel ID. | ||
* @param token The token. | ||
*/ | ||
public WebhookReddit(String guildId, String subreddit, String channelId, String token) { | ||
super(guildId, channelId, token); | ||
this.subreddit = subreddit; | ||
} | ||
|
||
/** | ||
* Get the name of the Subreddit. | ||
* @return the subreddit name. | ||
*/ | ||
public String getSubreddit() { | ||
return subreddit; | ||
} | ||
} |
Oops, something went wrong.