Пример #1
0
    def on_channel_message(self, who, channel, msg):
        direct = msg.startswith(self.cfg.nick)

        if direct:
            self.message(channel, Tags.LtGreen(Tags.Bold('WARK WARK WARK')))

        modes = who.user.modes_in(channel)
        evt = events.IRCMessage(str(who), channel, msg, modes, direct)
        events.dispatcher.dispatch('ircclient', evt)
Пример #2
0
    def on_message(self, umask, target, msg):
        if umask.host not in self.bot.admins:
            return

        parts = msg.split()
        if msg.startswith('!snip ') and len(parts) >= 3:
            self.snippets[parts[1]] = ' '.join(parts[2:])

        if msg.startswith('!unsnip ') and len(parts) >= 2:
            try:
                del self.snippets[parts[1]]
            except KeyError:
                pass

        if msg.startswith('.') and parts[0][1:] in self.snippets:
            try:
                exec(self.snippets[parts[0][1:]], locals(), globals())
            except Exception as ex:
                self.bot.message(target, Tags.Bold('Exception: ') + repr(ex))
Пример #3
0
    def handle_gh_push(self, evt):
        fmt_url = Tags.UnderlineBlue
        fmt_repo_name = Tags.UnderlinePink
        fmt_ref = Tags.Purple
        fmt_hash = lambda h: Tags.Grey(h[:6])

        commits = [utils.ObjectLike(c) for c in evt.commits]
        distinct_commits = [c for c in commits
                            if c.distinct and c.message.strip()]
        num_commits = len(distinct_commits)

        parts = []
        parts.append('[' + fmt_repo_name(evt.repo) + ']')
        parts.append(self.format_nickname(evt.pusher))

        if evt.created:
            if evt.ref_type == 'tags':
                parts.append('tagged ' + fmt_ref(evt.ref_name) + ' at')
                parts.append(fmt_ref(evt.base_ref_name)
                             if evt.base_ref_name else fmt_hash(evt.after_sha))
            else:
                parts.append('created ' + fmt_ref(evt.ref_name))
                if evt.base_ref_name:
                    parts.append('from ' + fmt_ref(evt.base_ref_name))
                elif not distinct_commits:
                    parts.append('at ' + fmt_hash(evt.after_sha))

                if distinct_commits:
                    parts.append('+' + Tags.Bold(str(num_commits)))
                    parts.append('new commit' + ('s'
                                                 if num_commits > 1 else ''))
        elif evt.deleted:
            parts.append(Tags.Red('deleted ') + fmt_ref(evt.ref_name))
            parts.append('at ' + fmt_hash(evt.before_sha))
        elif evt.forced:
            parts.append(Tags.Red('force-pushed ') + fmt_ref(evt.ref_name))
            parts.append('from ' + fmt_hash(evt.before_sha) + ' to ' +
                         fmt_hash(evt.after_sha))
        elif commits and not distinct_commits:
            if evt.base_ref_name:
                parts.append('merged ' + fmt_ref(evt.base_ref_name) + ' into '
                             + fmt_ref(evt.ref_name))
            else:
                parts.append('fast-forwarded ' + fmt_ref(evt.ref_name))
                parts.append('from ' + fmt_hash(evt.before_sha) + ' to ' +
                             fmt_hash(evt.after_sha))
        else:
            parts.append('pushed ' + Tags.Bold(str(num_commits)))
            parts.append('new commit' + ('s' if num_commits > 1 else ''))
            parts.append('to ' + fmt_ref(evt.ref_name))

        self.bot.say(' '.join(str(p) for p in parts))

        for commit in distinct_commits[:4]:
            firstline = commit.message.split('\n')[0]
            author = self.format_nickname(commit.author.name)
            added = Tags.LtGreen(str(len(commit.added)))
            modified = Tags.LtGreen(str(len(commit.modified)))
            removed = Tags.Red(str(len(commit.removed)))
            url = Tags.UnderlineBlue(utils.shorten_url(commit.url))
            self.bot.say('%s by %s [%s|%s|%s] %s %s' %
                         (commit.hash[:6], author, added, modified, removed,
                          url, firstline))

        if len(distinct_commits) > 4:
            self.bot.say('... and %d more commits' %
                         (len(distinct_commits) - 4))
Пример #4
0
 def help(self, cmd, args):
     out = '%s: %s %s' % (Tags.Green('usage'), Tags.Bold(cmd), args)
     self.bot.message(target, out)