Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b2967a6
Commit de prueba para crear paquete instalable desde GitHub
misanram Apr 17, 2026
733e654
Commit de prueba para crear paquete instalable desde GitHub
misanram Apr 17, 2026
8c3e90b
Corrección en README.md
misanram Apr 17, 2026
2a796c8
Corrección en pyproject.toml
misanram Apr 17, 2026
cc0e657
Corrección en pyproject.toml se añade version.
misanram Apr 17, 2026
1ece59e
Corrección en pyproject.toml se corrige license.
misanram Apr 17, 2026
471e080
Corrección en pyproject.toml se corrige requires-python.
misanram Apr 17, 2026
842eec4
Corrección en bot de importaciones internas del paquete.
misanram Apr 17, 2026
f1401d9
Corrección en bot de importaciones internas del paquete.
misanram Apr 17, 2026
43f2245
Corrección en utils de importaciones internas del paquete.
misanram Apr 17, 2026
4ed54fb
Creación del parametro setup para configurar el bot.
misanram Apr 17, 2026
9e1a385
Corrección de errores en bot.py
misanram Apr 17, 2026
c06c47c
Corrección de errores en bot.py
misanram Apr 17, 2026
cb7463e
Corrección de errores en bot.py
misanram Apr 17, 2026
4edd5cc
Moviendo el asistente de configuración a utils.py
misanram Apr 17, 2026
70b8ae8
Eliminando el argumento verbose de bot.py
misanram Apr 17, 2026
5afe475
Adaptar la función setup_bot a diferentes plataformas.
misanram Apr 17, 2026
64b7307
Manejar los unput de los items de .env como un diccionario para simpl…
misanram Apr 17, 2026
e95ee67
Cambio en la función config de config.py para que acepte items vacíos.
misanram Apr 17, 2026
b072429
Cambio en la función config de config.py para que acepte items vacíos.
misanram Apr 17, 2026
c8dede9
Cambio en la función config de config.py para que acepte items vacíos.
misanram Apr 17, 2026
37cdddd
Cambio en la función config de config.py para que acepte items vacíos.
misanram Apr 17, 2026
336bd3a
Primera versión de la función _input
misanram Apr 18, 2026
069ee33
Segunda versión de la función _input
misanram Apr 18, 2026
353f016
Tercera versión de la función _input
misanram Apr 18, 2026
d3bdadc
Cuarta versión de la función _input
misanram Apr 18, 2026
10a9888
Quinta versión de la función _input ahora se llama validate_input
misanram Apr 18, 2026
37b9926
Modificar pyproject.toml para poder instalar las paquetes dev desde c…
misanram Apr 18, 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
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TELEGRAM_BOT_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
VERBOSITY=0.33
LOG_LEVEL=WARNING
POLL_INTERVAL=3
BOT_GREETING="<b>Hi!</b> I'm a friendly, <s>crazy</s> slightly psychopath robot"
MAX_HUMAN_USERNAME_LENGTH=100
MAX_CHINESE_CHARS_PERCENT=0.15
WELCOME_DELAY=330
12 changes: 2 additions & 10 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
.env
.pytest_cache
.python-version
bot.log
.atico/
.env
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
dist: bionic
language: python
python:
- 3.6
- 3.7
python:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
install:
- pip install pipenv
- pipenv install -d
Expand Down
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ 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:
example we are using python -m venv:

~~~console
$ pyenv virtualenv 3.12.4 pydeckard
$ pyenv activate pydeckard
$ pip install -r requirements.txt
$ python -m venv pydeckard
$ cd pydeckard
$ source ./bin/activate
$ ./bin/pip install git+https://github.com/misanram/pydeckard.git@Instalar-desde-GitHub
~~~

A developer needs to install a few more packages:

~~~console
$ pip install -r dev-requirements.txt
$ ./bin/pip install git+https://github.com/misanram/pydeckard.git@Instalar-desde-GitHub[dev]
~~~

Next step is to set your bot token for development:
Expand All @@ -33,13 +34,19 @@ $ echo 'TELEGRAM_BOT_TOKEN = "<token of your dev bot>"' > .env
Now you can launch the bot with:

~~~console
$ python bot.py
$ python3 bot.py
~~~

You can use the flag `--verbose` (or `-v') to get more information in rhe console:
~~~systemd





You can use the flag `--verbose` (or `-v') to get more information in the console:

~~~console
$ python bot.py --verbose
$ python3 bot.py --verbose
~~~


Expand All @@ -48,5 +55,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.

18 changes: 18 additions & 0 deletions pydeckard.service.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=PyDeckard
After=network.target

[Service]
User=el_que_ejecute_el_bot
Group=el_que_ejecute_el_bot
Restart=always
WorkingDirectory=/ruta_al_entorno_virtual
ExecStart=/ruta_al_entorno_virtual/bin/bot
# La onfiguración del bot puede hacerse:
A) Colocando el archivo .env en el WorkingDirectory
B) Colocando el archivo .env en cualquier directorio que User pueda leer y declarandolo en
EnvironmentFile=/cualquier_directorio/.env

[Install]
WantedBy=multi-user.target
Alias=PyDeckard.service
Empty file added pydeckard/__init__.py
Empty file.
30 changes: 15 additions & 15 deletions bot.py → pydeckard/bot.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
#!/usr/bin/enb python3

from datetime import datetime as DateTime
import itertools
import argparse
import logging
import sys
import time
from logging.handlers import RotatingFileHandler

import telegram
from telegram import Update
from telegram.ext import ApplicationBuilder, filters, MessageHandler, CommandHandler, ContextTypes
from telegram.constants import ParseMode

import config
import utils

from pydeckard import utils
from pydeckard import config


class DeckardBot():

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

def get_options(self):
Expand All @@ -31,22 +29,20 @@ def get_options(self):
description='PyDeckard Bot',
epilog='Text at the bottom of help',
)
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()

console_handler = logging.StreamHandler()
logging.basicConfig(
level=logging.WARNING, # Pone el nivel de todos los logger a WARNING
level=logging.DEBUG, # 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 All @@ -57,6 +53,7 @@ def set_logger(self):
def trace(self, msg):
self.logger.info(msg)


async def command_status(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
self.trace('Received command: /status')
python_version = sys.version.split(maxsplit=1)[0]
Expand Down Expand Up @@ -188,6 +185,9 @@ def run(self):
application.run_polling(poll_interval=config.POLL_INTERVAL)


if __name__ == "__main__":
def main():
bot = DeckardBot()
bot.run()

if __name__ == "__main__":
main()
6 changes: 1 addition & 5 deletions 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!! ⊕",
(r"c\+\+",): "BIBA CEMASMÁS!! ⊕",
("javascript",): "BIBA JABAESCRIP!! 🔮",
("php",): "BIBA PEACHEPÉ!.! ⛱",
("perl",): "BIBA PERRRRRL! 🐫",
Expand All @@ -121,7 +121,3 @@ def bot_replies_enabled() -> bool:
"tiempo... como lágrimas en la lluvia. Es hora de morir. 🔫",
("python", "pitón", "piton"): THE_ZEN_OF_PYTHON,
}

MAXLEN_FOR_USERNAME_TO_TREAT_AS_HUMAN = 100

CHINESE_CHARS_MAX_PERCENT = 0.15
Loading
Loading