shikhir-arora / karma-simple

A simple, lightweight and functional Discord Karma tracking bot for guild members.
https://karmabot.vlexar.pw
Creative Commons Zero v1.0 Universal
12 stars 9 forks source link
bot discord discord-bot discord-js discordapp discordjs ec exclserver execsrvr hacktoberfest karma karmabot points vlexar

PRs Welcome Discord Discord Bots Downloads Discord Bots

Known Vulnerabilities Build Status CII Best Practices Language grade: JavaScript

Scrutinizer Code Quality npm-build StandardJS Codacy Badge

GitHub issues GitHub license

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).

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, but the "manual" install workflow is still the recommended way.

Requirements:

Node version v12+ (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. Because we like to stay up-to-date with things, Node v12 is required with the latest always being ideal in production. The project will throw an error if Node is below v12

Git is also required.

MongoDB or any Enmap-capable v3.x.x database is required; more on this below. This is a requirement from v2.0.1 as we switched to Enmap with MongoDB as the provider. Feel free to bug me about this if you need help: .vlexar#0001 on Discord. As of version 3.0.0, karma-simple uses the latest Enmap version, which ships with sqlite as a required database provider. Therefore, you do not need to configure an external provider.

npm or yarn (the lockfiles are kept in-sync on the git repo on every push) 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.0-dev: discord.js master branch -- and we require >=Node v12.x -- we also safely assume you know how to install Node on your system. 👍


Install

macOS/Linux: Installer Script (though the "manual" way is still recommended below)

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. No longer needed as of 3.0.0 - see below for more

Windows: Installer

- You will need a MongoDB URL setup. This in for Enmap. More on this below. No longer needed as of 3.0.0

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. Also, I can't guarantee npm will always be up-to-date as I don't push to npm unless there's some major release. It was put there a loooong time ago. 🙃

The manual instructions below are quite straightforward.

Standard manual instructions below:


git clone --recursive --depth 1 https://github.com/shikhir-arora/karma-simple.git
git clone --recursive --depth 1 https://github.com/shikhir-arora/karma-simple.git
cd karma-simple && mkdir karmaStore # we make this directory for Enmap's database (sqlite) contents'.
export npm_config_build_from_source=true
npm install # or yarn install, if using yarn

Continue below as normal to edit config.json

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. You can use Mongo or any of the Enmap-capable 3.x providers. It's just a few lines of switching code; please contact me if you need help with this. The change 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 another database supported by Enmap 3.x persistence) or simply use a service like Atlas which provides a basic, free tier that works fine for this project if you're not hosting thousands of servers. This doesn't need much resources at all, so almost any installation will work.

I'm not going to post a detailed guide on databases or 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:

// ENMAP PROVIDERS ARE DISCONTINUED IN KARMA-SIMPLE v3.0.0 -- NOT NEEDED AS OF BOT VERSION 3.0.0.

client.karmaStore = new Enmap({ provider: new EnmapMongo({
  name: `karmaStore`,
  dbName: `enmap`,
  url: 'mongodb+srv://karma:lexmark1@cluster0-g085d.gcp.mongodb.net/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:password@IP: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.

The above ^ is no longer needed as of version 3.0.0, karma-simple uses the latest Enmap version, which ships with sqlite as a required database provider. Therefore, you do not need to configure an external provider.

Configuration (for all users!)

You must edit the config.json file.

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:

Again, contact me on Discord if you need help with this!

Admin Console (Exec) Command

Note To Selfhosters (API Tokens)

This can be safely ignored by selfhosters.

nit: ^ it's actually not exactly like this anymore but I'm too lazy to update these docs for axios - if you care, please contact me!

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/ to create an application - click the ("New Application") button on the top right of the page. 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, have installed the packages with npm, yarn, or the installer script, and have configured config.json with the proper values for your instance.

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 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: invite 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 freely distributed under The Creative Commons CC0 1.0 Universal 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. This is a stronger worded, arguably more open than The Unlicense and this project has no restrictions (and no liability from myself) - this has not changed.

Discord Bots