How to use the pmxbot.karma 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_karma.py View on Github external
def test_linking_same_does_nothing(self, sqlite_karma):
        k = sqlite_karma
        k.set('foo', 99)
        with pytest.raises(karma.SameName):
            k.link('foo', 'foo')
        assert k.lookup('foo') == 99
github yougov / pmxbot / tests / unit / test_karma.py View on Github external
def test_already_linked_raises_error(self, sqlite_karma):
        k = sqlite_karma
        k.set('foo', 50)
        k.set('bar', 50)
        k.link('foo', 'bar')
        assert k.lookup('foo') == k.lookup('bar') == 100
        with pytest.raises(karma.AlreadyLinked):
            k.link('foo', 'bar')
        with pytest.raises(karma.AlreadyLinked):
            k.link('bar', 'foo')
        assert k.lookup('foo') == k.lookup('bar') == 100
github yougov / pmxbot / tests / unit / test_karma.py View on Github external
def sqlite_karma(self, request, tmpdir):
        filename = tmpdir / 'db.sqlite'
        return karma.Karma.from_URI('sqlite://{filename}'.format(**locals()))
github yougov / pmxbot / tests / unit / test_commands.py View on Github external
id = str(uuid.uuid4())
        flags = {}
        i = 0
        karmafetch = re.compile(r"^%s has (\-?\d+) karmas$" % id)
        while len(flags) < 3 and i <= 30:
            res = karma.karma(nick="testrunner", rest=id)
            prekarma = int(karmafetch.findall(res)[0])
            change = karma.karma(nick="testrunner", rest="%s~~" % id)
            assert change in [
                "%s karma++" % id,
                "%s karma--" % id,
                "%s karma shall remain the same" % id,
            ]
            if change.endswith('karma++'):
                flags['++'] = True
                res = karma.karma(nick="testrunner", rest=id)
                postkarma = int(karmafetch.findall(res)[0])
                assert postkarma == prekarma + 1
            elif change.endswith('karma--'):
                flags['--'] = True
                res = karma.karma(nick="testrunner", rest=id)
                postkarma = int(karmafetch.findall(res)[0])
                assert postkarma == prekarma - 1
            elif change.endswith('karma shall remain the same'):
                flags['same'] = True
                res = karma.karma(nick="testrunner", rest=id)
                postkarma = int(karmafetch.findall(res)[0])
                assert postkarma == prekarma
            i += 1
        assert len(flags) == 3
        assert i < 30
github yougov / pmxbot / tests / unit / test_karma.py View on Github external
def test_already_linked_raises_error(self, mongodb_karma):
        k = mongodb_karma
        k.set('foo', 50)
        k.set('bar', 50)
        k.link('foo', 'bar')
        assert k.lookup('foo') == k.lookup('bar') == 100
        with pytest.raises(karma.AlreadyLinked):
            k.link('foo', 'bar')
        with pytest.raises(karma.AlreadyLinked):
            k.link('bar', 'foo')
        assert k.lookup('foo') == k.lookup('bar') == 100
github yougov / pmxbot / pmxbot / commands.py View on Github external
def golfclap(rest):
    "Clap for something"
    clapv = random.choice(phrases.clapvl)
    adv = random.choice(phrases.advl)
    adj = random.choice(phrases.adjl)
    if rest:
        clapee = rest.strip()
        karma.Karma.store.change(clapee, 1)
        return "/me claps %s for %s, %s %s." % (clapv, rest, adv, adj)
    return "/me claps %s, %s %s." % (clapv, adv, adj)