def run_command(self, protocol, command, data, privmsg): prefix, channel, message = privmsg nick, ident, host = OmegaDoomUtil.parse_prefix(prefix) nick_or_channel = nick if channel == self.config['nickname'] else channel if command == 'ping': self.requests[(command, nick)] = OmegaDoomPluginRequest(privmsg, datetime.now()) protocol.ping(nick) elif command == 'weather': protocol.msg(nick_or_channel, 'Rain. :(') elif command == 'echo': protocol.msg(nick, message) elif command == 'karma': protocol.msg(nick_or_channel, '%s++' % (nick)) elif command == 'dns': self.requests[(command, nick)] = OmegaDoomPluginRequest(privmsg, datetime.now()) d = twisted.names.client.getHostByName(data) d.addBoth(self._dns_callback, protocol, prefix, data) elif command == 'karma': protocol.msg(nick_or_channel, '%s++' % (nick)) elif command == 'lol': if data == '∞': protocol.msg(nick_or_channel, "All hail the loloboros!") else: lol_len = min(int(data), 42) - 1 if data.isdigit() else 0 protocol.msg(nick_or_channel, "lol" + "ol"*lol_len)
def run_command(self, protocol, command, data, privmsg): prefix, channel, message = privmsg nick, ident, host = OmegaDoomUtil.parse_prefix(prefix) nick_or_channel = nick if channel == self.config['nickname'] else channel if command == 'youtube': try: # TODO: needs deferred url_matches = re.findall(self.matched_commands[command], data) if url_matches: for url in url_matches: video_id = url[0] if len(url) > 0 and url[0]: entry = self.yt_svc.GetYouTubeVideoEntry(video_id=video_id) else: return if entry: title = entry.media.title.text duration = timedelta(seconds=int(entry.media.duration.seconds)) categories = ', '.join([c.text for c in entry.media.category]) protocol.msg(nick_or_channel, '[%s | %s | %s] - %s' % (title, duration, categories, 'http://y2u.be/%s' % video_id)) else: protocol.msg(nick_or_channel, '[Error: invalid video URL]') except gdata.service.RequestError, inst: response = inst[0] protocol.msg(nick_or_channel, 'Error: %s (%s)' % (response['reason'], response['body'])) except Exception as e: protocol.msg(nick_or_channel, '[Error: unhandled exception]' % e)
def run_command(self, protocol, command, data, privmsg): prefix, channel, message = privmsg nick, ident, host = OmegaDoomUtil.parse_prefix(prefix) nick_or_channel = nick if channel == self.config['nickname'] else channel if nick not in self.config['admins']: protocol.msg(nick_or_channel, 'Access denied.') return if command == 'join': if data: protocol.join(data) print 'Joined channel: ', data elif command == 'leave': if data: protocol.leave(data) print 'Left channel: ', data elif command == 'quit': reactor.stop() elif command == 'say': if data: protocol.msg(nick_or_channel, data)
def _notify_dns(self, protocol, *args): prefix, hostname, ip = args nick, ident, host = OmegaDoomUtil.parse_prefix(prefix) if ('dns', nick) in self.requests: privmsg, timestamp = self.requests[('dns'), nick] prefix, channel, message = privmsg nick_or_channel = nick if channel == self.config['nickname'] else channel protocol.msg(nick_or_channel, '%s (%s)' % (hostname, ip)) del(self.requests[('dns'), nick])
def _notify_pong(self, protocol, *args): prefix, secs = args nick, ident, host = OmegaDoomUtil.parse_prefix(prefix) if ('ping', nick) in self.requests: privmsg, timestamp = self.requests[('ping', nick)] prefix, channel, message = privmsg nick_or_channel = nick if channel == self.config['nickname'] else channel protocol.msg(nick_or_channel, 'CTCP PING reply in %s secs' % (secs)) del(self.requests[('ping', nick)])
def run_command(self, protocol, command, data, privmsg): prefix, channel, message = privmsg nick, ident, host = OmegaDoomUtil.parse_prefix(prefix) target = nick if channel == self.config['nickname'] else channel if command == 'inventory': protocol.msg(target, 'Not implemented yet.') if command == 'roll': if data: protocol.msg(target, str(roll(data))) if command == 'search': search_check = roll('1d10') if search_check <= 2: w = random.choice(list(weapons.keys())) protocol.msg(target, 'You found a %s!' % (w)) elif search_check <= 5: player_credits = roll('1d100') protocol.msg(target, 'You found %s credits!' % (player_credits)) else: protocol.msg(target, 'You found... nothing.')