1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Create dateparser command

This commit is contained in:
Steffo 2019-04-09 10:39:19 +02:00
parent 6b4f39428b
commit 094a961b51
4 changed files with 27 additions and 4 deletions

View file

@ -4,3 +4,4 @@ pytest>=4.3.1
psycopg2-binary>=2.8
aiohttp>=3.5.4
Markdown>=3.1
dateparser>=0.7.1

View file

@ -3,7 +3,8 @@ import asyncio
from royalnet.bots import TelegramBot
from royalnet.commands import PingCommand, ShipCommand, SmecdsCommand, ColorCommand, CiaoruoziCommand, SyncCommand, DiarioCommand, RageCommand
from royalnet.commands.debug_create import DebugCreateCommand
from royalnet.commands.debug_author import DebugAuthorCommand
from royalnet.commands.author import AuthorCommand
from royalnet.commands.dateparser import DateparserCommand
from royalnet.commands.error_handler import ErrorHandlerCommand
from royalnet.network import RoyalnetServer
from royalnet.database.tables import Royal, Telegram
@ -11,7 +12,7 @@ from royalnet.database.tables import Royal, Telegram
loop = asyncio.get_event_loop()
commands = [PingCommand, ShipCommand, SmecdsCommand, ColorCommand, CiaoruoziCommand, DebugCreateCommand, SyncCommand,
DebugAuthorCommand, DiarioCommand, RageCommand]
AuthorCommand, DiarioCommand, RageCommand, DateparserCommand]
master = RoyalnetServer("localhost", 1234, "sas")
tg_bot = TelegramBot(os.environ["TG_AK"], "localhost:1234", "sas", commands, os.environ["DB_PATH"], Royal, Telegram, "tg_id", error_command=ErrorHandlerCommand)

View file

@ -2,9 +2,9 @@ from ..utils import Command, Call
from ..database.tables import Royal, Telegram
class DebugAuthorCommand(Command):
class AuthorCommand(Command):
command_name = "debug_author"
command_name = "author"
command_description = "Ottieni informazioni sull'autore di questa chiamata."
command_syntax = ""

View file

@ -0,0 +1,21 @@
import datetime
import dateparser
from ..utils import Command, Call, InvalidInputError
class DateparserCommand(Command):
command_name = "dateparser"
command_description = "Legge e comprende la data inserita."
command_syntax = "(data)"
@classmethod
async def common(cls, call: Call):
if len(call.args) == 0:
raise InvalidInputError("Missing arg")
text = " ".join(call.args)
date: datetime.datetime = dateparser.parse(text)
if date is None:
await call.reply("🕕 La data inserita non è valida.")
return
await call.reply(f"🕐 La data inserita è {date.isoformat()}")