Compare commits
34 Commits
profitroll
...
main
Author | SHA1 | Date | |
---|---|---|---|
a5824dbd6b | |||
f8472b1b3f | |||
13be95f0f8 | |||
524087f59f | |||
cc66cc386b | |||
39f7904bdc | |||
b5173a8dba | |||
0a06e8493f | |||
c2ee35b3d9 | |||
896262b83e | |||
f6b1749408 | |||
6867b64a18 | |||
f42117e542 | |||
a5a513cb82 | |||
3fef2eb028 | |||
11ca3223ab | |||
6b138126c1 | |||
e6adb03f61 | |||
d51fa1e04c | |||
8b2456c2fd | |||
6a6b4cd6cd | |||
852f4307f8 | |||
e73797d819 | |||
bfd99a44a6 | |||
d078ab37d8 | |||
ea0ab6443f | |||
04ee8e9c60 | |||
2c15bbb4d2 | |||
99d621d90f | |||
dc389ac1b7 | |||
e3e9ec0cc8 | |||
b29d2467d3 | |||
7f3803b79b | |||
3925f66882 |
@ -19,11 +19,11 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class PyroClient(LibPyroClient):
|
class PyroClient(LibPyroClient):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.__version__ = (0, 1, 2)
|
self.__version__ = (0, 1, 3)
|
||||||
|
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
self.updater = Updater(ClientSession())
|
self.updater = Updater()
|
||||||
self.contexts = []
|
self.contexts = []
|
||||||
|
|
||||||
if self.scheduler is not None:
|
if self.scheduler is not None:
|
||||||
@ -91,6 +91,7 @@ class PyroClient(LibPyroClient):
|
|||||||
]
|
]
|
||||||
|
|
||||||
async def check_updates(self) -> None:
|
async def check_updates(self) -> None:
|
||||||
|
"""Check for updates and send a message to the owner if newer version was found"""
|
||||||
if await self.updater.check_updates(
|
if await self.updater.check_updates(
|
||||||
self.__version__, self.config["strings"]["url_updater"]
|
self.__version__, self.config["strings"]["url_updater"]
|
||||||
):
|
):
|
||||||
|
@ -88,8 +88,7 @@ class PyroUser:
|
|||||||
### Args:
|
### Args:
|
||||||
* locale (`Union[str, None]`): New locale to be set.
|
* locale (`Union[str, None]`): New locale to be set.
|
||||||
"""
|
"""
|
||||||
|
logger.info("%s's locale has been set to %s", self.id, locale)
|
||||||
logger.debug("%s's locale has been set to %s", self.id, locale)
|
|
||||||
|
|
||||||
await col_users.update_one({"_id": self._id}, {"$set": {"locale": locale}})
|
await col_users.update_one({"_id": self._id}, {"$set": {"locale": locale}})
|
||||||
|
|
||||||
@ -98,7 +97,15 @@ class PyroUser:
|
|||||||
return self.locale
|
return self.locale
|
||||||
|
|
||||||
async def update_state(self, enabled: bool = False) -> bool:
|
async def update_state(self, enabled: bool = False) -> bool:
|
||||||
logger.debug("%s's state has been set to %s", self.id, enabled)
|
"""Update user's state (enabled/disabled)
|
||||||
|
|
||||||
|
### Args:
|
||||||
|
* enabled (`bool`, *optional*): Whether the user is enabled. Defaults to `False`.
|
||||||
|
|
||||||
|
### Returns:
|
||||||
|
* `bool`: User's current state
|
||||||
|
"""
|
||||||
|
logger.info("%s's state has been set to %s", self.id, enabled)
|
||||||
|
|
||||||
await col_users.update_one({"_id": self._id}, {"$set": {"enabled": enabled}})
|
await col_users.update_one({"_id": self._id}, {"$set": {"enabled": enabled}})
|
||||||
|
|
||||||
@ -106,8 +113,16 @@ class PyroUser:
|
|||||||
|
|
||||||
return self.enabled
|
return self.enabled
|
||||||
|
|
||||||
async def update_location(self, location_id: int = 0) -> Location:
|
async def update_location(self, location_id: int) -> Location:
|
||||||
logger.debug("%s's location has been set to %s", self.id, location_id)
|
"""Update user's location and move their time to the new timezone (if the user had a location set previously)
|
||||||
|
|
||||||
|
### Args:
|
||||||
|
* location_id (`int`): ID of the location
|
||||||
|
|
||||||
|
### Returns:
|
||||||
|
`Location`: New location
|
||||||
|
"""
|
||||||
|
logger.info("%s's location has been set to %s", self.id, location_id)
|
||||||
|
|
||||||
await col_users.update_one(
|
await col_users.update_one(
|
||||||
{"_id": self._id}, {"$set": {"location": location_id}}
|
{"_id": self._id}, {"$set": {"location": location_id}}
|
||||||
@ -136,7 +151,15 @@ class PyroUser:
|
|||||||
return self.location
|
return self.location
|
||||||
|
|
||||||
async def update_offset(self, offset: int = 1) -> int:
|
async def update_offset(self, offset: int = 1) -> int:
|
||||||
logger.debug("%s's offset has been set to %s", self.id, offset)
|
"""Update the offset of the reminder (in days)
|
||||||
|
|
||||||
|
### Args:
|
||||||
|
* offset (`int`, *optional*): Offset in days. Defaults to `1`.
|
||||||
|
|
||||||
|
### Returns:
|
||||||
|
* `int`: Offset in days
|
||||||
|
"""
|
||||||
|
logger.info("%s's offset has been set to %s", self.id, offset)
|
||||||
|
|
||||||
await col_users.update_one({"_id": self._id}, {"$set": {"offset": offset}})
|
await col_users.update_one({"_id": self._id}, {"$set": {"offset": offset}})
|
||||||
|
|
||||||
@ -145,7 +168,16 @@ class PyroUser:
|
|||||||
return offset
|
return offset
|
||||||
|
|
||||||
async def update_time(self, hour: int = 16, minute: int = 0) -> Tuple[int, int]:
|
async def update_time(self, hour: int = 16, minute: int = 0) -> Tuple[int, int]:
|
||||||
logger.debug("%s's time has been set to %s h. %s m.", self.id, hour, minute)
|
"""Update the time of the reminder (hour and minute, for UTC timezone)
|
||||||
|
|
||||||
|
### Args:
|
||||||
|
* hour (`int`, *optional*): Hour of the reminder. Defaults to `16`.
|
||||||
|
* minute (`int`, *optional*): Minute of the reminder. Defaults to `0`.
|
||||||
|
|
||||||
|
### Returns:
|
||||||
|
* `Tuple[int, int]`: Hour and minute of the reminder
|
||||||
|
"""
|
||||||
|
logger.info("%s's time has been set to %s h. %s m.", self.id, hour, minute)
|
||||||
|
|
||||||
await col_users.update_one(
|
await col_users.update_one(
|
||||||
{"_id": self._id}, {"$set": {"time_hour": hour, "time_minute": minute}}
|
{"_id": self._id}, {"$set": {"time_hour": hour, "time_minute": minute}}
|
||||||
@ -157,16 +189,27 @@ class PyroUser:
|
|||||||
return self.time_hour, self.time_minute
|
return self.time_hour, self.time_minute
|
||||||
|
|
||||||
async def delete(self) -> None:
|
async def delete(self) -> None:
|
||||||
logger.debug("%s's data has been deleted", self.id)
|
"""Delete the database record of the user"""
|
||||||
|
logger.info("%s's data has been deleted", self.id)
|
||||||
|
|
||||||
await col_users.delete_one({"_id": self._id})
|
await col_users.delete_one({"_id": self._id})
|
||||||
|
|
||||||
async def checkout(self) -> Mapping[str, Any]:
|
async def checkout(self) -> Mapping[str, Any]:
|
||||||
logger.debug("%s's data has been checked out", self.id)
|
"""Checkout the user's database record
|
||||||
|
|
||||||
|
### Raises:
|
||||||
|
* `KeyError`: Database record of the user was not found
|
||||||
|
|
||||||
|
### Returns:
|
||||||
|
* `Mapping[str, Any]`: Database record
|
||||||
|
"""
|
||||||
|
logger.info("%s's data has been checked out", self.id)
|
||||||
|
|
||||||
db_entry = await col_users.find_one({"_id": self._id})
|
db_entry = await col_users.find_one({"_id": self._id})
|
||||||
|
|
||||||
if db_entry is None:
|
if db_entry is None:
|
||||||
raise KeyError(
|
raise KeyError(
|
||||||
f"DB record with id {self._id} of user {self.id} is not found"
|
f"DB record with id {self._id} of user {self.id} was not found"
|
||||||
)
|
)
|
||||||
|
|
||||||
del db_entry["_id"] # type: ignore
|
del db_entry["_id"] # type: ignore
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, Tuple
|
from typing import Any, Dict, Tuple, Union
|
||||||
|
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
|
|
||||||
@ -7,12 +7,15 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class Updater:
|
class Updater:
|
||||||
def __init__(self, client_session: ClientSession) -> None:
|
def __init__(self, client_session: Union[ClientSession, None] = None) -> None:
|
||||||
self.client_session: ClientSession = client_session
|
self.client_session: Union[ClientSession, None] = client_session
|
||||||
|
|
||||||
async def check_updates(
|
async def check_updates(
|
||||||
self, version_current: Tuple[int, int, int], api_url: str
|
self, version_current: Tuple[int, int, int], api_url: str
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
if not self.client_session:
|
||||||
|
self.client_session = ClientSession()
|
||||||
|
|
||||||
response = await self.client_session.get(api_url)
|
response = await self.client_session.get(api_url)
|
||||||
|
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
@ -30,6 +33,9 @@ class Updater:
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def get_latest_release(self, api_url: str) -> Dict[str, Any]:
|
async def get_latest_release(self, api_url: str) -> Dict[str, Any]:
|
||||||
|
if not self.client_session:
|
||||||
|
self.client_session = ClientSession()
|
||||||
|
|
||||||
response = await self.client_session.get(api_url)
|
response = await self.client_session.get(api_url)
|
||||||
|
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"bot": {
|
"bot": {
|
||||||
"name": "Garbage Reminder",
|
"name": "Garbage Reminder",
|
||||||
"about": "Nie wieder Müllabfuhrtermin verpassen. Quellcode: https://garbagebot.eu",
|
"about": "Nie wieder Müllabfuhrtermin verpassen. Mehr erfahren: https://garbagebot.eu",
|
||||||
"description": "Sie können Erinnerungen an die Müllabfuhr für Orte Ihrer Wahl erhalten.\n\nVerwenden Sie /help, um die Funktionsweise des Bots besser zu verstehen, oder verwenden Sie /setup, um Ihre Erinnerungen zu konfigurieren."
|
"description": "Sie können Erinnerungen an die Müllabfuhr für Orte Ihrer Wahl erhalten.\n\nVerwenden Sie /help, um die Funktionsweise des Bots besser zu verstehen, oder verwenden Sie /setup, um Ihre Erinnerungen zu konfigurieren."
|
||||||
},
|
},
|
||||||
"formats": {
|
"formats": {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"bot": {
|
"bot": {
|
||||||
"name": "Garbage Reminder",
|
"name": "Garbage Reminder",
|
||||||
"about": "Never forget about garbage collection again. Source code: https://garbagebot.eu",
|
"about": "Never forget about garbage collection again. Learn more: https://garbagebot.eu",
|
||||||
"description": "You can receive reminders about garbage collection for locations of your choice.\n\nUse /help to better understand how the bot works or use /setup to configure your reminders."
|
"description": "You can receive reminders about garbage collection for locations of your choice.\n\nUse /help to better understand how the bot works or use /setup to configure your reminders."
|
||||||
},
|
},
|
||||||
"formats": {
|
"formats": {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"bot": {
|
"bot": {
|
||||||
"name": "Garbage Reminder 🇺🇦",
|
"name": "Garbage Reminder 🇺🇦",
|
||||||
"about": "Більше ніколи не забувайте про вивезення сміття. Вихідний код: https://garbagebot.eu",
|
"about": "Більше ніколи не забувайте про вивезення сміття. Дізнатись більше: https://garbagebot.eu",
|
||||||
"description": "Ви можете отримувати нагадування про вивезення сміття для обраних вами місць.\n\nВикористовуйте /help, щоб краще зрозуміти, як працює бот, або /setup, щоб налаштувати нагадування."
|
"description": "Ви можете отримувати нагадування про вивезення сміття для обраних вами місць.\n\nВикористовуйте /help, щоб краще зрозуміти, як працює бот, або /setup, щоб налаштувати нагадування."
|
||||||
},
|
},
|
||||||
"formats": {
|
"formats": {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"bot": {
|
"bot": {
|
||||||
"name": "Garbage Reminder 🇺🇦",
|
"name": "Garbage Reminder 🇺🇦",
|
||||||
"about": "Більше ніколи не забувайте про вивезення сміття. Вихідний код: https://garbagebot.eu",
|
"about": "Більше ніколи не забувайте про вивезення сміття. Дізнатись більше: https://garbagebot.eu",
|
||||||
"description": "Ви можете отримувати нагадування про вивезення сміття для обраних вами місць.\n\nВикористовуйте /help, щоб краще зрозуміти, як працює бот, або /setup, щоб налаштувати нагадування."
|
"description": "Ви можете отримувати нагадування про вивезення сміття для обраних вами місць.\n\nВикористовуйте /help, щоб краще зрозуміти, як працює бот, або /setup, щоб налаштувати нагадування."
|
||||||
},
|
},
|
||||||
"formats": {
|
"formats": {
|
||||||
|
4
main.py
4
main.py
@ -4,6 +4,7 @@ from argparse import ArgumentParser
|
|||||||
from os import getpid
|
from os import getpid
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from aiohttp import ClientSession
|
||||||
from convopyro import Conversation
|
from convopyro import Conversation
|
||||||
from libbot import sync
|
from libbot import sync
|
||||||
|
|
||||||
@ -41,7 +42,8 @@ def main():
|
|||||||
exit()
|
exit()
|
||||||
|
|
||||||
client = PyroClient(
|
client = PyroClient(
|
||||||
scheduler=scheduler, commands_source=sync.json_read(Path("commands.json"))
|
scheduler=scheduler,
|
||||||
|
commands_source=sync.json_read(Path("commands.json")),
|
||||||
)
|
)
|
||||||
Conversation(client)
|
Conversation(client)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ async def command_toggle(app: PyroClient, message: Message):
|
|||||||
|
|
||||||
await user.update_state(not user.enabled)
|
await user.update_state(not user.enabled)
|
||||||
|
|
||||||
if user.enabled:
|
if not user.enabled:
|
||||||
await message.reply_text(
|
await message.reply_text(
|
||||||
app._("toggle_disabled", "messages", locale=user.locale)
|
app._("toggle_disabled", "messages", locale=user.locale)
|
||||||
)
|
)
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
aiohttp~=3.9.5
|
aiohttp~=3.10.2
|
||||||
apscheduler~=3.10.4
|
apscheduler~=3.10.4
|
||||||
|
async_pymongo==0.1.9
|
||||||
convopyro==0.5
|
convopyro==0.5
|
||||||
mongodb-migrations==1.3.1
|
mongodb-migrations==1.3.1
|
||||||
pytz<=2023.2
|
pytz>=2024.1
|
||||||
tgcrypto==1.2.5
|
tgcrypto==1.2.5
|
||||||
ujson>=5.0.0
|
ujson>=5.0.0
|
||||||
uvloop==0.19.0
|
uvloop==0.20.0
|
||||||
--extra-index-url https://git.end-play.xyz/api/packages/profitroll/pypi/simple
|
--extra-index-url https://git.end-play.xyz/api/packages/profitroll/pypi/simple
|
||||||
async_pymongo==0.1.4
|
libbot[speed,pyrogram]==3.2.3
|
||||||
libbot[speed,pyrogram]==3.2.2
|
|
||||||
pykeyboard==0.1.7
|
pykeyboard==0.1.7
|
Reference in New Issue
Block a user