use of com.github.philippheuer.events4j.simple.domain.EventSubscriber in project pgda by jonteohr.
the class BankHandler method onDaily.
@EventSubscriber
public void onDaily(IRCMessageEvent e) {
if (!e.getChannel().getName().equalsIgnoreCase("tejbz"))
return;
if (!e.getMessage().isPresent() || e.getUser() == null)
return;
String[] args = e.getMessage().get().split("\\s+");
String user = e.getTags().get("display-name");
if (!args[0].equalsIgnoreCase("!bank") && !args[0].equalsIgnoreCase("!collect") && !args[0].equalsIgnoreCase("!roll") && !args[0].equalsIgnoreCase("!givecoins") && !args[0].equalsIgnoreCase("!transfer") && !args[0].equalsIgnoreCase("!dropcoins"))
return;
BankSQL bankSQL = new BankSQL();
if (args[0].equalsIgnoreCase("!bank")) {
int coins = bankSQL.getCoins(user);
String fCoins = String.format("%,d", coins);
Twitch.sendPm(user, "You currently have " + fCoins + " PGDA coins.");
return;
}
/*
MODERATOR
COMMANDS
*/
if (Twitch.isModerator(e.getTags())) {
if (args[0].equalsIgnoreCase("!givecoins")) {
if (args.length < 3) {
Twitch.sendPm(user, "Correct usage: !givecoins [user] [amount]");
return;
}
User target = Twitch.getUser(args[1]);
if (target == null) {
Twitch.sendPm(user, "Couldn't find user " + args[1]);
return;
}
if (!bankSQL.isUserInDatabase(target.getDisplayName())) {
Twitch.sendPm(user, target.getDisplayName() + " has never collected any coins. They must have done this at least once!");
return;
}
try {
int amount = Integer.parseInt(args[2]);
bankSQL.incrementCoins(target.getDisplayName(), amount);
Twitch.sendPm(user, "You've awarded " + target.getDisplayName() + " " + amount + " PGDA Coins.");
Twitch.sendPm(target.getDisplayName(), user + " has awarded you " + amount + " PGDA Coins.");
return;
} catch (NumberFormatException ex) {
Twitch.sendPm(user, args[2] + " is not a valid number.");
return;
}
}
if (args[0].equalsIgnoreCase("!dropcoins") && (user.equalsIgnoreCase("tejbz") || user.equalsIgnoreCase("rlhypr"))) {
int coins;
if (args.length < 2) {
coins = 100;
} else {
try {
coins = Integer.parseInt(args[1]);
} catch (NumberFormatException ex) {
ex.printStackTrace();
Twitch.chat(user + " " + args[1] + " is not a valid number.");
return;
}
}
List<String> chatters = Twitch.twitchClient.getMessagingInterface().getChatters("tejbz").execute().getAllViewers();
int finalCoins = coins;
chatters.forEach(chatter -> {
if (bankSQL.isUserInDatabase(chatter))
bankSQL.incrementCoins(chatter, finalCoins);
});
Twitch.chatMe("tejbzBeer " + user + " Just awarded all viewers with " + coins + " PGDA Coins! tejbzPog");
return;
}
}
if (args[0].equalsIgnoreCase("!collect")) {
Random random = new Random();
int maxDaily = 1000;
int minDaily = 500;
int coins = random.nextInt(maxDaily - minDaily) + minDaily;
String fCoins = String.format("%,d", coins);
if (!bankSQL.isUserInDatabase(user)) {
if (bankSQL.collectDaily(user, coins)) {
Twitch.sendPm(user, "You've collected your daily " + fCoins + " PGDA coins!");
}
return;
}
if (bankSQL.getLastCollected(user) == null) {
if (bankSQL.collectDaily(user, coins))
Twitch.sendPm(user, "You've collected your daily " + fCoins + " PGDA coins!");
return;
}
Calendar current = Calendar.getInstance();
current.set(Calendar.HOUR_OF_DAY, 0);
current.set(Calendar.MINUTE, 0);
current.set(Calendar.SECOND, 0);
current.set(Calendar.MILLISECOND, 0);
Calendar last = Calendar.getInstance();
last.setTime(bankSQL.getLastCollected(user));
last.set(Calendar.HOUR_OF_DAY, 0);
last.set(Calendar.MINUTE, 0);
last.set(Calendar.SECOND, 0);
last.set(Calendar.MILLISECOND, 0);
if (last.compareTo(current) < 0) {
if (bankSQL.collectDaily(user, coins)) {
Twitch.sendPm(user, "You've collected your daily " + fCoins + " PGDA coins!");
}
} else {
Twitch.sendPm(user, "You've already collected your daily PGDA Coins!");
}
return;
}
if (args[0].equalsIgnoreCase("!roll")) {
if (CoinsTimer.isCooldown(user)) {
Twitch.sendPm(user, "That command is currently in a cooldown! Try again in " + CoinsTimer.getCooldown(user) + " minutes.");
return;
}
if (args.length < 2) {
Twitch.chat("@" + user + " You didn't specify a bet amount.");
return;
}
try {
int bet = Integer.parseInt(args[1]);
rollCoins(user, bet);
return;
} catch (NumberFormatException ex) {
if (!args[1].equalsIgnoreCase("all")) {
Twitch.chat("@" + user + " Bet amount was not a valid number.");
return;
}
rollCoins(user, bankSQL.getCoins(user));
return;
}
}
if (args[0].equalsIgnoreCase("!transfer")) {
if (args.length < 3) {
Twitch.sendPm(user, "Invalid arguments. Need to specify who you want to give coins and how much. Like this: !transfer rlHypr 1337");
return;
}
try {
User target = Twitch.getUser(args[1]);
int amount = Integer.parseInt(args[2]);
if (target == null) {
Twitch.sendPm(user, "Could not find user " + args[1]);
return;
}
if (bankSQL.getCoins(user) < amount) {
Twitch.sendPm(user, "You don't have " + amount + " coins.");
return;
}
if (!bankSQL.incrementCoins(target.getDisplayName(), amount) && bankSQL.decrementCoins(user, amount)) {
Twitch.sendPm(user, "Couldn't transfer at the moment. Please try again later!");
return;
}
Twitch.sendPm(user, "You've given " + target + " " + amount + " Coins!");
Twitch.sendPm(target.getDisplayName(), user + " has given you " + amount + " Coins!");
} catch (NumberFormatException ex) {
Twitch.sendPm(user, args[2] + " is not a valid number.");
return;
}
}
}
use of com.github.philippheuer.events4j.simple.domain.EventSubscriber 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.philippheuer.events4j.simple.domain.EventSubscriber in project pgda by jonteohr.
the class TwitchHandler method onLive.
@EventSubscriber
public void onLive(ChannelGoLiveEvent e) {
System.out.println("**********************");
System.out.println("Tejbz went live!");
System.out.println("**********************");
Twitch.isStreamLive = true;
EmbedBuilder msg = new EmbedBuilder();
msg.setAuthor("Tejbz", null, Twitch.getUser(e.getChannel().getName()).getProfileImageUrl());
msg.setColor(App.color);
msg.setImage(e.getStream().getThumbnailUrl(1280, 720));
msg.setTitle("Tejbz just went live!", "https://www.twitch.tv/tejbz");
msg.addField("Title", e.getStream().getTitle(), false);
msg.addField("Playing", Twitch.getGameById(e.getStream().getGameId()), false);
App.liveChannel.sendMessage(App.guild.getPublicRole().getAsMention() + " Tejbz just went live!").queue();
App.liveChannel.sendMessageEmbeds(msg.build()).queue();
Twitch.chatMe("Tejbz Just went live! You can now collect your daily PGDA Coins with !collect");
}
use of com.github.philippheuer.events4j.simple.domain.EventSubscriber in project pgda by jonteohr.
the class GiveawayCommand method onCommand.
@EventSubscriber
public void onCommand(IRCMessageEvent e) {
if (!e.getChannel().getName().equalsIgnoreCase("tejbz"))
return;
if (!e.getMessage().isPresent() || e.getUser() == null)
return;
if (!Twitch.isModerator(e.getTags()))
return;
String[] args = e.getMessage().get().split("\\s+");
if (args[0].equalsIgnoreCase("!raffle")) {
if (giveawayActive) {
// Ignore if already active
Twitch.chat("A raffle is already active. Type !draw to draw a winner.");
return;
}
giveawayActive = true;
if (args.length < 2) {
Twitch.chatMe("A raffle has started! Type anything in chat to be a part of it and have a chance of winning!");
return;
}
keyword = args[1];
Twitch.chatMe("A raffle has started! To enter type this keyword in chat: " + keyword);
return;
}
if (args[0].equalsIgnoreCase("!draw")) {
if (!giveawayActive) {
Twitch.chat("A raffle is not active at the moment.");
return;
}
if (participants.size() == 0) {
Twitch.chat("No users participated in the raffle. There is no winner!");
clearRoll();
return;
}
int total = participants.size();
int winner = new Random().nextInt(total);
Twitch.chatMe("We have a winner! Congratulations @" + participants.get(winner) + "!");
clearRoll();
}
}
use of com.github.philippheuer.events4j.simple.domain.EventSubscriber in project pgda by jonteohr.
the class BankHandler method onRewardRedeemed.
@EventSubscriber
public void onRewardRedeemed(RewardRedeemedEvent e) {
String rewardId = e.getRedemption().getReward().getId();
String user = e.getRedemption().getUser().getDisplayName();
long cost = e.getRedemption().getReward().getCost();
int coins = 2000;
if (rewardId.equalsIgnoreCase("dcaa91f7-7e6f-4746-b081-9e444a010def")) {
BankSQL bankSQL = new BankSQL();
bankSQL.incrementCoins(user, coins);
Twitch.sendPm(user, "You just bought " + String.format("%,d", coins) + " PGDA Coins for " + String.format("%,d", cost) + " Channel Points.");
}
}
Aggregations