<commit_before>/*
 * Copyright 2014 ripxfrostbite
 * Coded by <NAME> for the CRaZyPANTS Server Network, released under the MIT Licence, we take no responsibility if something breaks when you change code.
 * If something breaks on the bot and you didn't change anything please log it as an issue so I can fix it.
 */

package org.frostbite.karren.listeners;

import org.frostbite.karren.Interactions;
import org.frostbite.karren.Karren;
import sx.blah.discord.api.DiscordException;
import sx.blah.discord.api.IDiscordClient;
import sx.blah.discord.api.MissingPermissionsException;
import sx.blah.discord.handle.IListener;
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
import sx.blah.discord.util.HTTP429Exception;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

public class InteractionCommands implements IListener<MessageReceivedEvent>{
    public void handle(MessageReceivedEvent event){
        String msg = event.getMessage().getContent();
        String returned = null;
        String[] tags;
        boolean hasBotTag = false;
        boolean privateMessage = false;
        String[] data = new String[1];
        ArrayList<Object> resultData = new ArrayList<>();
        if(Karren.conf.getEnableInteractions().equalsIgnoreCase("true")){
            for(Interactions check : Karren.bot.getInteractions()){
                returned = check.handleMessage(event);
                if(returned!=null){
                    tags = check.getTags();
                    for(String tag : tags){
                        switch (tag.toLowerCase()){
                            case "echo":
                                //Echo is limited by this code, only single trigger command will work (Ex. .echo Test)
                                returned = returned.replace("%echo", event.getMessage().getContent().replace(check.getTriggers()[0], "").trim());
                                break;
                            case "name":
                                returned = returned.replace("%name", event.getMessage().getAuthor().getName());
                                break;
                            case "depart":
                                data[0] = event.getMessage().getAuthor().getID();
                                try {
                                    resultData.addAll(Karren.bot.getSql().getUserData(event.getMessage().getAuthor().getID()));
                                    if(Boolean.parseBoolean(String.valueOf(resultData.get(2)))){
                                        returned = "Wait " + event.getMessage().getAuthor().getName() + ", you left earlier...well fine, good bye again.";
                                    }
                                    Karren.bot.getSql().userOperation("part", data);
                                } catch (SQLException e) {
                                    e.printStackTrace();
                                }
                                break;
                            case "fave":
                                if(Karren.bot.getListenCast().getSong().getSongID()!=0) {
                                    try {
                                        Karren.bot.getSql().addFave(event.getMessage().getAuthor().getID(), Karren.bot.getListenCast().getSong());
                                    } catch (SQLException e) {
                                        e.printStackTrace();
                                    }
                                } else {
                                    returned = check.getRandomTemplatesFail();
                                }<commit_msg>Fixed not removing the command prefix on echo based interactions<commit_after>/*
 * Copyright 2014 ripxfrostbite
 * Coded by <NAME> for the CRaZyPANTS Server Network, released under the MIT Licence, we take no responsibility if something breaks when you change code.
 * If something breaks on the bot and you didn't change anything please log it as an issue so I can fix it.
 */

package org.frostbite.karren.listeners;

import org.frostbite.karren.Interactions;
import org.frostbite.karren.Karren;
import sx.blah.discord.api.DiscordException;
import sx.blah.discord.api.IDiscordClient;
import sx.blah.discord.api.MissingPermissionsException;
import sx.blah.discord.handle.IListener;
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
import sx.blah.discord.util.HTTP429Exception;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

public class InteractionCommands implements IListener<MessageReceivedEvent>{
    public void handle(MessageReceivedEvent event){
        String msg = event.getMessage().getContent();
        String returned = null;
        String[] tags;
        boolean hasBotTag = false;
        boolean privateMessage = false;
        String[] data = new String[1];
        ArrayList<Object> resultData = new ArrayList<>();
        if(Karren.conf.getEnableInteractions().equalsIgnoreCase("true")){
            for(Interactions check : Karren.bot.getInteractions()){
                returned = check.handleMessage(event);
                if(returned!=null){
                    tags = check.getTags();
                    for(String tag : tags){
                        switch (tag.toLowerCase()){
                            case "echo":
                                //Echo is limited by this code, only single trigger command will work (Ex. .echo Test)
                                returned = returned.replace("%echo", event.getMessage().getContent().replace( Karren.conf.getCommandPrefix() + check.getTriggers()[0], "").trim());
                                break;
                            case "name":
                                returned = returned.replace("%name", event.getMessage().getAuthor().getName());
                                break;
                            case "depart":
                                data[0] = event.getMessage().getAuthor().getID();
                                try {
                                    resultData.addAll(Karren.bot.getSql().getUserData(event.getMessage().getAuthor().getID()));
                                    if(Boolean.parseBoolean(String.valueOf(resultData.get(2)))){
                                        returned = "Wait " + event.getMessage().getAuthor().getName() + ", you left earlier...well fine, good bye again.";
                                    }
                                    Karren.bot.getSql().userOperation("part", data);
                                } catch (SQLException e) {
                                    e.printStackTrace();
                                }
                                break;
                            case "fave":
                                if(Karren.bot.getListenCast().getSong().getSongID()!=0) {
                                    try {
                                        Karren.bot.getSql().addFave(event.getMessage().getAuthor().getID(), Karren.bot.getListenCast().getSong());
                                    } catch (SQLException e) {
                                        e.printStackTrace();
                                    }
                                } else {
                                    returned = check.getRandomTemplatesFail();
                                }
{'fraction_non_alphanumeric': 0.1011205616308897, 'fraction_numerical': 0.0032401782098015392, 'mean_word_length': 1.4784208765473403, 'pattern_counts': {'":': 8, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3869990', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1706, 'n_words': 383}