<commit_before>/** @author rlmw */

import java.security.AllPermission;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import uk.co.uwcs.choob.modules.Modules;
import uk.co.uwcs.choob.plugins.RequiresPermission;
import uk.co.uwcs.choob.support.ChoobNoSuchCallException;
import uk.co.uwcs.choob.support.IRCInterface;
import uk.co.uwcs.choob.support.events.Message;

/**
 * Client for Twitter implemented in choob
 * 
 * Issue - sends people tells if they're online but not in a common channel with choob.
 * 
 * @author rlmw
 * @see http://www.twitter.com
 * @see http://twitter4j.org/en/index.html
 */
// See hilarious end of file
@RequiresPermission(AllPermission.class)
public class Tweet {

	public String[] info()
	{
		return new String[] {
			"Twitter Client implemented in choob",
			"mulletron",
			"ALPHA ALPHA",
			"<3",
		};
	}
	
	public final String[] helpTopics = { "Using" };

	public final String[] helpUsing = {
		  "1: !Tweet.login <username> <password> to login",
		  "2: !Tweet.update <status> to change status",
		  "3: Sit on irc (preferrably nude), being pm'd tweets",
	};

	private final Modules mods;
	private final IRCInterface irc;
	private final Map<String,Twitter> loginCache;

	// 150 requests per hour MAX
	private final int _5_MINUTES = 5*60*1000;
	
	public Tweet(final Modules mods, final IRCInterface irc) throws TwitterException {
		super();
		this.mods = mods;
		this.irc = irc;
		this.loginCache = new HashMap<String, Twitter>();
		
		mods.interval.callBack(null, _5_MINUTES);
	}
	
	private void tell(final String nick, final String msg) {
		try {
			int ret = (Integer)mods.plugin.callAPI("Tell","Inject",irc.getNickname(), new String[]{nick}, msg,"tell");
			System.out.println(ret);
		} catch (ChoobNoSuchCallException e) {
			e.printStackTrace();
		}
	}
	
	public void interval(final Object param) {
		// Get Updates
		long id = (param == null) ? 1 : (Long) param;
		Paging p = new Paging(id);
		
		for(Map.Entry<String, Twitter> entry:loginCache.entrySet()) {
			final Twitter twitter = entry.getValue();
			final String username = entry.getKey();
			final boolean known = irc.isKnownUser(username);
			try {
				final ResponseList<Status> timeline = twitter.getHomeTimeline(p);
				Collections.sort(timeline, new Comparator<Status>() {
					public int compare(Status o1, Status o2) {
						return o1.getCreatedAt().compareTo(o2.getCreatedAt());
					}
				});
				for(Status status:timeline) {
					id = Math.max(status.getId(),id);
					final String from = status.getUser().getName();
					if(known) {
						irc.sendMessage(username,  from + ": "+status.getText());
					} else {
						tell(username,status.getText());
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		mods.interval.callBack(new Long(id), _5_MINUTES);<commit_msg>adds screename to tweet prints<commit_after>/** @author rlmw */

import java.security.AllPermission;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.User;
import uk.co.uwcs.choob.modules.Modules;
import uk.co.uwcs.choob.plugins.RequiresPermission;
import uk.co.uwcs.choob.support.ChoobNoSuchCallException;
import uk.co.uwcs.choob.support.IRCInterface;
import uk.co.uwcs.choob.support.events.Message;

/**
 * Client for Twitter implemented in choob
 * 
 * Issue - sends people tells if they're online but not in a common channel with choob.
 * 
 * @author rlmw
 * @see http://www.twitter.com
 * @see http://twitter4j.org/en/index.html
 */
// See hilarious end of file
@RequiresPermission(AllPermission.class)
public class Tweet {

	public String[] info()
	{
		return new String[] {
			"Twitter Client implemented in choob",
			"mulletron",
			"ALPHA ALPHA",
			"<3",
		};
	}
	
	public final String[] helpTopics = { "Using" };

	public final String[] helpUsing = {
		  "1: !Tweet.login <username> <password> to login",
		  "2: !Tweet.update <status> to change status",
		  "3: Sit on irc (preferrably nude), being pm'd tweets",
	};

	private final Modules mods;
	private final IRCInterface irc;
	private final Map<String,Twitter> loginCache;

	// 150 requests per hour MAX
	private final int _5_MINUTES = 5*60*1000;
	
	public Tweet(final Modules mods, final IRCInterface irc) throws TwitterException {
		super();
		this.mods = mods;
		this.irc = irc;
		this.loginCache = new HashMap<String, Twitter>();
		
		mods.interval.callBack(null, _5_MINUTES);
	}
	
	private void tell(final String nick, final String msg) {
		try {
			int ret = (Integer)mods.plugin.callAPI("Tell","Inject",irc.getNickname(), new String[]{nick}, msg,"tell");
			System.out.println(ret);
		} catch (ChoobNoSuchCallException e) {
			e.printStackTrace();
		}
	}
	
	public void interval(final Object param) {
		// Get Updates
		long id = (param == null) ? 1 : (Long) param;
		Paging p = new Paging(id);
		
		for(Map.Entry<String, Twitter> entry:loginCache.entrySet()) {
			final Twitter twitter = entry.getValue();
			final String username = entry.getKey();
			final boolean known = irc.isKnownUser(username);
			try {
				final ResponseList<Status> timeline = twitter.getHomeTimeline(p);
				Collections.sort(timeline, new Comparator<Status>() {
					public int compare(Status o1, Status o2) {
						return o1.getCreatedAt().compareTo(o2.getCreatedAt());
					}
				});
				for(Status status:timeline) {
					id = Math.max(status.getId(),id);
					final User user = status.getUser();
					final String from = user.getName();
					if(known) {
						irc.sendMessage(username,  from + " ("+ user.getScreenName() + ") : "+status.getText());
					} else {
						tell(username,status.getText());
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		mods.interval.callBack(new Long(id), _5_MINUTES);
{'fraction_non_alphanumeric': 0.13199611776124232, 'fraction_numerical': 0.009220317049498545, 'mean_word_length': 3.8380281690140845, 'pattern_counts': {'":': 1, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2192723', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2001, 'n_words': 508}