How to use the pmxbot.karma.Karma.store function in pmxbot

To help you get started, we’ve selected a few pmxbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yougov / pmxbot / tests / unit / test_commands.py View on Github external
def test_boo(self):
        """
        Test "boo foo"
        """
        subject = "foo"
        pre = karma.Karma.store.lookup(subject)
        res = commands.boo(subject)
        assert res == "/me BOOO %s!!! BOOO!!!" % subject
        post = karma.Karma.store.lookup(subject)
        assert post == pre - 1
github yougov / pmxbot / tests / unit / test_commands.py View on Github external
def test_motivate_with_spaces(self):
        """
        Test that motivate strips beginning and ending whitespace
        """
        subject = "foo"
        pre = karma.Karma.store.lookup(subject)
        res = commands.motivate(channel="#test", rest="   %s \t  " % subject)
        assert res == "you're doing good work, %s!" % subject
        post = karma.Karma.store.lookup(subject)
        assert post == pre + 1
github yougov / pmxbot / pmxbot / karma.py View on Github external
Karma.store.change(karmee, -1)
    elif '~~' in rest:
        change = random.choice([-1, 0, 1])
        Karma.store.change(karmee, change)
        if change == 1:
            return "%s karma++" % karmee
        elif change == 0:
            return "%s karma shall remain the same" % karmee
        elif change == -1:
            return "%s karma--" % karmee
    elif '==' in rest:
        t1, t2 = rest.split('==')
        try:
            Karma.store.link(t1, t2)
        except SameName:
            Karma.store.change(nick, -1)
            return "Don't try to link a name to itself!"
        except AlreadyLinked:
            return "Those names were previously linked."
        score = Karma.store.lookup(t1)
        return "%s and %s are now linked and have a score of %s" % (t1, t2, score)
    else:
        karmee = rest or nick
        score = Karma.store.lookup(karmee)
        return "%s has %s karmas" % (karmee, score)
github yougov / pmxbot / pmxbot / karma.py View on Github external
if change == 1:
            return "%s karma++" % karmee
        elif change == 0:
            return "%s karma shall remain the same" % karmee
        elif change == -1:
            return "%s karma--" % karmee
    elif '==' in rest:
        t1, t2 = rest.split('==')
        try:
            Karma.store.link(t1, t2)
        except SameName:
            Karma.store.change(nick, -1)
            return "Don't try to link a name to itself!"
        except AlreadyLinked:
            return "Those names were previously linked."
        score = Karma.store.lookup(t1)
        return "%s and %s are now linked and have a score of %s" % (t1, t2, score)
    else:
        karmee = rest or nick
        score = Karma.store.lookup(karmee)
        return "%s has %s karmas" % (karmee, score)
github yougov / pmxbot / pmxbot / karma.py View on Github external
Karma.store.change(karmee, 1)
    elif '--' in rest:
        Karma.store.change(karmee, -1)
    elif '~~' in rest:
        change = random.choice([-1, 0, 1])
        Karma.store.change(karmee, change)
        if change == 1:
            return "%s karma++" % karmee
        elif change == 0:
            return "%s karma shall remain the same" % karmee
        elif change == -1:
            return "%s karma--" % karmee
    elif '==' in rest:
        t1, t2 = rest.split('==')
        try:
            Karma.store.link(t1, t2)
        except SameName:
            Karma.store.change(nick, -1)
            return "Don't try to link a name to itself!"
        except AlreadyLinked:
            return "Those names were previously linked."
        score = Karma.store.lookup(t1)
        return "%s and %s are now linked and have a score of %s" % (t1, t2, score)
    else:
        karmee = rest or nick
        score = Karma.store.lookup(karmee)
        return "%s has %s karmas" % (karmee, score)
github yougov / pmxbot / pmxbot / web / viewer.py View on Github external
def default(self, term=""):
        page = jenv.get_template('karma.html')
        context = get_context()
        karma = pmxbot.karma.Karma.store
        term = term.strip()
        if term:
            context['lookup'] = self.karma_comma(karma.search(term)) or [
                ('NO RESULTS FOUND', '')
            ]
        context['top100'] = self.karma_comma(karma.list(select=100))
        context['bottom100'] = self.karma_comma(karma.list(select=-100))
        return page.render(**context).encode('utf-8')
github yougov / pmxbot / pmxbot / commands.py View on Github external
def boo(rest):
    "Boo someone"
    slapee = rest
    karma.Karma.store.change(slapee, -1)
    return "/me BOOO %s!!! BOOO!!!" % slapee
github yougov / pmxbot / pmxbot / karma.py View on Github external
def top10(rest):
    """
    Return the top n (default 10) highest entities by Karmic value.
    Use negative numbers for the bottom N.
    """
    if rest:
        topn = int(rest)
    else:
        topn = 10
    selection = Karma.store.list(topn)
    res = ' '.join('(%s: %s)' % (', '.join(n), k) for n, k in selection)
    return res
github yougov / pmxbot / pmxbot / commands.py View on Github external
def troutslap(rest):
    "Slap some(one|thing) with a fish"
    slapee = rest
    karma.Karma.store.change(slapee, -1)
    return "/me slaps %s around a bit with a large trout" % slapee