Search in sources :

Example 1 with MessageEvent

use of org.pircbotx.hooks.events.MessageEvent in project LanteaBot by PC-Logix.

the class Permissions method getPermLevel.

public static int getPermLevel(User u, GenericMessageEvent event) {
    String target = "";
    String NSAccount = "";
    if (event instanceof MessageEvent) {
        NSAccount = Account.getAccount(u, (MessageEvent) event);
        target = ((MessageEvent) event).getChannel().getName();
        if (((MessageEvent) event).getChannel().getOps().contains(u)) {
            return getPermLevel(Permissions.MOD);
        }
    } else if (event instanceof PrivateMessageEvent) {
        return 0;
    }
    if (NSAccount == null) {
        return 0;
    }
    try {
        PreparedStatement getPerm = Database.getPreparedStatement("getUserPerms");
        getPerm.setString(1, NSAccount);
        getPerm.setString(2, target);
        ResultSet results = getPerm.executeQuery();
        if (results.next()) {
            String rank = results.getString(1);
            for (int i = 0; i < ranks.length; i++) {
                if (ranks[i].equals(rank))
                    return i;
            }
            return 0;
        } else {
            return 0;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }
}
Also used : PrivateMessageEvent(org.pircbotx.hooks.events.PrivateMessageEvent) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent) MessageEvent(org.pircbotx.hooks.events.MessageEvent) PrivateMessageEvent(org.pircbotx.hooks.events.PrivateMessageEvent) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with MessageEvent

use of org.pircbotx.hooks.events.MessageEvent in project narchy by automenta.

the class IRCAgent method onGenericMessage.

@Override
public void onGenericMessage(GenericMessageEvent event) {
    if (event instanceof MessageEvent) {
        MessageEvent pevent = (MessageEvent) event;
        if (pevent.getUser().equals(irc.getUserBot())) {
            // ignore own messages (echo)
            return;
        }
        String msg = pevent.getMessage().trim();
        // if (channel.equals("unknown")) return;
        if (msg.startsWith("//"))
            // comment or previous output
            return;
        // TODO use hostmask ?
        String src = pevent.getUser().getNick();
        String channel = pevent.getChannel().getName();
        try {
            hear(msg, src);
        } catch (Exception e) {
            pevent.respond(e.toString());
        }
    // logger.info("hear({},{}): {}", channel, nick, msg);
    // talk.hear(msg, context(channel, nick), ircMessagePri);
    }
}
Also used : GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent) MessageEvent(org.pircbotx.hooks.events.MessageEvent) PrivateMessageEvent(org.pircbotx.hooks.events.PrivateMessageEvent) IrcException(org.pircbotx.exception.IrcException) IOException(java.io.IOException)

Example 3 with MessageEvent

use of org.pircbotx.hooks.events.MessageEvent in project narchy by automenta.

the class IRCNLP method onGenericMessage.

@Override
public void onGenericMessage(GenericMessageEvent event) {
    if (event instanceof MessageEvent) {
        MessageEvent pevent = (MessageEvent) event;
        if (pevent.getUser().equals(irc.getUserBot())) {
            // ignore own messages (echo)
            return;
        }
        String msg = pevent.getMessage().trim();
        // TODO use hostmask ?
        String src = pevent.getUser().getNick();
        String channel = pevent.getChannel().getName();
        try {
            hear(msg, src);
        } catch (Exception e) {
            pevent.respond(e.toString());
        }
    // logger.info("hear({},{}): {}", channel, nick, msg);
    // talk.hear(msg, context(channel, nick), ircMessagePri);
    }
}
Also used : GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent) MessageEvent(org.pircbotx.hooks.events.MessageEvent) PrivateMessageEvent(org.pircbotx.hooks.events.PrivateMessageEvent) IrcException(org.pircbotx.exception.IrcException) IOException(java.io.IOException)

Example 4 with MessageEvent

use of org.pircbotx.hooks.events.MessageEvent in project LanteaBot by PC-Logix.

the class Permissions method setPermLevel.

public static boolean setPermLevel(String user, GenericMessageEvent event, String level) {
    User u = Account.getUserFromString(user, (MessageEvent) event);
    if (u == null) {
        return false;
    }
    String NSAccount = Account.getAccount(u, (MessageEvent) event);
    try {
        SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
        dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
        PreparedStatement addPerm = Database.getPreparedStatement("setPermLevel");
        addPerm.setString(1, NSAccount);
        addPerm.setString(2, ((MessageEvent) event).getChannel().getName());
        addPerm.setString(3, level);
        addPerm.setString(4, event.getUser().getNick());
        addPerm.setString(5, dateFormatGmt.format(new Date()));
        if (addPerm.executeUpdate() > 0) {
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
Also used : User(org.pircbotx.User) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent) MessageEvent(org.pircbotx.hooks.events.MessageEvent) PrivateMessageEvent(org.pircbotx.hooks.events.PrivateMessageEvent) PreparedStatement(java.sql.PreparedStatement) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 5 with MessageEvent

use of org.pircbotx.hooks.events.MessageEvent in project LanteaBot by PC-Logix.

the class Permissions method getRank.

public static String getRank(GenericMessageEvent event) {
    User u = event.getUser();
    String target = "";
    String NSAccount = "";
    if (event instanceof MessageEvent) {
        NSAccount = Account.getAccount(u, (MessageEvent) event);
        target = ((MessageEvent) event).getChannel().getName();
        if (((MessageEvent) event).getChannel().getOps().contains(u)) {
            return Permissions.MOD;
        }
    } else if (event instanceof PrivateMessageEvent) {
        return "";
    }
    if (NSAccount == null) {
        return "";
    }
    try {
        PreparedStatement getPerm = Database.getPreparedStatement("getUserPerms");
        getPerm.setString(1, NSAccount);
        getPerm.setString(2, target);
        ResultSet results = getPerm.executeQuery();
        if (results.next()) {
            return results.getString(1);
        } else {
            return "";
        }
    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }
}
Also used : PrivateMessageEvent(org.pircbotx.hooks.events.PrivateMessageEvent) User(org.pircbotx.User) GenericMessageEvent(org.pircbotx.hooks.types.GenericMessageEvent) MessageEvent(org.pircbotx.hooks.events.MessageEvent) PrivateMessageEvent(org.pircbotx.hooks.events.PrivateMessageEvent) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

MessageEvent (org.pircbotx.hooks.events.MessageEvent)5 PrivateMessageEvent (org.pircbotx.hooks.events.PrivateMessageEvent)5 GenericMessageEvent (org.pircbotx.hooks.types.GenericMessageEvent)5 PreparedStatement (java.sql.PreparedStatement)3 IOException (java.io.IOException)2 ResultSet (java.sql.ResultSet)2 User (org.pircbotx.User)2 IrcException (org.pircbotx.exception.IrcException)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1