def get_memory(self, message, keywords): # Get memory usage information memory_info = os.popen('free -m') memory_info = memory_info.read().splitlines() # Get RAM specific information pieces = memory_info[1].split(' ') ram_info = [] for piece in pieces: if piece != '': ram_info.append(piece) ram_total = ram_info[1] ram_used = ram_info[2] ram_free = ram_info[3] # Get Swap specific information pieces = memory_info[3].split(' ') swap_info = [] for piece in pieces: if piece != '': swap_info.append(piece) swap_total = swap_info[1] swap_used = swap_info[2] swap_free = swap_info[3] # Format and send it! :) send = '[' + Format.color('red') + ' Memory ' + Format.normal() + ' |' send = send + ' Ram:' + Format.color('red') + ' ' + ram_used + ' / ' + ram_total + Format.normal() + ' MB |' send = send + ' Swap:' + Format.color('red') + ' ' + swap_used + ' / ' + swap_total + Format.normal() + ' MB ]' self.bot.client.send_pm(message.channel, send)
def get_cpu(self, message, keywords): # Get proccessor information cpu_info = os.popen('cat /proc/cpuinfo') cpu_info = cpu_info.read().splitlines() # Now get the specific information we want to display. for info in cpu_info: info = info.split(':') info[0] = info[0].strip() if info[0] == 'model name': cpu_model = info[1] elif info[0] == 'cpu MHz': cpu_mhz = info[1] elif info[0] == 'cache size': cpu_cache = info[1] # Get temperature information show_temp = self.bot.settings.get('SysInfo', 'sensors') if (show_temp == 'true'): sensors = os.popen('sensors') sensors = sensors.read().splitlines() for sensor in sensors: type = sensor.split(':') if type[0] == 'CPU Temp': cpu_temp = type[1].split('(') pieces = cpu_temp[0].split(' ') for piece in pieces: if piece != '': cpu_temp = piece break temp = '| Temp:' + Format.color('red') + ' ' + cpu_temp + ' ' + Format.normal() + ' ]' else: temp = ']' # Now, lets format the message and send the message! send = '[' + Format.color('red') + ' CPU ' + Format.normal() + ' |' send = send + ' Model:' + Format.color('red') + cpu_model + ' ' + Format.normal() + '|' send = send + ' Speed: ' + Format.color('red') + cpu_mhz + Format.normal() send = send + ' (' + Format.color('red') + cpu_cache + Format.normal() + ' ) ' send = send + temp self.bot.client.send_pm(message.channel, send)
def get_usage(self, message, keywords): # Get process information pid = os.getpid() usage = os.popen('ps -eo%cpu,%mem,rss,pid | grep ' + str(pid)) pieces = usage.read().split(' ') # Strip all the data that we dont need.. data = [] for piece in pieces: if piece != ' ': data.append(piece) # Now calculate and define the data cpu = data[1] memory = int(data[5]) / 1024 # Make and send the message :) send = '[' + Format.color('red') + ' Usage ' + Format.normal() + \ '| CPU:' + Format.color('red') + ' ' + cpu + Format.normal() + ' % \ | Memory:' + Format.color('red') + ' ' + str(memory) + Format.normal() + ' MB ]' self.bot.client.send_pm(message.channel, send)
def get_os(self, message, keywords): # Get kernel version kernel = os.popen('uname -r') kernel = kernel.read().splitlines() kernel = kernel[0] # Get release version distro = os.popen('lsb_release -a 2> /dev/null').read() distro = distro.strip() distro = distro.splitlines() for line in distro: split = line.split(':') if split[0] == 'Description': distro = split[1] break # Make and send the message! send = '[ Os:' + Format.color('red') + ' Linux ' + Format.normal() + '|\ Kernel:' + Format.color('red') + ' ' + kernel + Format.normal() + ' |\ Distro:' + Format.color('red') + ' ' + distro + Format.normal() + ' ]' self.bot.client.send_pm(message.channel, send)
def read_feed(self, message, keywords): try: url = Format.remove(message.bot_args) # Check URL if not self._validate_url(url): url = self.get_url(url) if url == None: raise RssException, self.lang.get('not_found') rss = RssFeed(url) rss.parse(5) self.bot.client.send_pm(message.channel, Format.color('darkblue') + Format.bold() + rss.title) for item in rss: send = "[ %s%s%s ] - %s" % (Format.color('red'), item['link'], Format.normal(), item['title']) self.bot.client.send_pm(message.channel, send) except RssException, error: self.bot.client.send_pm(message.channel, error)
def format_3fm(self, artist, title, program): # None naar Onbekend :) if artist == None: artist = 'Onbekend' if title == None: title = 'Onbekend' if program == None: program = 'Onbekend' # Capitalize artist = string.capwords(artist) title = string.capwords(title) # Make the message msg = Template('[$c 3FM $n| Now playing:$c $artist $n-$c $title $n | Program:$c $program $n]') msg = msg.substitute(c = Format.color('red'), n = Format.normal(), artist = artist, title = title, program = program) return msg
def show_plugin_info(self, message, keywords): # Check if plugin exists plugin_obj = None if self.bot.plugins.plugins.has_key(message.bot_args): plugin_obj = self.bot.plugins.plugins[message.bot_args] else: for plugin_dir, plugin in self.bot.plugins.plugins.iteritems(): if self.plugin_info['name'] == message.bot_args: plugin_obj = plugin break if plugin_obj != None: self.bot.client.send_pm(message.nick, Format.color('darkblue') + Format.bold() + plugin_obj.plugin_info['name']) if plugin_obj.plugin_info.has_key('description'): self.bot.client.send_pm(message.nick, plugin_obj.plugin_info['description']) if plugin_obj.plugin_info.has_key('authors'): self.bot.client.send_pm(message.nick, Format.color('darkblue') + "%s %s" % (_("Created By: "), ', '.join(plugin_obj.plugin_info['authors']))) if hasattr(plugin_obj, 'commands') and len(plugin_obj.commands) > 0: self.bot.client.send_pm(message.nick, Format.bold() + _("Plugin commands:")) for command, tuple in plugin_obj.commands.iteritems(): callback, data = tuple str = Format.color('darkred') + self.bot.settings.get('Bot', 'command_prefix') + command if data.has_key('args'): str += " %s%s%s" % (Format.color('orange'), data['args'], Format.normal()) if data.has_key('help'): str += " - %s%s" % (Format.color('darkblue'), data['help']) self.bot.client.send_pm(message.nick, str) else: self.bot.client.send_notice(message.nick, _("The specified plugin does not exists"))
def get_top_tracks(self): tree = self._get_xml('http://ws.audioscrobbler.com/1.0/user/%s/toptracks.xml' % self.username) tracks = tree.findall('track') to_return = [] i = 0 while i < 5: to_return.append(tracks[i].find('artist').text + " - " + tracks[i].find('name').text + " (" + Format.color('red') + _("Playcount:") + " " + tracks[i].find('playcount').text + Format.normal() + ")") i += 1 return to_return
def format_538(self, artist, title, program, dj): msg = Template('[$c 538 $n| Now playing:$c $artist $n-$c $title $n | Program:$c $program $n | DJ:$c $dj $n]') msg = msg.substitute(c = Format.color('red'), n = Format.normal(), artist = artist, title = title, program = program, dj = dj) pass