def send_spam(self, server, nick, user, host, target, msg): if host in self.pmed or target.lower() in self.excpt: return msg = choice(self.db) self.pmed.append(host) send_msg(server, nick, msg)
def run(self, server, nick, user, host, target, msg, lang, code): url, output = libpad.sandbox(code, lang) if len(output) <= self.max_width: send_msg(server, target, output) else: send_msg(server, target, url)
def list_folder(self, server, nick, user, host, target, msg): """ """ content = '\n'.join(os.listdir(self.folder)) url, _ = libpad.sandbox(content, '') send_msg(server, target, url)
def send_file(con, nick, user, host, target, msg): if not msg.startswith('.send'): return cmd, filename, port = msg.split(' ') resource = '%s/%s' % (FOLDER, filename) size = getsize(resource) fd = open(resource, 'rb') def is_done(msg): send_msg(con, nick, msg) fd.close() try: dcc = DccServer(fd, int(port), timeout=50) except Exception: is_done('Couldnt list on the port!') raise dcc.add_map(DONE, lambda *args: is_done('Done.')) dcc.add_map(CLOSE, lambda *args: is_done('Failed!')) dcc.add_map(ACCEPT_ERR, lambda *args: is_done("Accept error!")) dcc.add_map(TIMEOUT, lambda *args: is_done('TIMEOUT!')) HEADER = '\001DCC SEND %s %s %s %s\001' request = HEADER % (filename, ip_to_long(con.myaddr), port, size) send_msg(con, nick, request)
def check_file_existence(con, xxx_todo_changeme, filename, address, port, size): (nick, user, host, target, msg) = xxx_todo_changeme resource = '%s/%s' % (FOLDER, filename) if isfile(resource): send_msg(con, nick, 'File already exists.') else: recv_file(con, nick, resource, address, port, size)
def note_del(self, server, nick, user, host, target, msg, peer): peer = peer.lower() msgs = self.base.get(peer, []) orig_len = len(msgs) msgs = [m for m in msgs if m.source[1:] != (user, host)] if msgs: self.base[peer] = msgs elif peer in self.base: del self.base[peer] send_msg(server, target or nick, '%s: %d notes deleted.' % ( nick, orig_len - len(msgs)))
def check(self, server, nick, user, host, target, msg): struct = search(REG_LINK, msg) if not struct: return req = requests.get(struct.group('address')) html = Html() dom = html.feed(req.text) title = dom.fst('title').text() send_msg(server, target, title)
def drop_msg(self, area, wid, target): """ Drop msgs and update the areavi. """ data = wid.get() area.append(H1 % (self.misc.nick, data)) send_msg(self.con, target, data) wid.delete(0, 'end')
def build(self, server, nick, user, host, target, msg, exp): try: data = str(run(exp)) except Exception as e: send_msg(server, target, str(e)) else: send_msg(server, target, post(data, 'Math formulae', 'Ameliabot'))
def check(self, server, nick, user, host, target, msg, peer): try: initial = self.database[peer.lower()] except: send_msg(server, target, "No records for that nick.") else: final = time.time() rate = final - initial hour = int(rate / (60 ** 2)) rate = int(rate % (60 ** 2)) min = int(rate / 60) sec = int(rate % 60) send_msg(server, target, '%s last seen %s:%s:%s ago.' % (peer, hour, min, sec))
def send_auth(self, con): # It is what we use to send data. send_msg function uses # ssock.dump function to dump commands. SockWriter(con) SockReader(con) # This protocol spawns FOUND whenever it finds \r\n. Terminator(con) Irc(con) con.add_map(CLOSE, lambda con, err: lose(con)) # Now, it basically means: when it '376' irc command is # issued by the server then calls self.auto_join. # We use auto_join to send the sequence of JOIN # commands in order to join channels. con.add_map('376', self.auto_join) # Below the remaining stuff follows the same pattern. con.add_map('JOIN', self.on_join) con.add_map('PING', self.on_ping) con.add_map('PART', self.on_part) con.add_map('376', self.on_376) con.add_map('NOTICE', self.on_notice) con.add_map('PRIVMSG', self.on_privmsg) con.add_map('332', self.on_332) con.add_map('001', self.on_001) con.add_map('001', self.on_002) con.add_map('003', self.on_003) con.add_map('004', self.on_004) con.add_map('333', self.on_333) con.add_map('353', self.on_353) con.add_map('366', self.on_366) con.add_map('474', self.on_474) con.add_map('302', self.on_302) send_cmd(con, 'NICK %s' % self.nick) send_cmd(con, 'USER %s' % self.user) send_msg(con, 'nickserv', 'identify %s' % self.password)
def note_add(self, server, nick, user, host, target, msg, peer, data): msgs = self.base[peer.lower()] user_msgs = [m for m in msgs if m.source[1:] == (user, host) or user.startswith('~') and m.source[2] == host] if len(user_msgs) + 1 > MAX_NOTES_PER_PEER: send_msg(server, target, '%s: you may leave no more than %d notes for "%s".' % ( nick, MAX_NOTES_PER_PEER, peer)) elif len(msgs) + 1 > MAX_NOTES: send_msg(server, target, '%s: there are too many notes saved for "%s".' % ( nick, peer)) else: msgs.append(Message( source=(nick,user,host), message=data)) self.base[peer.lower()] = msgs send_msg(server, target, '%s: note for "%s" saved.' % (nick, peer))
def login(server, nick, user, host, target, msg, password): if password == server.adm_passwd: known.add(host) send_msg(server, nick, 'Logged!') else: send_msg(server, nick, 'Invalid password!')
def send_welcome(server, nick, user, host, channel): send_msg(server, channel, 'Welcome to our relaxed place !')
def listen(server, nick, user, target, msg, lang_x, lang_y): data = source.translate(msg, lang_x, lang_y) send_msg(server, target, '%s %s' % (nick, data))
def is_done(msg): send_msg(con, nick, msg) fd.close()
def send_question(self, server, nick, user, host, channel): if not (host.lower() in self.pmed or nick.lower() in self.pmed): Timer(randint(0, self.timeout), lambda : send_msg(server, nick, choice(self.questions))) self.register_user(self.pmed, self.pmed_file, nick, host)
def getinfo(self, server, nick, user, host, target, msg, player): result = getPlayerInfo(player) send_msg(server,target,str(ircOutput(result)))
def translate(self, server, nick, user, host, target, msg, lang1, lang2, data): data = self.google_translator.translate(data, lang1, lang2) send_msg(server, target, data)
def check_answer(self, server, nick, user, host, target, msg): if (nick in self.pmed or host in self.pmed) and \ not (nick in self.blacklist or host in self.blacklist): Timer(randint(0, self.timeout), lambda : send_msg(server, nick, choice(self.suggestions))) self.register_user(self.blacklist, self.blacklist_file, nick, host)
def send(server, nick, user, host, target, msg, person, note): send_msg(server, person, note)
def pipe_chan(server, nick, user, host, target, msg,): chan_list = mapping.get((server, target.upper())) if not chan_list: return for ind in chan_list: send_msg(server, ind, '(%s)%s %s' % (target, nick, msg))
def send_note(self, server, nick, user, host, channel): if nick.lower() not in self.base: return for msg in self.base[nick.lower()]: send_msg(server, channel, '%s: <%s> %s' % ( nick, '%s!%s@%s' % msg.source, msg.message)) del self.base[nick.lower()]
def check_msg(self, server, nick, user, host, target, msg): if search(self.pattern, msg): send_msg(server, target, self.make_seq())
def send_quote(self, server, nick, user, host, target, msg): quote = choice(self.data) send_msg(server, target, quote)