<commit_before>import king_phisher.client.gui_utilities as gui_utilities
import king_phisher.client.plugins as plugins
import king_phisher.client.server_events as server_events

try:
	from blink1 import blink1
except ImportError:
	has_blink1 = False
else:
	has_blink1 = True

class Plugin(plugins.ClientPlugin):
	authors = ['<NAME>']
	title = 'Blink(1) Notifications'
	description = """
	A plugin which will flash a Blink(1) peripheral based on campaign events.
	"""
	homepage = 'https://github.com/securestate/king-phisher-plugins'
	req_min_version = '1.6.0b0'
	req_packages = {
		'blink1': has_blink1
	}
	def initialize(self):
		try:
			self._blink1 = blink1.Blink1()
		except blink1.BlinkConnectionFailed:
			gui_utilities.show_dialog_error(
				'Connection Error',
				self.application.get_active_window(),
				'Unable to connect to the Blink(1) device.'
			)
			return False
		self.signal_connect_server_event(
			'db-credentials',
			self.signal_db_credentials
			('inserted',),
			('id', 'campaign_id')
		)
		self.signal_connect_server_event(
			'db-visits',
			self.signal_db_vists,
			('inserted',),
			('id', 'campaign_id')
		)
		return True

	@server_events.event_type_filter('inserted')
	def signal_db_credentials(self, _, event_type, objects):
		self._blink1.fade_to_color(0, 'blue')

	@server_events.event_type_filter('inserted')
	def signal_db_visits(self, _, event_type, objects):
		self._blink1.fade_to_color(0, 'cyan')<commit_msg>Fix typos and add management methods for blink1<commit_after>import king_phisher.client.gui_utilities as gui_utilities
import king_phisher.client.plugins as plugins
import king_phisher.client.server_events as server_events

try:
	from blink1 import blink1
	import usb.core
except ImportError:
	has_blink1 = False
else:
	has_blink1 = True

class Plugin(plugins.ClientPlugin):
	authors = ['<NAME>']
	title = 'Blink(1) Notifications'
	description = """
	A plugin which will flash a Blink(1) peripheral based on campaign events.
	"""
	homepage = 'https://github.com/securestate/king-phisher-plugins'
	req_min_version = '1.6.0b0'
	req_packages = {
		'blink1': has_blink1
	}
	def initialize(self):
		self._color = None
		try:
			self._blink1 = blink1.Blink1()
			self._blink1_off()
		except usb.core.USBError as error:
			gui_utilities.show_dialog_error(
				'Connection Error',
				self.application.get_active_window(),
				'Unable to connect to the Blink(1) device.'
			)
			return False
		except blink1.BlinkConnectionFailed:
			gui_utilities.show_dialog_error(
				'Connection Error',
				self.application.get_active_window(),
				'Unable to find the Blink(1) device.'
			)
			return False

		self.signal_connect_server_event(
			'db-credentials',
			self.signal_db_credentials,
			('inserted',),
			('id', 'campaign_id')
		)
		self.signal_connect_server_event(
			'db-visits',
			self.signal_db_visits,
			('inserted',),
			('id', 'campaign_id')
		)
		return True

	def finalize(self):
		self._blink1_off()
		self._blink1.close()
		self._blink1 = None

	@server_events.event_type_filter('inserted')
	def signal_db_credentials(self, _, event_type, objects):
		self._blink1_set_color('blue')

	@server_events.event_type_filter('inserted')
	def signal_db_visits(self, _, event_type, objects):
		self._blink1_set_color('cyan')

	def _blink1_set_color(self, color):
		self._blink1.fade_to_color(250, color)
		self._color = color

	def _blink1_off(self):
		self._blink1_set_color('black')
		self._color = None
{'fraction_non_alphanumeric': 0.1144927536231884, 'fraction_numerical': 0.01536231884057971, 'mean_word_length': 4.770903010033445, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '4391971', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1230, 'n_words': 241}