Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6f547f9
Reorganizar los ficheros y ajustar los import
misanram Apr 18, 2026
b15e463
Ajustar los import de los test
misanram Apr 18, 2026
e504a0b
Ajustar .gitignore
misanram Apr 18, 2026
413d3e6
Actualizar .travis.yml
misanram Apr 18, 2026
50fdfb1
Rehacer y actualizar pyproject.toml
misanram Apr 18, 2026
2ce109f
Actualizar README.md
misanram Apr 18, 2026
3058685
Se crea la funcion main en bot.py para arrancar el bot.
misanram Apr 18, 2026
36b8486
Mínimos ajustes en el README.md
misanram Apr 18, 2026
635a9a7
Corrección en constate REPLIES para c++
misanram Apr 18, 2026
c9963d7
Corrección en README.md
misanram Apr 19, 2026
94d57ef
Se crea fichero __init__.py para módulo pydeckard
misanram Apr 19, 2026
8a81576
Corrección en README.md
misanram Apr 19, 2026
edd8b65
Se añade la opción setup a bot.py, y se crean las funciones setup_bot…
misanram Apr 19, 2026
27bc70d
Se documento el proceso de setup en README.md
misanram Apr 19, 2026
9804bfe
Se documento el proceso de setup en README.md
misanram Apr 19, 2026
d84c64e
Se elimina el logueo en archivo y la opción verbose,
misanram Apr 19, 2026
42e47b8
Se crean los test para las nuevas funciones. Se completa la documenta…
misanram Apr 19, 2026
41825ab
Corrección de errores en util.py y en README.md
misanram Apr 19, 2026
4d0fc9d
Mínimos cambios enla función setup_bot de utils.py
misanram Apr 19, 2026
4aeacbe
Mínimos ajuste en la función get_options de bot.py
misanram Apr 19, 2026
4b0540d
Se cambia el nombre del Entry Point y del logger a pydeckard. Se docu…
misanram Apr 19, 2026
d453741
Se cambia la función setup_bot en utils para usar pydeckard como ejec…
misanram Apr 19, 2026
988c042
Corrección en nombre de clave "BOT_VERBOSITY" en setup_bot.
misanram Apr 19, 2026
67a19c8
Mejorando documentación en README.md
misanram Apr 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
*.pyc
pycache
myconfig.py
virtualenv
.idea
.vscode
.DS_Store
.atico/
.env
.pytest_cache
.python-version
bot.log
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
dist: bionic
language: python
python:
- 3.6
- 3.7
- "3.9"
- "3.10"
- "3.11"
- "3.12"
install:
- pip install pipenv
- pipenv install -d
Expand Down
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,47 @@ Telegram Bot made in Python to automate different tasks of [Python Canarias](htt

## Installation

Create a virtualenv for Python3 and install dependencies. In this
example we are using pyenv:
Create a virtualenv for Python3 and install bot.

~~~console
$ pyenv virtualenv 3.12.4 pydeckard
$ pyenv activate pydeckard
$ pip install -r requirements.txt
$ python3 -m venv /path/to/new/virtual/environment
$ cd /path/to/new/virtual/environment
$ source ./bin/activate
$ ./bin/pip3 install git+https://github.com/pythoncanarias/pydeckard.git
~~~

A developer needs to install a few more packages:
As a developer, you must install it in this other way:

~~~console
$ pip install -r dev-requirements.txt
$ git clone https://github.com/pythoncanarias/pydeckard.git
$ cd pydeckard
$ python3 -m venv venv
$ source ./venv/bin/activate
$ pip3 install -e .[dev]
~~~

Next step is to set your bot token for development:
After installation, the next step is to create the .env configuration file and the file for automatic program
startup.
During the process, you will be asked to enter your Telegram token and will be prompted with other
configuration-related questions. The only required item is the Telegram token.
To do this, activate the virtual environment and run:

~~~console
$ echo 'TELEGRAM_BOT_TOKEN = "<token of your dev bot>"' > .env
$ pydeckard --setup
~~~

Now you can launch the bot with:
You can now launch the bot, activating the virtual environment and running::

~~~console
$ python bot.py
$ pydeckard
~~~

You can use the flag `--verbose` (or `-v') to get more information in rhe console:
...or delegate the startup of the application to your operating system using the instructions that setup has provided.

You can view the bot log using:

~~~console
$ python bot.py --verbose
$ journalctl -u pydeckard.service -f
~~~


Expand All @@ -48,5 +58,5 @@ $ python bot.py --verbose
Use pytest:

~~~console
$ python -m pytest
$ python3 -m pytest
~~~
11 changes: 0 additions & 11 deletions fabfile.py

This file was deleted.

11 changes: 0 additions & 11 deletions pydeckard.service

This file was deleted.

Empty file added pydeckard/__init__.py
Empty file.
32 changes: 18 additions & 14 deletions bot.py → pydeckard/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,36 @@
from telegram.ext import ApplicationBuilder, filters, MessageHandler, CommandHandler, ContextTypes
from telegram.constants import ParseMode

import config
import utils
from pydeckard import config
from pydeckard import utils


class DeckardBot():

def __init__(self):
self.get_options()
self.set_logger()
self.verbose = False
self.started_at = DateTime.now()

def get_options(self):
parser = argparse.ArgumentParser(
prog='bot',
description='PyDeckard Bot',
epilog='Text at the bottom of help',
epilog='',
)
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('--setup', action='store_true', help='Start the setup wizard')
args = parser.parse_args()
self.verbose = args.verbose
if args.setup:
utils.setup_bot()

def set_logger(self):
self.logger = logging.getLogger('bot')

file_handler = RotatingFileHandler('bot.log', maxBytes=1_000_000, backupCount=5)
console_handler = logging.NullHandler()
if self.verbose:
console_handler = logging.StreamHandler()
self.logger = logging.getLogger('pydeckard')

console_handler = logging.StreamHandler()
logging.basicConfig(
level=logging.WARNING, # Pone el nivel de todos los logger a WARNING
format='%(asctime)s [%(name)s] %(levelname)s: %(message)s',
handlers=[file_handler,console_handler],
handlers=[console_handler],
force=True
)

Expand Down Expand Up @@ -188,6 +184,14 @@ def run(self):
application.run_polling(poll_interval=config.POLL_INTERVAL)


if __name__ == "__main__":
def main():
"""
Arranca el bot
"""

bot = DeckardBot()
bot.run()


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion config.py → pydeckard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def bot_replies_enabled() -> bool:
("elixir",): "BIBA ELICSÍR!! ¥",
("cobol",): "BIBA KOBOL!! 💾",
("fortran",): "BIBA FORRRTRÁN!! √",
("c\+\+",): "BIBA CEMASMÁS!! ⊕",
("c++",): "BIBA CEMASMÁS!! ⊕",
("javascript",): "BIBA JABAESCRIP!! 🔮",
("php",): "BIBA PEACHEPÉ!.! ⛱",
("perl",): "BIBA PERRRRRL! 🐫",
Expand Down
Loading
Loading