Search in sources :

Example 1 with Multiplier

use of gartham.c10ver.economy.Multiplier in project c10ver by Gartham.

the class CloverGuildMemberJoinConsumer method consume.

@Override
public boolean consume(GuildMemberJoinEvent event, InputProcessor<? extends GuildMemberJoinEvent> processor, InputConsumer<GuildMemberJoinEvent> consumer) {
    synchronized (this) {
        var ge = (GuildMemberJoinEvent) event;
        Invite inviteee = clover.getInviteTracker().calcUser(ge);
        if (inviteee == null)
            return false;
        var u = inviteee.getInviter();
        if (u == null || u.isBot())
            return false;
        var inviter = clover.getEconomy().getAccount(u.getId());
        var joinee = clover.getEconomy().getUser(ge.getUser().getId());
        var serv = clover.getEconomy().getServer(ge.getGuild().getId());
        if (serv.getIgnoredInvites().contains(inviteee.getCode())) {
            if (joinee.getJoinedGuilds().contains(ge.getGuild().getId())) {
                print(joinee.getUser().getAsTag() + '[' + joinee.getUserID() + "] joined " + ge.getGuild().getName() + '[' + ge.getGuild().getId() + "] with an ignored invite, again.");
                if (clover.getEconomy().hasServer(ge.getGuild().getId())) {
                    var g = clover.getEconomy().getServer(ge.getGuild().getId());
                    if (g.getGeneralChannel() != null) {
                        var gen = ge.getGuild().getTextChannelById(g.getGeneralChannel());
                        if (gen != null)
                            gen.sendMessage(ge.getUser().getAsMention() + " welcome back to the server. ^w^").queue();
                    }
                }
            } else {
                print(joinee.getUser().getAsTag() + '[' + joinee.getUserID() + "] joined " + ge.getGuild().getName() + '[' + ge.getGuild().getId() + "] with an ignored invite, for the FIRST time.");
                Multiplier mult = Multiplier.ofHr(3, BigDecimal.ONE);
                joinee.addMultiplier(mult);
                joinee.getJoinedGuilds().add(ge.getGuild().getId());
                joinee.save();
                if (clover.getEconomy().hasServer(ge.getGuild().getId())) {
                    var g = clover.getEconomy().getServer(ge.getGuild().getId());
                    if (g.getGeneralChannel() != null) {
                        var gen = ge.getGuild().getTextChannelById(g.getGeneralChannel());
                        if (gen != null)
                            gen.sendMessage(ge.getUser().getAsMention() + " welcome to the server. ^w^\nYou received a multiplier of " + Utilities.prettyPrintMultiplier(BigDecimal.ONE) + " that lasts for **3h**.").queue();
                    }
                }
            }
        } else {
            StringBuilder sb;
            var inv = inviter.getUser().getUser();
            var join = joinee.getUser();
            sb = new StringBuilder(inv == null ? "#Deleted Acc" : inv.getAsTag());
            sb.append('[').append(inv == null ? "#DelUser" : inv.getId()).append("] has invited ").append(join.getAsTag()).append('[').append(join.getId()).append("] to ").append(ge.getGuild().getName()).append('[').append(ge.getGuild().getId()).append(']');
            if (joinee.getJoinedGuilds().contains(ge.getGuild().getId())) {
                print(sb.append('.').toString());
                if (clover.getEconomy().hasServer(ge.getGuild().getId())) {
                    var g = clover.getEconomy().getServer(ge.getGuild().getId());
                    if (g.getGeneralChannel() != null) {
                        var gen = ge.getGuild().getTextChannelById(g.getGeneralChannel());
                        if (gen != null)
                            gen.sendMessage(ge.getUser().getAsMention() + " welcome back to the server.\nYou were invited back by: " + (inv == null ? "a deleted user" : inv.getAsMention()) + ".").queue();
                    }
                }
            } else {
                print(sb.append(" for the FIRST time.").toString());
                Multiplier mult = Multiplier.ofHr(3, BigDecimal.ONE);
                inviter.getUser().addMultiplier(mult);
                inviter.getUser().save();
                joinee.addMultiplier(mult);
                joinee.getJoinedGuilds().add(ge.getGuild().getId());
                joinee.save();
                if (clover.getEconomy().hasServer(ge.getGuild().getId())) {
                    var g = clover.getEconomy().getServer(ge.getGuild().getId());
                    if (g.getGeneralChannel() != null) {
                        var gen = ge.getGuild().getTextChannelById(g.getGeneralChannel());
                        if (gen != null)
                            gen.sendMessage(ge.getUser().getAsMention() + " welcome to the server. \nYou and " + inviter.getUser().getUser().getAsMention() + " both got a " + Utilities.prettyPrintMultiplier(BigDecimal.ONE) + " multiplier that lasts for **3h**.").queue();
                    }
                }
            }
        }
    }
    return false;
}
Also used : GuildMemberJoinEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent) Multiplier(gartham.c10ver.economy.Multiplier) Invite(net.dv8tion.jda.api.entities.Invite)

Aggregations

Multiplier (gartham.c10ver.economy.Multiplier)1 Invite (net.dv8tion.jda.api.entities.Invite)1 GuildMemberJoinEvent (net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent)1