Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Add znc command.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Feb 25, 2016
1 parent 8f4ffed commit fa0adc9
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/cnaude/purpleirc/CommandHandlers.java
Expand Up @@ -100,6 +100,7 @@ public CommandHandlers(PurpleIRC plugin) {
commands.put("voice", new Voice(plugin));
commands.put("whois", new Whois(plugin));
commands.put("help", new Help(plugin));
commands.put("znc", new Znc(plugin));

commands.put("test", new Test(plugin));

Expand Down
89 changes: 89 additions & 0 deletions src/main/java/com/cnaude/purpleirc/Commands/Znc.java
@@ -0,0 +1,89 @@
/*
* Copyright (C) 2014 cnaude
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cnaude.purpleirc.Commands;

import com.cnaude.purpleirc.PurpleBot;
import com.cnaude.purpleirc.PurpleIRC;
import java.util.ArrayList;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

/**
*
* @author Chris Naude
*/
public class Znc implements IRCCommandInterface {

private final PurpleIRC plugin;
private final String usage = "([bot]) [command] ([arguments])";
private final String desc = "Send a private message to an IRC user.";
private final String name = "znc";
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;

/**
*
* @param plugin the PurpleIRC plugin
*/
public Znc(PurpleIRC plugin) {
this.plugin = plugin;
}

/**
*
* @param sender
* @param args
*/
@Override
public void dispatch(CommandSender sender, String[] args) {
if (args.length >= 2) {
plugin.logDebug("Dispatching msg command...");
int msgIdx = 1;
java.util.List<PurpleBot> myBots = new ArrayList<>();
if (plugin.ircBots.containsKey(args[1])) {
myBots.add(plugin.ircBots.get(args[1]));
msgIdx = 2;
} else {
myBots.addAll(plugin.ircBots.values());
}

for (PurpleBot ircBot : myBots) {
String msg = "";
for (int i = msgIdx; i < args.length; i++) {
msg = msg + " " + args[i];
}
ircBot.znc(sender, msg.substring(1));
}
} else {
sender.sendMessage(fullUsage);
}
}

@Override
public String name() {
return name;
}

@Override
public String desc() {
return desc;
}

@Override
public String usage() {
return usage;
}
}
Expand Up @@ -55,6 +55,12 @@ public void onPrivateMessage(PrivateMessageEvent event) {

plugin.logDebug("Private message caught <" + user.getNick() + ">: " + message);

// Catch znc status messages
if (user.getNick().equals("*status")) {
ircBot.zncResponse("<ZNC:Status>: " + message);
return;
}

for (String myChannel : ircBot.botChannels) {
channel = ircBot.getChannel(myChannel);
if (channel != null) {
Expand Down
34 changes: 27 additions & 7 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -200,6 +200,7 @@ public final class PurpleBot {
private final List<String> tailerFiles;
private String tailerRecipient;
private boolean tailerCtcp;
private CommandSender zncSender;
/**
* Map of player names to IRC nicks.
*/
Expand Down Expand Up @@ -273,6 +274,7 @@ public PurpleBot(File file, PurpleIRC plugin) {
this.ircPrivateMsgMap = new CaseInsensitiveMap<>();
this.tailers = new ArrayList<>();
this.tailerFiles = new ArrayList<>();
this.zncSender = plugin.getServer().getConsoleSender();
config = new YamlConfiguration();
goodBot = loadConfig();
if (goodBot) {
Expand Down Expand Up @@ -669,6 +671,24 @@ public void run() {
});
}

public void znc(final CommandSender sender, final String message) {
zncSender = sender;
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
bot.sendRaw().rawLineNow("znc " + message);
}
});
}

public void zncResponse(String message) {
if (zncSender != null) {
zncSender.sendMessage(message);
} else {
plugin.getServer().getConsoleSender().sendMessage(message);
}
}

public void asyncIdentify(final String password) {
if (!this.isConnected()) {
return;
Expand Down Expand Up @@ -906,7 +926,7 @@ private boolean loadConfig() {

logIrcToHeroChat.put(channelName, config.getBoolean("channels." + enChannelName + ".log-irc-to-hero-chat", false));
plugin.logDebug(" LogIrcToHeroChat => " + logIrcToHeroChat.get(channelName));

logIrcToVentureChat.put(channelName, config.getBoolean("channels." + enChannelName + ".log-irc-to-venture-chat", false));
plugin.logDebug(" LogIrcToVentureChat => " + logIrcToVentureChat.get(channelName));

Expand Down Expand Up @@ -1222,7 +1242,7 @@ public void gameChat(AsyncPlayerChatEvent event) {
} else {
plugin.logDebug("No Factions");
}
if (plugin.ventureChatEnabled) {
if (plugin.ventureChatEnabled) {
plugin.getServer().getPluginManager().callEvent(new VentureChatEvent(event, this));
}
if (isMessageEnabled(channelName, TemplateName.GAME_CHAT)) {
Expand All @@ -1243,7 +1263,7 @@ public void sendFloodWarning(Player player) {

/**
* Called from HeroChat listener
*
*
* @param chatter
* @param chatColor
* @param message
Expand Down Expand Up @@ -1397,16 +1417,16 @@ public void adminChat(String name, String message, String world) {
}
}

/**
/**
* Called from SimpleTicketEvent
*
* @param uuid
* @param ticket
* @param botNick
* @param messageType
*/
public void simpleTicketNotify(UUID uuid,
uk.co.joshuawoolley.simpleticketmanager.ticketsystem.Ticket ticket,
public void simpleTicketNotify(UUID uuid,
uk.co.joshuawoolley.simpleticketmanager.ticketsystem.Ticket ticket,
String botNick, String messageType) {
if (!this.isConnected()) {
return;
Expand All @@ -1419,7 +1439,7 @@ public void simpleTicketNotify(UUID uuid,
}
}
}

/**
* Called from ReportRTS event
*
Expand Down

0 comments on commit fa0adc9

Please sign in to comment.