Lemming
Discord bot, for custom needs., (*1)
Features
Coming soon
- Gif provider - This has been specked out, planned and is being implemented.
- Daddy Jokes filter - This has been specked out, planned and is being implemented.
On our mind
- Reminders
- Self upgrade
- Jokes provider
- Wikipedia provider
- In depth configuration
Installation
This application is developed in PHP. Not the proudest moment of our lives, but why not?, (*2)
Going with trends, we're using composer
, to manage our dependencies, scripts and configuration., (*3)
In order to install the application and be able to use it, you will require few things:, (*4)
If you meet the requirements above, you're almost done!, (*5)
First, you may want to clone this repository., (*6)
git clone --depth=1 git@github.com:1337m/lemming.git
Note, we've added an extra parameter --depth=1
, which is totally optional. It simply tells github
:
Yeah, I want that! But I dont't really care for the history of this software... Just get me what I want.
, (*7)
Once you succeed to clone the repository, you may enter the directory. Typically, it would be:, (*8)
cd lemming
Inside the directory, you may find a lot of useless stuff.
You probably don't need to know what's going on in here...
However, if you do, you're awesome and be sure, to visit the Contributing section of this README
file., (*9)
You will need, to give the bot some information, so it knows how to human. Pretend at least., (*10)
The application, expects you to store your information in the .env
file. It's the easiest solution,
to have a desired setup on different environments., (*11)
Our .env
file, looks like this:, (*12)
DISCORD_API_TOKEN="TOP_SECRET_API_TOKEN"
LANG="en_US.utf-8"
Most important are:, (*13)
-
DISCORD_API_TOKEN
- Refer to the application, you created on Discord.
Once you have configured the environment variables to meet your needs, install the dependencies with composer., (*14)
composer install
We're done now. That was easy, right?, (*15)
Why don't you go ahead and run the application?, (*16)
composer run
TL;DR
Lazy? You... I like you. Here:, (*17)
git clone --depth=1 git@github.com:1337m/lemming.git
cd lemming
touch .env
echo 'DISCORD_API_TOKEN="TOP_SECRET_API_TOKEN"' >> .env # Make sure to use a real token...
echo 'LANG="en_US.utf-8"' >> .env
composer install
composer run
Commands
This list, shall grow in time..., (*18)
!hello - This greet the bot.
!help - This will generate the list of commands.
!gif [set of key words] - This will look for any GIF maches and post int on to the channel.
Testing
We love TDD. Testing is love. We use this great php tool, called phpunit
to configure our tests., (*19)
These are mostly ready, so you can have a look at running the command below:, (*20)
composer test
Contributing
You're amazing. We like amazing. The idea of Open Source, is to make things better, by using different/fresh
set of eyes. If you:, (*21)
- found a bug which you know how to fix
- found a spelling mistake
- are urged to add new translation or a new feature
- want to fix a previously reported issue
Please, feel free to do so! But to make everybody's life easier, we'd like you to follow some path., (*22)
-
Create/Comment an issue - Would be nice, to know what's going on.
Perhaps, it'd help by stopping one of us to work on the same issue?, (*23)
-
Fork out - Make your own copy of the repository. You may not necessarily have a write permission for this one..., (*24)
-
Run the tests before you start coding! - Make sure, it wasn't you, who broke something in the code.
Run the tests, if everything is in order, continue., (*25)
-
Make your own tests - It's a good idea, to follow TDD pattern. Write a test, make sure it fails, then fix the
code to make the test success. Either way, Make some tests :D, (*26)
-
Be amazing. Be great. Be yourself. Be a developer. - Code your way to the top., (*27)
-
Create a Pull Request
- We'll make sure, to review your code. Give you feedback,
ask questions or discuss solutions. Don't be offended! Feel privileged. We're all here to learn.
We may learn something from you, which we hope for, and you may learn something from us,
which would make us very happy. Feel free, to disagree with something, but try to reason the disagreement., (*28)
-
Have a cookie! - Every work deserves a reward. Although, we'd love to give you cookie,
you may need to sort this on your own. Internet is great, but it has some limitations., (*29)
Plugins
Lemming has a nice and easy support for plugins, using composer!, (*30)
Installing plugins
Well, it's very simple! For the sake of documentation, I'll be referencing one of our official plugins
Lemming Giphy., (*31)
By default, the installation is only one command! Check it out:, (*32)
composer require 1337m/lemming-giphy
The plugin should be installed in it's latest version. Now it's time to reference it!
You should be having a config/commands.php
file. Open it up, and somewhere in the middle of an array,
add new key (command to be recorded) and array of options including required action.
After all, it should look something like this:, (*33)
<?php
return [
'gif' => [
'action' => Lemming\Giphy\Command::class,
'aliases' => ['giphy', 'moving-picture'],
'description' => 'Search the big database, of GIFs, and return the matching result.',
'usage' => '/gif [phrase]',
],
];
Sometimes, the plugin developers may give you instructions on how to do so. These are amazing developers.
The plugin above, has a nice README
file associated, explaining the steps you may need to take,
in order to make the plugin work. Be sure to check it out!, (*34)
Developing plugins
If you know at least basics of PHP, you know how to write plugin for Lemming...
- Start off with initialising composer package! Be sure to add description and some keywords.
- Use PSR-4
, for easier integration.
- Write tests! We all love tests. So should you.
- Publish your plugin on both GitHub and Packagist. Make it available to everyone!, (*35)
We have created a little abstract class, you may need to use., (*36)
Here, have a nice starting point for your app:, (*37)
<?php
namespace MyAwesomePlugin;
use Lemming\Command\Base;
class MyAwesomeCommand extends Base
{
public function fire()
{
return 'AWESOME!';
}
}
Now if you reference this, in your bot:, (*38)
<?php
return [
'awesome' => [
'action' => MyAwesomePlugin\MyAwesomeCommand::class,
],
];
you will be able, to write /awesome
in the chat and expect the bot to reply!, (*39)
Bit of technicality:, (*40)
Base
class, provides both $message
and $params
variables., (*41)
-
$message
is Discord-PHP
implementation of Message
class.
-
$params
is an array, containing any extra parameters passed with the command.
The above class, could look like this:, (*42)
<?php
namespace MyAwesomePlugin;
use Lemming\Command\Base;
class RandomCommand extends Base
{
public function fire()
{
if (empty($this->params)) {
return 'Nothing to pick from...';
}
shuffle($this->params);
return $this->message->channel->sendMessage('Personally, I would go with: ' . $this->params[0]);
}
}
Reference the new command:, (*43)
<?php
return [
'random' => [
'action' => MyAwesomePlugin\RandomCommand::class,
],
];
And test out with the discord client:, (*44)
[user] /random Pizza Burger ChowMain Pierogi
[bot] Personally, I would go with: Pierogi
Licence
Lemming is open-sourced software licensed under the MIT license., (*45)