def whatinfo(self): if not self.values: whom = Id(self.lastsender) else: whom = Id(self.values[0]) types = [str,int,unicode,float] data = [x for x in whom.prop.data if type(whom[x]) in types] return ', '.join(data)
def gen_device_id(self): # Get device id self.device_id_str = Id(self.cert).get_device_id() self.device_id_bytes = bytes( (self.device_id_str.replace('-', '')).encode('utf-8')) if self.verbose_mode: print("Device id: %s\n" % self.device_id_str)
def __init__(self, master, electroshock=False): print '* Initializing' self.master = master self.settings = master.settings self.secrets = master.secrets self.channels = self.secrets.channels self.context = self.secrets.primary_channel self.personality = self.settings.bot self.enabled = self.settings.plugins.values().pop(0) metacortex.botnick = self.personality.nick print '* Exciting neurons' Neurons.cortex = self print '* Connecting to datastore' connectdb() print '* Fondly remembering daddy' admin = Id(self.secrets.owner) if not admin.password: print '*' * 40 print 'Hey %s! You haven\'t set a password yet! As my daddy you really need a password.' % self.secrets.owner tmp_pass = getpass( 'Before I can continue, please enter a password: '******'See? Was that so hard?' admin.setpassword(tmp_pass, True) tmp_pass = None print '* Loading brainmeats' self.loadbrains(electroshock)
def peep_incdec(self, target, source, args): input = args[-1] matches = re.match('^([a-zA-Z0-9_\\\[\]\{\}\^`\|]+)([\+|\-]{2}(?![\+|\-])).*', input) if not matches: return entity = matches.group(1) method = matches.group(2) if not entity: return source = Id(source) if not source.name or not source.is_authenticated: return if source.name == entity: self.chat("No self love.") simpleupdate(entity, -1000000) return mod = 1 if method == '--': mod = -1 if not simpleupdate(entity, False, random.randint(1, 100000) * mod, True): self.chat("mongodb seems borked", target=target) return self.chat('%s brought %s to %d' % (source.name, entity, entityScore(entity)), target=target)
def cashmoney(self): whom = self.lastsender drinker = Id(whom) self.chat("You gots $%.02f" % drinker.cash)
def _get_drinker(self): drinker = Id(self.lastid) if not drinker.is_authenticated: self.chat('Be gone peasant.') return None return drinker
def _create_position(self, ptype): whom = self.lastsender try: quantity = int(self.values[0]) symbol = self.values[1].upper() except: self.chat("That's not right") return if quantity <= 0: self.chat("Do you think this is a muthafuckin game?") return stock = Broker(symbol) if not stock: self.chat("Stock not found") return if stock.exchange.upper() in self.config.blacklist: self.chat("Stock exchange %s DENIED!" % stock.exchange) return if stock.price < 0.01: self.chat("No penny stocks") return drinker = Id(self.lastid) if not drinker.cash: drinker.cash = self.config.startupcash if not drinker.positions: drinker.positions = [] cost = stock.price * quantity if cost > drinker.cash: self.chat("You is poor") return position = Position(symbol=stock.symbol, price=stock.price, quantity=quantity, date=datetime.utcnow(), type=ptype) drinker.positions.append(position) drinker.cash -= cost # drinker.save() verb = 'bought' if ptype == 'long' else 'shorted' self.chat("%s %s %d shares of %s (%s) at %s" % (drinker.nick, verb, position.quantity, stock.company, position.symbol, position.price))
def adduser(self): if not self.values: self.chat("Who are you trying to add?") return whom = Id(self.lastid) if not whom.is_authenticated: self.chat("I'm sorry, Dave, I'm afraid I can't do that") return new_user = Id(self.values[0]) tmp_pass = str(totp.now()) new_user.setpassword(tmp_pass, True) self.chat('Hi %s, your temporary password is %s. Please set up your user ' 'by identifying yourself to me via private message (.identify %s) and ' 'then changing your password (.passwd <newpass>).' % (new_user.nick, tmp_pass, tmp_pass), target=new_user.nick)
def setinfo(self): if not self.values or not len(self.values) > 1: return "Need a name and a value, champ" key = self.values[0] value = ' '.join(self.values[1:]) whom = Id(self.lastid) whom[key] = value return 'Updated %s for %s' % (key, whom.name)
def digits(self): if not self.values: search_for = self.lastsender else: search_for = self.values[0] user = Id(search_for) if not user or not user.phone: return "No such numba. No such zone." else: return user.name + ': ' + user.phone
def __init__(self, _outputFile: PathModel, _tempFolder: PathModel = None) -> None: if _tempFolder is None: _tempFolder = _outputFile.temp() os.chdir(_tempFolder.path) try: progress = int(re.findall("file tmp_(.*).mp4", open('temp.txt', 'r').readlines()[-3])[0])+1 except: progress = 0 key, M3U8s = M3U8.getAll(self) dec = Decrypt(key) l = len(M3U8s) id = Id(l, progress) try: for i in range(progress, l): file_name = 'tmp_%s.mp4' % id.add() print('Processing %d of %d' % (i+1, l)) url = M3U8s[i].url url = "http" + url.removeprefix("https") open(file_name, 'wb').write( dec.get(self.getFile(url))) open('temp.txt', 'a').write( "file %s\nduration %s\n\n" % (file_name, M3U8s[i].duration)) except: print("Errore nel download dei file\nRiprova in seguito") else: # size = 0 # st = os.stat_result. # free = st.f_bavail * st.f_frsize # for file_name in os.listdir(tempPath): # size += os.path.getsize(file_name) # # if free >= size: self._concatenateAll() # else: # self._concatenateProgress(l) os.chdir(_tempFolder.dir) shutil.move("%s\\output.mp4" % _tempFolder.name, _outputFile.path) shutil.rmtree(_tempFolder.path)
def addphone(self): if not self.values: self.chat("What number?") return phone = self.values[0] if not re.search("^[0-9]{10}$", phone): self.chat("Just one good ol'merican ten-digit number, thank ya kindly.") return whom = Id(self.lastid) whom.phone = phone self.chat("Number updated.")
def identify(self): if not self.values: self.chat('Enter a password.') return if self.context_is_channel: self.chat('Not in the channel, you twit.') return whom = Id(self.lastid) if not whom.identify(' '.join(self.values)): self.chat("I don't know you... go away...") return self.chat('Welcome back %s' % whom.name)
def passwd(self): whom = Id(self.lastid) if not whom.is_authenticated: self.chat('STRANGER DANGER!') return if not self.values: self.chat('Enter a password.') return if self.context_is_channel: self.chat('Not in the channel, you twit.') return whom.setpassword(' '.join(self.values)) self.chat('All clear.')
def chat(self, message, target=False, error=False): if self.context in self.channels \ and not target \ and 'speak' not in self.channels[self.context]['mods']: return if self.bequiet: return if not message: return if target: whom = target elif self.context in self.channels: whom = self.context else: user = Id(self.lastsender) whom = user.nick if randint(1, 170) == 13: message = zalgo(message) # test later # message = filter(lambda x: x in string.printable, message) try: message = message.encode('utf-8') self.logroom('___%s: %s\n' % (self.personality.nick, str(message))) m = str(message) if randint(1, 170) == 23: i = m.split() pos = randint(0, len(i)) i.insert(pos, 'fnord') m = ' '.join(i) if error: m += ' %s' % str(error) self.thalamus.send('PRIVMSG %s :%s' % (whom, m)) except Exception as e: try: self.thalamus.send('PRIVMSG %s :ERROR: ' % (whom, str(e))) except: pass
def all(self, whom=False): peeps = self.cx.thalamus.channels[self.cx.context]['users'] announcer = whom or self.lastsender announcer = Id(announcer) try: del peeps[announcer.name] del peeps[self.botname] except: pass if not peeps: return 'Is this real life? No one to announce anything to...' peeps = ', '.join('%s' % (key) for (key, val) in peeps.iteritems()) return '%s, %s has something very important to say.' % (peeps, announcer.name)
def workat(self): if not self.values: return 'If you\'re unemployed, that\'s cool, just don\'t abuse the bot' user = Id(self.lastid) if not user.is_authenticated: return 'That\'s cool bro, but I don\'t know you!' drinker = Drinker.objects(name=user.name) if drinker: drinker = drinker[0] drinker.company = ' '.join(self.values) else: drinker = Drinker(name=user.name, company=' '.join(self.values)) drinker.save() return 'I know where you work... watch your back.'
def getinfo(self): if not self.values: return "Need at least a key name, brah" if len(self.values) == 2: search_for = self.values[0] key = self.values[1] else: search_for = self.lastsender key = self.values[0] whom = Id(search_for) if not whom: return "Couldn't find %s" % search_for if not whom[key]: return "Couldn't find %s for %s" % (key, search_for) return "%s's %s: %s" % (search_for, key, whom[key])
def portfolio(self): if not self.values: whom = self.lastsender else: whom = self.values[0] drinker = Id(whom) if not drinker.is_authenticated: self.chat("%s doesn't exist" % whom) return if not drinker.positions: self.chat("%s doesn't have one" % whom) else: drinker.positions.sort(key=lambda p: p.symbol) self.chat("%8s %10s %10s %10s %10s %10s" % ('type', 'symbol', 'qty', 'price', 'last', 'gain')) total = 0 for p in drinker.positions: stock = Stock(p.symbol) if p.type == 'long': net = p.quantity * (stock.price - p.price) else: net = p.quantity * (p.price - stock.price) if net >= 10000000: # Get rid of stupid twitter positions continue self.chat( "%8s %10s %10d %10.02f %10.02f %10.02f" % (p.type, p.symbol, p.quantity, p.price, stock.price, net)) total += net self.chat("%8s %10s %10s %10s %10s %10.02f" % ('', '', '', '', '', total))
def _cmd_PRIVMSG(self, source, args): # Parse the incoming message for a command with the selected command prefix match = re.search( '^{0}(\w+)[ ]?(.+)?'.format(self.settings.bot.command_prefix), args[-1]) if not match: return (source, args) # Parse the user, targer, command and arguments information user = Id(source) target = args[0] if args[0] != self.name else user.nick command = match.group(1) arguments = match.group(2) print "*** target: %s; user: %s" % (target, user.nick) # Only listen to authenticated users if not user.is_authenticated: self.send('PRIVMSG %s :My daddy says not to listen to you.' % target) return (source, args) # If there was no command specified, return the source and args so any bound # Receptors can get triggered with the same information if not command: return (source, args) # Butler that command out yo if arguments: self.cx.values = arguments else: self.cx.values = False self.cx.context = target self.cx.butler.do(self.cx.command, (source, args[-1])) return (source, args)
def sms(self): if self.context not in self.cx.channels: self.chat('No private sms abuse. Tsk tsk.') return if not self.values: self.chat('-sms <number> <message>') return to = self.values[0] msg = ' '.join(self.values[1:]) if not re.search('^[+0-9]+$', to): user = Id(to) if not user or not user.phone: self.chat("Don't know who that is :(") return else: to = user.phone try: params = {'to': to, 'from_': self.secrets.number} regex = '^http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+#]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+$' match = re.search(regex, msg) if match: params['media_url'] = msg else: params['body'] = msg message = self.client.messages.create(**params) self.chat('Message sent: %s (%s)' % (msg, message.sid)) except Exception as e: self.chat(str(e)) return
def salias(self): whom = self.lastsender name = self.values[0] evil = ['salias', 'ralias', 'lalias', 'dalias'] definition = ' '.join(self.values[1:]) drinker = Id(self.lastid) # drinker = Drinker.objects(name=whom).first() if not drinker.is_authenticated: self.chat("Nope.") return if any(sin in definition for sin in evil): self.chat("You're trying to hurt me aren't you?") return #if not drinker: # drinker = Drinker(name=whom) new_alias = Alias(name=name, definition=definition) drinker.aliases.append(new_alias) # drinker.save() self.chat(name + " saved.")
def tourettes(self, target, source, args): sentence = args[-1] whom = Id(source) nick = whom.nick if "mom" in sentence.translate(string.maketrans("", ""), string.punctuation).split(): open("%s/mom.log" % self.cx.settings.directory.logdir, 'a').write(sentence + '\n') # This could be more like a dict if sentence.lower().find("oh snap") != -1: self.chat("yeah WHAT?? Oh yes he DID", target=target) return if sentence.lower() == 'boom': self.chat(u'(\u2022_\u2022)', target=target) self.chat(u'( \u2022_\u2022)>\u2310 \u25A1-\u25A1', target=target) self.chat(u'(\u2310 \u25A1_\u25A1)', target=target) return if sentence.lower() == "sup": self.chat("chillin", target=target) return if sentence.lower().find("murica") != -1: self.chat("f**k yeah", target=target) return if sentence.lower().find("hail satan") != -1: self.chat(u"\u26E7\u26E7\u26E7\u26E7\u26E7", target=target) return if sentence.lower().find("race condition") != -1: self.chat("It's never a race condition.", target=target) return if sentence.lower().find("rimshot") != -1: self.chat("*ting*", target=target) return if sentence.lower().find( "stop") == len(sentence) - 4 and len(sentence) != 3: stops = [ 'Hammertime', "Children, what's that sound", 'Collaborate and listen', ] self.chat(random.choice(stops), target=target) return if sentence.lower().find("idk") != -1: self.chat( u'\u00AF\u005C\u005F\u0028\u30C4\u0029\u005F\u002F\u00AF', target=target) return if sentence.lower().strip( ) in self.config.frustration or sentence.lower().find('stupid') == 0: self.chat(self.cx.commands.get('table')(), target=target) return if sentence.strip() in ['ls', 'jjk', ':wq', 'ifconfig']: self.chat('Wrong window.') return inquiries = [ sentence.lower().find(t) != -1 for t in self.config.questions ] if self.config.smartass and True in inquiries: # Naively parse out the question being asked try: smartassery = sentence.lower().split( self.config.questions[inquiries.index(True)])[1] except: return responses = self.config.ithelp # Dynamic cases need to be appended responses.append('http://lmgtfy.com/?q=' + smartassery.replace(' ', '+')) self.chat(random.choice(responses), target=target) return # There's a very good reason for this. if sentence == "oh shit its your birthday erikbeta happy birthday" and nick == "jcb": self._act(" slaps jcb") self.chat("LEAVE ERIK ALONE!", target=target) return
from id import Id from friends import Friends name = input('Имя пользователя: ') client = Id(name) uid = client.execute() friends_client = Friends(uid) friends = friends_client.execute() for (age, count) in friends: print('{} {}'.format(int(age), '#' * count))
def _cmd_PRIVMSG(self, source, args): user = Id(source) target = args[0] if args[0] != self.name else user.nick self.cx.lastid = user.fullid self.cx.lastsender = user.nick self.cx.context = target if target in self.cx.channels \ and 'spy' in self.cx.channels[target]['mods']: self.cx.chat('%s: %s' % (target, args[-1]), self.cx.secrets.primary_channel) return if target not in self.cx.channels: self.cx.lastprivate = args[-1] else: self.cx.lastpublic = args[-1] self.cx.lastchat = args[-1] # Parse the incoming message for a command with the selected command prefix match = re.search( '^[\{0}|\{1}](\w*)[ ]?(.+)?'.format( self.settings.bot.command_prefix, self.settings.bot.multi_command_prefix), args[-1]) if not match: return (target, source, args) # Parse the user, target, command and arguments information command = match.group(1) arguments = match.group(2) if not command: command = self.cx.lastcommand # Only listen to authenticated users if not user.is_authenticated \ and command not in self.cx.public_commands: self.send('PRIVMSG %s :My daddy says not to listen to you.' % target) # If we recognize the username, at least let them know that we know if user.is_recognized: self.send( 'PRIVMSG %s :I recognize you, but first user %sidentify...' % (user.nick, self.settings.bot.command_prefix)) return (target, source, args) # If there was no command specified, return the source and args so any bound # Receptors can get triggered with the same information if not command: return (target, source, args) # Butler that command out yo if arguments: self.cx.values = arguments else: self.cx.values = False butler = Butler(self.cx) butler.do(self.cx.command, (user.name, target, args[-1])) #self.cx.butler.do(self.cx.command, (user.name, args[-1])) return (target, source, args)
def smsticker(self): self.current = mktime(localtime()) # Only check every 10 seconds if self.current < self.next_: return self.next_ += 10 try: messages = self.client.sms.messages.list(to=self.secrets.number) except: print "Error fetching" return while messages: item = messages.pop() sid = item.sid if sid in self.incoming: continue self.incoming.append(sid) # Don't parse previously received messages until the # incoming list has been fully parsed if not self.loaded: continue clipped = item.from_[2:] drinker = Id(phone=clipped) # Note that this trusts the phone number, on the grounds # there must have been access to the system to get the # number in there. Normal ident auths can't be applied. if drinker.name: from_ = drinker.name else: from_ = item.from_ self.cx.context = self.cx.secrets.primary_channel message = 'SMS from %s: %s' % (from_, item.body) self.announce(message) name = drinker.name numba = drinker.phone bypass = False if clipped in self.secrets.bypass: bypass = True name = clipped numba = clipped # Check if the incoming message contained a command match = re.search( '^\{0}(\w+)[ ]?(.+)?'.format( self.cx.settings.bot.command_prefix), item.body) if match and (drinker.name or bypass): command = match.group(1) arguments = match.group(2) try: resp = self.cx.command(name, self.cx.secrets.primary_channel, item.body, silent=True) message = self.client.messages.create( body=resp, to=numba, from_=self.secrets.number) self.chat('Message sent: ' + message.sid) except Exception as e: self.chat(str(e)) self.loaded = True
def _close_position(self, ptype): whom = self.lastsender try: quantity = int(self.values[0]) symbol = self.values[1].upper() except: self.chat("That's not right") return if quantity <= 0: self.chat("Do you think this is a muthafuckin game?") return stock = Broker(symbol) if not stock: self.chat("Stock not found") return drinker = Id(self.lastid) if not drinker.is_authenticated: self.chat("You don't have a portfolio") return check = [] keep = [] for p in drinker.positions: if p.symbol.upper() == stock.symbol and p.type == ptype: check.append(p) else: keep.append(p) if not check: self.chat("I don't see %s in your portfolio" % stock.symbol) return check.sort(key=lambda x: x.date) verb = 'sold' if ptype == 'long' else 'covered' for p in check: if quantity <= 0: keep.append(p) continue q = min(quantity, p.quantity) basis = p.price * q value = stock.price * q if ptype == 'long': drinker.cash += value net = value - basis else: net = basis - value drinker.cash += basis + net quantity -= q p.quantity -= q if p.quantity > 0: keep.append(p) self.chat("%s %s %d shares of %s at %s (net: %.02f)" % (drinker.nick, verb, q, stock.symbol, stock.price, net)) drinker.positions = keep