【问题标题】:PircBot how to get a hostnamePircBot 如何获取主机名
【发布时间】:2012-05-13 03:13:53
【问题描述】:

有人知道如何在 PircBots 中使用它吗? http://www.jibble.org/javadocs/pircbot/index.html 我只需要获取用户主机名并禁止他们。感谢阅读!

                if (cmd.equalsIgnoreCase("ban")) {
                        if (command[1] != null && command[2] != null) {
                            //Command[1] is the users name.
                            //Command[2] is the reason.
                            //how do i make this ban someone?
                        }
                    }

【问题讨论】:

  • 我读过,我只是不知道如何解析主机名。 @吉姆加里森

标签: java irc


【解决方案1】:

你不能有理由禁止,只能有理由踢。在这种情况下,我假设您想要 kban,即 kick + ban。

            if (cmd.equalsIgnoreCase("ban")) {
                    if (command[1] != null && command[2] != null) {
                        //Command[1] is the users name.
                        //Command[2] is the reason.
                        //how do i make this ban someone?

                        // ban first 
                        //make sure to input the current channel in "currentChannel"
                        ban(currentChannel, command[1]+"!*@*");

                        // kick with a reason
                        kick(currentChannel, command[1], command[2]);
                    }
                }

如果您的命令需要主机掩码,您应该让用户指定它 - 他可能想要一个特定的禁令,可能是整个范围的禁令等。否则,生成一个糟糕的昵称禁令(如果用户离线,您可以使用"whowas" 找出来,否则你应该使用 "whois"。注意 "whowas" 可能不起作用。)

来自 PircBot 的 JavaDoc - http://www.jibble.org/javadocs/pircbot/index.html

ban(字符串通道,字符串主机掩码) 禁止用户进入频道。

kick(字符串通道,字符串尼克) 将用户踢出频道。

kick(String channel, String nick, String reason) 将用户踢出频道,并给出理由。

【讨论】:

    【解决方案2】:

    虽然这是一个老问题,但我想我会分享一下我是如何解决这个问题的。我假设您正在处理 onMessage 事件中的禁令命令。在这种情况下,您必须将command[1] 保存在地图中。然后调用

    sendRawLine("WHO " + command[1]);
    

    覆盖 onServerResponse 并捕获代码 RPL_WHOREPLY 和 split("\\s") 响应。然后你可以用splitResult[5]在地图中查找,主机将在splitResult[3],然后你可以用String.format("*!*%s", splitResult[3])执行禁令

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      • 2014-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多