<commit_before>package modules;

import bot.Message;
import bot.Module;
import bot.Server;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Scanner;

import com.google.gson.*;

import bot.config.Config;
import bot.info.Info;
import bot.info.User;

public class NoBro implements Module {
	private String[] triggers = {"kittykatt","man","shut up","python"};
	private JsonObject json;
	private File jsonfile;
	private final int MAX_OFFENCES = 5;
	private final int WARN_OFFENCES = 3;
	private HashMap<String, Integer> offences = new HashMap<String,Integer>();
	
	public NoBro() {
		try {
			jsonfile = new File(this.getClass().getResource("json/bros.json").toURI());
			Scanner scan;
			scan = new Scanner(new FileInputStream(jsonfile));
			String jsonstring = "";
			while(scan.hasNext()){
				jsonstring += scan.next() + " ";
			}
			scan.close();
			Gson gson = new GsonBuilder().create();
			json = gson.fromJson(jsonstring, JsonElement.class).getAsJsonObject();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
	}
	@Override
	public void parse(Message m) {
		if(m.sender().equals(Config.getNick()))return;
		String target = m.param();
		if(!m.param().startsWith("#")) target = m.sender();
		if(m.botCommand().equals("addbro") && m.senderIsAdmin()){
			if(m.hasBotParams())addBro(m.botParams());
		}
		if(m.botCommand().equals("delbro") && m.senderIsAdmin()){
			if(m.hasBotParams())delBro(m.botParams());
		}
		if(m.command().equals("PRIVMSG")){
			String bro = checkBro(m);
			if(bro.equals("possible")){
				for(String trigger : triggers){
					if(m.trailing().toLowerCase().contains(trigger)){
						if(!offences.containsKey(m.sender())){
							offences.put(m.sender(), 1);
						}
						else{
							offences.put(m.sender(),offences.get(m.sender())+1);
						}
						if(offences.get(m.sender()) == WARN_OFFENCES){
							m.say(target,"4" + m.sender() + ": Warning, you are being very liquid like.");
						}
						if(offences.get(m.sender()) == MAX_OFFENCES){
							addBro(m.senderWhole());
							m.say(target, "shut up bro");
							offences.put(m.sender(),offences.get(m.sender())+1);
							Server.send("KICK " + m.param() + " " + m.sender());
						}
					}
				}
			}
			else if(bro.equals("yes")){
				m.say(target, "shut up bro");
			}
		}
		if(m.command().equals("JOIN")){
			String checkbro = checkBro(m);
			if(checkbro.equals("yes")){
				m.say(m.trailing(), "4ALERT ALERT BRO DETECTED");
				offences.put(m.sender(), 4);
			}
			else if(checkbro.equals("possible")){
				m.say(m.trailing(), "4ALERT ALERT POSSIBLE BRO DETECTED");
			}
		}
	}
	
	private void addBro(String sender){
		if(!sender.contains("!")){
			User user = Info.getUserInfo(sender);
			sender = sender + "!" + user.getUser() + "@" + user.getHost();
		}
		String nickname = sender.split("!")[0];
		String host = "";
		String user = "";
		try{
			host = sender.split("@")[1];
			user = sender.split("@")[0].split("!")[1];
			if(user.startsWith("~"))user = user.substring(1);
		}
		catch(ArrayIndexOutOfBoundsException e){
			return;
		}
		JsonArray array = json.get("bros").getAsJsonArray();<commit_msg>change detection methods<commit_after>package modules;

import bot.Message;
import bot.Module;
import bot.Server;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Scanner;

import com.google.gson.*;

import bot.config.Config;
import bot.info.Info;
import bot.info.User;

public class NoBro implements Module {
	private String[] triggers = {"kittykatt","man","shut up","python"};
	private JsonObject json;
	private File jsonfile;
	private final int MAX_OFFENCES = 8;
	private final int WARN_OFFENCES = 5;
	private HashMap<String, Integer> offences = new HashMap<String,Integer>();
	
	public NoBro() {
		try {
			jsonfile = new File(this.getClass().getResource("json/bros.json").toURI());
			Scanner scan;
			scan = new Scanner(new FileInputStream(jsonfile));
			String jsonstring = "";
			while(scan.hasNext()){
				jsonstring += scan.next() + " ";
			}
			scan.close();
			Gson gson = new GsonBuilder().create();
			json = gson.fromJson(jsonstring, JsonElement.class).getAsJsonObject();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
	}
	@Override
	public void parse(Message m) {
		if(m.sender().equals(Config.getNick()))return;
		String target = m.param();
		if(!m.param().startsWith("#")) target = m.sender();
		if(m.botCommand().equals("addbro") && m.senderIsAdmin()){
			if(m.hasBotParams())addBro(m.botParams());
		}
		if(m.botCommand().equals("delbro") && m.senderIsAdmin()){
			if(m.hasBotParams())delBro(m.botParams());
		}
		if(m.command().equals("PRIVMSG")){
			String bro = checkBro(m);
			if(bro.equals("possible")){
				if(m.trailing().toUpperCase().equals(m.trailing())){
					if(!offences.containsKey(m.sender())){
						offences.put(m.sender(), 1);
					}
					else{
						offences.put(m.sender(),offences.get(m.sender())+1);
					}
					if(offences.get(m.sender()) == WARN_OFFENCES){
						m.say(target,"4" + m.sender() + ": Warning, you are being very liquid like.");
					}
					if(offences.get(m.sender()) >= MAX_OFFENCES){
						offences.put(m.sender(),offences.get(m.sender())+1);
						if(m.param().equals("#pasta")){
							m.say(target, "shut up bro");
							Server.send("KICK " + m.param() + " :" + m.sender());
						}
					}
					if(offences.get(m.sender()) == MAX_OFFENCES){
						addBro(m.senderWhole());
					}
				}
				for(String trigger : triggers){
					if(m.trailing().toLowerCase().contains(trigger)){
						if(!offences.containsKey(m.sender())){
							offences.put(m.sender(), 1);
						}
						else{
							offences.put(m.sender(),offences.get(m.sender())+1);
						}
						if(offences.get(m.sender()) == WARN_OFFENCES){
							m.say(target,"4" + m.sender() + ": Warning, you are being very liquid like.");
						}
						if(offences.get(m.sender()) >= MAX_OFFENCES){
							offences.put(m.sender(),offences.get(m.sender())+1);
							if(m.param().equals("#pasta")){
								m.say(target, "shut up bro");
								Server.send("KICK " + m.param() + " :" + m.sender());
							}
						}
						if(offences.get(m.sender()) == MAX_OFFENCES){
							addBro(m.senderWhole());
						}
					}
				}
			}
			else if(bro.equals("yes")){
				m.say(target, "shut up bro");
			}
		}
		if(m.command().equals("JOIN")){
			String checkbro = checkBro(m);
			if(checkbro.equals("yes")){
				m.say(m.trailing(), "4ALERT ALERT BRO DETECTED");
				offences.put(m.sender(), 5);
			}
			else if(checkbro.equals("possible")){
				m.say(m.trailing(), "4ALERT ALERT POSSIBLE BRO DETECTED");
			}
		}
	}
	
	private void addBro(String sender){
		if(!sender.contains("!")){
			User user = Info.getUserInfo(sender);
			sender = sender + "!" + user.getUser() + "@" + user.getHost();
		}
		String nickname = sender.split("!")[0];
		String host = "";
		String user = "";
		try{
			host = sender.split("@")[1];
			user = sender.split("@")[0].split("!")[1];
			if(user.startsWith("~"))user = user.substring(1);
		}
		catch(ArrayIndexOutOfBoundsException e){
			return;
		}
		JsonArray array = json.get("bros").getAsJsonArray();
{'fraction_non_alphanumeric': 0.19062047161111842, 'fraction_numerical': 0.0042155183770254245, 'mean_word_length': 3.6434250764525995, 'pattern_counts': {'":': 3, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3697237', 'n_tokens_mistral': 3195, 'n_tokens_neox': 2644, 'n_words': 457}