def whois(args): "check if a user registered on the site" if not args: return "who is who?" else: u = User.objects.filter(profile__irc_nick=args[0]) if not u: return "%s is not know at %s"%(args[0], Site.objects.get_current()) elif len(u) > 1: return "Err...found more than one user with irc nick '%s'." % (args[0]) else: u = u[0] return str("%s is known as %s: http://%s%s"% (args[0], u.get_profile().display_name, Site.objects.get_current(), get_tiny_url(u.get_profile())))
def set_title(self): """ update news in channel titles (topics) """ n = News.objects.latest() current_site = Site.objects.get_current() news = "%s: http://%s%s" % (n.title, current_site, get_tiny_url(n)) for channel in self.channels: if channel in self.topics: old_topic = self.topics[channel] new_topic = re.sub(settings.BOT_TITLE_REGEX, "\\1%s\\2" % news, old_topic) if new_topic != old_topic: self.topic(channel, new_topic.encode("utf-8")) else: print "don't know topic of ", channel
def _last_objects(cls, args): if args: try: # 1 <= n <= 5 n = min(max(int(args[0]), 1), 5) except ValueError: n = 1 else: n = 1 obj_list = cls.objects.all()[:n] retvals = [] for obj in obj_list: retvals.append("%s: http://%s%s" % (obj, Site.objects.get_current(), get_tiny_url(obj))) return retvals
def check_notifications(sender, instance, created, **kwargs): if not created or sender not in (News, Release, Poll, Comment, Snippet): return obj_id = None kind = None current_site = Site.objects.get_current() if sender == News and instance.active: kind = "n" url = reverse("news_overview") title = "Latest News on %s: %s" % (current_site, instance.title) if SEND_NEWS: msg = "%s: http://%s%s" % (instance.title, current_site, get_tiny_url(instance)) send_to_bot(msg) if SET_TITLE: msg = "::settitle::" send_to_bot(msg) elif sender == Release: kind = "pr" obj_id = instance.project.id url = instance.project.get_absolute_url() title = "%s released" % instance if SEND_RELEASES: msg = "%s: http://%s%s" % (title, current_site, get_tiny_url(instance)) send_to_bot(msg) elif sender == Poll and not instance.active: # only handle closed polls kind = "pm" url = reverse("potm-overview") title = "Poll notification not yet ready" #TODO: notify on close elif sender == Snippet: kind = "s" url = reverse("snippets") title = "Latest Snippet on %s: %s" % (current_site, instance.title) if SEND_SNIPPETS: msg = "%s: http://%s%s" % (instance.title, current_site, get_tiny_url(instance)) send_to_bot(msg) elif sender == Comment and not instance.is_auto_comment(): obj_id = instance.object_id if isinstance(instance.content_object, News): kind = "nc" elif isinstance(instance.content_object, Project): kind = "pc" elif isinstance(instance.content_object, Snippet): kind = "sc" else: return obj_id = instance.object_id url = instance.content_object.get_absolute_url() title = str(instance) if kind: subscriptions = Subscription.objects.by_kind(kind=kind, obj_id=obj_id) if not subscriptions: return args = { 'readable_kind': CHOICES[kind], 'instance': instance, 'current_site': current_site, 'unsubscribe_link': "%s?unsubscribe=%s" % (url, CHOICES[kind].replace(" ", "-"))} if "c" in kind: kind = "c" mail_body = render_to_string('notification/mail-%s.txt' % kind, args) for sub in subscriptions: send_mail(title, mail_body % sub.user.get_profile().display_name, None, [sub.user.email], fail_silently=True)