use of com.github.jonteohr.tejbz.PropertyHandler in project pgda by jonteohr.
the class TwitchHandler method onTwitchChat.
@EventSubscriber
public void onTwitchChat(IRCMessageEvent e) {
if (!e.getChannel().getName().equalsIgnoreCase("tejbz"))
return;
if (!e.getMessage().isPresent() || e.getUser() == null)
return;
// Increment to counter for automessaging
AutoMessage.count++;
String[] args = e.getMessage().get().split("\\s+");
CommandSQL sql = new CommandSQL();
String user = e.getTags().get("display-name");
if ((Twitch.settings.get("excemptSubs") && !Twitch.isSubscribed(user)) || (!Twitch.settings.get("excemptSubs"))) {
// Link check
if ((Twitch.settings.get("preventLinks")) && !Twitch.isModerator(e.getTags())) {
for (String arg : args) {
Matcher m = pattern.matcher(arg);
if (m.find()) {
if (arg.contains("clips.twitch.tv"))
continue;
Twitch.chat("/timeout " + user + " 3 Don't post links.");
Twitch.chat(user + " Links are not allowed! tejbzW (1s)");
System.out.println("Removed " + user + "s message due to links disabled.");
break;
}
}
}
// Check if message is all caps
if ((!Twitch.settings.get("allowCaps")) && !Twitch.isModerator(e.getTags())) {
if (App.isStringUppercase(e.getMessage().get(), 10)) {
Twitch.chat("/timeout " + user + " 3 Wrote in all caps.");
Twitch.chat(user + " Feeling a little hectic, are we? Don't use all uppercase...");
System.out.println("Removed " + user + "'s message due to all caps.");
return;
}
}
// Blacklisted words check
if (!Twitch.isModerator(e.getTags())) {
for (String arg : args) {
if (BlackList.blockedPhrases.contains(arg)) {
Twitch.chat("/timeout " + user + " 3 Used a blacklisted word/phrase");
Twitch.chat(user + " You're using a blacklisted word/phrase! (1s)");
System.out.println("Removed " + user + "s message due to blacklisted word.");
return;
}
}
}
// Used a /me prefix
if (!Twitch.settings.get("allowMe") && !Twitch.isModerator(e.getTags())) {
if (args[0].equalsIgnoreCase("ACTION")) {
Twitch.chat("/timeout " + user + " 3 Not allowed to use /me");
Twitch.chat(user + " you're not allowed to use /me (1s)");
return;
}
}
}
// Check to see if command is in cooldown!
if (CommandTimer.isInCooldown(args[0]) && !Twitch.isModerator(e.getTags()))
return;
if (args[0].equalsIgnoreCase("!clip")) {
if (!Twitch.isStreamLive) {
Twitch.chat("@" + user + " Tejbz is offline, there's nothing to clip!");
return;
}
if (// Clip cooldown
clipTime > 0)
return;
CreateClipList clipData = Twitch.twitchClient.getHelix().createClip(Identity.getAccessToken(Twitch.getOAuth2()), "25622462", false).execute();
String clipLink = "https://clips.twitch.tv/" + clipData.getData().get(0).getId();
Twitch.chat("@" + user + " " + clipLink);
EmbedBuilder msg = new EmbedBuilder();
msg.setAuthor(user, "https://twitch.tv/" + user, Twitch.getUser(user).getProfileImageUrl());
msg.setDescription("Just clipped Tejbz stream. Check it out!\n" + clipLink);
App.twitchLog.sendMessageEmbeds(msg.build()).queue();
clipTimer();
return;
}
if (args[0].equalsIgnoreCase("!commands")) {
if (args.length == 1) {
Twitch.chat("@" + user + " List of commands are available at: http://pgda.xyz/commands");
CommandTimer.addToCooldown(args[0]);
return;
}
}
if (args[0].equalsIgnoreCase("!vanish")) {
if (Twitch.isModerator(e.getTags()))
return;
Twitch.chat("/timeout " + user + " 1");
Twitch.chat(user + " Disappeared into the mist...");
CommandTimer.addToCooldown(args[0]);
return;
}
if (args[0].equalsIgnoreCase("!connect")) {
if (args.length < 2) {
Twitch.chat("@" + user + " You need to specify your Minecraft username like this: !connect username");
return;
}
String username = args[1];
if (!MinecraftSQL.connectToMinecraft(user, username)) {
Twitch.chat("@" + user + " Couldn't connect your minecraft at the moment. Have you already connected yours?");
return;
}
Twitch.chat("@" + user + " You've been connected with the account \"" + username + "\".");
return;
}
if (Twitch.isModerator(e.getTags())) {
if (args[0].equalsIgnoreCase("!commands")) {
if (args.length >= 3) {
String setting = args[1];
if (setting.equalsIgnoreCase("add")) {
if (args.length < 4) {
Twitch.chat(user + " No reply specified.");
return;
}
String cmdName = args[2];
StringBuilder msg = new StringBuilder();
for (int i = 3; i < args.length; i++) {
msg.append(" ").append(args[i]);
}
if (sql.getCommands().contains(cmdName)) {
Twitch.chat("@" + user + " The command " + cmdName + " already exists. Did you mean to use !editcmd maybe?");
return;
}
if (sql.addCommand(cmdName, msg.toString())) {
Twitch.chat("@" + user + " Command " + cmdName + " stored!");
Twitch.commands.put(cmdName, msg.toString());
WebLog.addToWeblog("TWITCH", user, "Created the command <code>" + cmdName + "</code>");
}
return;
}
if (setting.equalsIgnoreCase("edit")) {
if (args.length < 4) {
Twitch.chat(user + " No new reply specified.");
return;
}
String cmdName = args[2];
StringBuilder msg = new StringBuilder();
for (int i = 3; i < args.length; i++) {
msg.append(" ").append(args[i]);
}
if (!sql.getCommands().contains(cmdName)) {
Twitch.chat("@" + user + " There is no command named " + cmdName);
return;
}
if (sql.editCommand(cmdName, msg.toString())) {
Twitch.chat("@" + user + " Command " + cmdName + " stored!");
Twitch.commands.replace(cmdName, msg.toString());
WebLog.addToWeblog("TWITCH", user, "Edited the command <code>" + cmdName + "</code>");
} else {
Twitch.chat("@" + user + " Failed editing the command " + cmdName);
}
return;
}
if (setting.equalsIgnoreCase("delete")) {
if (!sql.getCommands().contains(args[2])) {
Twitch.chat("@" + user + " There is no command named " + args[2]);
return;
}
if (sql.deleteCommand(args[2])) {
Twitch.chat("@" + user + " Command " + args[2] + " successfully deleted!");
Twitch.commands.remove(args[2]);
WebLog.addToWeblog("TWITCH", user, "Deleted the command <code>" + args[2] + "</code>");
}
return;
}
}
}
if (args[0].equalsIgnoreCase("!automessage")) {
if (args.length < 3) {
Twitch.chat("@" + user + " Invalid arguments. Visit http://pgda.xyz/commands for commands list.");
return;
}
String setting = args[1];
if (setting.equalsIgnoreCase("interval")) {
AutoMessageSQL amSql = new AutoMessageSQL();
if (amSql.setInterval(Integer.parseInt(args[2]))) {
Twitch.chat("@" + user + " Successfully saved the auto-message delay to: " + args[2] + "!");
WebLog.addToWeblog("TWITCH", user, "Changed the automessage interval to " + args[2]);
return;
}
} else if (setting.equalsIgnoreCase("add")) {
StringBuilder message = new StringBuilder();
for (int i = 2; i < args.length; i++) {
message.append(args[i]).append(" ");
}
AutoMessageSQL amSql = new AutoMessageSQL();
if (!amSql.addAutoMessage(message.toString())) {
Twitch.chat("Failed to add/update playlist. Try again later!");
return;
}
AutoMessage.updateAutoMessages();
Twitch.chat("Added message and updated playlist.");
WebLog.addToWeblog("TWITCH", user, "Added a message to auto-message: <code>" + message + "</code>");
return;
} else if (setting.equalsIgnoreCase("remove")) {
StringBuilder message = new StringBuilder();
for (int i = 2; i < args.length; i++) {
message.append(args[i]).append(" ");
}
AutoMessageSQL amSql = new AutoMessageSQL();
if (!amSql.removeAutoMessage(message.toString())) {
Twitch.chat("Failed to remove/update playlist. Try again later!");
return;
}
AutoMessage.updateAutoMessages();
Twitch.chat("Removed the message from the playlist!");
WebLog.addToWeblog("TWITCH", user, "Removed a message from auto-message: <code>" + message + "</code>");
return;
}
}
if (args[0].equalsIgnoreCase("!title")) {
if (args.length < 2) {
String title = Twitch.getChannelInfo().getTitle();
Twitch.chat("Current title set to: " + title);
return;
}
StringBuilder title = new StringBuilder();
for (int i = 1; i < args.length; i++) {
title.append(args[i]).append(" ");
}
Twitch.setTitle(title.toString());
Twitch.chat("Title set to: " + title);
return;
}
if (args[0].equalsIgnoreCase("!game")) {
if (args.length < 2) {
String game = Twitch.getChannelInfo().getGameName();
Twitch.chat("Tejbz is currently playing " + game);
return;
}
StringBuilder game = new StringBuilder();
for (int i = 1; i < args.length; i++) {
if (i == args.length - 1)
game.append(args[i]);
else
game.append(args[i]).append(" ");
}
Twitch.setGame(game.toString());
Twitch.chat("Game set to: " + game);
return;
}
if (args[0].equalsIgnoreCase("!ad")) {
if (!Twitch.isStreamLive) {
Twitch.chat("Tejbz is not live.");
return;
}
int time = 30;
if (args.length > 1) {
try {
time = Integer.parseInt(args[1]);
} catch (NumberFormatException ex) {
Twitch.chat("@" + user + " Invalid argument");
return;
}
}
if (Twitch.runAd(time))
Twitch.chat("Running a " + time + " second ad.");
else
Twitch.chat("Couldn't start the ad.");
return;
}
if (args[0].equalsIgnoreCase("!help")) {
Twitch.chat("@" + user + " Bot formatting and commands are available over at http://pgda.xyz/commands");
return;
}
}
if (Twitch.commands.containsKey(args[0].toLowerCase())) {
String reply = Twitch.commands.get(args[0]);
if (Twitch.specCommands.containsKey(args[0])) {
if (Twitch.specCommands.get(args[0]).equalsIgnoreCase("mod") && !Twitch.isModerator(e.getTags()))
return;
if (Twitch.specCommands.get(args[0]).equalsIgnoreCase("sub") && !Twitch.isSubscribed(user))
return;
}
if (reply.contains("[@user]"))
reply = reply.replace("[@user]", "@" + user);
if (reply.contains("[user]"))
reply = reply.replace("[user]", user);
if (reply.contains("[subcount]"))
reply = reply.replace("[subcount]", Twitch.getSubscribers("tejbz") + "");
if (reply.contains("[follows]"))
reply = reply.replace("[follows]", "" + Twitch.getFollowers("tejbz"));
if (reply.contains("[count]"))
reply = reply.replace("[count]", String.valueOf(CommandSQL.getUses(args[0])));
if (reply.contains("[watchtime]"))
reply = reply.replace("[watchtime]", Twitch.getWatchTime(user));
if (reply.contains("[followage]"))
reply = reply.replace("[followage]", Twitch.getFollowAge(user));
if (reply.contains("[uptime]")) {
Stream stream = Twitch.getStream("tejbz");
if (stream == null) {
reply = "Tejbz is offline.";
} else {
reply = reply.replace("[uptime]", App.formatDuration(stream.getUptime()));
}
}
if (reply.contains("[touser]"))
reply = reply.replace("[touser]", (args.length > 1 ? args[1] : user));
if (reply.contains("[@touser]"))
reply = reply.replace("[@touser]", (args.length > 1 ? "@" + args[1] : "@" + user));
if (reply.contains("[recent_video]")) {
PropertyHandler propertyHandler = new PropertyHandler();
reply = reply.replace("[recent_video]", propertyHandler.getPropertyValue("recent_video"));
}
Twitch.chat(reply);
CommandSQL.incrementUses(args[0]);
CommandTimer.addToCooldown(args[0]);
return;
}
}
use of com.github.jonteohr.tejbz.PropertyHandler in project pgda by jonteohr.
the class Identity method refreshToken.
public static OAuth2Credential refreshToken(OAuth2Credential credential) {
OAuth2Credential newOauth = identityProvider.refreshCredential(getCredential(credential)).get();
PropertyHandler props = new PropertyHandler();
props.setProperty("access_token", newOauth.getAccessToken());
props.setProperty("refresh_token", newOauth.getRefreshToken());
// revoke the old one for safety
identityProvider.revokeCredential(getCredential(credential));
saveOAuth(props.getPropertyValue("access_token"), props.getPropertyValue("refresh_token"));
return newOauth;
}
use of com.github.jonteohr.tejbz.PropertyHandler in project pgda by jonteohr.
the class Video method sendAd.
public static void sendAd(TextChannel channel) {
PropertyHandler prop = new PropertyHandler();
String url = prop.getPropertyValue("recent_video");
channel.sendMessage("Check out the latest video on the YouTube channel!\n" + url).queue();
}
use of com.github.jonteohr.tejbz.PropertyHandler in project pgda by jonteohr.
the class SetSchedule method setSchedule.
public static void setSchedule(SlashCommandInteractionEvent e, InteractionHook hook) {
PermissionHandler perms = new PermissionHandler();
PropertyHandler props = new PropertyHandler();
if (!perms.isAdmin(e.getMember()))
return;
if (e.getOptions().size() < 1) {
hook.sendMessage("Incorrect usage.\nCorrect usage: `!setschedule <imageURL>`").queue();
return;
}
try {
URL url = new URL(e.getOption("image_url").getAsString());
if (props.setProperty("schedule_url", url.toString())) {
hook.sendMessage("Saved new schedule image!").queue();
WebLog.addToWeblog("DISCORD", e.getUser().getAsTag(), "Updated the schedule: <a href='" + url + "'>New Schedule</a>");
return;
}
hook.sendMessage("Error while saving. Try again later!").queue();
return;
} catch (MalformedURLException e1) {
hook.sendMessage("Argument was not a valid image URL!").queue();
System.out.println(e1);
return;
}
}
use of com.github.jonteohr.tejbz.PropertyHandler in project pgda by jonteohr.
the class SetVideo method setVideo.
public static void setVideo(SlashCommandInteractionEvent e, InteractionHook hook) {
PropertyHandler prop = new PropertyHandler();
PermissionHandler perm = new PermissionHandler();
if (!perm.isMod(e.getMember()))
return;
if (e.getOptions().size() < 1) {
hook.sendMessage("Invalid usage.\nCorrect usage: `!setvid <youtubeURL>`").queue();
return;
}
String url = e.getOption("video_url").getAsString();
if (prop.setProperty("recent_video", url)) {
hook.sendMessage("Successfully saved!").queue();
WebLog.addToWeblog("DISCORD", e.getUser().getAsTag(), "Updated the latest video: <a href='" + url + "'>New Video</a>");
} else {
hook.sendMessage("Failed to save...").queue();
}
}
Aggregations