def command_raw(self, network, params): if network == '*': log.info('sending raw command to all networks: {0}'.format(params)) for network in self.networks.values(): network.raw(params) else: network = self.networks[network] log.info('sending raw command to {0}: {1}'.format(network.name, params)) network.raw(params)
def on_command_keydown(self, widget, event): command = self.keymap.gtk_event(event) if command is None: return False log.info('key command: {0}'.format(command)) if command == 'send-buffer': text_buffer = self.command_entry.get_buffer() message = text_buffer.get_text(text_buffer.get_start_iter(), text_buffer.get_end_iter(), True).strip() log.info('message: {0}'.format(message)) channel_window = self.current_channel async_engine_command('send', channel_window.network, (channel_window.channel, message)) text_buffer.set_text('') return True elif command == 'window-next': l = [] for n in self.network_channels: for c in self.network_channels[n]: l.append(self.network_channels[n][c]) p = l.index(self.current_channel) + 1 if p == len(l): self.set_channel(l[0]) else: self.set_channel(l[p]) elif command == 'window-previous': l = [] for n in self.network_channels: for c in self.network_channels[n]: l.append(self.network_channels[n][c]) p = l.index(self.current_channel) - 1 if p < 0: self.set_channel(l[-1]) else: self.set_channel(l[p]) elif command == 'quit': self.stop() else: method = command.replace('-', '_') method = getattr(self, method, None) if method is not None: method() return True
def process_commands(self): while self.running: try: command, network, params = self.next_command(block=True) log.info('processing command {0} from {1} with parameters {2}'.format(command, network, params)) method = 'command_' + command if hasattr(self, method): getattr(self, method)(network, params) else: log.warning('method {0} not found, command discarded'.format(method)) except Exception as e: log.exception('exception processing command: {0}'.format(e))
def on_welcome(self, event): log_irc_event(event) self.connected = True self.nick = event.target() self.root.add_message(event.source(), event.arguments()[0]) for channel in self.config['channels']: key = self.config['channels'][channel] key = '' if key is None else key if not channel.startswith('#'): channel = '#' + channel log.info('auto-joining {0}'.format(channel)) self.connection.join(channel, key=key)
def run(self): self.irc = IRC() self.irc.add_global_handler(event='all_events', handler=self.process_events, priority=-1) self.network_config = Dotfile('networks', use_defaults=False) self.connections = {} self.networks = {} log.info('starting engine') irc_thread = threading.Thread(target=self.process_irc) irc_thread.start() command_thread = threading.Thread(target=self.process_commands) command_thread.start() while command_thread.is_alive(): command_thread.join() log.debug('command_thread stopped') while irc_thread.is_alive(): irc_thread.join() log.debug('irc_thread stopped') async_ui_message('stopped')
def command_stop(self, network, params): for network in self.networks.values(): log.info('disconnecting {0}...'.format(network.name)) network.disconnect() time.sleep(1) self.running = False