/*
 * Copyright (C) 2017 Dennis Neufeld
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package space.npstr.wolfia.events;

import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import space.npstr.wolfia.App;
import space.npstr.wolfia.Config;
import space.npstr.wolfia.utils.discord.Emojis;
import space.npstr.wolfia.utils.discord.RestActions;

/**
 * Created by napster on 07.01.18.
 * <p>
 * Handles special events for the official Wolfia guild
 */
public class WolfiaGuildListener extends ListenerAdapter {

    public static final long SPAM_CHANNEL_ID = 388705267916734465L; //#spam-and-bot-commands
    public static final long ANNOUNCEMENTS_ROLE_ID = 390997867332108298L; //@Announcements
    public static final long ALPHAWOLVES_ROLE_ID = 389492617567797258L; //@AlphaWolves

    private static final Logger log = LoggerFactory.getLogger(WolfiaGuildListener.class);
    private static final String welcomePattern = "Welcome %s to the **Wolfia Lounge**! Please take a moment and read "
            + "<#326353722701774848> for information, rules, and how to play games. Don't forget to enjoy and have "
            + "fun! " + Emojis.WINK;

    @Override
    public void onGuildMemberJoin(final GuildMemberJoinEvent event) {
        if (event.getGuild().getIdLong() != App.WOLFIA_LOUNGE_ID
                || Config.C.isDebug) {
            return;
        }

        //send greetings to spam channel
        final TextChannel spam = event.getGuild().getTextChannelById(SPAM_CHANNEL_ID);
        if (spam != null) {
            RestActions.sendMessage(spam, String.format(welcomePattern, event.getMember().getAsMention()));
        } else {
            log.warn("Did the spam channel disappear in the Wolfia Lounge?");
        }

        //add role announcements
        final Role announcements = event.getGuild().getRoleById(ANNOUNCEMENTS_ROLE_ID);
        if (announcements != null) {
            event.getGuild().getController().addSingleRoleToMember(event.getMember(), announcements).queue();
        } else {
            log.warn("Did the Announcements role disappear in the Wolfia Lounge?");
        }
    }
}

@@ -1499,25 +1499,25 @@
  = 3
-90997867332108298
+31505585344479232
 L; /
@@ -1588,25 +1588,25 @@
  = 3
-89492617567797258
+26147400790179840
 L; /

Fix roles ids