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

Commit

Permalink
Add voice commands
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed May 15, 2014
1 parent eb5a1bb commit 2d3c2d9
Show file tree
Hide file tree
Showing 8 changed files with 516 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/cnaude/purpleirc/CommandHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public CommandHandlers(PurpleIRC plugin) {
this.plugin = plugin;

commands.put("addop", new AddOp(plugin));
commands.put("addvoice", new AddVoice(plugin));
commands.put("connect", new Connect(plugin));
commands.put("ctcp", new CTCP(plugin));
commands.put("deop", new DeOp(plugin));
commands.put("devoice", new DeVoice(plugin));
commands.put("debug", new Debug(plugin));
commands.put("disconnect", new Disconnect(plugin));
commands.put("join", new Join(plugin));
Expand All @@ -40,6 +42,7 @@ public CommandHandlers(PurpleIRC plugin) {
commands.put("list", new List(plugin));
commands.put("listbots", new ListBots(plugin));
commands.put("listops", new ListOps(plugin));
commands.put("listvoices", new ListVoices(plugin));
commands.put("login", new Login(plugin));
commands.put("messagedelay", new MessageDelay(plugin));
commands.put("msg", new Msg(plugin));
Expand All @@ -56,13 +59,15 @@ public CommandHandlers(PurpleIRC plugin) {
commands.put("reloadbots", new ReloadBots(plugin));
commands.put("reloadconfig", new ReloadConfig(plugin));
commands.put("removeop", new RemoveOp(plugin));
commands.put("removevoice", new RemoveVoice(plugin));
commands.put("save", new Save(plugin));
commands.put("say", new Say(plugin));
commands.put("send", new Send(plugin));
commands.put("sendraw", new SendRaw(plugin));
commands.put("server", new Server(plugin));
commands.put("topic", new Topic(plugin));
commands.put("unmute", new UnMute(plugin));
commands.put("voice", new Voice(plugin));
commands.put("whois", new Whois(plugin));
commands.put("help", new Help(plugin));

Expand Down
80 changes: 80 additions & 0 deletions src/main/java/com/cnaude/purpleirc/Commands/AddVoice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.cnaude.purpleirc.Commands;

import com.cnaude.purpleirc.PurpleIRC;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.pircbotx.Channel;
import org.pircbotx.User;

/**
*
* @author cnaude
*/
public class AddVoice implements IRCCommandInterface {

private final PurpleIRC plugin;
private final String usage = "[bot] [channel] [user|mask]";
private final String desc = "Add IRC users to IRC auto voice list.";
private final String name = "addvoice";
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;

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

/**
*
* @param sender
* @param args
*/
@Override
public void dispatch(CommandSender sender, String[] args) {
if (args.length == 4) {
String bot = args[1];
String channelName = args[2];
if (plugin.ircBots.containsKey(bot)) {
// #channel, user
String nick = args[3];
String mask = nick;
Channel channel = plugin.ircBots.get(bot).getChannel(channelName);
if (channel != null) {
for (User user : channel.getUsers()) {
if (user.getNick().equalsIgnoreCase(nick)) {
mask = "*!*" + user.getLogin() + "@" + user.getHostmask();
}
}
}
if (mask.split("[\\!\\@]", 3).length == 3) {
plugin.ircBots.get(bot).addVoice(channelName, mask, sender);
plugin.ircBots.get(bot).voiceFriends(channelName);
} else {
sender.sendMessage(ChatColor.RED + "Invalid user or mask: "
+ ChatColor.WHITE + mask);
}
} else {
sender.sendMessage(plugin.invalidBotName.replace("%BOT%", bot));
}
} else {
sender.sendMessage(fullUsage);
}
}

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

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

@Override
public String usage() {
return usage;
}
}
77 changes: 77 additions & 0 deletions src/main/java/com/cnaude/purpleirc/Commands/DeVoice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.cnaude.purpleirc.Commands;

import com.cnaude.purpleirc.PurpleIRC;
import com.cnaude.purpleirc.Utilities.BotsAndChannels;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

/**
*
* @author cnaude
*/
public class DeVoice implements IRCCommandInterface {

private final PurpleIRC plugin;
private final String usage = "([bot]) ([channel]) [user(s)]";
private final String desc = "De-voice IRC user(s).";
private final String name = "devoice";
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;

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

/**
*
* @param sender
* @param args
*/
@Override
public void dispatch(CommandSender sender, String[] args) {
BotsAndChannels bac;
int idx;

if (args.length >= 4) {
bac = new BotsAndChannels(plugin, sender, args[1], args[2]);
idx = 3;
} else if (args.length == 2) {
bac = new BotsAndChannels(plugin, sender);
idx = 1;
} else {
sender.sendMessage(fullUsage);
return;
}
if (bac.bot.size() > 0 && bac.channel.size() > 0) {
for (String botName : bac.bot) {
for (String channelName : bac.channel) {
for (int i = idx; i < args.length; i++) {
plugin.ircBots.get(botName).deVoice(channelName, args[i]);
sender.sendMessage("Removing voice status from "
+ ChatColor.WHITE + args[i]
+ ChatColor.RESET + " in "
+ ChatColor.WHITE + channelName);
}
}
}
}
}

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

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

@Override
public String usage() {
return usage;
}
}
69 changes: 69 additions & 0 deletions src/main/java/com/cnaude/purpleirc/Commands/ListVoices.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.cnaude.purpleirc.Commands;

import com.cnaude.purpleirc.PurpleIRC;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

/**
*
* @author cnaude
*/
public class ListVoices implements IRCCommandInterface {

private final PurpleIRC plugin;
private final String usage = "[bot] [channel]";
private final String desc = "List IRC user mask in auto-voice list.";
private final String name = "listvoices";
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;

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

/**
*
* @param sender
* @param args
*/
@Override
public void dispatch(CommandSender sender, String[] args) {
if (args.length == 3) {
String bot = args[1];
String channelName = args[2];
if (plugin.ircBots.containsKey(bot)) {
if (plugin.ircBots.get(bot).voicesList.containsKey(channelName)) {
sender.sendMessage(ChatColor.DARK_PURPLE + "-----[ " + ChatColor.WHITE + channelName
+ ChatColor.DARK_PURPLE + " - " + ChatColor.WHITE + "Auto Voice Masks" + ChatColor.DARK_PURPLE + " ]-----");
for (String userMask : plugin.ircBots.get(bot).voicesList.get(channelName)) {
sender.sendMessage(" - " + userMask);
}
} else {
sender.sendMessage(plugin.invalidChannel.replace("%CHANNEL%", channelName));
}
} else {
sender.sendMessage(plugin.invalidBotName.replace("%BOT%", bot));
}
} else {
sender.sendMessage(fullUsage);
}
}

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

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

@Override
public String usage() {
return usage;
}
}
62 changes: 62 additions & 0 deletions src/main/java/com/cnaude/purpleirc/Commands/RemoveVoice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.cnaude.purpleirc.Commands;

import com.cnaude.purpleirc.PurpleIRC;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

/**
*
* @author cnaude
*/
public class RemoveVoice implements IRCCommandInterface {

private final PurpleIRC plugin;
private final String usage = "[bot] [channel] [user mask]";
private final String desc = "Remove a user mask from the auto-voice list.";
private final String name = "removevoice";
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;

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

/**
*
* @param sender
* @param args
*/
@Override
public void dispatch(CommandSender sender, String[] args) {
if (args.length == 4) {
String bot = args[1];
String channel = args[2];
if (plugin.ircBots.containsKey(bot)) {
// #channel, user
plugin.ircBots.get(bot).removeVoice(channel, args[3], sender);
} else {
sender.sendMessage(plugin.invalidBotName.replace("%BOT%", bot));
}
} else {
sender.sendMessage(fullUsage);
}
}

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

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

@Override
public String usage() {
return usage;
}
}
68 changes: 68 additions & 0 deletions src/main/java/com/cnaude/purpleirc/Commands/Voice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.cnaude.purpleirc.Commands;

import com.cnaude.purpleirc.PurpleIRC;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

/**
*
* @author cnaude
*/
public class Voice implements IRCCommandInterface {

private final PurpleIRC plugin;
private final String usage = "[bot] [channel] [user(s)]";
private final String desc = "Voice an IRC user in a channel.";
private final String name = "voice";
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;

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

/**
*
* @param sender
* @param args
*/
@Override
public void dispatch(CommandSender sender, String[] args) {
if (args.length >= 4) {
String bot = args[1];
String channelName = args[2];
if (plugin.ircBots.containsKey(bot)) {
for (int i = 3; i < args.length; i++) {
// #channel, user
plugin.ircBots.get(bot).voice(channelName, args[i]);
sender.sendMessage("Giving voice status to "
+ ChatColor.WHITE + args[i]
+ ChatColor.RESET + " on "
+ ChatColor.WHITE + channelName);
}
} else {
sender.sendMessage(plugin.invalidBotName.replace("%BOT%", bot));
}
} else {
sender.sendMessage(fullUsage);
}
}

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

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

@Override
public String usage() {
return usage;
}
}
Loading

0 comments on commit 2d3c2d9

Please sign in to comment.