Skip to content

Commit 5635d65

Browse files
authored
Merge pull request #172 from KittyBot-Org/development
some bug fixes & restrict emote command
2 parents 55894be + 1cd2402 commit 5635d65

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@ repositories {
2727

2828
dependencies {
2929
// discord/jda related
30-
implementation 'net.dv8tion:JDA:4.2.0_214'
30+
implementation 'net.dv8tion:JDA:4.2.0_222'
3131
implementation 'com.jagrosh:jda-utilities:3.0.5'
3232

3333
// audio
3434
implementation("com.github.KittyBot-Org:Lavalink-Client:f7842dfdb4") {
3535
exclude group: 'com.sedmelluq', module: 'lavaplayer'
3636
}
37-
implementation 'com.sedmelluq:lavaplayer:1.3.59'
37+
implementation 'com.sedmelluq:lavaplayer:1.3.62'
3838
implementation 'com.sedmelluq:jda-nas:1.1.0'
3939

4040
// database
4141
implementation 'com.zaxxer:HikariCP:3.4.5'
42-
implementation 'org.jooq:jooq:3.14.2'
42+
implementation 'org.jooq:jooq:3.14.4'
4343

4444
implementation 'org.postgresql:postgresql:42.2.18'
4545
jooqGenerator 'org.postgresql:postgresql:42.2.18'
4646

4747
// logging
4848
implementation 'ch.qos.logback:logback-classic:1.3.0-alpha5'
49-
implementation 'io.sentry:sentry-logback:3.1.3'
49+
implementation 'io.sentry:sentry-logback:3.2.0'
5050

5151
// eval
5252
implementation 'org.codehaus.groovy:groovy-jsr223:3.0.6'
@@ -57,11 +57,12 @@ dependencies {
5757
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'
5858

5959
// other
60-
implementation 'io.javalin:javalin:3.11.2'
60+
implementation 'io.javalin:javalin:3.12.0'
6161
implementation 'io.github.classgraph:classgraph:4.8.90'
6262
}
6363

6464
jooq {
65+
version = '3.14.4'
6566
configurations {
6667
main {
6768
generateSchemaSourceOnCompilation = false

src/main/java/de/kittybot/kittybot/WebService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.jsonwebtoken.security.Keys;
2525
import net.dv8tion.jda.api.Permission;
2626
import net.dv8tion.jda.api.entities.Guild;
27+
import net.dv8tion.jda.api.exceptions.HttpException;
2728
import net.dv8tion.jda.api.utils.data.DataArray;
2829
import net.dv8tion.jda.api.utils.data.DataObject;
2930

@@ -104,6 +105,9 @@ private void login(Context ctx){
104105
var session = (DashboardSession) O_AUTH_2_CLIENT.startSession(code, state, "", SCOPES).complete();
105106
created(ctx, DataObject.empty().put("token", Jwts.builder().setIssuedAt(new Date()).setSubject(session.getUserId()).signWith(KEY).compact()));
106107
}
108+
catch(HttpException e){
109+
error(ctx, 429, "Don't spam login");
110+
}
107111
catch(InvalidStateException e){
108112
error(ctx, 401, "State invalid/expired. Please try again");
109113
}

src/main/java/de/kittybot/kittybot/cache/GuildCache.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import de.kittybot.kittybot.objects.session.DashboardSession;
77
import net.dv8tion.jda.api.Permission;
88
import net.dv8tion.jda.api.entities.Guild;
9+
import net.dv8tion.jda.api.exceptions.HttpException;
910

1011
import java.io.IOException;
1112
import java.util.*;
@@ -18,7 +19,7 @@ public class GuildCache{
1819

1920
private GuildCache(){}
2021

21-
public static List<GuildData> getGuilds(final DashboardSession dashboardSession) throws IOException{
22+
public static List<GuildData> getGuilds(final DashboardSession dashboardSession) throws IOException, HttpException{
2223
var userId = dashboardSession.getUserId();
2324
var userGuilds = USER_GUILD_CACHE.get(userId);
2425
if(userGuilds == null || userGuilds.isEmpty()){
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package de.kittybot.kittybot.commands.utilities;
2+
3+
import de.kittybot.kittybot.objects.command.ACommand;
4+
import de.kittybot.kittybot.objects.command.Category;
5+
import de.kittybot.kittybot.objects.command.CommandContext;
6+
import net.dv8tion.jda.api.Permission;
7+
8+
import java.util.HashSet;
9+
10+
11+
public class RestrictEmoteCommand extends ACommand{
12+
13+
public static final String COMMAND = "restrictemote";
14+
public static final String USAGE = "restrictemote <:Emote:, @Role, ...>";
15+
public static final String DESCRIPTION = "Restricts a given emote to one or more roles";
16+
protected static final String[] ALIASES = {"restricte", "remote", "re"};
17+
protected static final Category CATEGORY = Category.UTILITIES;
18+
19+
public RestrictEmoteCommand(){
20+
super(COMMAND, USAGE, DESCRIPTION, ALIASES, CATEGORY);
21+
}
22+
23+
@Override
24+
public void run(CommandContext ctx){
25+
var emotes = ctx.getMessage().getEmotes();
26+
var roles = ctx.getMentionedRoles();
27+
if(emotes.isEmpty() || roles.isEmpty()){
28+
sendUsage(ctx);
29+
return;
30+
}
31+
if(!ctx.getSelfMember().hasPermission(Permission.MANAGE_EMOTES)){
32+
sendError(ctx, "I can't manage emotes due to lack of permissions. Please give me the `MANAGE_EMOTES` permission to use this command.");
33+
return;
34+
}
35+
var emote = emotes.get(0);
36+
emote.getManager().setRoles(new HashSet<>(roles)).queue(success -> sendSuccess(ctx, "Successfully set roles"), error -> sendError(ctx, "Failed to set roles.\nPlease try again or report this in our discord"));
37+
}
38+
39+
}

src/main/java/de/kittybot/kittybot/database/jooq/tables/pojos/Commands.java

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)