diff --git a/.gitignore b/.gitignore index 738e240..b024370 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,8 @@ __pycache__ .env error_* *.log +test.py +*.pyc +.pytest_cache +.coverage +tmp \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9bcd9a8 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +[![Total alerts](https://img.shields.io/lgtm/alerts/g/Klemek/miniscord.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Klemek/miniscord/alerts/) +[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Klemek/miniscord.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Klemek/miniscord/context:python) +[![Coverage Status](https://coveralls.io/repos/github/Klemek/miniscord/badge.svg?branch=master)](https://coveralls.io/github/Klemek/miniscord?branch=master) + +# Miniscord +*A minimalist discord bot API* + +```python +from miniscord import Bot +import discord + + +async def hello(client: discord.client, message: discord.Message, *args: str): + await message.channel.send("Hello!") + + +bot = Bot( + "test-app", # name + "0.1-alpha", # version + alias="|" # respond to '|command' messages +) +bot.register_command( + "hello", # command text (regex) + hello, # command function + "hello: says 'Hello!'", # short help + f"```\n" # long help + f"* |help\n" + f"\tSays 'Hello!'.\n" + f"```" +) +bot.start() +# this bot respond to "|help", "|info" and "|hello" +``` + +![](./sample.jpg) + +> **⚠ Disclaimer:** I intend to use this project personally, I'm open to ideas but I don't care if it doesn't work for you. Same for the name, feel free to use it, I'm not registering it on PyPI + +## Features + +*TODO* + +## Installation + +*TODO* + +## Documentation + +*TODO* + +## Versions + +*TODO* + +## TODO + +* Finish README.md +* Write tests +* Add comments to code +* Separate branches +* Working CI +* Fix bugs \ No newline at end of file diff --git a/main.py b/main.py deleted file mode 100644 index 852955d..0000000 --- a/main.py +++ /dev/null @@ -1,8 +0,0 @@ -import logging -from bot import Bot - -logging.basicConfig(format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.INFO) - -bot = Bot("test-app", "0.1-alpha", alias="|") -bot.log_calls = True -bot.start() diff --git a/miniscord/__init__.py b/miniscord/__init__.py new file mode 100644 index 0000000..e34e5d9 --- /dev/null +++ b/miniscord/__init__.py @@ -0,0 +1 @@ +from .bot import Bot diff --git a/bot.py b/miniscord/bot.py similarity index 98% rename from bot.py rename to miniscord/bot.py index 58a0af3..6b72386 100644 --- a/bot.py +++ b/miniscord/bot.py @@ -70,7 +70,7 @@ class Bot(object): self.alias = alias # can call bot with {alias}{command_name} self.any_mention = False # bot mention can be anywhere self.log_calls = False - self.guild_logs_file = "guilds.log" + self.guild_logs_file = "../guilds.log" self.enforce_write_permission = True self.lower_command_names = True self.game_change_delay = 10 @@ -197,6 +197,7 @@ class Bot(object): f" #{message.channel} in server '{message.guild}'") return await command.compute(self.client, message, *command_args) + break async def on_guild_join(self, guild: discord.guild): if self.guild_logs_file is not None: @@ -210,7 +211,7 @@ class Bot(object): pass def register_command(self, regex: str, compute: CommandFunction, help_short: str, help_long: str): - self.__commands += [Command(regex, compute, help_short, help_long)] + self.__commands.insert(0, Command(regex, compute, help_short, help_long)) def start(self): logging.info(f"Current PID: {os.getpid()}") diff --git a/sample.jpg b/sample.jpg new file mode 100644 index 0000000..527b821 Binary files /dev/null and b/sample.jpg differ