13 Commits
45 changed files with 1145 additions and 1031 deletions
+2 -2
View File
@@ -12,7 +12,6 @@
<classpathentry kind="lib" path="lib/httpclient-4.5.5.jar"/>
<classpathentry kind="lib" path="lib/httpcore-4.4.9.jar"/>
<classpathentry kind="lib" path="lib/WolframAlpha-1.1.jar"/>
<classpathentry kind="lib" path="lib/JDA-3.7.1_385-withDependencies.jar"/>
<classpathentry kind="lib" path="lib/sqlite-jdbc-3.23.1.jar"/>
<classpathentry kind="lib" path="lib/slf4j-jdk14-1.7.25.jar"/>
<classpathentry kind="lib" path="lib/twitter4j-core-4.0.7-javadoc.jar"/>
@@ -27,6 +26,7 @@
<classpathentry kind="lib" path="lib/google-http-client-1.32.0.jar"/>
<classpathentry kind="lib" path="lib/google-api-services-youtube-v3-rev212-1.25.0.jar"/>
<classpathentry kind="lib" path="lib/nanohttpd-2.3.1.jar"/>
<classpathentry kind="lib" path="G:/Shared/Coding/Java/workspace/ProKitty/lib/LavaPlayerJar-1.3.50-jar-with-dependencies.jar"/>
<classpathentry kind="lib" path="lib/LavaPlayerJar-1.3.50-jar-with-dependencies.jar"/>
<classpathentry kind="lib" path="lib/JDA-4.2.0_168-withDependencies.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+2
View File
@@ -68,3 +68,5 @@ rP\.txt
*.log
cloc\.exe
beanImage.png
+5 -1
View File
@@ -1,5 +1,6 @@
"Type","Key","Value"
"Globals","mode (dev or release)","dev"
"Globals","activity","with a laser pointer"
"Localized Commands","beans",""
"Localized Commands","benchmark, bench",""
"Localized Commands","bet",""
@@ -57,6 +58,8 @@
"Localized Commands","work",""
"Localized Commands","yeet",""
"Localized Strings","AddGuildRoleFailure","Failed to add %s to %s"
"Localized Strings","BeansImageBottomText","BEANS"
"Localized Strings","BeansImageTopText","YOU HAVE"
"Localized Strings","BeansShowDisplay","You have %s beans!"
"Localized Strings","BeansShowInfo","Displays how many beans you have"
"Localized Strings","BeansShowMentioned","I took a look and %sbeans!"
@@ -70,7 +73,8 @@
"Localized Strings","BetBeansNotValid","That's not a valid bet!"
"Localized Strings","BetBeansWin","You won %s beans!"
"Localized Strings","BetHistoryInfo","Gives how many beans I've ~~stolen~~ won from your bets!"
"Localized Strings","BetHistoryOutput","I have %s treats from betting!"
"Localized Strings","BetHistoryOptionalPNGPath",""
"Localized Strings","BetHistoryOutput","I have %s beans from betting!"
"Localized Strings","BlurryInfo","Blurs your icon or the icon of a friend you mentioned"
"Localized Strings","BoopInfo","Kitty will react with a counter"
"Localized Strings","BoopMultiple","%s booped several others - %s!"
1 Type Key Value
2 Globals mode (dev or release) dev
3 Globals activity with a laser pointer
4 Localized Commands beans
5 Localized Commands benchmark, bench
6 Localized Commands bet
58 Localized Commands work
59 Localized Commands yeet
60 Localized Strings AddGuildRoleFailure Failed to add %s to %s
61 Localized Strings BeansImageBottomText BEANS
62 Localized Strings BeansImageTopText YOU HAVE
63 Localized Strings BeansShowDisplay You have %s beans!
64 Localized Strings BeansShowInfo Displays how many beans you have
65 Localized Strings BeansShowMentioned I took a look and %sbeans!
73 Localized Strings BetBeansNotValid That's not a valid bet!
74 Localized Strings BetBeansWin You won %s beans!
75 Localized Strings BetHistoryInfo Gives how many beans I've ~~stolen~~ won from your bets!
76 Localized Strings BetHistoryOutput BetHistoryOptionalPNGPath I have %s treats from betting!
77 Localized Strings BetHistoryOutput I have %s beans from betting!
78 Localized Strings BlurryInfo Blurs your icon or the icon of a friend you mentioned
79 Localized Strings BoopInfo Kitty will react with a counter
80 Localized Strings BoopMultiple %s booped several others - %s!
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

