KarmaBot's Avatar

KarmaBot

A simple, modern & lightweight/efficient utility to award positive or negative "Karma" to any user/keyword.


Prefix: >kUpvote Botdiscord.js0 upvotes this month1,059 servers

PRs Welcome Discord Discord Bots Codacy Badge Downloads Discord Bots

Build Status Scrutinizer Code Quality Dependencies npm-build StandardJS GitHub issues GitHub license GitHub stars

karma-simple

A simple, lightweight and functional Discord utility/Bot used for awarding positive or negative “Karma” to any user/keyword.

Public Bot Direct Invite: https://bot.discord.io/karmabot [scroll to the bottom of this page for support!] We’d appreciate if you could also give us a vote on DiscordBots :)

Screenshot In Action

karma-simple

GIF: https://i.imgur.com/hqehZjR.gif

We make sure to keep up-to-date. Although this is a small bot, we still run the same CI and build tests (as shown above). Our buildfile test includes our autoinstaller script(s). The config we use for Travis is here for anyone curious.

Installation

The bot is built for Discord using discord.js v12.0.0-dev and - for ease of access, we are including an basic install script for macOS/Linux and Windows.

Requirements:

Node version v8.0.0+ (to check your node version, you can type node --version - to update Node, you can use nvm and nvm install latest or your package manager (like apt-get or yum) to update. As of v1.0.5, Node v8 is strictly required. The project will throw an error if Node is below v8.

Git is also required.

MongoDB is required; more on this below. This is a requirement from v2.0.0 as we switched to Enmap with MongoDB as the provider.

npm manages the packages we need, which are found in package.json and are always kept up-to-date. This project uses discord.js v12.0-dev and requires >=Node v8.x or Node v9.x – built with npm version 5.6.0.


Install

macOS/Linux: Installer Script

wget -qO- https://raw.githubusercontent.com/shikhir-arora/karma-simple/master/installer.sh | bash

You may need to run this with sudo depending on your permissions! (it is likely depending on how your configuration and setups are) In that case, you should add sudo in front of the wget and before the bash otherwise the sudo action will only be applied to the download of the installer.sh file itself.

We will have super seamless update scripts - in-fact if you use the installer all one needs to do to update is git pull and we will have a way for the Botowner to do that in Discord shortly!

You will need a MongoDB URL setup. This in for Enmap. More on this below.

Windows: Installer

While we are on the npm directory and the bot can indeed can be installed via. npm in a single-pass: npm install karma-simple - which manages everything, you must be aware of where it installs, as all users need to configure config.json which links in the project. Our install-script makes sure this folder structure is kept intact by installing to a temporary directory and deleting it after.

The manual instructions below are quite straightforward.

Standard manual instructions below:


git clone --recursive --depth 1 https://github.com/shikhir-arora/karma-simple.git 

Enmap w/ MongoDB Configuration

As of v2.0.0, KarmaBot no longer uses node-localStorage to store Karma. Instead, we switched to Enmap with MongoDB as a provider enmap-mongo. This allows us to add much more capability when wanted/needed, is faster and cleaner and uses a persistent enhanced-map data structure.

You will need to either setup MongoDB or use a service like Atlas which provides a basic, free plan. This doesn’t need much resources at all, so almost any installation will work.

I’m not going to post a detailed guide on MongoDB installation as they exist out there and getting it setup isn’t too difficult. Once you have set up MongoDB, you’ll simply need to edit the following in karma.js:


client.karmaStore = new Enmap({ provider: new EnmapMongo({
  name: `karmaStore`,
  dbName: `enmap`,
  url: 'mongodb+srv://karma:[email protected]/enmap'
})
})

This can be found at the top of the karma.js file. Don’t change anything but the URL! MongoDB URL formats are usually in the form: mongodb://user:[email protected]:PORT/name and we’ll call ours enmap – in our example (no, it’s not a working database), we’re using a Google Compute Cluster with Atlas, and that uses the newer drivers and supports DNS seedlisting. So, our URL looks a little different. In either case, you should simply edit the URL. Save this.

That’s the only switch on the user end for Enmap/Mongo! Everything else is handled in the code.

Please don’t hesitate to contact me (.vlexar#0001) on Discord if you need assistance with Mongo.

Configuration (for all users!)

You must edit the config.json.example file. Insert your bot token and change the prefix if you wish to.

Save the file as config.json when complete. This can be before or after the installer script.

Admin Configuration and Eval Command (for the owner of the bot!)

Administrators should pay attention to the following parameters in the config.json file:

Admin Console (Exec) Command

Note To Selfhosters (API Tokens)

Getting a Bot Token and Invite Link

If you have done this before, then this should be pretty straightforward. If not, go visit https://discordapp.com/developers/applications/me/create to create an application. Name the application with something you want to name it and save it - then choose “generate a Bot user” afterwords and generate the token, client ID, etc.

If you plan to give your bot to other servers, check the “Public Bot” when generating it, so others can use your invite link. Otherwise, it will only work if (you) - the person who created the bot token - invites the bot.

Save your client ID and token. They are different things! :-)

There are better guides out there, but most who would use this kind of tool likely are fine with getting this part finished. But, here is a good guide from jagrosh - this page applies for getting a token and client ID

Once you do get the client ID and token, for the invite link, if you wish I have populated a pre-made form: https://discordapi.com/permissions.html#201673792 in which you can enter your bot client ID in and it will generate the proper invite link with permissions and the bot will be assigned a role that is the name of your Bot application upon joining the server (so if you call the bot KarmaBot, it will get a role called KarmaBot with the right permissions - if that link is used)

Run

Ensure you are in the karma-simple directory!

pm2 - Strongly Recommended

pm2 can be found here: https://github.com/Unitech/pm2

You can read their quick install instructions, it takes just a minute. Please make sure you run pm2 update if you have pm2 but haven’t updated in a while. It is seamless.

Once installed, instead of using node karma.js we go/cd into our same karma-simple directory and can run:

pm2 start karma.js --name "somename" where you can edit somename to call your application.

RUNNING AS SYSTEMD Once we did all this with pm2, we can have it so it will restart on things like server reboots. For Linux, systemd manages the startup tasks. Once we started the bot, we can simply run pm2 startup systemd which will take your pm2 projects and run them in the systemd for autostartup on harder reboots.

pm2 unstartup [platform]                    disable and clear auto startup    
pm2 startup [platform]                      setup script for pm2 at boot   

where [platform]=systemd,upstart,launchd,rcd   # one of these, with most Linux it is just systemd

(this step was optional re: systemd, but it is a good step to take and only is a few seconds to enable as pm2 will automate the config)


Usage

Add/Subtract Karma

This is a simple Discord karma app. Simply put, to add karma, append any keyword (user ID, name, or anything, even emotes) with a ++

To subtract, append the keyword with --

Only the last two ++ or -- count, so doing keyword+++++++++ or @user--------+++---- will result in keyword gaining one regular karma and @user losing one in this example. That is, the messages are cleaned before counting.

So, assuming the prefix is >k here, one can simply type:

user123++ (will add (+1) Karma to user123) or user123-- (will subtract (-1) Karma to user123) and the bot will display the following in a random color embed:

[KARMA] user123 has X Karma! To lookup later use >k and type >k user123

(where X can be positive or negative Karma count)

You can also add karma for an emoticon, :emoticonname: ++/-- if you wish; this will work as well and is stored correctly. Can be useful for specific emoticons (such as custom ones in your server)

NOTE: Because of this, if you add a user’s karma with @username vs. username, it will be two different keywords to the karma counter. That is intended. It is not limited for users. Karma can be awarded to anyone, or any keyword, or even an emoji :-)

Lookup Karma

You can lookup karma by simply typing the following:

{PREFIX} {KEYWORD} where PREFIX is setup in config.json for example, >k will set the prefix to >k and keyword is simply the lookup term.

Example: >k string in the above example would return:

@user, string has X Karma!

Ratelimiting

Blacklist / Misc.

Support

You can reach me .vlexar#0001 (User ID: 243902693666455553) pretty easily on my Discord server: https://discord.io/ec or feel free to always open a GitHub issue: https://github.com/shikhir-arora/karma-simple/issues or open an issue/pull-request if need be.

For users of the public KarmaBot - typing @KarmaBot help will bring up a quick and easy help menu with support/invite links and basic usage info, commands, blacklist info, etc.

Direct invite link for the public bot: https://bot.discord.io/karmabot


License

This project is under The Unlicense and we give full freedom to anyone who wishes to use this little bot! You are not obligated to link back to this repo in any way.

Discord Bots