forked from ya64/Toybot
-
Notifications
You must be signed in to change notification settings - Fork 0
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 ya64#30 from TheCaptainYaya/tag-dev
Add tags
- Loading branch information
Showing
8 changed files
with
348 additions
and
36 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
58 changes: 58 additions & 0 deletions
58
src/main/java/com/jagrosh/vortex/commands/general/ListTagsCmd.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,58 @@ | ||
package com.jagrosh.vortex.commands.general; | ||
|
||
import com.jagrosh.jdautilities.command.Command; | ||
import com.jagrosh.jdautilities.command.CommandEvent; | ||
import com.jagrosh.vortex.Vortex; | ||
import net.dv8tion.jda.core.Permission; | ||
import net.dv8tion.jda.core.entities.Role; | ||
|
||
import java.util.List; | ||
|
||
public class ListTagsCmd extends Command | ||
{ | ||
private final Vortex vortex; | ||
|
||
public ListTagsCmd(Vortex vortex) | ||
{ | ||
this.name = "listtags"; | ||
this.arguments = ""; | ||
this.help = "lists all tags"; | ||
this.guildOnly = true; | ||
this.vortex = vortex; | ||
} | ||
|
||
@Override | ||
public void execute(CommandEvent event) | ||
{ | ||
Role rtcRole = vortex.getDatabase().settings.getSettings(event.getGuild()).getRtcRole(event.getGuild()); | ||
Role modRole = vortex.getDatabase().settings.getSettings(event.getGuild()).getModeratorRole(event.getGuild()); | ||
|
||
/* Checks if the user has permission to use tags. People may use tags if they meet any of the following criteria: | ||
- Has the manage messages permission | ||
- Has the predesignated moderator role | ||
- Is an RTC | ||
*/ | ||
if ( | ||
!event.getMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_MANAGE) && | ||
!(modRole != null && event.getMember().getRoles().contains(modRole)) && | ||
!(rtcRole != null && event.getMember().getRoles().contains(rtcRole)) | ||
) | ||
return; | ||
|
||
List<String> tags = vortex.getDatabase().tags.getTagNames(event.getGuild()); | ||
|
||
if (tags.isEmpty()) | ||
{ | ||
event.reply("There are no tags on this server"); | ||
return; | ||
} | ||
|
||
String response = tags.get(0).toUpperCase().substring(0,1) + tags.get(0).substring(1) + (tags.size() != 1 ? ", " : "."); | ||
for (int i = 1; i < tags.size(); i++) | ||
{ | ||
response += tags.get(i) + (i == tags.size() - 1 ? "." : ", "); | ||
} | ||
|
||
event.reply(response); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/jagrosh/vortex/commands/general/TagCmd.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,46 @@ | ||
package com.jagrosh.vortex.commands.general; | ||
|
||
import com.jagrosh.jdautilities.command.Command; | ||
import com.jagrosh.jdautilities.command.CommandEvent; | ||
import com.jagrosh.vortex.Vortex; | ||
import net.dv8tion.jda.core.Permission; | ||
import net.dv8tion.jda.core.entities.Role; | ||
|
||
public class TagCmd extends Command | ||
{ | ||
private final Vortex vortex; | ||
|
||
public TagCmd(Vortex vortex) { | ||
this.vortex = vortex; | ||
this.name = "tag"; | ||
this.arguments = "<tagName>"; | ||
this.help = "displays a tag"; | ||
} | ||
|
||
@Override | ||
protected void execute(CommandEvent event) | ||
{ | ||
Role rtcRole = vortex.getDatabase().settings.getSettings(event.getGuild()).getRtcRole(event.getGuild()); | ||
Role modRole = vortex.getDatabase().settings.getSettings(event.getGuild()).getModeratorRole(event.getGuild()); | ||
|
||
/* Checks if the user has permission to use tags. People may use tags if they meet any of the following criteria: | ||
- Has the manage messages permission | ||
- Has the predesignated moderator role | ||
- Is an RTC | ||
*/ | ||
if ( | ||
!event.getMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_MANAGE) && | ||
!(modRole != null && event.getMember().getRoles().contains(modRole)) && | ||
!(rtcRole != null && event.getMember().getRoles().contains(rtcRole)) | ||
) | ||
return; | ||
|
||
String tagName = event.getArgs().trim().split(" ")[0]; | ||
String tagValue = vortex.getDatabase().tags.getTagValue(event.getGuild(), tagName); | ||
|
||
if (tagValue == null) | ||
return; | ||
|
||
event.reply(tagValue); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/jagrosh/vortex/commands/moderation/AddTagCmd.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,47 @@ | ||
package com.jagrosh.vortex.commands.moderation; | ||
|
||
import com.jagrosh.jdautilities.command.CommandEvent; | ||
import com.jagrosh.vortex.Vortex; | ||
import com.jagrosh.vortex.commands.ModCommand; | ||
import net.dv8tion.jda.core.Permission; | ||
|
||
public class AddTagCmd extends ModCommand | ||
{ | ||
public AddTagCmd(Vortex vortex) | ||
{ | ||
super(vortex, Permission.MESSAGE_MANAGE); | ||
this.name = "addtag"; | ||
this.arguments = "<tagName> [tagValue]"; | ||
this.help = "adds a tag"; | ||
this.guildOnly = true; | ||
} | ||
|
||
@Override | ||
protected void execute(CommandEvent event) | ||
{ | ||
String args = event.getArgs().trim(); | ||
String[] argsArray = args.split(" "); | ||
String tagName; | ||
String tagValue; | ||
|
||
try | ||
{ | ||
tagName = argsArray[0]; | ||
} | ||
catch(IndexOutOfBoundsException e) | ||
{ | ||
event.reply("Please enter a tag name to create"); | ||
return; | ||
} | ||
|
||
tagValue = args.substring(argsArray[0].length() + 1); | ||
if (tagValue.isEmpty()) | ||
{ | ||
event.reply("Please enter a value for the tag"); | ||
return; | ||
} | ||
|
||
vortex.getDatabase().tags.addTagValue(event.getGuild(), tagName, tagValue); | ||
event.reply("Successfully created the `" + tagName + "` tag!"); | ||
} | ||
} |
Oops, something went wrong.