
an Abbot package for Discord by Serious Business
Give everything a score
About Abbot
Abbot is a programmable bot that turns your team chat into a shared command center. We handle all the boilerplate of building and running these conmmands so that you can focus on making tools that help you ship faster.
We built Abbot because we saw the power of this style of work (called ChatOps), when we worked at GitHub. ChatOps made it possible for GitHub to work productively without meetings, while globally distributed. We think it’s a pretty great way to work, so we made it easy to use in Slack, Discord, and Microsoft Teams.
You can read more about Abbot here, check out our blog, or take a look at some of the other cool packages available as a one-click install from Abbot’s Package Directory.
README
Karma lets your team upvote and downvote everything. This way you can keep track of what really matters — internet points for everything.
Give things Karma by saying word++ and remove it by saying word–. With Pattern support, you don’t have to mention Abbot at all!
Add these two Regular Expression Patterns after installing the skill:
Upvotes:
(\S+[^+:\s])[: ]*++(\s|$)
Downvotes:
(\S+[^-:\s])[: ]*–(\s|$)
What will they think of next?
Usage
Karma works with a Pattern. Give something points by saying term++
, and remove them with term--
.
This was inspired by Hubot’s Karma script: https://github.com/github/hubot-scripts/blob/master/src/scripts/karma.coffee
Code
karmas = bot.brain.get(‘karma’)
if karmas is None:
karmas = {}
increment_responses = [
“+1!”, “gained a level!”, “is on the rise!”, “leveled up!”, “is going up. Nice!”
]
decrement_responses = [
“took a hit! Ouch.”, “took a dive.”, “lost a life.”, “lost a level.”, “got worse. dang.”
]
def upsert_term(term, score):
“””Upsert a term’s score. Create one if it doesn’t exist”””
item = karmas.get(term)
if item is None:
karmas[term] = score
else:
karmas[term] = karmas[term] + score
bot.brain.write(‘karma’, karmas)
def the_best():
“””Report the top 5 items”””
if len(karmas) == 0:
bot.reply(“There isn’t anything to report yet…”)
return
items = sorted(karmas.items(), key=lambda x: x[1], reverse=True)
output = “”
counter = 0
for item in items:
output = output + “\n * {}: {} point(s)”.format(item[0], item[1])
counter = counter + 1
if counter == 5: break
bot.reply(“Simply the best: ” + output)
def the_worst():
“””Report the worst 5 items”””
if len(karmas) == 0:
bot.reply(“There isn’t anything to report yet…”)
return
items = sorted(karmas.items(), key=lambda x: x[1])
output = “”
for item in items:
output = output + “\n * {}: {} point(s)”.format(item[0], item[1])
counter = counter + 1
if counter == 5: break
bot.reply(“Simply the WORST: ” + output)
if bot.is_pattern_match:
pos = re.match(r'(\S+[^+:\s])[: ]*\+\+(\s|$)’, bot.arguments)
if pos:
term = pos.groups()[0]
upsert_term(term, 1)
bot.reply(term + ” ” + random.choice(increment_responses))
neg = re.match(r'(\S+[^+:\s])[: ]*\-\-(\s|$)’,bot.arguments)
if neg:
term = neg.groups()[0]
upsert_term(term, -1)
bot.reply(term + ” ” + random.choice(decrement_responses))
elif bot.arguments == “best”:
the_best()
elif bot.arguments == “worst”:
the_worst()
elif bot.is_pattern_match:
bot.reply(bot.arguments)
elif bot.arguments == “clear”:
bot.brain.write(“karma”, None)
bot.reply(“All karma has been reset. It’s a fresh start!”)
elif len(bot.arguments) == 0:
the_best()
else:
bot.reply(“I don’t know what you meant by that. Are you sure that’s a karma command?”)
Version History
Version | Created | Author | Release Notes | Installs |
---|---|---|---|---|
1.0.1 | 11/8/2021 |
![]() Paul |
Better leaderboards |
1 |
1.0.0 | 11/2/2021 |
![]() Paul |
initial release |
0 |
You need an account to install this package with Abbot. Signing in with Discord will create an account if you don’t have one already.
Not using Discord? No worries! Abbot works in Slack, Discord, and Microsoft Teams.
It’s free to get started!
Details
-
Last updated -
Installs - 1 total install
-
Language - Python
-
License - MIT License