def choose(self, server, msg, query): if "," not in query: return context = server.lower(msg.context) self.decision[context] = time.time() self.results[context] = { strip(i): 0 for i in re.split(r",|\bor\b", query) } schedule_after(1, self.report, args=(server, msg.context))
def report(self, server, channel): if time.time() - self.decision[server.lower(channel)] < 2: schedule_after(1, self.report, args=(server, channel)) return results = self.results[server.lower(channel)] highest = max(results.values()) choice = random.choice([i for i in results if results[i] == highest]) results[choice] += 1 server.message("\x0309│\x03 " + choice, channel) data = sorted(results.items(), key=lambda x: -x[1]) if len(data) < 2: return output = " · ".join("%s%s (%d)\x0f" % ("\x02" if i[0] == choice else "", i[0], i[1]) for i in data) server.message("\x039│\x03 " + output, channel)
def __init__(self, server): self.settingsf = server.get_config_dir(self.SETTINGS_FILE) try: self.settings = json.load(open(self.settingsf)) except FileNotFoundError: self.settings = {} self.deletionf = server.get_config_dir(self.DELETION_FILE) try: self.deletion = json.load(open(self.deletionf)) except FileNotFoundError: self.deletion = {} self.usersf = server.get_config_dir(self.USERS_FILE) try: self.users = json.load(open(self.usersf)) except FileNotFoundError: self.users = {} self.unverified = {} self.accounts = {i: pysnap.Snapchat() for i in self.settings} for i in self.settings: self.accounts[i].login(self.settings[i]["username"], self.settings[i]["password"]) self.cache = {} self.checker = scheduler.schedule_after(45, self.checksnaps, args=(server,), stop_after=None) self.server = server super().__init__(server)
def report(self, server, channel): if time.time() - self.decision[server.lower(channel)] < 2: schedule_after(1, self.report, args=(server, channel)) return results = self.results[server.lower(channel)] highest = max(results.values()) choice = random.choice([i for i in results if results[i] == highest]) results[choice] += 1 server.message("\x0309│\x03 " + choice, channel) data = sorted(results.items(), key=lambda x: -x[1]) if len(data) < 2 or sum(results[i] for i in results) == 1: return output = " · ".join("%s%s (%d)\x0f" % ("\x02" if i[0] == choice else "", i[0], i[1]) for i in data) server.message("\x039│\x03 " + output, channel)
def reminder(self, server, msg, user, after, text, after2, method, repeat, cancel): # TODO: handle inactive people # TODO: print reminders in last-spoke channel after = parse_time(after or after2) repeat = parse_time(repeat) method = (method or "channel message").lower() text = re.sub("\bs?he's\b", "you're", text, flags=re.IGNORECASE) text = re.sub("\bs?he|they\b\s+(\S+)s", r"you \1", text, flags=re.IGNORECASE) if user.lower() in ["me", "self"]: user = msg.address.nick if method == "snapchat": return "Snapchat not yet implemented." if re.match(r"what\s+to\s+\S+|(again\s+)later", text, re.IGNORECASE): return "Not yet implemented" jobid = uuid.uuid4().hex job = {"id": jobid, "sender": msg.address.nick, "message": text, "method": method, "time": time.time(), "after": after + time.time(), "channel": msg.context} def setreminder(job): self.waiting.setdefault(server.lower(user), {}).pop(jobid, None) comchans = sorted([i for i in server.channels if server.isIn(user, server.channels[i])], key=lambda x:not server.eq(x, msg.context)) if comchans: self.send_messages([i for i in server.channels[comchans[0]] if server.lower(i) == server.lower(user)][0], comchans[0]) self.reminders.setdefault(server.lower(user), []).append(job) if after: self.waiting.setdefault(server.lower(user), {})[jobid] = {"job": scheduler.schedule_after(after, setreminder, args=(job,)), "args": job} with open(self.server.get_config_dir(self.REMINDERF), "w") as f: json.dump(self.reminders, f) return "user=%(user)s, after=%(after)s, text=%(text)s, method=%(method)s, repeat=%(repeat)s, cancel=%(cancel)s" % locals()
def __init__(self, server): self.server = server self.last = time.time() self.lastcheck = time.time() self.watchdog = scheduler.schedule_after(90, self.check, stop_after=None) super().__init__(server)
def __init__(self, server): self.server = server self.last = time.time() self.lastcheck = time.time() self.watchdog = schedule_after(90, self.check, stop_after=None) super().__init__(server)
def choose(self, server, msg, query): if "," not in query: return context = server.lower(msg.context) self.decision[context] = time.time() self.results[context] = {strip(i): 0 for i in re.split(r",|\bor\b", query)} schedule_after(1, self.report, args=(server, msg.context))
def reminder(self, server, msg, user, after, text, after2, method, repeat, cancel): # TODO: handle inactive people # TODO: print reminders in last-spoke channel after = parse_time(after or after2) repeat = parse_time(repeat) if msg.context.startswith("#"): method = (method or "channel message").lower() else: method = (method or "private message").lower() text = re.sub("\bs?he's\b", "you're", text, flags=re.IGNORECASE) text = re.sub("\bs?he|they\b\s+(\S+)s", r"you \1", text, flags=re.IGNORECASE) if user.lower() in ["me", "self"]: user = msg.address.nick user = user.lstrip("@") if method == "snapchat": return "Snapchat not yet implemented." if re.match(r"what\s+to\s+\S+|(again\s+)later", text, re.IGNORECASE): return "Not yet implemented" jobid = uuid.uuid4().hex job = { "id": jobid, "sender": msg.address.nick, "message": text, "method": method, "time": time.time(), "after": after + time.time(), "channel": msg.context } def setreminder(job): self.waiting.setdefault(server.lower(user), {}).pop(jobid, None) comchans = sorted([ i for i in server.channels if server.isIn(user, server.channels[i]) ], key=lambda x: not server.eq(x, msg.context)) if comchans: self.send_messages([ i for i in server.channels[comchans[0]] if server.lower(i) == server.lower(user) ][0], comchans[0]) self.reminders.setdefault(server.lower(user), []).append(job) if after: self.waiting.setdefault(server.lower(user), {})[jobid] = { "job": scheduler.schedule_after(after, setreminder, args=(job, )), "args": job } with open(self.server.get_config_dir(self.REMINDERF), "w") as f: json.dump(self.reminders, f) when = "in %s" % from_now(after) if after else "next time I see them" return "03│ I'll tell %s that %s." % (user, when)