Package: karmabot
PyBites Karmabot - A Python based Slack ChatbotA Python based Slack Chatbot for Community interactionFeaturesKarmabot's main features is the management of Karma within the slack community server. You can give karma, reduce karma, check your current karma points and manage your karma related username.Demo Youtube VideoAdditional commands / features are:Jokes powered byPyJokesOverview on top channels of the slack serverRandom Python tip, quote or nugget from CodeChalleng.esBrowse and search python documentation, "pydoc help"Installationpip install karmabotBasic UsageAfter installing you can start karmabot by using the commandkarmabotHowever, you need to some setup and supply some settings prior to this.SetupFor app creation and tokens please follow theslack-bolt guideand enablesocket mode.SettingsBy default we will look for a.karmabotfile in the directory you used thekarmabotcommand. The file should supply the following information.# Slack bot app
KARMABOT_SLACK_BOT_TOKEN=
KARMABOT_SLACK_APP_TOKEN=

# Workspace
KARMABOT_SLACK_USER=
KARMABOT_GENERAL_CHANNEL=
KARMABOT_ADMINS=

# Backend
KARMABOT_DATABASE_URL=

# Testing
KARMABOT_TEST_MODE=KARMABOT_SLACK_BOT_TOKEN
:   TheSLACK_BOT_TOKENfor your bot. You will find it underOAuth & Permission 🠊 Bot User OAuth Access Tokenin yourapp. The token starts withxoxb-.KARMABOT_SLACK_APP_TOKEN
: The SLACK_APP_TOKEN used for running the bot inSocket Mode. You will find it underBasic Information 🠊 App-Level Tokensin yourapp.
The token starts withxapp-.KARMABOT_SLACK_USER
: The bot's user id. Initially, you can fill in a placeholder. Once you've run your own Karmabot for the first time, you can ask it as admin in private chat via@Karmabot your_id. This will return a value starting withU, e.g.,U0123XYZ. Replace your placeholder with this value.KARMABOT_GENERAL_CHANNEL
: The channel id of your main channel in slack. Initially, you can fill in a placeholder. Once you've run your own Karmabot for the first time, you can ask it as admin in private chat via@Karmabot general_channel_id. This will return a value starting withC, e.g.,C0123XYZ. Replace your placeholder with this value.KARMABOT_ADMINS
: Theslack user idsof the users that should have admin command access separated by commas.KARMABOT_DATABASE_URL
: The database url which should be compatible with SqlAlchemy. For the provided docker file usepostgresql://user42:pw42@localhost:5432/karmabot.
:heavy_exclamation_mark: To start the provided Docker-based Postgres server, be sure you have Docker Composeinstalledand rundocker-compose up -dfrom the karmabot directory.KARMABOT_TEST_MODE=
: Determines if the code is run in test mode. UserKARMABOT_TEST_MODE=trueto enable testing mode. Everything else will default tofalse. This setting has to be provided astrue, if you want run tests without a validKARMABOT_SLACK_BOT_TOKEN. Otherwise, you will receive an exceptions withslack_bolt.error.BoltError: token is invalid ....If you do not want to use a file you have to provide environment variables with the above names. If no file is present we default to environment variables.PermissionsGo to yourslack appand click onAdd features and functionality. Then go into the following categories and set permissions.Event SubscriptionsEnable Events 🠊 Toggle the slider to onSubscribe to bot events 🠊 Add via theAdd Bot User Eventbuttonteam_joinchannel_createmessage.channelsmessage.groupsmessage.imPermissionsScopes 🠊 Add the following permissions via theAdd an OAuth Scopebuttonapp_mentions:readchannels:historychannels:joinchannels:readchat:writegroups:historygroups:readgroups:writeim:historyim:readim:writeusers.profile:readusers:readDevelopment pattern for contributorsWe usepoetryandpyproject.tomlfor managing packages, dependencies and some settings.Setup virtual environment for developmentYou should follow theinstructionsto get poetry up and running for your system. We recommend to use a UNIX-based development system (Linux, Mac, WSL). After setting up poetry you can usepoetry installwithin the project folder to install all dependencies.The poetry virtual environment should be available in the the project folder as.venvfolder as specified inpoetry.toml. This helps with.venvdetection in IDEs.Conda usersIf you use the Anaconda Python distribution (strongly recommended for Windows users) andconda createfor your virtual environments, then you will not be able to use the.venvenvironment created by poetry because it is not a conda environment. If you want to usepoetrydisable poetry's behavior of creating a new virtual environment with the following command:poetry config virtualenvs.create false. You can add--localif you don't want to change this setting globally but only for the current project. See thepoetry configuration docsfor more details.Now, when you runpoetry install, poetry will install all dependencies to your conda environment. You can verify this by runningpip freezeafterpoetry install.Testing and lintingFor testing you need to installnoxseparately from the project venv created by poetry. For testing just use thenoxcommand within the project folder. You can run all the nox sessions separately if need, e.g.,only lintingnox -rs lintonly testingnox -rs testsIfnoxcannot be found, usepython -m noxinstead.For different sessions see thenox.pyfile. You can runnox --listto see a list of all available sessions.If you want to run tests locally viapytestyou have to provide a valid.karmabotsettings file or the respective enviroment variables.Please make sure all tests and checks pass before opening pull requests!Using nox under Windows and Linux (WSL)Make sure to delete the.noxfolder when you switch from Windows to WSL and vice versa, because the environments are not compatible.pre-commitTo ensure consistency you can use pre-commit.pip install pre-commitand after cloning the karmabot repo runpre-commit installwithin the project folder.This will enable pre-commit hooks for checking before every commit.