Skip to content

Commit

Permalink
Merge pull request #386 from KittyBot-Org/development
Browse files Browse the repository at this point in the history
fixes & new filters
  • Loading branch information
topi314 committed Jul 25, 2021
2 parents 818aa91 + 6689ef2 commit c59c94c
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 26 deletions.
20 changes: 10 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '7.0.0'
id 'nu.studer.jooq' version '5.2.2'
id 'nu.studer.jooq' version '6.0'
}

group 'de.kittybot'
Expand All @@ -17,25 +17,25 @@ repositories {

dependencies {
// discord/jda related
implementation('net.dv8tion:JDA:4.3.0_289') {
implementation('net.dv8tion:JDA:4.3.0_298') {
exclude group: 'club.minnced', module: 'opus-java'
}
implementation 'com.jagrosh:jda-utilities:3.0.5'
implementation 'club.minnced:discord-webhooks:0.5.7'
implementation 'dev.mlnr:BotListHandler-jda:2.0.0_7'
implementation 'dev.mlnr:BotListHandler-jda:2.0.0_8'

// audio
implementation('com.github.KittyBot-Org:Lavalink-Client:176ca86') {
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'

// database
implementation 'com.zaxxer:HikariCP:4.0.3'
implementation 'org.jooq:jooq:3.14.12'
implementation 'org.postgresql:postgresql:42.2.22'
jooqGenerator 'org.postgresql:postgresql:42.2.22'
implementation 'com.zaxxer:HikariCP:5.0.0'
implementation 'org.jooq:jooq:3.15.1'
implementation 'org.postgresql:postgresql:42.2.23'
jooqGenerator 'org.postgresql:postgresql:42.2.23'

// logging
implementation 'ch.qos.logback:logback-classic:1.3.0-alpha5'
Expand All @@ -55,8 +55,8 @@ dependencies {
implementation 'io.prometheus:simpleclient_httpserver:0.11.0'

// other
implementation 'io.javalin:javalin:3.13.8'
implementation 'io.github.classgraph:classgraph:4.8.109'
implementation 'io.javalin:javalin:3.13.10'
implementation 'io.github.classgraph:classgraph:4.8.110'
implementation 'com.github.ben-manes.caffeine:caffeine:3.0.3'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
import de.kittybot.kittybot.slashcommands.interaction.Interaction;
import de.kittybot.kittybot.slashcommands.interaction.Options;
import de.kittybot.kittybot.slashcommands.interaction.response.FollowupMessage;
import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponse;
import de.kittybot.kittybot.slashcommands.interaction.response.InteractionResponseType;
import de.kittybot.kittybot.utils.Colors;
import net.dv8tion.jda.api.EmbedBuilder;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public FilterCommand(){
new VibratoCommand(),
new RotationCommand(),
new DistortionCommand(),
new ChannelMixCommand(),
new LowPassCommand(),
new ClearCommand()
);
}
Expand Down Expand Up @@ -262,6 +264,70 @@ public void run(Options options, GuildInteraction ia){

}

private static class ChannelMixCommand extends GuildSubCommand{

public ChannelMixCommand(){
super("channel-mix", "Mixes both channels, with a configurable factor on how much each channel affects the other.");
addOptions(
new CommandOptionFloat("left-to-left", "How much audio from the left channel goes to the left channel"),
new CommandOptionFloat("left-to-right", "How much audio from the left channel goes to the right channel"),
new CommandOptionFloat("right-to-left", "How much audio from the right channel goes to the left channel"),
new CommandOptionFloat("right-to-right", "How much audio from the right channel goes to the right channel")
);
}

@Override
public void run(Options options, GuildInteraction ia){
var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId());
if(!MusicUtils.checkCommandRequirements(ia, scheduler) || !MusicUtils.checkMusicPermissions(ia, scheduler)){
return;
}
var channelMix = new ChannelMix();
if(options.has("left-to-left")){
channelMix = channelMix.setLeftToLeft(options.getFloat("left-to-left"));
}
if(options.has("left-to-right")){
channelMix = channelMix.setLeftToRight(options.getFloat("left-to-right"));
}
if(options.has("right-to-left")){
channelMix = channelMix.setRightToLeft(options.getFloat("right-to-left"));
}
if(options.has("right-to-right")){
channelMix = channelMix.setRightToLeft(options.getFloat("right-to-right"));
}

scheduler.getFilters().setChannelMix(channelMix).commit();
ia.reply("Set channel-mix filter");
}

}

private static class LowPassCommand extends GuildSubCommand{

public LowPassCommand(){
super("low-pass", "Higher frequencies get suppressed, while lower frequencies pass through this filter.");
addOptions(
new CommandOptionFloat("smoothing", "The smoothing level")
);
}

@Override
public void run(Options options, GuildInteraction ia){
var scheduler = ia.get(MusicModule.class).getScheduler(ia.getGuildId());
if(!MusicUtils.checkCommandRequirements(ia, scheduler) || !MusicUtils.checkMusicPermissions(ia, scheduler)){
return;
}
var lowPass = new LowPass();
if(options.has("smoothing")){
lowPass = lowPass.setSmoothing(options.getFloat("smoothing"));
}

scheduler.getFilters().setLowPass(lowPass).commit();
ia.reply("Set low-pass filter");
}

}

private static class ClearCommand extends GuildSubCommand{

public ClearCommand(){
Expand Down
1 change: 0 additions & 1 deletion src/main/java/de/kittybot/kittybot/main/KittyBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public KittyBot() throws IOException, MissingConfigValuesException, LoginExcepti
.addBotList(BotList.TOP_GG, Config.TOP_GG_TOKEN)
.addBotList(BotList.DBOATS, Config.DISCORD_BOATS_TOKEN)
.addBotList(BotList.DISCORDLIST_SPACE, Config.BOTLIST_SPACE_TOKEN)
.addBotList(BotList.BOTS_FOR_DISCORD, Config.BOTS_FOR_DISCORD_TOKEN)
.addBotList(BotList.DSERVICES, Config.DISCORD_SERVICES_TOKEN)
.addBotList(BotList.DBL, Config.DISCORD_BOT_LIST_TOKEN)
.addBotList(BotList.DEL, Config.DISCORD_EXTREME_LIST_TOKEN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import javax.annotation.Nonnull;
import java.awt.Color;
import java.text.MessageFormat;
import java.time.Instant;
import java.util.Set;

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/de/kittybot/kittybot/modules/StreamModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ private void checkTwitch(){
if(userIds.isEmpty()){
return;
}
var streams = this.twitchWrapper.getStreams(userIds, false);
var streams = this.twitchWrapper.getStreams(userIds);

for(var streamAnnouncement : this.streams){
var stream = streams.stream().filter(st -> st.getUserId() == streamAnnouncement.getUserId()).findFirst();
if(stream.isPresent() && stream.get().hasError()){
// error while fetching stream skip
continue;
}
if(stream.isPresent() && !streamAnnouncement.getIsLive()){
setLiveStatus(streamAnnouncement, true);
// send online
Expand Down Expand Up @@ -133,7 +137,7 @@ private void sendAnnouncementMessage(StreamUsersRecord streamAnnouncement, Strea
break;
}
channel.sendMessage(settings.getStreamAnnouncementMessage().replace("${user}", stream.getUserName()))
.embed(embed
.setEmbeds(embed
.setTimestamp(Instant.now())
.setColor(Colors.TWITCH_PURPLE)
.build()
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/de/kittybot/kittybot/objects/streams/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public class Stream{
private final Instant startedAt;
private final Language language;
private final StreamType type;
private final boolean error;
private Game game;

public Stream(long streamId, String streamTitle, String thumbnailUrl, long userId, String userName, Game game, int viewerCount, Instant startedAt, Language language, StreamType type){
public Stream(long streamId, String streamTitle, String thumbnailUrl, long userId, String userName, Game game, int viewerCount, Instant startedAt, Language language, StreamType type, boolean error){
this.streamId = streamId;
this.streamTitle = streamTitle;
this.thumbnailUrl = thumbnailUrl;
Expand All @@ -28,6 +29,7 @@ public Stream(long streamId, String streamTitle, String thumbnailUrl, long userI
this.startedAt = startedAt;
this.language = language;
this.type = type;
this.error = error;
}

public static Stream fromTwitchJSON(DataObject json){
Expand All @@ -42,7 +44,8 @@ public static Stream fromTwitchJSON(DataObject json){
json.getInt("viewer_count"),
Instant.parse(json.getString("started_at")),
lang.orElse(Language.UNKNOWN),
StreamType.TWITCH
StreamType.TWITCH,
false
);
}

Expand Down Expand Up @@ -100,4 +103,8 @@ public String getStreamUrl(){
return null;
}

public boolean hasError(){
return this.error;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package de.kittybot.kittybot.objects.streams.twitch;

import de.kittybot.kittybot.objects.streams.BearerToken;
import de.kittybot.kittybot.objects.streams.Game;
import de.kittybot.kittybot.objects.streams.Stream;
import de.kittybot.kittybot.objects.streams.StreamType;
import net.dv8tion.jda.api.utils.data.DataObject;
import okhttp3.Call;
import okhttp3.FormBody;
Expand Down Expand Up @@ -100,7 +102,7 @@ private Call newRequest(String url, Object... params){
);
}

public List<Stream> getStreams(List<Long> userIds, boolean reTry){
public List<Stream> getStreams(List<Long> userIds){
var streams = new ArrayList<Stream>();
do{
var users = userIds.subList(0, Math.min(userIds.size(), 100));
Expand All @@ -112,9 +114,9 @@ public List<Stream> getStreams(List<Long> userIds, boolean reTry){
LOG.error("Url: {} Code: {} Body: {}", resp.request().url(), resp.code(), body == null ? "null" : body.string());
if(resp.code() == 401){
this.bearerToken = null;
if(!reTry){
return getStreams(userIds, true);
}
}
for(var userId : users){
streams.add(new Stream(0L, "", "", userId, "", Game.getUnknown(), 0, null, null, StreamType.YOUTUBE, true));
}
continue;
}
Expand Down

0 comments on commit c59c94c

Please sign in to comment.