use of com.gamebuster19901.excite.bot.audit.Audit in project ExciteBot by TheGameCommunity.
the class WiiRegistrationAudit method addWiiRegistrationAudit.
public static WiiRegistrationAudit addWiiRegistrationAudit(MessageContext registrant, Wii wii, boolean unregister) {
Audit parent;
if (!unregister) {
parent = Audit.addAudit(registrant, AuditType.WII_REGISTRATION_AUDIT, registrant.getAuthor().getIdentifierName() + " registered " + wii.getWiiCode().hyphenate());
} else {
parent = Audit.addAudit(registrant, AuditType.WII_REGISTRATION_AUDIT, registrant.getAuthor().getIdentifierName() + " unregistered " + wii.getWiiCode().hyphenate());
}
PreparedStatement st;
try {
st = Insertion.insertInto(Table.AUDIT_WII_REGISTER).setColumns(AUDIT_ID, WII_ID, DISCORD_ID, UNREGISTER).to(parent.getID(), wii.getWiiCode().toString(), registrant.getSenderId(), unregister).prepare(true);
st.execute();
WiiRegistrationAudit ret = getWiiRegistrationAuditByID(ConsoleContext.INSTANCE, parent.getID());
ret.parentData = parent;
return ret;
} catch (SQLException e) {
throw new IOError(e);
}
}
use of com.gamebuster19901.excite.bot.audit.Audit in project ExciteBot by TheGameCommunity.
the class Ban method addBan.
@SuppressWarnings({ "rawtypes", "deprecation" })
public static Ban addBan(MessageContext context, Banee banee, String reason, Duration banDuration, Instant banExpire, long pardon) {
Audit parent = Audit.addAudit(context, AuditType.BAN, reason);
PreparedStatement st;
context.sendMessage(banee.getClass().getCanonicalName());
try {
st = Insertion.insertInto(AUDIT_BANS).setColumns(AUDIT_ID, BAN_DURATION, BAN_EXPIRE, BANNED_ID, BANNED_USERNAME).to(parent.getID(), banDuration, banExpire, banee.getID(), banee.getName()).prepare(context, true);
st.execute();
Ban ret = getBanByAuditId(context, parent.getID());
ret.parentData = parent;
return ret;
} catch (SQLException e) {
throw new IOError(e);
}
}
use of com.gamebuster19901.excite.bot.audit.Audit in project ExciteBot by TheGameCommunity.
the class Audit method createAudit.
@Nullable
@SuppressWarnings({ "rawtypes", "unchecked" })
protected static Audit createAudit(MessageContext context, Row row) throws SQLException {
AuditType type = AuditType.getType(row);
long auditID = row.getLong(AUDIT_ID);
Class<? extends Audit> auditTypeClazz = AuditType.getType(row).getType();
try {
Constructor<? extends Audit> constructor = auditTypeClazz.getDeclaredConstructor(Row.class);
constructor.setAccessible(true);
Result result = Table.selectAllFromJoinedUsingWhere(new MessageContext(context.getAuthor()), AUDITS, type.getTable(), AUDIT_ID, new Comparison(AUDIT_ID, EQUALS, auditID));
result.next();
if (result.cursorValid()) {
Row resultRow = result.getRow();
return constructor.newInstance(resultRow);
}
return null;
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new AssertionError(e);
}
}
use of com.gamebuster19901.excite.bot.audit.Audit in project ExciteBot by TheGameCommunity.
the class Audit method addAudit.
@Deprecated
@SuppressWarnings("rawtypes")
protected static Audit addAudit(MessageContext executor, MessageContext context, AuditType type, String description, Instant dateIssued) {
PreparedStatement ps;
try {
ps = Insertion.insertInto(AUDITS).setColumns(AUDIT_TYPE, ISSUER_ID, ISSUER_NAME, DESCRIPTION, DATE_ISSUED).to(type, context.getAuthor().getID(), context.getAuthor().getName(), description, Instant.now()).prepare(executor, true);
ps.execute();
ResultSet results = ps.getGeneratedKeys();
results.next();
long auditID = results.getLong(GENERATED_KEY);
Row row = Table.selectAllFromWhere(executor, AUDITS, new Comparison(AUDIT_ID, EQUALS, auditID)).getRow(true);
return new Audit(row, type);
} catch (SQLException e) {
throw new IOError(e);
}
}
use of com.gamebuster19901.excite.bot.audit.Audit in project ExciteBot by TheGameCommunity.
the class CommandAudit method addCommandAudit.
@SuppressWarnings("rawtypes")
public static CommandAudit addCommandAudit(MessageContext context, String command) {
Audit parent = Audit.addAudit(ConsoleContext.INSTANCE, context, AuditType.COMMAND_AUDIT, command);
PreparedStatement st;
try {
String serverName = null;
long serverID = 0;
String channelName = null;
long channelID = 0;
long messageID = 0;
boolean isGuildMessage = context.isGuildMessage();
boolean isPrivateMessage = context.isPrivateMessage();
boolean isConsoleMessage = context.isConsoleMessage();
boolean isAdmin = context.isAdmin();
boolean isOperator = context.isOperator();
if (isPrivateMessage || isConsoleMessage) {
channelName = context.getDiscordAuthor().getName();
channelID = context.getSenderId();
} else {
serverName = context.getServer().getName();
serverID = context.getServer().getID();
channelName = context.getChannel().getName();
channelID = context.getChannel().getIdLong();
messageID = context.getMessage().getIdLong();
}
st = Insertion.insertInto(AUDIT_COMMANDS).setColumns(AUDIT_ID, SERVER_NAME, SERVER_ID, CHANNEL_NAME, CHANNEL_ID, MESSAGE_ID, IS_GUILD_MESSAGE, IS_PRIVATE_MESSAGE, IS_CONSOLE_MESSAGE, IS_ADMIN, IS_OPERATOR).to(parent.getID(), serverName, serverID, channelName, channelID, messageID, isGuildMessage, isPrivateMessage, isConsoleMessage, isAdmin, isOperator).prepare(ConsoleContext.INSTANCE, true);
st.execute();
CommandAudit ret = getCommandAuditByID(ConsoleContext.INSTANCE, parent.getID());
ret.parentData = parent;
return ret;
} catch (SQLException e) {
throw new IOError(e);
}
}
Aggregations