• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WaitForQueue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.pircbotx.hooks.WaitForQueue的典型用法代码示例。如果您正苦于以下问题:Java WaitForQueue类的具体用法?Java WaitForQueue怎么用?Java WaitForQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WaitForQueue类属于org.pircbotx.hooks包,在下文中一共展示了WaitForQueue类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: handleCommand

import org.pircbotx.hooks.WaitForQueue; //导入依赖的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();
		}
	}
}
 
开发者ID:MCUpdater,项目名称:RavenBot,代码行数:27,代码来源:DebugHandler.java


示例2: isOp

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
public boolean isOp(PircBotX sourceBot, User user) {
 String nsRegistration = "";
 if (userCache.containsKey(user.getUserId()) && userCache.get(user.getUserId()).getExpiration().after(Calendar.getInstance().getTime())) {
  nsRegistration = userCache.get(user.getUserId()).getValue();
  System.out.println(user.getNick() + " is cached");
 } else {
  System.out.println(user.getNick() + " is NOT cached");
  user.isVerified();
  try {
   sourceBot.sendRaw().rawLine("WHOIS " + user.getNick() + " " + user.getNick());
   WaitForQueue waitForQueue = new WaitForQueue(sourceBot);
   WhoisEvent whoisEvent = waitForQueue.waitFor(WhoisEvent.class);
   waitForQueue.close();
   nsRegistration = whoisEvent.getRegisteredAs();
  } catch (Exception e) {
   e.printStackTrace();
  }
  if (!nsRegistration.isEmpty()) {
   Calendar future = Calendar.getInstance();
   future.add(Calendar.MINUTE,5);
   userCache.put(user.getUserId(), new ExpiringToken(future.getTime(),nsRegistration));
   System.out.println(user.getUserId().toString() + " added to cache: " + nsRegistration + " expires at " + future.toString());
  }
 }
 return (getOps().contains(nsRegistration));
}
 
开发者ID:MCUpdater,项目名称:RavenBot,代码行数:27,代码来源:RavenBot.java


示例3: onMessage

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
@Override
public void onMessage(MessageEvent event) throws Exception {
    if (event.getMessage().startsWith(Helix.botPrefix + Commands.nick + " ") && event.getMessage().length() > (Commands.nick.length() + 2) && admins.contains(Util.getLogin(event.getUser()).toLowerCase()) && Util.isVerified(event.getUser())) {
        String newNick = event.getMessage().split(" ", 2)[1];
        WaitForQueue queue = new WaitForQueue(event.getBot());
        event.getBot().sendIRC().changeNick(newNick);
        while (true) {
            Event currentEvent = queue.waitFor(Arrays.asList(ServerResponseEvent.class, NickChangeEvent.class));
            if (currentEvent instanceof ServerResponseEvent) {
                switch (((ServerResponseEvent)currentEvent).getCode()) {
                    case 431:
                        event.getUser().send().notice("No nickname given");
                        return;
                    case 432:
                        event.getUser().send().notice("Erroneous nickname");
                        return;
                    case 433:
                        event.getUser().send().notice("Nickname is already in use");
                        return;
                }
            } else if (currentEvent instanceof NickChangeEvent && ((NickChangeEvent)currentEvent).getUser() == event.getBot().getUserBot()) return;
        }
    }
}
 
开发者ID:MatheusVigaro,项目名称:Helix,代码行数:25,代码来源:ListenerCommandNick.java


示例4: isVerified

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
public static boolean isVerified(User user) throws InterruptedException {
    String nick = user.getNick();
    WaitForQueue queue = new WaitForQueue(Helix.helix);
    Helix.helix.sendIRC().message("NickServ", "ACC " + nick);
    for (int i = 0; i < 50; i++) {
        NoticeEvent event = queue.waitFor(NoticeEvent.class);
        if (event.getUser().getNick().equals("NickServ")) {
            if (event.getMessage().startsWith(nick + " ACC 3 ")) {
                return true;
            } else if (event.getMessage().startsWith(nick + " ACC ")) {
                return false;
            }
        }
    }
    return false;
}
 
开发者ID:MatheusVigaro,项目名称:Helix,代码行数:17,代码来源:Util.java


