<commit_before>import ircbot.plugin
import json
import urllib.request
import urllib.error
import socket


def _get_qlr_elo(nick, modes = None):
	"""Get someone's QLRanks ELO.

	nick should be a valid Quake Live nickname. modes should be an iterable
	(list, tuple) of game-modes to display ELO for (duel, ctf, tdm...)
	"""
	if modes is None:
		modes = ('duel',)

	try:
		response = urllib.request.urlopen('http://www.qlranks.com/api.aspx?nick='+nick, timeout=4)
		content = response.read().decode()
	except (urllib.error.URLError, socket.timeout):
		return 'HTTP error, try again!'

	data = json.loads(content)['players'][0]

	# qlranks returns a player with Elo 1200 for all modes if the player either
	# has no games played or does not exist
	elos = [mode['elo'] == 1200 for mode in data]
	if all(elos):
		return 'Player not found or no games played: ' + data['nick']

	retval = data['nick']

	# convert to set to prevent duplicates
	for mode in set(modes):
		if mode not in data:
			return 'Unknown mode: ' + mode
		retval += ' - {mode}: {elo} (rank {rank:,})'.format(
			mode=mode, elo=data[mode]['elo'], rank=data[mode]['rank'])

	return retval


class QlranksPlugin(ircbot.plugin.Plugin):
	"""QLRanks plugin."""
	@ircbot.plugin.command('elo')
	def get_elo(self, msg):
		if len(msg.args) < 1:
			return

		if len(msg.args) > 1:
			return _get_qlr_elo(msg.args[0], msg.args[1:])
		else:
			return _get_qlr_elo(msg.args[0])
<commit_msg>fix 1200 elo check<commit_after>import ircbot.plugin
import json
import urllib.request
import urllib.error
import socket


def _get_qlr_elo(nick, modes = None):
	"""Get someone's QLRanks ELO.

	nick should be a valid Quake Live nickname. modes should be an iterable
	(list, tuple) of game-modes to display ELO for (duel, ctf, tdm...)
	"""
	if modes is None:
		modes = ('duel',)

	try:
		response = urllib.request.urlopen('http://www.qlranks.com/api.aspx?nick='+nick, timeout=4)
		content = response.read().decode()
	except (urllib.error.URLError, socket.timeout):
		return 'HTTP error, try again!'

	data = json.loads(content)['players'][0]

	# qlranks returns a player with Elo 1200 for all modes if the player either
	# has no games played or does not exist
	elos = [mode['elo'] == 1200 for mode in data.values() if isinstance(mode, dict)]
	if all(elos):
		return 'Player not found or no games played: ' + data['nick']

	retval = data['nick']

	# convert to set to prevent duplicates
	for mode in set(modes):
		if mode not in data:
			return 'Unknown mode: ' + mode
		retval += ' - {mode}: {elo} (rank {rank:,})'.format(
			mode=mode, elo=data[mode]['elo'], rank=data[mode]['rank'])

	return retval


class QlranksPlugin(ircbot.plugin.Plugin):
	"""QLRanks plugin."""
	@ircbot.plugin.command('elo')
	def get_elo(self, msg):
		if len(msg.args) < 1:
			return

		if len(msg.args) > 1:
			return _get_qlr_elo(msg.args[0], msg.args[1:])
		else:
			return _get_qlr_elo(msg.args[0])

{'fraction_non_alphanumeric': 0.1440329218106996, 'fraction_numerical': 0.011659807956104253, 'mean_word_length': 4.171985815602837, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2453128', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1031, 'n_words': 318}