Compare commits
50 Commits
Author | SHA1 | Date | |
---|---|---|---|
2b017c02d6 | |||
d632201f65 | |||
3b3f39a8f6 | |||
dd1ce61cd1 | |||
a4a95a61e2 | |||
9b4df44564 | |||
247c670b2e | |||
00d6418c88 | |||
a559f4c319 | |||
91ad1baafa | |||
8832ba89e4 | |||
7102ba5922 | |||
c679af095d | |||
6f644b5236 | |||
c85140ee8b | |||
63ac55d831 | |||
a2ebfe5867 | |||
76074a46b8 | |||
3d1d7e2701 | |||
46bb3db995 | |||
b6fb7e51b4 | |||
f91ed1fba4 | |||
dc63cbb563 | |||
87c3a3cea2 | |||
80b2f47403 | |||
9708fd6c2f | |||
1bc84f0fcb | |||
beb542b834 | |||
8f599c776a | |||
a352da2f3e | |||
2a7f582dd8 | |||
1e09ea7ec6 | |||
c6e048177e | |||
331184a7fd | |||
00642835bd | |||
bbe72f2fdf | |||
c7c46060e8 | |||
da969dad58 | |||
dd368733d4 | |||
6bfc329666 | |||
edfd739023 | |||
e2c05f3bf6 | |||
fe4dcc4a92 | |||
d5691c2bbb | |||
40376d2e6d | |||
507c9dc9ed | |||
4d178bc3f2 | |||
|
00f907c09c | ||
|
45573c48ae | ||
57a5b5b4b3 |
1
classes/enums/__init__.py
Normal file
1
classes/enums/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .message_events import MessageEvents
|
5
classes/enums/message_events.py
Normal file
5
classes/enums/message_events.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class MessageEvents(Enum):
|
||||||
|
WEATHER_FORECAST = 0
|
@ -14,6 +14,9 @@ class PycordBot(LibPycordBot):
|
|||||||
|
|
||||||
self.client_session = ClientSession()
|
self.client_session = ClientSession()
|
||||||
|
|
||||||
|
if self.scheduler is None:
|
||||||
|
return
|
||||||
|
|
||||||
# Scheduler job for DHL parcel tracking
|
# Scheduler job for DHL parcel tracking
|
||||||
self.scheduler.add_job(
|
self.scheduler.add_job(
|
||||||
update_tracks_dhl,
|
update_tracks_dhl,
|
||||||
@ -40,6 +43,8 @@ class PycordBot(LibPycordBot):
|
|||||||
|
|
||||||
async def close(self, *args: Any, **kwargs: Any) -> None:
|
async def close(self, *args: Any, **kwargs: Any) -> None:
|
||||||
await self.client_session.close()
|
await self.client_session.close()
|
||||||
|
|
||||||
|
if self.scheduler is not None:
|
||||||
self.scheduler.shutdown()
|
self.scheduler.shutdown()
|
||||||
|
|
||||||
await super().close(*args, **kwargs)
|
await super().close(*args, **kwargs)
|
||||||
|
9
classes/pycordguild_colors.py
Normal file
9
classes/pycordguild_colors.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class PycordGuildColors:
|
||||||
|
default: str
|
||||||
|
success: str
|
||||||
|
warning: str
|
||||||
|
error: str
|
94
locale/de.json
Normal file
94
locale/de.json
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
{
|
||||||
|
"actions": {
|
||||||
|
"bite": {
|
||||||
|
"name": "Вкусити",
|
||||||
|
"text": "**{user_name}** робить кусь **{target_name}**"
|
||||||
|
},
|
||||||
|
"poke": {
|
||||||
|
"name": "Тикнути",
|
||||||
|
"text": "**{user_name}** тикає в **{target_name}**"
|
||||||
|
},
|
||||||
|
"hug": {
|
||||||
|
"name": "Обійняти",
|
||||||
|
"text": "**{user_name}** обіймає **{target_name}**"
|
||||||
|
},
|
||||||
|
"kiss": {
|
||||||
|
"name": "Поцілувати",
|
||||||
|
"text": "**{user_name}** цілує **{target_name}**"
|
||||||
|
},
|
||||||
|
"lick": {
|
||||||
|
"name": "Лизнути",
|
||||||
|
"text": "**{user_name}** лиже **{target_name}**"
|
||||||
|
},
|
||||||
|
"pat": {
|
||||||
|
"name": "Погладити",
|
||||||
|
"text": "**{user_name}** гладить **{target_name}**"
|
||||||
|
},
|
||||||
|
"wave": {
|
||||||
|
"name": "Помахати",
|
||||||
|
"text": "**{user_name}** махає **{target_name}**"
|
||||||
|
},
|
||||||
|
"wink": {
|
||||||
|
"name": "Підморгнути",
|
||||||
|
"text": "**{user_name}** підморгує **{target_name}**"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"messages": {
|
||||||
|
"welcome": {
|
||||||
|
"morning": [
|
||||||
|
"{0} Добрий ранок та ласкаво просимо! {1}",
|
||||||
|
"{0} Доброго ранку та ласкаво просимо! {1}",
|
||||||
|
"{0} Вітаннячко! Ласкаво просимо! {1}",
|
||||||
|
"{0} Доброго ранку! Ласкаво просимо! {1}"
|
||||||
|
],
|
||||||
|
"midday": [
|
||||||
|
"{0} Добрий день! Ласкаво просимо! {1}",
|
||||||
|
"{0} Добридень! Ласкаво просимо! {1}",
|
||||||
|
"{0} День добрий! Ласкаво просимо! {1}",
|
||||||
|
"{0} Мої вітання! Ласкаво просимо! {1}",
|
||||||
|
"{0} Здоровенькі були! Ласкаво просимо! {1}",
|
||||||
|
"{0} Раді вітати вас! Ласкаво просимо! {1}",
|
||||||
|
"{0} Доброго здоров’ячка! Ласкаво просимо! {1}"
|
||||||
|
],
|
||||||
|
"evening": [
|
||||||
|
"{0} Добрий вечір! Ласкаво просимо! {1}",
|
||||||
|
"{0} Доброго вечора! Ласкаво просимо! {1}",
|
||||||
|
"{0} Добривечір! Ласкаво просимо! {1}",
|
||||||
|
"{0} Доброго вечора та ласкаво просимо! {1}",
|
||||||
|
"{0} Добрий вечір та ласкаво просимо! {1}"
|
||||||
|
],
|
||||||
|
"night": [
|
||||||
|
"{0} Доброї ночі! Ласкаво просимо! {1}",
|
||||||
|
"{0} Здоровенькі були! Ласкаво просимо! {1}"
|
||||||
|
],
|
||||||
|
"unknown": [
|
||||||
|
"{0} Вітаннячко! Ласкаво просимо! {1}"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tracking": {
|
||||||
|
"dhl": {
|
||||||
|
"statuses": {
|
||||||
|
"delivered": "Доставлено",
|
||||||
|
"transit": "Транзит",
|
||||||
|
"pre-transit": "Пре-транзит",
|
||||||
|
"failure": "Невдача"
|
||||||
|
},
|
||||||
|
"messages": {
|
||||||
|
"DHL PAKET (parcel)": "DHL PAKET (посилка)",
|
||||||
|
"The shipment was prepared for onward transport.": "Вантаж підготовлено до подальшого транспортування.",
|
||||||
|
"Warenpost (Merchandise Shipment)": "Варенпост (відвантаження товарів)",
|
||||||
|
"The shipment has been processed in the parcel center": "Відправлення пройшло обробку в посилковому центрі",
|
||||||
|
"Unfortunately, the shipment could not be delivered today due to a strike action.": "На жаль, сьогодні вантаж не вдалося доставити через страйк.",
|
||||||
|
"Die Sendung wurde von DHL abgeholt.": "Відправлення забрала компанія DHL.",
|
||||||
|
"The shipment has been successfully delivered": "Відправлення успішно доставлено",
|
||||||
|
"The shipment could not be delivered, and the recipient has been notified": "Відправлення не вдалося доставити, одержувача було повідомлено про це",
|
||||||
|
"The shipment has been loaded onto the delivery vehicle": "Вантаж завантажено на транспортний засіб доставки",
|
||||||
|
"The shipment arrived in the region of recipient and will be transported to the delivery base in the next step.": "Відправлення прибуло в регіон одержувача і буде доставлено на базу доставки на наступному кроці",
|
||||||
|
"The shipment has been processed in the parcel center of origin": "Відправлення оброблено в центрі відправлення посилок",
|
||||||
|
"The shipment has been posted by the sender at the retail outlet": "Відправлення відправлено відправником у торговій точці",
|
||||||
|
"The instruction data for this shipment have been provided by the sender to DHL electronically": "Дані інструкцій для цього відправлення були надані DHL відправником в електронному вигляді"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
94
locale/en.json
Normal file
94
locale/en.json
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
{
|
||||||
|
"messages": {
|
||||||
|
"welcome": {
|
||||||
|
"morning": [
|
||||||
|
"{0} Good morning and welcome! {1}",
|
||||||
|
"{0} Доброго ранку та ласкаво просимо! {1}",
|
||||||
|
"{0} Вітаннячко! Ласкаво просимо! {1}",
|
||||||
|
"{0} Доброго ранку! Ласкаво просимо! {1}"
|
||||||
|
],
|
||||||
|
"midday": [
|
||||||
|
"{0} Good day and welcome! {1}",
|
||||||
|
"{0} Добридень! Ласкаво просимо! {1}",
|
||||||
|
"{0} День добрий! Ласкаво просимо! {1}",
|
||||||
|
"{0} Мої вітання! Ласкаво просимо! {1}",
|
||||||
|
"{0} Здоровенькі були! Ласкаво просимо! {1}",
|
||||||
|
"{0} Раді вітати вас! Ласкаво просимо! {1}",
|
||||||
|
"{0} Доброго здоров’ячка! Ласкаво просимо! {1}"
|
||||||
|
],
|
||||||
|
"evening": [
|
||||||
|
"{0} Good evening and welcome! {1}",
|
||||||
|
"{0} Доброго вечора! Ласкаво просимо! {1}",
|
||||||
|
"{0} Добривечір! Ласкаво просимо! {1}",
|
||||||
|
"{0} Доброго вечора та ласкаво просимо! {1}",
|
||||||
|
"{0} Добрий вечір та ласкаво просимо! {1}"
|
||||||
|
],
|
||||||
|
"night": [
|
||||||
|
"{0} Good night and welcome! {1}",
|
||||||
|
"{0} Здоровенькі були! Ласкаво просимо! {1}"
|
||||||
|
],
|
||||||
|
"unknown": [
|
||||||
|
"{0} Hello and welcome! {1}"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"actions": {
|
||||||
|
"bite": {
|
||||||
|
"name": "Bite",
|
||||||
|
"text": "**{user_name}** bites **{target_name}**"
|
||||||
|
},
|
||||||
|
"hug": {
|
||||||
|
"name": "Hug",
|
||||||
|
"text": "**{user_name}** hugs **{target_name}**"
|
||||||
|
},
|
||||||
|
"kiss": {
|
||||||
|
"name": "Kiss",
|
||||||
|
"text": "**{user_name}** kisses **{target_name}**"
|
||||||
|
},
|
||||||
|
"lick": {
|
||||||
|
"name": "Lick",
|
||||||
|
"text": "**{user_name}** licks **{target_name}**"
|
||||||
|
},
|
||||||
|
"pat": {
|
||||||
|
"name": "Pat",
|
||||||
|
"text": "**{user_name}** pats **{target_name}**"
|
||||||
|
},
|
||||||
|
"poke": {
|
||||||
|
"name": "Poke",
|
||||||
|
"text": "**{user_name}** pokes **{target_name}**"
|
||||||
|
},
|
||||||
|
"wave": {
|
||||||
|
"name": "Wave",
|
||||||
|
"text": "**{user_name}** waves **{target_name}**"
|
||||||
|
},
|
||||||
|
"wink": {
|
||||||
|
"name": "Wink",
|
||||||
|
"text": "**{user_name}** winks **{target_name}**"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tracking": {
|
||||||
|
"dhl": {
|
||||||
|
"statuses": {
|
||||||
|
"delivered": "Delivered",
|
||||||
|
"transit": "Transit",
|
||||||
|
"pre-transit": "Pre-transit",
|
||||||
|
"failure": "Failure"
|
||||||
|
},
|
||||||
|
"messages": {
|
||||||
|
"DHL PAKET (parcel)": "DHL PAKET (parcel)",
|
||||||
|
"The shipment was prepared for onward transport.": "The shipment was prepared for onward transport.",
|
||||||
|
"Warenpost (Merchandise Shipment)": "Warenpost (Merchandise Shipment)",
|
||||||
|
"The shipment has been processed in the parcel center": "The shipment has been processed in the parcel center",
|
||||||
|
"Unfortunately, the shipment could not be delivered today due to a strike action.": "Unfortunately, the shipment could not be delivered today due to a strike action.",
|
||||||
|
"Die Sendung wurde von DHL abgeholt.": "The shipment has been picked up by DHL.",
|
||||||
|
"The shipment has been successfully delivered": "The shipment has been successfully delivered",
|
||||||
|
"The shipment could not be delivered, and the recipient has been notified": "The shipment could not be delivered, and the recipient has been notified",
|
||||||
|
"The shipment has been loaded onto the delivery vehicle": "The shipment has been loaded onto the delivery vehicle",
|
||||||
|
"The shipment arrived in the region of recipient and will be transported to the delivery base in the next step.": "The shipment arrived in the region of recipient and will be transported to the delivery base in the next step.",
|
||||||
|
"The shipment has been processed in the parcel center of origin": "The shipment has been processed in the parcel center of origin",
|
||||||
|
"The shipment has been posted by the sender at the retail outlet": "The shipment has been posted by the sender at the retail outlet",
|
||||||
|
"The instruction data for this shipment have been provided by the sender to DHL electronically": "The instruction data for this shipment have been provided by the sender to DHL electronically"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -38,7 +38,7 @@
|
|||||||
"text": "**{user_name}** робить кусь **{target_name}**"
|
"text": "**{user_name}** робить кусь **{target_name}**"
|
||||||
},
|
},
|
||||||
"hug": {
|
"hug": {
|
||||||
"name": "",
|
"name": "Обійняти",
|
||||||
"text": "**{user_name}** обіймає **{target_name}**"
|
"text": "**{user_name}** обіймає **{target_name}**"
|
||||||
},
|
},
|
||||||
"kiss": {
|
"kiss": {
|
||||||
|
@ -24,6 +24,7 @@ db_client = AsyncClient(con_string)
|
|||||||
db: AsyncDatabase = db_client.get_database(name=db_config["name"])
|
db: AsyncDatabase = db_client.get_database(name=db_config["name"])
|
||||||
|
|
||||||
col_users: AsyncCollection = db.get_collection("users")
|
col_users: AsyncCollection = db.get_collection("users")
|
||||||
|
col_messages: AsyncCollection = db.get_collection("messages")
|
||||||
col_warnings: AsyncCollection = db.get_collection("warnings")
|
col_warnings: AsyncCollection = db.get_collection("warnings")
|
||||||
col_checkouts: AsyncCollection = db.get_collection("checkouts")
|
col_checkouts: AsyncCollection = db.get_collection("checkouts")
|
||||||
col_trackings: AsyncCollection = db.get_collection("trackings")
|
col_trackings: AsyncCollection = db.get_collection("trackings")
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
def hex_to_int(hex_color: str) -> int:
|
||||||
|
return int(hex_color.lstrip("#"), 16)
|
||||||
|
|
||||||
|
|
||||||
|
def int_to_hex(integer_color: int) -> str:
|
||||||
|
return "#" + format(integer_color, "06x")
|
9
modules/weather/parser.py
Normal file
9
modules/weather/parser.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from typing import Any, Dict
|
||||||
|
|
||||||
|
|
||||||
|
def parse_weather(api_response: Dict[str, Any]) -> str:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def parse_weather_current(api_response: Dict[str, Any]) -> str:
|
||||||
|
return ""
|
106
modules/weather/reporter.py
Normal file
106
modules/weather/reporter.py
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
import logging
|
||||||
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
|
from discord import Embed
|
||||||
|
from pymongo import DESCENDING
|
||||||
|
from pytz import timezone
|
||||||
|
from classes.enums import MessageEvents
|
||||||
|
from classes.pycordbot import PycordBot
|
||||||
|
from ujson import loads
|
||||||
|
from modules.utils import hex_to_int
|
||||||
|
from database import col_messages
|
||||||
|
|
||||||
|
from modules.weather.parser import parse_weather
|
||||||
|
|
||||||
|
# Example guild key
|
||||||
|
# "forecast": {
|
||||||
|
# "channel": 0,
|
||||||
|
# "time": "10:00:00",
|
||||||
|
# "delete_previous": true
|
||||||
|
# "locations": [{"name": "Sample Location", "location": [10.000, 20.000]}],
|
||||||
|
# }
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
async def report_weather(
|
||||||
|
bot: PycordBot,
|
||||||
|
guild: PycordGuild, # TODO
|
||||||
|
channel_id: int,
|
||||||
|
delete_previous: bool,
|
||||||
|
locations: List[Dict[str, Any]],
|
||||||
|
) -> None: # sourcery skip: aware-datetime-for-utc
|
||||||
|
channel = bot.get_channel(channel_id)
|
||||||
|
|
||||||
|
if channel is None:
|
||||||
|
logger.error(
|
||||||
|
"Cannot generate weather report for %s's channel %s because channel was not found.",
|
||||||
|
guild.id,
|
||||||
|
channel_id,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Find and delete previous forecast, if needed
|
||||||
|
if delete_previous:
|
||||||
|
async for event in col_messages.find(
|
||||||
|
{
|
||||||
|
"event": MessageEvents.WEATHER_FORECAST,
|
||||||
|
"guild": guild.id,
|
||||||
|
"channel": channel_id,
|
||||||
|
},
|
||||||
|
limit=1,
|
||||||
|
).sort("date", direction=DESCENDING):
|
||||||
|
try:
|
||||||
|
old_message = bot.get_message(event["message"])
|
||||||
|
if old_message is not None:
|
||||||
|
await old_message.delete(
|
||||||
|
reason="Cleanup of the old weather report (look in guild config for details)"
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
logger.warning(
|
||||||
|
"Could not delete the previous weather report in %s' channel %s due to %s",
|
||||||
|
guild.id,
|
||||||
|
channel_id,
|
||||||
|
exc,
|
||||||
|
)
|
||||||
|
|
||||||
|
embeds: List[Embed] = []
|
||||||
|
|
||||||
|
# Iterate through the locations and request their forecasts.
|
||||||
|
# Results must be parsed and added as embeds to the embeds lits.
|
||||||
|
for location in locations:
|
||||||
|
location_timezone_offset = ":".join(
|
||||||
|
str(
|
||||||
|
timezone(bot.config["bot"]["timezone"]).utcoffset(datetime.utcnow())
|
||||||
|
).split(":")[:2]
|
||||||
|
)
|
||||||
|
|
||||||
|
api_response = await (
|
||||||
|
await bot.client_session.get(
|
||||||
|
f"https://api.openweathermap.org/data/2.5/onecall?lat={location['location'][0]}&lon={location['location'][1]}&exclude=minutely&units=metric&lang=uk&appid={bot.config['modules']['weather']['forecasts']['api_key']}&tz={location_timezone_offset}"
|
||||||
|
)
|
||||||
|
).json(loads=loads)
|
||||||
|
|
||||||
|
parsed_weather = parse_weather(api_response)
|
||||||
|
|
||||||
|
embeds.append(
|
||||||
|
Embed(
|
||||||
|
title=location["name"],
|
||||||
|
description=parsed_weather,
|
||||||
|
color=hex_to_int(guild.colors.default),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add a trailing embed with OWM information
|
||||||
|
embeds.append(
|
||||||
|
Embed(
|
||||||
|
title=bot._("weather_report_title", "embeds"),
|
||||||
|
description=bot._("weather_report_description", "embeds"),
|
||||||
|
color=hex_to_int(guild.colors.default),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
await channel.send( # type: ignore
|
||||||
|
content=bot._("weather_report_content", "messages"), embeds=embeds
|
||||||
|
)
|
@ -1,12 +1,12 @@
|
|||||||
aiohttp>=3.6.0
|
aiohttp>=3.6.0
|
||||||
apscheduler~=3.10.4
|
apscheduler~=3.10.4
|
||||||
|
async_pymongo==0.1.11
|
||||||
colorthief==0.2.1
|
colorthief==0.2.1
|
||||||
deepl==1.16.1
|
deepl==1.19.1
|
||||||
fastapi[all]~=0.109.1
|
fastapi[all]~=0.115.0
|
||||||
mongodb-migrations==1.3.0
|
mongodb-migrations==1.3.1
|
||||||
pynacl~=1.5.0
|
pynacl~=1.5.0
|
||||||
pyrmv==0.3.5
|
pyrmv==0.4.0
|
||||||
pytz~=2024.1
|
pytz~=2024.1
|
||||||
--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,pycord]==3.2.3
|
||||||
libbot[speed,pycord]==3.0.0
|
|
||||||
|
Loading…
Reference in New Issue
Block a user