Skip to content

Commit

Permalink
Merge pull request #505 from KittyBot-Org/development
Browse files Browse the repository at this point in the history
new release
  • Loading branch information
topi314 authored Jan 7, 2022
2 parents e106b61 + 636d4aa commit b709d41
Show file tree
Hide file tree
Showing 24 changed files with 117 additions and 276 deletions.
6 changes: 0 additions & 6 deletions Dockerfile-dev

This file was deleted.

91 changes: 43 additions & 48 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,93 +1,91 @@
plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '7.1.0'
id 'nu.studer.jooq' version '6.0.1'
id "java"
id "application"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "nu.studer.jooq" version "6.0.1"
}

group 'de.kittybot'
mainClassName = 'de.kittybot.kittybot.main.Main'
group "de.kittybot"
mainClassName = "de.kittybot.kittybot.main.Main"
sourceCompatibility = 1.11
compileJava.options.encoding = "UTF-8"


repositories {
maven { url 'https://m2.dv8tion.net/releases' }
maven { url 'https://jitpack.io' }
maven { url "https://m2.dv8tion.net/releases" }
maven { url "https://jitpack.io" }
mavenCentral()
jcenter() // this is still required because of jda utilities
}

dependencies {
// discord/jda related
implementation('net.dv8tion:JDA:4.3.0_339') {
exclude group: 'club.minnced', module: 'opus-java'
implementation("net.dv8tion:JDA:4.4.0_352") {
exclude group: "club.minnced", module: "opus-java"
}
implementation 'com.jagrosh:jda-utilities:3.0.5'
implementation 'club.minnced:discord-webhooks:0.7.2'
implementation 'dev.mlnr:BotListHandler-jda:2.0.0_11'
implementation "com.jagrosh:jda-utilities:3.0.5"
implementation "club.minnced:discord-webhooks:0.7.5"
implementation "dev.mlnr:BotListHandler-jda:2.0.0_11"

// audio
implementation('com.github.KittyBot-Org:Lavalink-Client:d48f1a6') {
exclude group: 'com.sedmelluq', module: 'lavaplayer'
}
implementation 'com.sedmelluq:lavaplayer:1.3.78'
implementation 'se.michaelthelin.spotify:spotify-web-api-java:6.5.4'
implementation "com.github.KittyBot-Org:Lavalink-Client:1.0.0"

// database
implementation 'com.zaxxer:HikariCP:5.0.0'
implementation 'org.jooq:jooq:3.15.4'
implementation 'org.postgresql:postgresql:42.3.0'
jooqGenerator 'org.postgresql:postgresql:42.3.0'

implementation "com.zaxxer:HikariCP:5.0.0"
implementation "org.jooq:jooq:3.16.0"
implementation "org.postgresql:postgresql:42.3.1"
jooqGenerator "org.postgresql:postgresql:42.3.1"
// logging
implementation 'ch.qos.logback:logback-classic:1.3.0-alpha10'
implementation 'io.sentry:sentry-logback:5.2.4'
implementation "ch.qos.logback:logback-classic:1.2.8"
implementation "io.sentry:sentry-logback:5.5.2"

// eval
implementation 'org.codehaus.groovy:groovy-jsr223:3.0.9'
implementation "org.codehaus.groovy:groovy-jsr223:3.0.9"

// jjwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'
implementation "io.jsonwebtoken:jjwt-api:0.11.2"
implementation "io.jsonwebtoken:jjwt-impl:0.11.2"
implementation "io.jsonwebtoken:jjwt-jackson:0.11.2"

// Prometheus
implementation 'io.prometheus:simpleclient:0.12.0'
implementation 'io.prometheus:simpleclient_hotspot:0.12.0'
implementation 'io.prometheus:simpleclient_httpserver:0.12.0'
implementation "io.prometheus:simpleclient:0.14.1"
implementation "io.prometheus:simpleclient_hotspot:0.14.1"
implementation "io.prometheus:simpleclient_httpserver:0.14.1"

// other
implementation 'io.javalin:javalin:4.1.1'
implementation 'io.github.classgraph:classgraph:4.8.129'
implementation 'com.github.ben-manes.caffeine:caffeine:3.0.4'
implementation 'com.squareup.okhttp3:okhttp:4.9.2'
implementation "io.javalin:javalin:4.2.0"
implementation "io.github.classgraph:classgraph:4.8.138"
implementation "com.github.ben-manes.caffeine:caffeine:3.0.5"
implementation "com.squareup.okhttp3:okhttp:4.9.3"
}

jooq {
version = '3.15.2'
version = "3.15.2"
configurations {
main {
generateSchemaSourceOnCompilation = false
generationTool {
logging = org.jooq.meta.jaxb.Logging.WARN
jdbc {
driver = 'org.postgresql.Driver'
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://${KITTYBOT_DB_HOST}:${KITTYBOT_DB_PORT}/${KITTYBOT_DB_DATABASE}"
user = KITTYBOT_DB_USER
password = KITTYBOT_DB_PASSWORD
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
name = "org.jooq.codegen.DefaultGenerator"
database {
name = 'org.jooq.meta.postgres.PostgresDatabase'
inputSchema = 'public'
includes = '.*'
excludes = ''
name = "org.jooq.meta.postgres.PostgresDatabase"
inputSchema = "public"
includes = ".*"
excludes = ""
}
generate {
records = true
fluentSetters = true
}
target {
packageName = 'de.kittybot.kittybot.jooq'
packageName = "de.kittybot.kittybot.jooq"
directory = "src/main/jooq"
}
strategy.name = "org.jooq.codegen.DefaultGeneratorStrategy"
Expand All @@ -98,8 +96,5 @@ jooq {
}

ext {
moduleName = 'KittyBot'
moduleName = "KittyBot"
}

sourceCompatibility = 1.11
compileJava.options.encoding = 'UTF-8'
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void run(Options options, GuildInteraction ia){
var lavalinkPlayer = scheduler.getPlayer();
var position = lavalinkPlayer.getTrackPosition();
var newPos = position + forward;
if(newPos > scheduler.getPlayingTrack().getDuration()){
if(newPos > scheduler.getPlayingTrack().getInfo().getLength()){
scheduler.next(true);
ia.reply("Skipped to next track");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void run(Options options, GuildInteraction ia){
}
var newPos = options.getLong("seconds") * 1000;
var lavalinkPlayer = scheduler.getPlayer();
if(newPos > scheduler.getPlayingTrack().getDuration()){
if(newPos > scheduler.getPlayingTrack().getInfo().getLength()){
scheduler.next(true);
ia.reply("Skipped to next track");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void run(Options options, GuildInteraction ia){
return;
}
ia.acknowledge().queue(success ->
ia.getChannel().sendMessage(embed).queue(message -> {
ia.getChannel().sendMessageEmbeds(embed).queue(message -> {
ia.get(ReactionRoleModule.class).add(message.getGuild().getIdLong(), message.getIdLong());
sortedRoles.forEach(role -> message.addReaction("test:" + role.getEmoteId()).queue());
})
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/de/kittybot/kittybot/main/KittyBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public KittyBot() throws IOException, MissingConfigValuesException, LoginExcepti
.disableCache(
CacheFlag.MEMBER_OVERRIDES,
CacheFlag.ACTIVITY,
CacheFlag.CLIENT_STATUS,
CacheFlag.ROLE_TAGS
CacheFlag.CLIENT_STATUS
)
.setMemberCachePolicy(MemberCachePolicy.VOICE)
.setChunkingFilter(ChunkingFilter.NONE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event){
return;
}
if((msg.contains("<@" + Config.BOT_ID + ">") || msg.contains("<@!" + Config.BOT_ID + ">")) && msg.contains("help")){
event.getChannel().sendMessage(new EmbedBuilder()
event.getChannel().sendMessageEmbeds(new EmbedBuilder()
.setColor(Colors.KITTYBOT_BLUE)
.setAuthor("KittyBot Slash Commands Update", event.getJDA().getSelfUser().getEffectiveAvatarUrl(), Config.ORIGIN_URL)
.setDescription("KittyBot now uses the new slash commands.\n" +
Expand Down Expand Up @@ -92,7 +92,7 @@ public void onGuildJoin(@Nonnull GuildJoinEvent event){
if(channel == null || !channel.canTalk()){
return;
}
channel.sendMessage(embed).queue();
channel.sendMessageEmbeds(embed).queue();
return;
}
guild.retrieveAuditLogs().type(ActionType.BOT_ADD).limit(1).cache(false).queue(entries -> {
Expand All @@ -105,14 +105,14 @@ public void onGuildJoin(@Nonnull GuildJoinEvent event){
return;
}

user.openPrivateChannel().flatMap(channel -> channel.sendMessage(embed)).queue(
user.openPrivateChannel().flatMap(channel -> channel.sendMessageEmbeds(embed)).queue(
null,
error -> {
var channel = guild.getDefaultChannel();
if(channel == null || !channel.canTalk()){
return;
}
channel.sendMessage(embed).queue();
channel.sendMessageEmbeds(embed).queue();
}
);
});
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/de/kittybot/kittybot/modules/CommandsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ public void deployCommands(long guildId, Map<String, Command> commands){
LOG.info("Registering commands {}...", guildId == -1 ? "global" : "for guild " + guildId);

var rqBody = RequestBody.create(
DataArray.fromCollection(commands.values().stream().map(Command::toJSON).collect(Collectors.toList())).toJson(),
MediaType.parse("application/json")
MediaType.parse("application/json"),
DataArray.fromCollection(commands.values().stream().map(Command::toJSON).collect(Collectors.toList())).toJson()
);

var route = guildId == -1L ? COMMANDS_CREATE.compile(String.valueOf(Config.BOT_ID)) : GUILD_COMMANDS_CREATE.compile(String.valueOf(Config.BOT_ID), String.valueOf(guildId));
try(var resp = newCall(route, rqBody).execute()){
if(!resp.isSuccessful()){
var body = resp.body();
LOG.error("Registering commands failed. Request Body: {}, Response Body: {}", commands.toString(), body == null ? "null" : body.string());
LOG.error("Registering commands failed. Request Body: {}, Response Body: {}", commands, body == null ? "null" : body.string());
}
var body = resp.body();
if(body == null){
Expand Down Expand Up @@ -142,13 +142,13 @@ public Map<Long, Command> getCommands(){
}

public long registerGuildCommand(long guildId, DataObject command){
var rqBody = RequestBody.create(command.toJson(), MediaType.parse("application/json"));
var rqBody = RequestBody.create(MediaType.parse("application/json"), command.toJson());

var route = GUILD_COMMAND_CREATE.compile(String.valueOf(Config.BOT_ID), String.valueOf(guildId));
try(var resp = newCall(route, rqBody).execute()){
if(!resp.isSuccessful()){
var body = resp.body();
LOG.error("Registering command failed. Request Body: {}, Response Body: {}", command.toString(), body == null ? "null" : body.string());
LOG.error("Registering command failed. Request Body: {}, Response Body: {}", command, body == null ? "null" : body.string());
return -1L;
}
var body = resp.body();
Expand Down Expand Up @@ -182,7 +182,7 @@ public boolean deleteGuildCommand(long guildId, long commandId){
}

public boolean editGuildCommand(long guildId, long commandId, DataObject command){
var rqBody = RequestBody.create(command.toJson(), MediaType.parse("application/json"));
var rqBody = RequestBody.create(MediaType.parse("application/json"), command.toJson());

var route = GUILD_COMMAND_EDIT.compile(String.valueOf(Config.BOT_ID), String.valueOf(guildId), String.valueOf(commandId));
try(var resp = newCall(route, rqBody).execute()){
Expand Down Expand Up @@ -220,7 +220,7 @@ public DataArray getGuildCommands(long guildId){

public void deleteAllCommands(long guildId){
LOG.info("Deleting commands {}...", guildId == -1 ? "global" : "for guild " + guildId);
var rqBody = RequestBody.create(DataArray.empty().toString(), MediaType.parse("application/json"));
var rqBody = RequestBody.create(MediaType.parse("application/json"), DataArray.empty().toString());

var route = guildId == -1L ? COMMANDS_CREATE.compile(String.valueOf(Config.BOT_ID)) : GUILD_COMMANDS_CREATE.compile(String.valueOf(Config.BOT_ID), String.valueOf(guildId));
try(var resp = newCall(route, rqBody).execute()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void logEvent(GenericGuildEvent event, Color color, User user, String ev
if(channel == null){
return;
}
channel.sendMessage(new EmbedBuilder()
channel.sendMessageEmbeds(new EmbedBuilder()
.setColor(color)
.setDescription(String.format(message, args))
.setFooter(eventName, user == null ? null : user.getEffectiveAvatarUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ else if(interaction.isFromGuild()){
}
}
catch(Exception e){
LOG.error("Error while executing command", e);
interaction.error(e.getMessage());
}
return;
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/de/kittybot/kittybot/modules/MusicModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
public class MusicModule extends Module implements Serializable{

public static final Pattern URL_PATTERN = Pattern.compile("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]?");
public static final Pattern SPOTIFY_URL_PATTERN = Pattern.compile("(https?://)?(www\\.)?open\\.spotify\\.com/(user/[a-zA-Z0-9-_]+/)?(?<type>track|album|playlist)/(?<identifier>[a-zA-Z0-9-_]+)");

private Map<Long, MusicManager> musicPlayers;

Expand Down Expand Up @@ -66,7 +65,7 @@ public void onGuildMessageReactionAdd(@NotNull GuildMessageReactionAddEvent even
var messageId = event.getMessageIdLong();
var currentTrack = scheduler.getPlayingTrack();
var userId = event.getUserIdLong();
var requesterId = currentTrack == null ? -1L : currentTrack.getUserData(Long.class);
var requesterId = currentTrack == null ? -1L : currentTrack.getUserData(Long.class) == null ? -1L : currentTrack.getUserData(Long.class);
var settings = this.modules.get(SettingsModule.class).getSettings(event.getGuild().getIdLong());

if(messageId != scheduler.getControllerMessageId()){
Expand Down Expand Up @@ -202,12 +201,6 @@ public void play(GuildInteraction ia, String query, SearchProvider searchProvide
ia.acknowledge().queue();
var manager = this.musicPlayers.computeIfAbsent(ia.getGuildId(), guildId -> new MusicManager(this.modules, guildId, ia.getChannelId()));

var matcher = SPOTIFY_URL_PATTERN.matcher(query);
if(matcher.find()){
this.modules.get(SpotifyModule.class).load(ia, manager, matcher);
return;
}

if(!URL_PATTERN.matcher(query).matches()){
switch(searchProvider){
case YOUTUBE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void schedule(Set<Notification> notifs){
return;
}
guild.retrieveMemberById(notification.getUserId()).flatMap(member ->
channel.sendMessage(member.getAsMention()).embed(
channel.sendMessage(member.getAsMention()).setEmbeds(
new EmbedBuilder()
.setAuthor("Notification", Category.NOTIFICATION.getUrl(), Category.NOTIFICATION.getEmoteUrl())
.setColor(Colors.NOTIFICATION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public void onGuildMessageReactionAdd(@NotNull GuildMessageReactionAddEvent even
if(Emoji.ARROW_LEFT.get().equals(code)){
if(currentPage != 0){
paginator.previousPage();
event.getChannel().editMessageById(event.getMessageIdLong(), paginator.constructEmbed()).queue();
event.getChannel().editMessageEmbedsById(event.getMessageIdLong(), paginator.constructEmbed()).queue();
}
}
else if(Emoji.ARROW_RIGHT.get().equals(code)){
if(currentPage != maxPages - 1){
paginator.nextPage();
event.getChannel().editMessageById(event.getMessageIdLong(), paginator.constructEmbed()).queue();
event.getChannel().editMessageEmbedsById(event.getMessageIdLong(), paginator.constructEmbed()).queue();
}
}
else if(Emoji.WASTEBASKET.get().equals(code)){
Expand All @@ -84,7 +84,7 @@ public void create(TextChannel channel, long authorId, int maxPages, BiFunction<
}

public void create(int maxPages, BiFunction<Integer, EmbedBuilder, EmbedBuilder> embedFunction, MessageEmbed embedBuilder, MessageChannel channel, long userId){
channel.sendMessage(embedBuilder).queue(message -> {
channel.sendMessageEmbeds(embedBuilder).queue(message -> {
var paginator = new Paginator(message, userId, maxPages, embedFunction);
this.paginators.put(paginator.getMessageId(), paginator);
if(channel instanceof GuildChannel && !((GuildChannel) channel).getGuild().getSelfMember().hasPermission(Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION)){
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/kittybot/kittybot/modules/RequestModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public String executeRequest(Request request, API api){

public void postToHastebin(String content, Consumer<String> callback){
this.requestBuilder.url(API.HASTEBIN.getUrl() + "/documents");
this.requestBuilder.post(RequestBody.create(content, MediaType.parse("text/html; charset=utf-8")));
this.requestBuilder.post(RequestBody.create(MediaType.parse("text/html; charset=utf-8"), content));
executeAsync(this.requestBuilder.build(), (call, response) -> {
var body = response.body();
String key = null;
Expand Down Expand Up @@ -155,7 +155,7 @@ public void uploadCommands(Collection<Command> commands){
var json = DataArray.fromCollection(commands.stream().map(Command::toDiscordServicesJSON).collect(Collectors.toList()));

this.requestBuilder.url("https://api.discordservices.net/bot/" + Config.BOT_ID + "/commands");
this.requestBuilder.post(RequestBody.create(json.toJson(), MediaType.parse("application/json")));
this.requestBuilder.post(RequestBody.create(MediaType.parse("application/json"), json.toJson()));
this.requestBuilder.header("Authorization", Config.DISCORD_SERVICES_TOKEN);
executeAsync(this.requestBuilder.build(), (call, response) -> {}, (call, response) -> {
var body = response.body();
Expand Down
Loading

0 comments on commit b709d41

Please sign in to comment.