@@ -1,4 +1,4 @@
package commands.general;
package commands.beans;
import java.awt.Font;
import java.awt.FontMetrics;
@@ -118,9 +118,9 @@ public class CommandBeansShow extends Command
Font beanFont = new Font("font", Font.BOLD, 45);
beanGraphics.setFont(beanFont);
drawCenteredString(beanGraphics, "YOU HAVE", rect, beanFont, .25);
drawCenteredString(beanGraphics, LocStrings.stub("BeansImageTopText"), rect, beanFont, .25);
drawCenteredString(beanGraphics, "" + beans, rect, beanFont, .5);
drawCenteredString(beanGraphics, "BEANS!", rect, beanFont, .75);
drawCenteredString(beanGraphics, LocStrings.stub("BeansImageBottomText"), rect, beanFont, .75);
ImageIO.write(beanImage, "PNG", new File("beanImage.png"));
return new File("beanImage.png");
@@ -1,4 +1,4 @@
package commands.general;
package commands.beans;
import java.util.Random;
@@ -1,4 +1,6 @@
package commands.general;
package commands.beans;
import java.io.File;
import core.Command;
import core.LocStrings;
@@ -9,6 +11,8 @@ import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
import utils.GlobalLog;
import utils.LogFilter;
public class CommandBetHistory extends Command
{
@@ -20,6 +24,22 @@ public class CommandBetHistory extends Command
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
// Send primary response
res.send(String.format(LocStrings.stub("BetHistoryOutput"), guild.beans.get()));
// Look up extra information to see if we ahve a flair image
String optional = LocStrings.stub("BetHistoryOptionalPNGPath");
if(optional != null && optional.length() > 0)
{
File responseImage = new File(optional);
if(responseImage.exists())
{
res.sendFile(responseImage, ".png");
}
else
{
GlobalLog.warn(LogFilter.Command, "Optional PNG image for bet history was specified, but the file could not be found.");
}
}
}
}
@@ -1,4 +1,4 @@
package commands.general;
package commands.beans;
import core.Command;
import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general;
package commands.beans;
import core.Command;
import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general;
package commands.dev;
import core.Command;
import core.Constants;
@@ -1,4 +1,4 @@
package commands.general;
package commands.dev;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -1,4 +1,4 @@
package commands.general;
package commands.dev;
import core.*;
import dataStructures.KittyChannel;
@@ -1,4 +1,4 @@
package commands.general;
package commands.dev;
import java.io.File;
import java.io.FileNotFoundException;
@@ -1,4 +1,4 @@
package commands.general;
package commands.dev;
import core.Command;
import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general;
package commands.dev;
import core.Command;
import core.DatabaseManager;
@@ -1,4 +1,4 @@
package commands.general;
package commands.dev;
import core.Command;
import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general;
package commands.dev;
import core.Command;
import core.LocStrings;
+2 -2
View File
@@ -7,7 +7,7 @@ import core.Command;
import core.Constants;
import core.DatabaseManager;
import core.LocStrings;
import core.ObjectBuilderFactory;
import core.ObjectBuilder;
import dataStructures.KittyChannel;
import dataStructures.KittyEmbed;
import dataStructures.KittyGuild;
@@ -98,7 +98,7 @@ public class CommandLeaderboard extends Command
{
// Only now that we've sorted do we do the full construction and caching of users
Pair<Long, String> userPair = users.get(i);
KittyUser cachedUser = ObjectBuilderFactory.getKittyUser(guildID, userPair.Second);
KittyUser cachedUser = ObjectBuilder.getKittyUser(guildID, userPair.Second);
if(cachedUser == null)
continue;
@@ -1,4 +1,4 @@
package commands.general;
package commands.images;
import java.awt.Color;
import java.awt.image.BufferedImage;
@@ -1,4 +1,4 @@
package commands.general;
package commands.images;
import java.io.File;
import java.io.IOException;
@@ -1,4 +1,4 @@
package commands.general;
package commands.images;
import java.io.File;
import java.io.IOException;
@@ -1,4 +1,4 @@
package commands.general;
package commands.images;
import java.awt.Color;
import java.awt.image.BufferedImage;
@@ -1,4 +1,4 @@
package commands.general;
package commands.images;
import java.awt.Color;
import java.awt.image.BufferedImage;
@@ -1,4 +1,4 @@
package commands.general;
package commands.images;
import java.io.File;
import java.io.IOException;
@@ -1,4 +1,4 @@
package commands.general;
package commands.images;
import java.io.File;
import java.io.IOException;
@@ -1,4 +1,4 @@
package commands.general;
package commands.network;
import core.Command;
import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general;
package commands.network;
import core.Command;
import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general;
package commands.network;
import core.Command;
import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general;
package commands.network;
import core.Command;
import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general;
package commands.network;
import core.Command;
import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general;
package commands.network;
import java.io.File;
import java.io.IOException;
+26
View File
@@ -4,11 +4,37 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import commands.beans.CommandBeansShow;
import commands.beans.CommandBetBeans;
import commands.beans.CommandBetHistory;
import commands.beans.CommandGiveBeans;
import commands.beans.CommandTradeBeans;
import commands.characters.CommandCharacterMain;
import commands.dev.CommandDBFlush;
import commands.dev.CommandDBStats;
import commands.dev.CommandDoWork;
import commands.dev.CommandHelpBuilder;
import commands.dev.CommandInvite;
import commands.dev.CommandShutdown;
import commands.dev.CommandStats;
import commands.dev.CommandTweet;
import commands.general.*;
import commands.guildrole.CommandGuildRoleMain;
import commands.images.CommandBlurry;
import commands.images.CommandCatch;
import commands.images.CommandDefaultDance;
import commands.images.CommandPerish;
import commands.images.CommandStark;
import commands.images.CommandTeey;
import commands.images.CommandYeet;
import commands.mod.CommandModMain;
import commands.music.CommandMusicMain;
import commands.network.CommandColiru;
import commands.network.CommandDerpi;
import commands.network.CommandE6;
import commands.network.CommandGetSauce;
import commands.network.CommandJDoodle;
import commands.network.CommandWolfram;
import commands.poll.CommandPollMain;
import commands.raffle.CommandRaffleMain;
import dataStructures.*;
+35 -1
View File
@@ -18,13 +18,20 @@ public class ConfigGlobals implements IConfigSection
private static final String startupStyleKey = "mode (dev or release)";
private KittyStartupMode startupStyleValue = KittyStartupMode.Dev;
// Constructor
private static final String activityKey = "activity";
private String activityValue = "with a laser pointer"; // Appears as "Playing with a laser pointer"
// Singleton Constructor - explode if there's a problem.
public ConfigGlobals()
{
if(instance == null)
{
instance = this;
}
else
{
GlobalLog.error("Attempted to initialize a second config globals! Probably don't do this!");
}
}
@Override
@@ -38,6 +45,11 @@ public class ConfigGlobals implements IConfigSection
return instance.startupStyleValue;
}
public static String getActivity()
{
return instance.activityValue;
}
@Override
public void consume(List<ConfigItem> pairs)
{
@@ -52,8 +64,29 @@ public class ConfigGlobals implements IConfigSection
startupStyleValue = KittyStartupMode.Dev;
if(value.equalsIgnoreCase(KittyStartupMode.Release.name()))
{
startupStyleValue = KittyStartupMode.Release;
}
if(value.equalsIgnoreCase(KittyStartupMode.PoguRelease.name()))
{
startupStyleValue = KittyStartupMode.PoguRelease;
}
continue;
}
// Parse text for 'playing'
if(key.equalsIgnoreCase(activityKey))
{
activityValue = value;
}
}
// If we change any globals, update anything we need to.
if(ObjectBuilder.getHasInitialized())
{
ObjectBuilder.updateActivity();
}
}
@@ -62,6 +95,7 @@ public class ConfigGlobals implements IConfigSection
{
List<ConfigItem> items = new ArrayList<ConfigItem>();
items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.name().toLowerCase()));
items.add(new ConfigItem(getSectionTitle(), activityKey, activityValue));
return items;
}
@@ -23,15 +23,15 @@ import dataStructures.KittyRole;
import dataStructures.KittyStartupMode;
import dataStructures.KittyUser;
import main.Main;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.entities.Emote;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import offline.Ref;
import utils.AdminControl;
//import utils.AudioUtils;
@@ -39,11 +39,11 @@ import utils.GlobalLog;
import utils.LogFilter;
import utils.audio.AudioUtils;
// NOTE(wisp): Isolated factory to assist with storage and caching if needed.
// NOTE: Isolated factory to assist with storage and caching if needed.
// This also minimizes the number of places JDA interacts with our codebase.
// As it stands, if the object name begins with Kitty, it's constructed here.
// TODO: Make all methods ID based instead of event based
public class ObjectBuilderFactory
public class ObjectBuilder
{
// Key: guild string id, Value: guild information
private static HashMap<String, KittyGuild> guildCache;
@@ -82,15 +82,20 @@ public class ObjectBuilderFactory
// Lazy initialization multithreaded mutex stuff to prevent explosions.
// TODO: Investigate using 'synchronized' instead potentially
private static boolean hasInitialized;
private static Boolean hasInitialized = false;
private static Semaphore initMutex = new Semaphore(1);
private static JDA kitty;
// This is it, this is how the lazy init starts!
private static void lazyInit()
{
if(hasInitialized)
return;
synchronized(hasInitialized)
{
if(hasInitialized)
{
return;
}
}
try
{
@@ -109,14 +114,17 @@ public class ObjectBuilderFactory
AudioSourceManagers.registerLocalSource(playerManager);
// Start by reading from things that are external. Because
// we require these things to be resolved before the rest of the application,
// we place them here.
// we require these things to be resolved before the rest of
// the application, we place them here.
config = new Config();
}
finally
{
initMutex.release();
hasInitialized = true;
synchronized(hasInitialized)
{
hasInitialized = true;
}
}
}
catch(InterruptedException ie)
@@ -126,6 +134,14 @@ public class ObjectBuilderFactory
}
}
public static boolean getHasInitialized()
{
synchronized(hasInitialized)
{
return hasInitialized;
}
}
////////////////////////
// Extraction Methods //
////////////////////////
@@ -189,7 +205,7 @@ public class ObjectBuilderFactory
// allowed to use the bot at a general level.
KittyRole role = KittyRole.General;
if(event.getAuthor().getId() == event.getGuild().getOwner().getUser().getId())
if(event.getAuthor().getId() == event.getGuild().getOwnerId())
{
role = KittyRole.Admin;
}
@@ -389,21 +405,32 @@ public class ObjectBuilderFactory
// Determine token based on config. Default to test token.
String tokenToUse = Ref.TestToken;
if(ConfigGlobals.getStartupMode() == KittyStartupMode.Release)
tokenToUse = Ref.Token;
if(ConfigGlobals.getStartupMode() == KittyStartupMode.PoguRelease)
tokenToUse = Ref.PoguToken;
switch(ConfigGlobals.getStartupMode())
{
case Release: tokenToUse = Ref.Token; break;
case PoguRelease: tokenToUse = Ref.PoguToken; break;
default: tokenToUse = Ref.TestToken; break;
}
// Construct bot based on token using the JDA Builder
JDABuilder builder = JDABuilder.createDefault(tokenToUse);
kitty = builder.build();
// Construct bot based on token
kitty = new JDABuilder(AccountType.BOT)
.setToken(tokenToUse).buildBlocking();
kitty.getPresence().setGame(Game.playing("with a laser pointer"));
// Set activity, and add primariy event listener.
updateActivity();
kitty.addEventListener(new Main());
return new KittyCore(kitty);
}
// Updates the bots current activity based on the globals value.
public static void updateActivity()
{
String activity = ConfigGlobals.getActivity();
GlobalLog.log(LogFilter.Core, "Updating activity to " + activity);
kitty.getPresence().setActivity(Activity.playing(activity));
}
// Default construction of the command manager. In order to remotely resolve command enabling
// and disabling, what we do is construct the commands with a localized pair that is checked against
// the CommandEnabler object passed in. In theory, we could have multiple CommandManagers, tho we can
+2 -2
View File
@@ -107,12 +107,12 @@ public class Stats
public int getGuildCount()
{
return ObjectBuilderFactory.getGuildCount();
return ObjectBuilder.getGuildCount();
}
public int getUserCount()
{
return ObjectBuilderFactory.getUserCount();
return ObjectBuilder.getUserCount();
}
public ArrayList<Command> getAllCommands()
+1 -1
View File
@@ -1,6 +1,6 @@
package dataStructures;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.api.JDA;
public class KittyCore
{
+11 -6
View File
@@ -3,11 +3,12 @@ package dataStructures;
import java.io.File;
import java.io.InputStream;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.events.message.guild.*;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.utils.AttachmentOption;
import utils.GlobalLog;
import utils.LogFilter;
@@ -72,10 +73,14 @@ public class Response
embed.setThumbnail(thumbPath);
message.setEmbed(embed.build());
GlobalLog.log("We're trying to send a response that has a locally defined thumbnail file...");
File thumbImage = new File(thumbName);
if(thumbImage.exists())
{
event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
// Used to eb as follows:
//event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
event.getChannel().sendMessage(message.build()).queue();
}
}
else
+4 -4
View File
@@ -2,9 +2,9 @@ package dataStructures;
import java.util.List;
import core.ObjectBuilderFactory;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import core.ObjectBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class UserInput
{
@@ -93,7 +93,7 @@ public class UserInput
KittyUser [] KittyMentions = new KittyUser[JDAMentions.size()];
for(int i = 0; i < KittyMentions.length; i ++)
{
KittyMentions [i] = ObjectBuilderFactory.getKittyUser(event.getGuild().getId(), JDAMentions.get(i).getUser().getId());
KittyMentions [i] = ObjectBuilder.getKittyUser(event.getGuild().getId(), JDAMentions.get(i).getUser().getId());
}
return KittyMentions;
}
+12 -33
View File
@@ -1,26 +1,14 @@
package main;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.security.auth.login.LoginException;
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
import core.CharacterManager;
import core.CommandEnabler;
import core.CommandManager;
import core.DatabaseManager;
import core.ObjectBuilderFactory;
import core.ObjectBuilder;
import core.RPManager;
import core.Stats;
import core.lua.PluginManager;
@@ -30,17 +18,8 @@ import dataStructures.KittyGuild;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.audio.AudioSendHandler;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.managers.AudioManager;
import offline.Ref;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import utils.GlobalLog;
// http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
@@ -64,15 +43,15 @@ public class Main extends ListenerAdapter
{
// Factory startup. The ordering is intentional.
GlobalLog.initialize();
databaseManager = ObjectBuilderFactory.constructDatabaseManager();
commandManager = ObjectBuilderFactory.constructCommandManager(CommandEnabler.instance); // TODO: Untangle this singleton
stats = ObjectBuilderFactory.constructStats(commandManager);
databaseManager = ObjectBuilder.constructDatabaseManager();
commandManager = ObjectBuilder.constructCommandManager(CommandEnabler.instance); // TODO: Untangle this singleton
stats = ObjectBuilder.constructStats(commandManager);
charManager = new CharacterManager();
rpManager = ObjectBuilderFactory.constructRPManager();
pluginManager = ObjectBuilderFactory.constructPluginManager();
rpManager = ObjectBuilder.constructRPManager();
pluginManager = ObjectBuilder.constructPluginManager();
// Bot startup
kittyCore = ObjectBuilderFactory.constructKittyCore();
kittyCore = ObjectBuilder.constructKittyCore();
}
// When a message is sent in a server that kitty is in, this is what's called.
@@ -84,9 +63,9 @@ public class Main extends ListenerAdapter
return;
// Factory objects
KittyUser user = ObjectBuilderFactory.extractUser(event);
KittyGuild guild = ObjectBuilderFactory.extractGuild(event);
KittyChannel channel = ObjectBuilderFactory.extractChannel(event);
KittyUser user = ObjectBuilder.extractUser(event);
KittyGuild guild = ObjectBuilder.extractGuild(event);
KittyChannel channel = ObjectBuilder.extractChannel(event);
// Specialized uncached objects
Response response = new Response(event, kittyCore);
+1 -1
View File
@@ -14,7 +14,7 @@ import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import offline.Ref;
// Manages the fiddly bits and upkeep of the bot - while not
+20 -9
View File
@@ -1,24 +1,30 @@
package utils;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.managers.GuildController;
import java.util.*;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.internal.handle.GuildSetupController;
public class AdminControl
{
private GuildController guildCon;
private Guild guild;
public AdminControl(Guild guild)
{
this.guild = guild;
guildCon = guild.getController();
}
public boolean addRole(String memberID, String roleName)
{
try
{
guildCon.addRolesToMember(guild.getMemberById(memberID), guild.getRolesByName(roleName, true)).complete();
Member member = guild.getMemberById(memberID);
List<Role> roles = guild.getRolesByName(roleName, true);
for(Role role : roles)
{
guild.addRoleToMember(member, role).complete();// submit instead? We need to queue.
}
}
catch(Exception e)
{
@@ -31,7 +37,12 @@ public class AdminControl
{
try
{
guildCon.removeRolesFromMember(guild.getMemberById(memberID), guild.getRolesByName(roleName, true)).complete();
Member member = guild.getMemberById(memberID);
List<Role> roles = guild.getRolesByName(roleName, true);
for(Role role : roles)
{
guild.removeRoleFromMember(member, role).complete();
}
}
catch(Exception e)
{
@@ -44,7 +55,7 @@ public class AdminControl
{
try
{
guildCon.kick(guild.getMemberById(memberID)).complete();
guild.kick(guild.getMemberById(memberID)).complete();
}
catch(Exception e)
{
@@ -57,7 +68,7 @@ public class AdminControl
{
try
{
guildCon.setMute(guild.getMemberById(memberID), true);
guild.mute(guild.getMemberById(memberID), true);
return true;
}
catch(Exception e)
@@ -70,7 +81,7 @@ public class AdminControl
{
try
{
guildCon.ban(guild.getMemberById(memberID), 0).complete();
guild.ban(guild.getMemberById(memberID), 0).complete();
return true;
}
catch(Exception e)
+2
View File
@@ -36,11 +36,13 @@ public class GlobalLog
System.out.println(logLine);
}
public static void log(LogFilter filter, Object obj) { write(log, filter, obj.toString()); }
public static void log(LogFilter filter, String msg) { write(log, filter, msg); }
public static void warn(LogFilter filter, String msg) { write(warn, filter, msg); }
public static void error(LogFilter filter, String msg) { write(error, filter, msg); System.err.println(msg); System.err.flush(); }
public static void fatal(LogFilter filter, String msg) throws Exception { write(fatal, filter, msg); throw new Exception(msg); }
public static void log(Object obj) { log(LogFilter.Debug, obj); }
public static void log(String msg) { log(LogFilter.Debug, msg); }
public static void warn(String msg) { warn(LogFilter.Debug, msg); }
public static void error(String msg) { error(LogFilter.Debug, msg); }
+10 -6
View File
@@ -1,4 +1,5 @@
package utils.audio;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
@@ -9,10 +10,11 @@ import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
import net.dv8tion.jda.core.audio.AudioSendHandler;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.managers.AudioManager;
import net.dv8tion.jda.api.audio.AudioSendHandler;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.managers.AudioManager;
public class AudioUtils
{
@@ -72,9 +74,11 @@ public class AudioUtils
return lastFrame != null;
}
@Override public byte[] provide20MsAudio()
@Override
public ByteBuffer provide20MsAudio()
{
return lastFrame.getData();
ByteBuffer outputBuffer = ByteBuffer.wrap(lastFrame.getData());
return outputBuffer;
}
@Override public boolean isOpus()