Skip to content

Commit

Permalink
Unit test and documentation for blueprint bot (#12)
Browse files Browse the repository at this point in the history
* Add unit test for intent registration

* Add unit testing for startup

* Add test for startup cogs

* Create unit testing for formatters

* Update constants.py

Co-Authored-By: Manuel CH <26100917+akotadi@users.noreply.github.com>

* Test precommit

* Create unit testing for formatters

* Add Readme

* Fix typo in readme

* Ignore rule to avoid unneccesary comments

* Delete unnecesary comments

* Move fixture to conftest

Co-authored-by: Manuel CH <26100917+akotadi@users.noreply.github.com>
  • Loading branch information
GoberInfinity and akotadi committed Nov 28, 2022
1 parent 18928b9 commit 4155e28
Show file tree
Hide file tree
Showing 18 changed files with 356 additions and 69 deletions.
125 changes: 124 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,124 @@
#Otter Welcome Buddy
<a name="readme-top"></a>

<!-- PROJECT LOGO -->
<br />
<div align="center">
<img src="images/nutria_logo.png">
<h2 align="center">Otter ... Welcome Buddy</h2>
<p align="center">
Bot to help the management of Proyecto Nutria's discord
<br />
<a href="https://github.com/Proyecto-Nutria/otter-welcome-buddy/issues">Report Bug</a>
</p>
<br />
</div>


<!-- TABLE OF CONTENTS -->
<details>
<summary>Table of Contents</summary>
<ol>
<li>
<a href="#about-the-project">About The Project</a>
</li>
<li>
<a href="#getting-started">Getting Started</a>
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#installation">Installation</a></li>
</ul>
</li>
<li><a href="#usage">Usage</a></li>
<li><a href="#roadmap">Roadmap</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#acknowledgments">Acknowledgments</a></li>
</ol>
</details>


<!-- ABOUT THE PROJECT -->
## About The Project

Otter Welcome Buddy has the intention of leverage human interaction with the persons in the discord to help them navigate trough all of our resources.
<p align="right">(<a href="#readme-top">back to top</a>)</p>


<!-- GETTING STARTED -->
## Getting Started

### Prerequisites

You need to install all the prerequisites before following with the instalation **except Tox**.

1. [Precommit](https://pre-commit.com/#installation)
1. [Poetry](https://python-poetry.org/)
1. [Tox](https://tox.wiki/en/latest/)
1. [Docker](https://docs.docker.com/get-docker/)

### Installation
1. Install our precommits configuration
```sh
pre-commit install
```
1. Install all the dependencies for python
```sh
poetry install
```
1. Install tox inside poetry's env
```sh
poetry shell # activate poetry env
pip install tox
```
<p align="right">(<a href="#readme-top">back to top</a>)</p>


<!-- USAGE EXAMPLES -->
## Usage

1. Activate your virtual environment
```sh
poetry shell
```
1. Run the bot using:
```sh
poetry run python otter_welcome_buddy
```
1. If you would like to run the build locally:
```sh
tox
```

<!-- ROADMAP -->
## Roadmap

- [ ] Link the repository to our project dashboard
- [ ] Add deepsource
- [ ] Add vale
- [ ] Enable logging

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- CONTRIBUTING -->
## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/amazing-feature`)
5. Open a Pull Request

<p align="right">(<a href="#readme-top">back to top</a>)</p>


<!-- ACKNOWLEDGMENTS -->
## Acknowledgments

This README was possible thanks to [Best-README](https://github.com/othneildrew/Best-README-Template)


<p align="right">(<a href="#readme-top">back to top</a>)</p>
Binary file added images/nutria_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions otter_welcome_buddy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Principal function to be called by Docker
"""

import asyncio
import os

Expand All @@ -11,7 +7,8 @@


async def main() -> None:
"""Orchestration function"""
"""Principal function to be called by Docker"""

bot: Bot = Bot(
command_prefix=COMMAND_PREFIX, intents=intents.get_registered_intents()
)
Expand Down
21 changes: 14 additions & 7 deletions otter_welcome_buddy/cogs/new_user_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,38 @@
"""
from discord.ext import commands

from otter_welcome_buddy.formatters import debug, messages


# We need to create easier test by migrating everything to protected methods
class Greetings(commands.Cog):
"""Custom message"""

def __init__(self, bot):
def __init__(self, bot, messages_dependency, debug_dependency):
self.bot = bot
self.messages_formatter = messages_dependency
self.debug_formatter = debug_dependency

def _command_message(self):
return self.messages_formatter.welcome_message()

@commands.Cog.listener()
async def on_ready(self):
"""Ready Event"""
print("We have logged in ")
print(self.debug_formatter.bot_is_ready())

@commands.Cog.listener()
async def on_member_join(self, member):
"""Send Welcome message to new member"""
print("User Joined")
await member.send("Welcome To Project Nutria")
await member.send(self.messages_formatter.welcome_message())

@commands.command()
async def hello(self, ctx, *, member=None):
"""Says hello"""
"""Sends welcome message with !hello"""
member = member or ctx.author
await ctx.send(f"Hello {member.name}... This feels familiar.")
await ctx.send(self._command_message())


async def setup(bot):
"""Required setup method"""
await bot.add_cog(Greetings(bot=bot))
await bot.add_cog(Greetings(bot, messages.Formatter, debug.Formatter))
2 changes: 1 addition & 1 deletion otter_welcome_buddy/common/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""This module defines project-level constants."""
"""Project-level constants"""

COMMAND_PREFIX = "!"
Empty file.
15 changes: 15 additions & 0 deletions otter_welcome_buddy/formatters/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
""" Formatters only for development """


class Formatter:
"""Dependency for debug messages"""

@staticmethod
def bot_is_ready():
"""It indicates when the bot is up and running"""
return "Ready"

@staticmethod
def bot_is_ready_2():
"""Place holder to avoid problems with pylint"""
return "Ready"
12 changes: 12 additions & 0 deletions otter_welcome_buddy/formatters/messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Formatter:
"""Dependency to inject messages"""

@staticmethod
def welcome_message():
"""Message when a new user joins the discord"""
return "Welcome to Proyecto Nutria"

@staticmethod
def welcome_message_2():
"""Place holder to avoid pylint rule"""
return "Welcome to Proyecto Nutria"
4 changes: 3 additions & 1 deletion otter_welcome_buddy/startup/cogs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Cogs allow to organize a collection of commands, listeners,into one class"""
from cogs import new_user_joins

from discord.ext.commands import Bot

from otter_welcome_buddy.cogs import new_user_joins


def __format_module_path_into_cog_extension(absolute_module_path: str) -> str:
"""Transforms absolute module path into <base_path>.<cog_path>.<file>"""
Expand Down
Loading

0 comments on commit 4155e28

Please sign in to comment.