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;
}
}
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);
}
}
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);
}
}
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;
}
}
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 "";
}
}
Aggregations