def random(self, mess, args): """Get a random infobit""" x = 0 while x < 10: index = random.randint(0, len(infobits)) - 1 bit = infobits.keys()[index] bitval = infobits[infobits.keys()[index]] out = '%s definition: %s' % (bit, bitval[0]) if bitval[1]: return out return 'I couldn\'t find any approved infobits for you :( You could try again!'
def infoadmin(self, mess, args): """A tool for admins to check for disapproved infobits""" admin = str(mess.getFrom()).split('@')[0] in admins if not admin: return 'You are not admin' out = [] for bit in infobits.keys(): if not infobits[bit][1]: out += [bit] return str(out)
def approve(self, mess, args): """An admin-only command""" admin = str(mess.getFrom()).split('@')[0] in admins if not admin: return 'You are not admin' if len(args.split()) >= 1: if args.lower() in infobits.keys() and not infobits.get(args, ('not found', True))[1]: self.setbit(mess, args) infobits.update({' '.join(args.lower().split('_')): (infobits.get(args, ('not found', True))[0], True)}) return 'InfoBit Approved' return 'Error'
def setbit(self, mess, args): """Set an infobit use 'set infobit description of infobit' and wait for admin approval""" args = args.split() admin = str(mess.getFrom()).split('@')[0] in admins if len(args) > 1: if ' '.join(args[0].lower().split('_')) in infobits.keys() and not admin: return 'Somebody already told me what that means' infobits.update({' '.join(args[0].lower().split('_')): (' '.join(args[1:]), admin)}) print 'Somebody set ' + ' '.join(args[0].lower().split('_')) return 'Infobit set!' return 'Invalid usage'
def lookup(self, mess, args): """Look up a word in the very small and useless dictionary This command looks for infobits set with the setbit command Upd8! It also ducks anything not found in the dictionary and W|As anything duckduckgo doesn't know""" admin = str(mess.getFrom()).split('@')[0] in admins if args.lower() in infobits.keys() and infobits.get(args, ('not found', True))[1]: return infobits.get(args.lower(), ('not found', True))[0] elif args.lower() in infobits.keys() and not infobits.get(args, ('not found', True))[1] and admin: return 'This infobit is not yet approved: ' + infobits.get(args.lower(), ('not found', True))[0] res = ddg.query(args.lower()) out = '' abstext = unicode(res.abstract.text) if abstext: out += 'From DuckDuckGo: ' + abstext elif res.related: for resu in res.related: if resu.text: out += resu.text + '\n' if out: return out return self.wa(mess, args) return 'That infobit either doesn\'t exist, or has not been approved'