Search in sources :

Example 1 with ElectronicAddress

use of com.gamebuster19901.excite.bot.mail.ElectronicAddress in project ExciteBot by TheGameCommunity.

the class Mailbox method analyzeMail.

private static LinkedHashSet<MailResponse> analyzeMail(Wii responder, MimeMessage prompt) throws MessagingException {
    LinkedHashSet<MailResponse> responses = new LinkedHashSet<MailResponse>();
    Session session = Session.getInstance(new Properties());
    Address[] from = prompt.getFrom();
    LOGGER.log(Level.FINEST, "Analyzing mail from: " + (from != null ? from[0] : from));
    if (from == null) {
        responses.add(new NoResponse(prompt));
        return responses;
    }
    ElectronicAddress senderEmail = new EmailAddress(prompt.getFrom()[0]);
    Wii sender = Wii.getWii(senderEmail);
    if (sender instanceof InvalidWii) {
        LOGGER.log(Level.FINEST, "Ignoring non-wii mail");
        responses.add(new NoResponse(prompt));
        return responses;
    } else {
        boolean wasKnown;
        if (!(wasKnown = sender.isKnown())) {
            try {
                Insertion.insertInto(WIIS).setColumns(WII_ID).to(sender.getWiiCode().toString()).prepare(ConsoleContext.INSTANCE).execute();
            } catch (SQLException e) {
                throw new MessagingException("Database error", e);
            }
        }
        String[] appheaders = prompt.getHeader(APP_ID_HEADER);
        String app = "";
        if (appheaders.length > 0) {
            app = appheaders[0];
        }
        Rewardable attachment = InvalidChallenge.INSTANCE;
        if (app.equals(EXCITEBOTS)) {
            attachment = analyzeIngameMail(prompt, sender);
        }
        // if(sender.getOwner() instanceof UnknownDiscordUser) { //if wii is not registered
        // if(app.equals(FRIEND_REQUEST) /*&& !wasKnown*/) {
        MailResponse friendResponse = new AddFriendResponse(responder, sender, prompt);
        LOGGER.finest("Sending friend request to " + sender.getEmail());
        MailResponse codeResponse = new DiscordCodeResponse(responder, sender, prompt);
        LOGGER.finest("Sending verification discord code to " + sender.getEmail());
        responses.add(friendResponse);
        responses.add(codeResponse);
        if (attachment.getReward() > 0) {
        // responses.add(new RefundResponse(responder, prompt, attachment));
        }
    // }
    /*else { //excitebot is not currently accepting mail from anything other than Excitebots
				LOGGER.log(Level.FINEST, "Excitebot is not currently accepting mail from anything other than Excitebots");
				responses.add(new NoResponse(prompt));
			}*/
    }
    return responses;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InvalidWii(com.gamebuster19901.excite.bot.user.Wii.InvalidWii) Address(javax.mail.Address) SQLException(java.sql.SQLException) MessagingException(javax.mail.MessagingException) Properties(java.util.Properties) Rewardable(com.gamebuster19901.excite.game.challenge.Rewardable) InvalidWii(com.gamebuster19901.excite.bot.user.Wii.InvalidWii) Wii(com.gamebuster19901.excite.bot.user.Wii) Session(javax.mail.Session)

Example 2 with ElectronicAddress

use of com.gamebuster19901.excite.bot.mail.ElectronicAddress in project ExciteBot by TheGameCommunity.

the class MailAudit method addMailAudit.

@SuppressWarnings("rawtypes")
public static MailAudit addMailAudit(MessageContext context, MailReplyResponse message, boolean incoming, File file) {
    ElectronicAddress from = message.getResponder();
    ElectronicAddress to = message.getRespondee();
    String description = from.getEmail() + " sent mail to " + to.getEmail();
    String mailType = "GENERIC";
    if (message instanceof AddFriendResponse) {
        description = from.getEmail() + " sent a friend request to " + to.getEmail();
        mailType = "FRIEND_REQUEST";
    } else if (message instanceof RefundResponse) {
        description = "refunded " + ((RefundResponse) message).getReward() + " to " + to.getEmail();
        mailType = "REFUND";
    }
    Audit parent = Audit.addAudit(context, AuditType.MAIL_AUDIT, description);
    PreparedStatement st;
    try {
        st = Insertion.insertInto(Table.MAIL).setColumns(AUDIT_ID, SENDER, RECIPIENT, INCOMING, MAIL_TYPE, FILE).to(parent.getID(), from.getEmail(), to.getEmail(), incoming, mailType, file.getAbsolutePath()).prepare(context, true);
        st.execute();
        MailAudit ret = getMailAuditByAuditID(ConsoleContext.INSTANCE, parent.getID());
        ret.parentData = parent;
        return ret;
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : AddFriendResponse(com.gamebuster19901.excite.bot.mail.AddFriendResponse) SQLException(java.sql.SQLException) IOError(java.io.IOError) ElectronicAddress(com.gamebuster19901.excite.bot.mail.ElectronicAddress) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement) RefundResponse(com.gamebuster19901.excite.bot.mail.RefundResponse)

Example 3 with ElectronicAddress

use of com.gamebuster19901.excite.bot.mail.ElectronicAddress in project ExciteBot by TheGameCommunity.

the class Wii method register.

public void register(MessageContext owner) throws SQLException, MessagingException {
    Table.updateWhere(owner, WIIS, DISCORD_ID, owner.getSenderId(), new Comparison(WII_ID, EQUALS, wiiCode.code));
    Table.updateWhere(owner, WIIS, REGISTRATION_CODE, null, new Comparison(WII_ID, EQUALS, wiiCode.code));
    WiiRegistrationAudit.addWiiRegistrationAudit(owner, this, false);
    EmbedBuilder embed = new EmbedBuilder();
    embed.setColor(Color.GREEN);
    embed.setTitle("Registration Successful");
    embed.setDescription("You have succesfully registered the following wii:\n\n" + this.getIdentifierName());
    ElectronicAddress exciteEmail = Mailbox.ADDRESS;
    owner.sendMessage(embed.build());
    LinkedHashSet<MailResponse> wiiMail = Mailbox.packResponses(new TextualMailResponse((Wii) exciteEmail, this, null).setText("This wii has been registered with\n Excitebot.\n" + "registrant: " + owner.getDiscordAuthor().getIdentifierName() + "\n\n" + "If this is not you, contact a TCG\nadmin immediately.\n\n" + "-The Game Community"));
    Mailbox.sendResponses(wiiMail);
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Comparison(com.gamebuster19901.excite.bot.database.Comparison) TextualMailResponse(com.gamebuster19901.excite.bot.mail.TextualMailResponse) ElectronicAddress(com.gamebuster19901.excite.bot.mail.ElectronicAddress) MailResponse(com.gamebuster19901.excite.bot.mail.MailResponse) TextualMailResponse(com.gamebuster19901.excite.bot.mail.TextualMailResponse)

Example 4 with ElectronicAddress

use of com.gamebuster19901.excite.bot.mail.ElectronicAddress in project ExciteBot by TheGameCommunity.

the class MailAudit method addMailAudit.

@SuppressWarnings("rawtypes")
public static MailAudit addMailAudit(MessageContext context, MimeMessage message, boolean incoming, File file) throws AddressException, MessagingException {
    ElectronicAddress from = new EmailAddress(message.getFrom()[0]);
    ElectronicAddress to = new EmailAddress(new InternetAddress(message.getHeader("To")[0]));
    String description = from.getEmail() + " sent mail to " + to.getEmail();
    String[] appIDHeader = message.getHeader(Mailbox.APP_ID_HEADER);
    String mailType = "GENERIC";
    if (appIDHeader != null) {
        switch(appIDHeader[0]) {
            case Mailbox.FRIEND_REQUEST:
                description = from + " sent a friend request to " + to;
                mailType = "FRIEND_REQUEST";
                break;
            case Mailbox.EXCITEBOTS:
                description = from + " sent a challenge to " + to;
                mailType = "CHALLENGE";
                break;
        }
    }
    Audit parent = Audit.addAudit(context, AuditType.MAIL_AUDIT, description);
    PreparedStatement st;
    try {
        st = Insertion.insertInto(Table.MAIL).setColumns(AUDIT_ID, SENDER, RECIPIENT, INCOMING, MAIL_TYPE, FILE).to(parent.getID(), from.getEmail(), to.getEmail(), incoming, mailType, file.getAbsolutePath()).prepare(context, true);
        st.execute();
        MailAudit ret = getMailAuditByAuditID(ConsoleContext.INSTANCE, parent.getID());
        ret.parentData = parent;
        return ret;
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) SQLException(java.sql.SQLException) IOError(java.io.IOError) ElectronicAddress(com.gamebuster19901.excite.bot.mail.ElectronicAddress) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement) EmailAddress(com.gamebuster19901.excite.bot.mail.EmailAddress)

Aggregations

ElectronicAddress (com.gamebuster19901.excite.bot.mail.ElectronicAddress)3 SQLException (java.sql.SQLException)3 PreparedStatement (com.gamebuster19901.excite.bot.database.sql.PreparedStatement)2 IOError (java.io.IOError)2 Comparison (com.gamebuster19901.excite.bot.database.Comparison)1 AddFriendResponse (com.gamebuster19901.excite.bot.mail.AddFriendResponse)1 EmailAddress (com.gamebuster19901.excite.bot.mail.EmailAddress)1 MailResponse (com.gamebuster19901.excite.bot.mail.MailResponse)1 RefundResponse (com.gamebuster19901.excite.bot.mail.RefundResponse)1 TextualMailResponse (com.gamebuster19901.excite.bot.mail.TextualMailResponse)1 Wii (com.gamebuster19901.excite.bot.user.Wii)1 InvalidWii (com.gamebuster19901.excite.bot.user.Wii.InvalidWii)1 Rewardable (com.gamebuster19901.excite.game.challenge.Rewardable)1 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1 Address (javax.mail.Address)1 MessagingException (javax.mail.MessagingException)1 Session (javax.mail.Session)1 InternetAddress (javax.mail.internet.InternetAddress)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1