Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test and documentation for blueprint bot #12

Merged
merged 12 commits into from
Nov 28, 2022
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repos:
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black"]
GoberInfinity marked this conversation as resolved.
Show resolved Hide resolved

- repo: https://github.com/PyCQA/flake8
rev: 5.0.3
Expand Down
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>
GoberInfinity marked this conversation as resolved.
Show resolved Hide resolved

<!-- 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.
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()
GoberInfinity marked this conversation as resolved.
Show resolved Hide resolved

@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"""
GoberInfinity marked this conversation as resolved.
Show resolved Hide resolved
return "Ready"
15 changes: 15 additions & 0 deletions otter_welcome_buddy/formatters/messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
""" General messages of the bot """


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