Search in sources :

Example 1 with PrivateMessageEvent

use of org.pircbotx.hooks.events.PrivateMessageEvent 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 PrivateMessageEvent

use of org.pircbotx.hooks.events.PrivateMessageEvent 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

PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 MessageEvent (org.pircbotx.hooks.events.MessageEvent)2 PrivateMessageEvent (org.pircbotx.hooks.events.PrivateMessageEvent)2 GenericMessageEvent (org.pircbotx.hooks.types.GenericMessageEvent)2 User (org.pircbotx.User)1