本文整理汇总了Java中org.pircbotx.hooks.events.MessageEvent类的典型用法代码示例。如果您正苦于以下问题:Java MessageEvent类的具体用法?Java MessageEvent怎么用?Java MessageEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageEvent类属于org.pircbotx.hooks.events包,在下文中一共展示了MessageEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: channelCommand
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
@Override
public void channelCommand(MessageEvent<PircBotX> event) throws Exception {
super.channelCommand(event);
if(Permissions.getLevel(user) >= 2) {
if(Bot.commandList.containsKey(args[1])) {
List<String> response = new ArrayList<>();
response.addAll(Arrays.asList(args).subList(2, args.length));
StringBuilder result = new StringBuilder();
for (int i = 0; i < response.size(); i++) {
result.append(response.get(i));
if (i != response.size() - 1) {
result.append(" ");
}
}
String responseComplete = result.toString();
editCommand(args[1], responseComplete, event);
}
} else {
MessageSending.sendNormalMessage("You don't have permission to edit a command", event);
}
}
示例2: containsLink
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
public static boolean containsLink(String s, MessageEvent<PircBotX> event) throws InterruptedException {
Matcher matcher = urlPattern.matcher(s);
if (matcher.find()) {
if (!Permissions.isPermitted(getNick(event).toLowerCase())) {
Thread.sleep(1000);
Timeout(event, "link");
return true;
} else {
ChannelMethods.youtubeDescription(s, Defaults.songRequestBoolean);
Bot.permitted.remove(event.getUser().getNick().toLowerCase());
return false;
}
} else {
return false;
}
}
示例3: Timeout
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
public static void Timeout(MessageEvent<PircBotX> event, String type) {
if (Bot.strikeList.get(event.getUser().getNick().toLowerCase()) == null) {
Bot.strikeList.put(event.getUser().getNick().toLowerCase(), (long) 1);
} else {
Bot.strikeList.put(event.getUser().getNick().toLowerCase(), Bot.strikeList.get(event.getUser().getNick().toLowerCase()) + 1);
}
if (type.equals("link")) {
MessageSending.sendWhisper(event.getUser().getNick().toLowerCase(), "You are not permitted to post links. (Strike : #" + Bot.strikeList.get(event.getUser().getNick().toLowerCase()) + ")");
MessageSending.sendNormalMessage("You are not permitted to post links.");
} else if (type.equals("caps")) {
MessageSending.sendWhisper(event.getUser().getNick().toLowerCase(), "Please refrain from using big amounts of caps. (Strike : #" + Bot.strikeList.get(event.getUser().getNick().toLowerCase()) + ")");
MessageSending.sendNormalMessage("Please refrain from using big amounts of caps.");
} else if (type.equals("wot")) {
MessageSending.sendWhisper(event.getUser().getNick().toLowerCase(), "Please refrain from using walls of text. (Strike : #" + Bot.strikeList.get(event.getUser().getNick().toLowerCase()) + ")");
MessageSending.sendNormalMessage("Please refrain from using walls of text.");
} else {
MessageSending.sendWhisper(event.getUser().getNick().toLowerCase(), "You were purged. (Strike : #" + Bot.strikeList.get(event.getUser().getNick().toLowerCase()) + ")");
}
if (Bot.strikeList.get(event.getUser().getNick().toLowerCase()) <= 3) {
event.getBot().sendRaw().rawLine("PRIVMSG " + event.getChannel().getName() + " :.timeout " + event.getUser().getNick() + " 1");
} else {
event.getBot().sendRaw().rawLine("PRIVMSG " + event.getChannel().getName() + " :.timeout " + event.getUser().getNick() + " 600");
}
}
示例4: containsCaps
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
public static void containsCaps(String message, MessageEvent<PircBotX> event) throws InterruptedException {
if (message.length() > 10) {
double threshold = Math.floor(message.length() / 2);
String isUp = "";
int z = message.length();
for (int y = 0; y < z; y++) {
if (Character.isUpperCase(message.charAt(y))) {
char w = message.charAt(y);
isUp = isUp + w;
}
}
if (isUp.length() > threshold) {
Thread.sleep(1000);
if (!Permissions.isPermitted(getNick(event).toLowerCase())) {
Timeout(event, "caps");
}
}
}
}
示例5: channelCommand
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
@Override
public void channelCommand(final MessageEvent<PircBotX> event) throws Exception {
super.channelCommand(event);
if (Permissions.getLevel(user.toLowerCase()) >= 2) {
if (args.length != 4) {
MessageSending.sendNormalMessage("Wrong Syntax user : !timer <command1> <time in minutes> <command2>", event);
}
if (args.length == 4) {
if (Bot.commandList.containsKey(args[1]) && Bot.commandList.containsKey(args[3])) {
MessageSending.sendNormalMessage(Bot.commandList.get(args[1]), event);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
MessageSending.sendNormalMessage(Bot.commandList.get(args[3]), event);
}
}, Integer.parseInt(args[2]) * 60 * 1000);
}
}
}
}
示例6: buyRank
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
private void buyRank(String user, String rank, MessageEvent<PircBotX> event) {
try {
Long points = Bot.userList.get(user);
Long rankCost = Bot.rankList.get(rank);
if (Bot.rankList.get(rank) != null) {
if (points >= rankCost) {
Bot.userList.put(user, Bot.userList.get(user) - rankCost);
Bot.rankUserList.put(user, rank);
MessageSending.sendMessageWithPrefix(user + " successfully bought " + rank, user, event);
Bot.saveAllTheThings();
} else {
MessageSending.sendMessageWithPrefix(user + " you do not have enough " + Defaults.getPointName(), user, event);
}
} else {
System.out.println(rank);
System.out.println(Bot.rankList.get(rank));
MessageSending.sendMessageWithPrefix(user + " this rank doesn't exist.", user, event);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: sellRank
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
private void sellRank(String user, MessageEvent<PircBotX> event) {
try {
Long rankCost = Bot.rankList.get(getRank(user));
Long points = Bot.userList.get(user);
if (Bot.rankUserList.get(user) != null) {
Bot.rankUserList.remove(user);
Bot.userList.put(user, (points + (rankCost / 2)));
MessageSending.sendMessageWithPrefix(user + " you have successfully sold your rank. But you only received half of your " + Defaults.getPointName() + " back, because inflation.", user, event);
Bot.saveAllTheThings();
} else {
MessageSending.sendMessageWithPrefix(user + " you either have no rank, or you have a unsellable rank.", user, event);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: channelCommand
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
@Override
public void channelCommand(MessageEvent<PircBotX> event) throws Exception {
super.channelCommand(event);
if (args.length == 1) {
System.out.println(Bot.permList.get(user.toLowerCase()));
if (Bot.permList.get(user.toLowerCase()) != null) {
MessageSending.sendWhisper(event.getUser().getNick().toLowerCase(),"You have the following level of permissions : " + getPermission(user));
} else {
MessageSending.sendWhisper(event.getUser().getNick().toLowerCase(),"You have no permissions");
}
} else if (args.length == 4) {
if(args[3].equalsIgnoreCase("reg") && Permissions.getLevel(user) >= 2) {
addPermission(args[2], args[3], event);
}else if(Permissions.getLevel(user) == 4){
addPermission(args[2], args[3], event);
}else{
MessageSending.sendNormalMessage("You do not have permission to give a user a higher permission level than regular",event);
}
} else if (args.length == 3 && Permissions.getLevel(user) == 4) {
removePermission(args[2], event);
} else {
MessageSending.sendMessageWithPrefix("Correct Args: !permission <add|remove> <name> [<mod|reg|smod>]", user, event);
}
}
示例9: addPermission
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
private void addPermission(String user, String level, MessageEvent<PircBotX> event) throws IOException {
if (level.equalsIgnoreCase("mod") || level.equalsIgnoreCase("reg") || level.equalsIgnoreCase("smod")) {
if (Bot.permList.containsKey(user)) {
Bot.permList.replace(user.toLowerCase(), user.toLowerCase(), level.toLowerCase());
MessageSending.sendNormalMessage(user + " has been given " + level + " permissions.", event);
Bot.log.info(user + " has been given " + level + " permissions.");
Bot.saveAllTheThings();
MainController.getInstance().permissionFiller();
} else {
Bot.permList.put(user.toLowerCase(), level.toLowerCase());
MessageSending.sendNormalMessage(user + " has been given " + level + " permissions.", event);
Bot.log.info(user + " has been given " + level + " permissions.");
Bot.saveAllTheThings();
MainController.getInstance().permissionFiller();
}
} else {
MessageSending.sendNormalMessage("Only permission levels are MOD and REG", event);
}
}
示例10: preMessage
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
public static void preMessage(MessageEvent<PircBotX> event) {
arg = "";
argList.clear();
if (event.getMessage().split(" ").length >= 2) {
for (int i = 1; i < event.getMessage().split(" ").length; i++) {
if (i == event.getMessage().split(" ").length) {
arg += (event.getMessage().split(" ")[i]);
argList.add(event.getMessage().split(" ")[i]);
} else {
arg += (event.getMessage().split(" ")[i] + " ");
argList.add(event.getMessage().split(" ")[i]);
}
}
}
}
示例11: Note
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
public static void Note(MessageEvent<PircBotX> event) throws IOException {
if (Permissions.getLevel(getNick(event)) >= 2) {
boolean noteAdded = false;
try {
String completeQuote = arg;
long note = (long) Bot.noteList.size() + 1;
while (!noteAdded) {
if (!Bot.noteList.containsKey(note)) {
Bot.noteList.put(note, completeQuote);
noteAdded = true;
MessageSending.sendWhisper(event.getUser().getNick().toLowerCase(), " Note has been added as #" + note + ".");
Bot.log.info("Note " + note + " has been added");
} else {
note += 1;
noteAdded = false;
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
Bot.saveAllTheThings();
}
}
}
示例12: SteamGame
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
public static void SteamGame(MessageEvent<PircBotX> event) throws Exception {
JSONObject json = new JSONObject(JSONParser.readUrl("https://api.twitch.tv/kraken/channels/" + Bot.config.getProperty("autoJoinChannel")));
if (json != null) {
String game = json.get("game").toString();
if (Bot.steamList.containsKey(game)) {
Integer appid = Bot.steamList.get(game);
String url = "http://store.steampowered.com/app/" + appid + "/";
if (Defaults.whisperToggle) {
MessageSending.sendWhisper(event.getUser().getNick().toLowerCase(), "I'm currently playing " + game + ". You can find more info about it right here : " + url);
} else {
MessageSending.sendNormalMessage("I'm currently playing " + game + ". You can find more info about it right here : " + url);
}
} else {
if (Defaults.whisperToggle) {
MessageSending.sendWhisper(event.getUser().getNick().toLowerCase(), "I'm currently playing " + game + ".");
} else {
MessageSending.sendNormalMessage("I'm currently playing " + game + ".");
}
}
}
}
示例13: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
@Override
public void onMessage(final MessageEvent event) {
PircBotX bot = event.getBot();
String[] splitMessage = event.getMessage().split(" ");
for (String aSplitMessage : splitMessage) {
if (aSplitMessage.contains("twitter.com") && aSplitMessage.contains("/status/")) {
int index = aSplitMessage.lastIndexOf("/") + 1;
long status = Long.parseLong(aSplitMessage.substring(index));
try {
Status lookup = twitter.showStatus(status);
bot.sendIRC().message(event.getChannel().getName(), lookup.getCreatedAt() + " @" + lookup.getUser().getScreenName() + ": " + lookup.getText());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
示例14: handleCommand
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
@Override
public void handleCommand(String sender, MessageEvent event, String command, String[] args) {
if (command.equals(".youtube") || command.equals(".yt")) {
// Perform search
String query = StringUtils.join(args, " ");
try {
YouTube.Search.List search = youtube.search().list("id,snippet");
search.setKey(SettingsManager.getInstance().getSettings().getYoutubeKey());
search.setQ(query);
search.setMaxResults(1L);
search.setType("video");
SearchListResponse searchListResponse = search.execute();
List<SearchResult> searchResults = searchListResponse.getItems();
if (searchResults != null) {
SearchResult firstResult = searchResults.get(0);
event.getBot().sendIRC().message(event.getChannel().getName(), formatSearchResult(firstResult));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例15: handleCommand
import org.pircbotx.hooks.events.MessageEvent; //导入依赖的package包/类
@Override
public void handleCommand(String sender, MessageEvent event, String command, String[] args) {
if (command.equals(".ping")) {
event.respond("Pong!");
}
if (command.equals(".whoami")) {
event.getUser().send().notice("UUID: " + event.getUser().getUserId().toString());
event.getUser().send().notice("Verified: " + event.getUser().isVerified() + "\n");
event.getUser().send().notice("Login: " + event.getUser().getLogin() + "\n");
event.getUser().send().notice("Real name: " + event.getUser().getRealName() + "\n");
event.getUser().send().notice("Hostmask: " + event.getUser().getHostmask() + "\n");
try {
event.getBot().sendRaw().rawLine("WHOIS " + event.getUser().getNick() + " " + event.getUser().getNick());
WaitForQueue waitForQueue = new WaitForQueue(event.getBot());
while (true) {
WhoisEvent whoisEvent = waitForQueue.waitFor(WhoisEvent.class);
if (!whoisEvent.getNick().equals(event.getUser().getNick()))
continue;
waitForQueue.close();
event.getUser().send().notice("Registered as: " + whoisEvent.getRegisteredAs());
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}