示例5: getAccount

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
public static String getAccount(User u, org.pircbotx.hooks.events.MessageEvent event) {
    String user = null;
    event.getBot().sendRaw().rawLineNow("WHOIS " + u.getNick());
    WaitForQueue waitForQueue = new WaitForQueue(event.getBot());
    WhoisEvent test;
    try {
        test = waitForQueue.waitFor(WhoisEvent.class);
        waitForQueue.close();
        user = test.getRegisteredAs();
    } catch (InterruptedException ex) {
        Logger.getLogger(MessageEvent.class.getName()).log(Level.SEVERE, null, ex);
        event.getUser().send().notice("Please enter a valid username!");
    }
    waitForQueue.close();

    return user;
}
 
开发者ID:harry2258,项目名称:AlfredV2-FTB-IRC-,代码行数:18,代码来源:Utils.java


示例6: getIP

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
public static String getIP(String User, org.pircbotx.hooks.events.MessageEvent event) {
    String ip = null;

    User u = event.getBot().getUserChannelDao().getUser(User);
    event.getBot().sendRaw().rawLineNow("WHOIS " + u.getNick());
    WaitForQueue waitForQueue = new WaitForQueue(event.getBot());
    WhoisEvent test;
    try {
        test = waitForQueue.waitFor(WhoisEvent.class);
        waitForQueue.close();
        if (Utils.ValidIP(test.getHostname()))
            ip = test.getHostname();
        else
            ip = java.net.InetAddress.getByName(test.getHostname()).getHostAddress();
    } catch (InterruptedException ex) {
        Logger.getLogger(com.harry2258.Alfred.listeners.MessageEvent.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return ip;
}
 
开发者ID:harry2258,项目名称:AlfredV2-FTB-IRC-,代码行数:22,代码来源:Utils.java


示例7: call

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
@Override
public AuthLevel call() throws Exception {
    user.getBot().sendIRC().message("NickServ", "STATUS " + user.getNick());
    WaitForQueue queue = new WaitForQueue(user.getBot());
    while (true) {
        @SuppressWarnings("unchecked") NoticeEvent<PircBotX> event =
                queue.waitFor(NoticeEvent.class);
        if (!isMessage(event)) {
            continue;
        }
        queue.close();
        return getLevel(event.getMessage());
    }
}
 
开发者ID:likcoras,项目名称:A-Gario,代码行数:15,代码来源:AuthChecker.java


示例8: getLogin

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
public static String getLogin(User user) throws InterruptedException {
    String nick = user.getNick().toLowerCase();
    WaitForQueue queue = new WaitForQueue(Helix.helix);
    Helix.helix.sendIRC().message("NickServ", "INFO " + nick);
    for (int i = 0; i < 50; i++) {
        NoticeEvent event = queue.waitFor(NoticeEvent.class);
        String m = Colors.removeFormattingAndColors(event.getNotice()).toLowerCase();
        if (m.startsWith("information on " + nick + " (account ")) {
            String[] n = m.split(" ");
            String login = n[n.length - 1];
            return login.substring(0, login.length() - 2);
        } else if (m.startsWith(nick + " is not registered")) return null;
    }
    return null;
}
 
开发者ID:MatheusVigaro,项目名称:Helix,代码行数:16,代码来源:Util.java


示例9: getAccount

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
private static String getAccount(User u, org.pircbotx.hooks.events.InviteEvent event) {
    String user = "";
    event.getBot().sendRaw().rawLineNow("WHOIS " + u.getNick());
    WaitForQueue waitForQueue = new WaitForQueue(event.getBot());
    WhoisEvent test;
    try {
        test = waitForQueue.waitFor(WhoisEvent.class);
        waitForQueue.close();
        user = test.getRegisteredAs();
    } catch (InterruptedException ex) {
        Logger.getLogger(com.harry2258.Alfred.listeners.MessageEvent.class.getName()).log(Level.SEVERE, null, ex);
    }
    waitForQueue.close();
    return user;
}
 
开发者ID:harry2258,项目名称:AlfredV2-FTB-IRC-,代码行数:16,代码来源:InviteEvent.java


示例10: getAccount

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
private static String getAccount(User u, org.pircbotx.hooks.events.JoinEvent event) {
    String user = "";
    event.getBot().sendRaw().rawLineNow("WHOIS " + u.getNick());
    WaitForQueue waitForQueue = new WaitForQueue(event.getBot());
    WhoisEvent test;
    try {
        test = waitForQueue.waitFor(WhoisEvent.class);
        waitForQueue.close();
        user = test.getRegisteredAs();
    } catch (InterruptedException ex) {
        Logger.getLogger(com.harry2258.Alfred.listeners.MessageEvent.class.getName()).log(Level.SEVERE, null, ex);
    }
    waitForQueue.close();
    return user;
}
 
开发者ID:harry2258,项目名称:AlfredV2-FTB-IRC-,代码行数:16,代码来源:JoinEvent.java


示例11: getAccount

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
private static String getAccount(User u, org.pircbotx.hooks.events.NickChangeEvent event) {
    String user = "";
    event.getBot().sendRaw().rawLineNow("WHOIS " + u.getNick());
    WaitForQueue waitForQueue = new WaitForQueue(event.getBot());
    WhoisEvent test;
    try {
        test = waitForQueue.waitFor(WhoisEvent.class);
        waitForQueue.close();
        user = test.getRegisteredAs();
    } catch (InterruptedException ex) {
        Logger.getLogger(com.harry2258.Alfred.listeners.MessageEvent.class.getName()).log(Level.SEVERE, null, ex);
    }
    waitForQueue.close();
    return user;
}
 
开发者ID:harry2258,项目名称:AlfredV2-FTB-IRC-,代码行数:16,代码来源:NickChangeEvent.java


示例12: checkAuth

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
/**
 * Gets the authentication status of a User.
 *
 * @param user User to check
 * @return AuthResponse - never null
 */
public static AuthResponse checkAuth(User user) {
    final RoyalBot rb = RoyalBot.getInstance();
    rb.getBot().sendIRC().message("NickServ", String.format("ACC %s *", user.getNick()));
    try (WaitForQueue queue = new WaitForQueue(rb.getBot())) {
        NoticeEvent<?> event = queue.waitFor(NoticeEvent.class);
        return new AuthResponse(rb, event, user);
    } catch (Exception ignored) {
    }
    return new AuthResponse();
}
 
开发者ID:RoyalDev,项目名称:RoyalBot,代码行数:17,代码来源:Auth.java


示例13: execute

import org.pircbotx.hooks.WaitForQueue; //导入依赖的package包/类
@Override
public boolean execute(final MessageEvent event) {
    try {
        if (PermissionManager.hasExec(event.getUser().getNick())) {
            final String user = event.getUser().getNick();
            final WaitForQueue queue = new WaitForQueue(event.getBot());
            event.respond("Please type " + Colors.BOLD + config.getTrigger() + "kill" + Colors.NORMAL + " again in the next 10 seconds to kill the bot!");
            ExecutorService service = Executors.newSingleThreadExecutor();

            try {
                Runnable r = new Runnable() {
                    @Override
                    public void run() {
                        while (true) {
                            MessageEvent currentEvent = null;
                            com.harry2258.Alfred.listeners.MessageEvent.waiting = true;
                            try {
                                currentEvent = queue.waitFor(MessageEvent.class);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }

                            if (currentEvent != null) {
                                if (currentEvent.getMessage().equalsIgnoreCase(config.getTrigger() + "kill") && currentEvent.getUser().getNick().equals(user)) {
                                    System.out.println("Shutting down");
                                    event.getBot().stopBotReconnect();
                                    event.getBot().sendIRC().quitServer("Killed by " + event.getUser().getNick());
                                    Main.SafeStop = true;
                                    if (config.isEnableChatSocket()) {
                                        ChatSocketListener.kill();
                                    }
                                    if (config.isTwitterEnabled()) {
                                        Twitter.kill();
                                    }
                                    if (config.isRedditEnabled()) {
                                        Reddit.kill();
                                    }
                                    if (config.UpdaterChecker()) {
                                        com.harry2258.Alfred.Misc.Update.kill();
                                    }
                                    RecentChanges.kill();
                                    System.exit(2258);
                                }
                            }
                        }
                    }

                };

                if (!com.harry2258.Alfred.listeners.MessageEvent.waiting) {
                    Future<?> f = service.submit(r);
                    f.get(10, TimeUnit.SECONDS);
                }

            } catch (InterruptedException ignored) {
            }
            service.shutdown();
            queue.close();
            com.harry2258.Alfred.listeners.MessageEvent.waiting = false;
            event.respond("Bot shutdown aborted!");
            return true;
        }
        event.respond("You need to be an Exec. user to be able to kill the bot!");
    } catch (ExecutionException | TimeoutException ex) {
        Logger.getLogger(Kill.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
    return true;
}
 
开发者ID:harry2258,项目名称:AlfredV2-FTB-IRC-,代码行数:70,代码来源:Kill.java



注:本文中的org.pircbotx.hooks.WaitForQueue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Registry类代码示例发布时间:2022-05-22
下一篇:
Java StreamType类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap