Skip to content

Commit

Permalink
Merge pull request #114 from LanceMaverick/getbeard
Browse files Browse the repository at this point in the history
New beard package manager! And more instructions for newbeard.py.
  • Loading branch information
LanceMaverick committed Mar 8, 2017
2 parents d61b600 + 1ef63dc commit 1d5e6b6
Show file tree
Hide file tree
Showing 26 changed files with 273 additions and 195 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Custom
beard_cache/*
*.dbbin
beards/*/config.yml
config.py
Expand Down
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,51 @@ To run skybeard define your key in the environment variable `$TG_BOT_TOKEN` or a

## Skybeard's many beards
Skybeard source documentation: http://skybeard-2.readthedocs.io/en/latest/

Skybeard wears many beards. The bot will automatically load any "beard" (a plug-in) that is placed in the beards folder. Beards are typically structured like so:

```
beards
|
|___myBeard
| __init__.py
| config.py
|___my_beard
| config.yml
| requirements.txt
| ...
| setup_beard.py
|___python
|___my_beard
| __init__.py
|
|___docs
| README
| ...
```

In this example the `myBeard` folder containts a `requirements.txt` for any additonal dependencies so they can be pipped, a `config.py` file for configuration of the beard and settings and the `__init__.py` which contains the class that that is the interface between the plug-in and skybeard.
This interface class inherits from skybeard.beards.BeardChatHandler` which handles the mounting of the plug-in, registering of commands etc, and also the `telepot.aio.helper.ChatHandler`.
This interface class inherits from `skybeard.beards.BeardChatHandler` which handles the mounting of the plug-in, registering of commands etc, and also the `telepot.aio.helper.ChatHandler`.

The folder can also contain any other python modules and files that are needed for the plugin.

## Growing a new beard
Creating a new beard requires knowledge of the **telepot** telegram API, see: http://telepot.readthedocs.io/en/latest/

An example async plug-in that would echo the user's message would look like this:
The quickest way to make a new beard is to use the utility script `utils/newbeard.py` which creates the folder structure and basic files.

```
$ utils/newbeard.py foo_beard
$ tree foo_beard
foo_beard
├── python
│   └── foo_beard
│   └── __init__.py
├── README.txt
└── setup_beard.py
2 directories, 3 files
```

The main part of the code is in `python/beard_name/__init__.py`.

An example async plug-in that would echo the user's message would look like this:


```Python
Expand Down Expand Up @@ -82,5 +101,3 @@ This plug-in will greet the user when they send "/hello" to Skybeard and will a


See the examples folder for examples of callback functionality, timers, and regex predication.


1 change: 1 addition & 0 deletions beard_cache/.do-not-remove
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is intentionally committed to git to keep the folder beard_cache in the repo.
2 changes: 2 additions & 0 deletions beard_repo/dicebeard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{description: A dice module for skybeard (telepot), git_url: 'https://github.com/nasfarley88/dicebeard.git',
name: dicebeard}
3 changes: 3 additions & 0 deletions beard_repo/githubbeard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: Browse github with telegram using skybeard-2.
git_url: https://github.com/nasfarley88/githubbeard.git
name: githubbeard
3 changes: 3 additions & 0 deletions beard_repo/letthemknowbeard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: A beard to let people know things for skybeard-2
git_url: https://github.com/nasfarley88/letthemknowbeard.git
name: letthemknowbeard
3 changes: 3 additions & 0 deletions beard_repo/listbeard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: Makes lists for skybeard-2
git_url: https://github.com/nasfarley88/listbeard.git
name: listbeard
3 changes: 3 additions & 0 deletions beard_repo/namedvotebeard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: null
git_url: https://github.com/nasfarley88/namedvotebeard.git
name: namedvotebeard
3 changes: 3 additions & 0 deletions beard_repo/pdfpreviewbeard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: pdfpreviewbeard
description: Shows a preview of the first page for any pdf sent to the chat.
git_url: https://github.com/nasfarley88/pdfpreviewbeard.git
3 changes: 3 additions & 0 deletions beard_repo/thankyoubeard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: A beard that thanks users for skybeard-2.
git_url: https://github.com/nasfarley88/thankyoubeard.git
name: thankyoubeard
3 changes: 3 additions & 0 deletions beard_repo/xkcdbeard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: null
git_url: https://github.com/nasfarley88/xkcdbeard.git
name: xkcdbeard
1 change: 0 additions & 1 deletion beards/githubbeard/config.yml.example

This file was deleted.

137 changes: 0 additions & 137 deletions beards/githubbeard/python/githubbeard/__init__.py

This file was deleted.

35 changes: 0 additions & 35 deletions beards/githubbeard/python/githubbeard/format_.py

This file was deleted.

3 changes: 0 additions & 3 deletions beards/githubbeard/requirements.txt

This file was deleted.

8 changes: 0 additions & 8 deletions beards/githubbeard/setup_beard.py

This file was deleted.

1 change: 1 addition & 0 deletions beards/repo_helper/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A beard named repo_helper for skybeard-2.
47 changes: 47 additions & 0 deletions beards/repo_helper/python/repo_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from pygithub3 import Github
import yaml

from skybeard.beards import BeardChatHandler
from skybeard.decorators import onerror
from skybeard.utils import get_args


class RepoHelper(BeardChatHandler):

__userhelp__ = """Helps make yamls for beard repository."""

__commands__ = [
("makerepoyamlfromgithub", 'make_repo_yaml',
'Makes yaml for repo based on github repo name.')
]

# __init__ is implicit

@onerror
async def make_repo_yaml(self, msg):
args = get_args(msg)
try:
repo_name = args[0]
except IndexError:
await self.sender.sendMessage(
"Please provide the full name of the repo.")
resp = await self.listener.wait()
repo_name = resp['text']

await self.sender.sendChatAction("upload_document")

gh = Github()
repo = gh.get_repo(repo_name)
data = {
"name": repo.name,
"description": repo.description,
"git_url": repo.clone_url
}

name = "{}.yml".format(data["name"])
encoded_data = yaml.dump(data,
encoding="utf-8",
default_flow_style=False)
self.logger.debug("Yaml made:\n\n{}".format(
encoded_data.decode('utf-8')))
await self.sender.sendDocument((name, encoded_data))
1 change: 1 addition & 0 deletions beards/repo_helper/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pygithub3
5 changes: 5 additions & 0 deletions beards/repo_helper/setup_beard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from skybeard.utils import setup_beard

setup_beard(
"repo_helper",
)
1 change: 1 addition & 0 deletions config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from autoloaders import Git

beard_paths = [
"beards/",
"beard_cache/",
# Beards can come from anywhere!
# os.path.expanduser("~/beards/"),
# Even from git!
Expand Down

0 comments on commit 1d5e6b6

Please sign in to comment.