Added decorator tests; fixed README typo
parent
d1dc46c17b
commit
beb5bf49cc
|
@ -1,6 +1,5 @@
|
|||
# Changelog
|
||||
## v0.1 (2020/08/26)
|
||||
|
||||
## 0.1 (2020/08/26)
|
||||
### Added
|
||||
- Prefix can now be passed as argument to init
|
||||
- Pre-made help module
|
||||
|
|
22
README.md
22
README.md
|
@ -36,7 +36,7 @@ This first part shows the three important variables in any module.
|
|||
With fr being the default prefix for Frank (can be overwritten). As you define more modules, they should all have a
|
||||
unique prefix. This is how Frank's modular system works, and any modules added to the list will automatically be
|
||||
picked up by Frank. The PREFIX value can also be list, allowing for multiple prefixes: for example a long,
|
||||
description one, and a short, easy to type one (e.g. minecraft and mc).
|
||||
descriptive one, and a short, easy to type one (e.g. minecraft and mc).
|
||||
|
||||
```python
|
||||
def pre_start(self):
|
||||
|
@ -60,7 +60,7 @@ Frank.
|
|||
pass
|
||||
|
||||
@frank.default()
|
||||
async def default_cmd(self):
|
||||
async def default_cmd(self, author, channel, mid):
|
||||
# do some default action
|
||||
pass
|
||||
```
|
||||
|
@ -73,12 +73,24 @@ These three decorators are the bread and butter of Frank. Let's break them down:
|
|||
fr examp command [ARGS]
|
||||
```
|
||||
This is how you can define as many Discord commands as you want, without needing to know how to parse the messages
|
||||
etc. Each command gets the `author`, `channel`, and `id` of the message. The `cmd` variable contains all the arguments passed
|
||||
to the command.
|
||||
etc. Each command gets the `author`, `channel`, and `id` of the message. The `cmd` variable contains all the
|
||||
arguments passed to the command.
|
||||
- `frank.daemon` defines a daemon, a process that should run in the background for as long as the bot is active. It
|
||||
should contain a while loop and preferably a sleep function using `asyncio.sleep()` (there are plans to improve this
|
||||
behavior). Because a daemon is just a method of the module class, it has access to all class variables, including
|
||||
those defined in `pre_start`.
|
||||
- `frank.default` defines the command that should be run if the module is called without explicitely giving a command.
|
||||
- `frank.default` defines the command that should be run if the module is called without explicitly giving a command.
|
||||
For example, if you call `fr examp` without specifying a command, it will run the default command. This is useful for
|
||||
making a command that's used very often easier to execute.
|
||||
|
||||
In the end, all you need to do is add the following in your main script:
|
||||
|
||||
```python
|
||||
from frank import Frank
|
||||
# Or whatever your package containing your modules is called
|
||||
from modules import ExampleMod
|
||||
|
||||
if __name__ == '__main__':
|
||||
client = Frank([ExampleMod])
|
||||
client.run(YOUR_DISCORD_TOKEN)
|
||||
```
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
# =====IMPORTS=====
|
||||
# Own imports
|
||||
from frank import default, command, daemon
|
||||
|
||||
|
||||
class TestDecorators:
|
||||
"""
|
||||
This test makes sure the decorated functions return the same result as
|
||||
their non-decorated counterparts
|
||||
"""
|
||||
|
||||
def default_no_dec(self):
|
||||
return 'default'
|
||||
|
||||
@default()
|
||||
def default_dec(self):
|
||||
return self.default_no_dec()
|
||||
|
||||
def command_no_dec(self):
|
||||
return 'command'
|
||||
|
||||
@command('cmd')
|
||||
def command_dec(self):
|
||||
return self.command_no_dec()
|
||||
|
||||
def daemon_no_dec(self):
|
||||
return 'daemon'
|
||||
|
||||
@daemon()
|
||||
def daemon_dec(self):
|
||||
return self.daemon_no_dec()
|
||||
|
||||
def test_default(self):
|
||||
assert self.default_no_dec() == self.default_dec()
|
||||
|
||||
def test_command(self):
|
||||
assert self.command_no_dec() == self.command_dec()
|
||||
|
||||
def test_daemon(self):
|
||||
assert self.daemon_no_dec() == self.daemon_dec()
|
Reference in New Issue