Giter Club home page Giter Club logo

karmachameleon's Introduction

Karma Chameleon

License: GPL v3

A simple karma bot for Slack.

This is a simple, standalone Slack bot that watches for “karma events” and will keep track of scores for users and topics.

Adding Karma

In a channel where Karma Chameleon is present, do the following to add a point to a user or topic.

@user++

subject++

Removing Karma

In a channel where Karma Chameleon is present, do the following to remove a point from the user or topic.

@user—-

subject--

Note that decrementing or incrementing a user's own karma (the self-bump) is not a valid operation. You will be chastised by the Chameleon.

Setting up a Development Environment

Karma Chameleon relies on pip to install its dependencies and is easiest to develop with a Python Virtual Environment.

$ git clone https://github.com/subecho/KarmaChameleon.git
$ cd KarmaChameleon
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ python3 -m pip install -r requirements.txt

Running the Bot in a Development Environment

Before running the code, we need to do some initial setup on the Slack side so that Slack knows who we are, we are who we say we are, and which events we wish to subscribe to. You will need to create a new app in Slack and add the following scopes:

Bot Token Scopes:

  • channels:history
  • channels:join
  • channels:manage
  • chat:write
  • chat:write.customize
  • chat:write.public
  • commands
  • users:read

App-Level Tokens Scopes:

  • connections:write

User Token Scopes:

  • channels:history

There are two steps to testing the bot on your local machine: running the code and forwarding the port on which Karma Chameleon is listening to some publicly available URL. The CLI tool ngrok may be used to do this.

The following environment variables must be present in order for Karma Chameleon to function:

  • SLACK_BOT_TOKEN: populated with the contents of the SLACK_BOT_TOKEN OAuth key in the Slack App OAuth settings
  • SLACK_APP_TOKEN: populated with the contents of an App-Level Token specifically generated for use with socket mode, which may be found in Slack App Basic Information
  • KARMA_FILE_PATH: the path to which Karma Chameleon will create and maintain a JSON record of all karma.

In one terminal window, run: python3 karma_chameleon.py

After running that, in another terminal window, run: ngrok http 3000

This command will output an https URL that can be used to interact with the bot. You will want to paste this URL into the Request URL field in the Event Subscriptions page for your app. The format of the URL should be "/slack/events". You will also want to make sure that you add the message.channels event to the subscribed events for the bot. For slash-command support, a new command must be added with the request URL also being the ngrok URL in the format of "/slack/events".

The Karma Chameleon icon was made by Eucalyp from www.flaticon.com.

karmachameleon's People

Contributors

wrideout avatar dependabot[bot] avatar subecho avatar bdecato avatar

Stargazers

 avatar pseudoramble avatar  avatar Jake Schwartz avatar  avatar

Watchers

James Cloos avatar  avatar  avatar  avatar Kostas Georgiou avatar  avatar

Forkers

jngrosso

karmachameleon's Issues

Move the Backing Karma System from JSON to SQLite

Using a JSON file is...fine, but if we want to potentially use KC across multiple Slack instances, we should probably have a more robust backend for it than a single JSON file. We could start with SQLite to get the ball rolling and could inform our decision to use something else (e.g. Postgres) when we possibly containerize the lot of it.

Add the Ability to Save and Load Karma Data

Currently there is no way to save or load Karma Data so if the service is shut off the karma data is lost as it was only stored in memory. We should add the ability to save the current state of the karma data and then be able to read that back when the service is restarted.

Leaderboard 2.0 improvements

  • Merge entries that are identical except for case ("C" and "c" should be merged)

  • Merge entries that are identical except for a leading hashtag (#ChIPS vs ChIPS) and display them with no hashtag.

  • Remove users from the "Thing leaderboard." Currently it displays @wrideout as having 4 points there, because often people delete the mention link and then double-increment him. I think the default behavior here should be to only count a user in the users column, and only count an increment/decrement if it @'s them in the message. Open to opinions on this.

Pinging owner on crash

@wrideout brought up a good potential feature.

KarmaChameleon should ping its owner/handler if it goes down. Potentially with a KC-flavored Slack DM like "A Captain always goes down with the ship!" followed by informative messages for restarting or debugging(?) the bot.

Broken Pipe HELL

54.167.217.233 - - [07/Apr/2021 23:46:34] "POST /slack/events HTTP/1.1" 200 -
3.80.156.142 - - [08/Apr/2021 00:19:47] "POST /slack/events HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('74.120.14.38', 58126)
Traceback (most recent call last):
  File "/usr/lib/python3.8/socketserver.py", line 316, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.8/socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.8/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.8/http/server.py", line 647, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/lib/python3.8/socketserver.py", line 720, in __init__
    self.handle()
  File "/usr/lib/python3.8/http/server.py", line 427, in handle
    self.handle_one_request()
  File "/usr/lib/python3.8/http/server.py", line 395, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python3.8/socket.py", line 669, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
----------------------------------------
74.120.14.38 - - [08/Apr/2021 01:26:44] code 400, message Bad request version ('À\x14À')
74.120.14.38 - - [08/Apr/2021 01:26:44] "{wh�Zú¸
                                                °Þ#@�+òcë�PÎô¢�vÃl²ÌÛ�|ïÀ/À+ÀÀÀÀ        ÀÀ" 400 -
74.120.14.38 - - [08/Apr/2021 01:26:46] "GET / HTTP/1.1" 404 -
74.120.14.38 - - [08/Apr/2021 01:26:49] "GET / HTTP/1.1" 404 -
35.175.200.162 - - [08/Apr/2021 02:38:20] "POST /slack/events HTTP/1.1" 200 -

Karma Chameleon is Missing Unit Tests

Currently there are not any unit tests for exercising the basic functionality of Karma Chameleon. Unit tests should be added to ensure a baseline of quality.

Normalize Names on Increment and Decrement Operations

Currently, Karma Chameleon treats the following messages as discrete entries:
#topic++
topic++
@topic++
When the @topic is not a username. This causes three separate karma entities to exist each with its own score. We should try to "normalize" these so that all three of the previous messages will refer to the same entity.

Implement the Slash Command "/leaderboard"

Rudimentary leaderboard will just show everything that's ever been incremented or decremented with their + total, - total, and the difference, sorted by difference.

Future implementations should rely on the hierarchy of Items: we'll probably want to split that into People and Things somehow.

Missing test coverage

Currently, overall unittest coverage is as follows (it would be nice to be 100% covered):


---------- coverage: platform darwin, python 3.9.1-final-0 -----------
Name                 Stmts   Miss Branch BrPart     Cover
---------------------------------------------------------
bot.py                 116     76     24      2    30.00%
karma_chameleon.py      46      2     16      2    93.55%
karma_item.py           36      1     10      1    95.65%
snark.py                 8      0      0      0   100.00%
---------------------------------------------------------
TOTAL                  206     79     50      5    59.38%```

Use Docker Compose to Deploy Karma Chameleon

It would be super rad to have a simple docker-compose.yaml file available for more easily deploying Karma Chameleon to servers without the hassle of setting up Python/dependencies/virtual environments/etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.