def quote(self, channel, sender, line): if not line: return random.choice(self.quotes) try: command, params = line.split(None, 1) except ValueError: command, params = line, '' command = command.lower() if not params: if command.isdigit(): try: return self.quotes[int(command) - 1] except IndexError: return 'No quote number ' + command if command == 'dump': return pastebin.paste(self, channel, sender, '\n\n'.join( 'Quote {}:\n{}'.format(e + 1, i) for e, i in enumerate(self.quotes) )) return 'Invalid call.' if command == 'add': self.quotes.append(params.replace('\\n', '\n')) syncquotes(self) return 'Quote {} added.'.format(len(self.quotes)) if command == 'find': params = params.lower() for quote in self.quotes: if params in quote.lower(): return quote return 'Syntax: quote [{<digits> | dump | add <quote> | find <string>}]'
def use(self, channel, sender, line): if not line: return pastebin.paste(self, channel, sender, '''Total lines: {lines[total]} Total commands: {lines[commands]} ({cp:%}) Total misspelled/unknown commands: {lines[bad_commands]} ({bp:%}) Individual command usage: {ic} Module usage: {im}'''.format(lines=self.use['lines'], cp=self.use['lines']['commands']/self.use['lines']['total'], bp=self.use['lines']['bad_commands']/self.use['lines']['total'], ic='\n'.join(sorted(['{}: {} ({:%})'.format(i, n, n/self.use['lines']['commands']) for i, n in self.use['commands'].items()], key=lambda x: self.use['commands'][x[:x.find(': ')]], reverse=True)), im='\n'.join(sorted(['{}: {} ({:%})'.format(i, n, n/self.use['lines']['commands']) for i, n in self.use['modules'].items()], key=lambda x: self.use['modules'][x[:x.find(': ')]], reverse=True)) ), name='{} command usage as of {}'.format(self.initnick, time.ctime())) if line in self.use['commands']: return '{}: {} ({:%})'.format(line, self.use['commands'][line], self.use['commands'][line]/self.use['lines']['commands']) return 'Command unknown.'
def TryUpload(fname, pastename="AutoBuild-", mode="HW-"): success = True try: PRIVATEKEY = LoginToPasteBin() logcontent = ReadLogFile(fname) joinedpname = ''.join([pastename, mode, pname]) pastebin.paste(APIKEY, logcontent, api_user_key=PRIVATEKEY, paste_private='private', paste_name=joinedpname) except not pastebin.PastebinError: print("An exception occurred") success = False except pastebin.PastebinError as e: print "\tPasteBin Controller Handled Exception:" print ''.join(['\t', str(e)]) return success
def source(self, channel, sender, line): if not line: # No args; send the pyircbot source. try: f, _, _ = imp.find_module('pyircbot', ['.']) except ImportError: return "Funnily enough, I don't seem to exist." else: try: f, _, _ = imp.find_module(line, ['.', 'ext', 'plugins']) except ImportError as e: return str(e) return pastebin.paste(self, channel, sender, f.read(), name=line, format='python')
def additem(self, group, term): if not term: s = str(self.chooses[group]) if len(s) > 800: return pastebin.paste(self, None, None, '\n'.join(self.chooses[group])) return s if term in self.chooses[group]: return 'Item already in ' + group + ' list.' self.chooses[group].append(term) with open(path, 'w') as f: json.dump(self.chooses, f) return 'Item added to {} list. There are now {} items therein.'.format( group, len(self.chooses[group]) )
def log(self, channel, sender, line): if line: if line.lower() == 'today': try: with open(os.path.join('logs', '{2}.{1}.{0}.log'.format( channel, time.strftime('%Y%m%d'), self.initnick )), errors='replace') as f: return pastebin.paste(self, channel, sender, f.read()) except IOError: return if line.lower() == 'yesterday': try: with open(os.path.join('logs', '{2}.{1}.{0}.log'.format( channel, time.strftime( '%Y%m%d', time.localtime(time.time() - 86400) ), self.initnick )), errors='replace') as f: return pastebin.paste(self, channel, sender, f.read()) except IOError: return try: t = time.strptime(line, '%Y %m %d') except ValueError: return 'Date string must be of the form YYYY MM DD.' try: with open(os.path.join('logs', '{2}.{1}.{0}.log'.format( channel, time.strftime('%Y%m%d', t), self.initnick )), errors='replace') as f: return pastebin.paste(self, channel, sender, f.read()) except IOError: return 'No logs for given date.' try: return pastebin.paste( self, channel, sender, '\n'.join(self.logs[channel.target]) ) except KeyError: return
async def action(self, message, match): channel = match[2] queue = [] attrition = None auth = None tmp = await message.channel.send('Pulling messages from ' + channel + ':') async for log in message.channel.history(limit=maxsize): log, name, who = self.logged_format(log) if auth is None: auth = who attrition = name elif auth != who: queue.append(attrition) auth = who attrition = name queue.append(log) queue.append(attrition) # TODO use makedirs here open(join('DizzyHoG/batch-logs', channel + '.md'), 'w').writelines(reversed(queue)) url = pastebin.paste(channel, '\n'.join(reversed(queue))) await message.channel.send('Logging done @ ' + repr(url))
#!/usr/bin/env python import pastebin try: paste_url = pastebin.paste('test') print paste_url # print the paste url except pastebin.PasteError, err: # handle pastebin API error. print err exit(0)