4 Commits

Author SHA1 Message Date
AlberLC
d137f220cc Fix message find by date 2022-06-29 06:48:06 +02:00
AlberLC
00323f99fb Update HEAT_NAMES 2022-06-27 05:08:08 +02:00
AlberLC
6237ccf8b6 Fix _on_choose 2022-06-27 04:59:14 +02:00
AlberLC
f402293c99 Upgrade _on_choose 2022-06-27 04:22:47 +02:00
3 changed files with 39 additions and 12 deletions

View File

@@ -2,6 +2,7 @@ __all__ = ['FlanaBot']
import asyncio
import datetime
import math
import random
import re
import time as time_module
@@ -167,12 +168,12 @@ class FlanaBot(MultiBot, ABC):
last_2s_messages = Message.find({
'platform': self.platform.value,
'author': message.author.object_id,
'last_update': {'$gte': datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(seconds=2)}
'date': {'$gte': datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(seconds=2)}
})
last_7s_messages = Message.find({
'platform': self.platform.value,
'author': message.author.object_id,
'last_update': {'$gte': datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(seconds=7)}
'date': {'$gte': datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(seconds=7)}
})
if len(last_2s_messages) >= constants.FLOOD_2s_LIMIT or len(last_7s_messages) >= constants.FLOOD_7s_LIMIT:
@@ -303,21 +304,46 @@ class FlanaBot(MultiBot, ABC):
if message.chat.is_group and not self.is_bot_mentioned(message):
return
discarded_words = {*constants.KEYWORDS['choose'], *constants.KEYWORDS['random'], self.name.lower(), f'<@{self.id}>'}
discarded_words = {
*constants.KEYWORDS['choose'],
*constants.KEYWORDS['random'],
self.name.lower(), f'<@{self.id}>',
*flanautils.CommonWords.get('conjunctions'),
'entre', 'between'
}
if final_words := [word for word in message.text.split() if not flanautils.cartesian_product_string_matching(word.lower(), discarded_words, min_ratio=multibot_constants.PARSE_CALLBACKS_MIN_RATIO_DEFAULT)]:
for i in range(1, len(final_words) - 1):
try:
n1 = flanautils.cast_number(final_words[i - 1])
except ValueError:
try:
n1 = flanautils.words_to_numbers(final_words[i - 1], ignore_no_numbers=False)
except KeyError:
continue
try:
n2 = flanautils.cast_number(final_words[i + 1])
except ValueError:
try:
n2 = flanautils.words_to_numbers(final_words[i + 1], ignore_no_numbers=False)
except KeyError:
continue
if final_words[i] in ('al', 'el', 'to'):
await self.send(random.randint(math.ceil(n1), math.floor(n2)), message)
return
await self.send(random.choice(final_words), message)
else:
await self.send(random.choice(('¿Que elija el qué?', '¿Y las opciones?', '?', '🤔')), message)
async def _on_config_button_press(self, message: Message):
await self._accept_button_event(message)
await self.accept_button_event(message)
if message.buttons_info.presser_user.is_admin is False:
return
config = message.buttons_info.pressed_text.split()[1]
message.chat.config[config] = not message.chat.config[config]
pressed_button = message.buttons_info[message.buttons_info.pressed_text]
pressed_button = message.buttons_info.pressed_button
pressed_button.is_checked = not pressed_button.is_checked
pressed_button.text = f"{'' if pressed_button.is_checked else ''} {config}"
@@ -388,7 +414,7 @@ class FlanaBot(MultiBot, ABC):
return
if top_number := flanautils.sum_numbers_in_text(message.text):
await self.send(random.randint(1, top_number), message)
await self.send(random.randint(1, math.floor(top_number)), message)
else:
await self.send(random.choice(('¿De cuántas caras?', '¿Y el número?', '?', '🤔')), message)
@@ -451,7 +477,7 @@ class FlanaBot(MultiBot, ABC):
await self.send(random.choice(('¿Y las opciones?', '?', '🤔')), message)
async def _on_poll_button_press(self, message: Message):
await self._accept_button_event(message)
await self.accept_button_event(message)
if not message.contents['poll']['is_active']:
return
@@ -636,7 +662,7 @@ class FlanaBot(MultiBot, ABC):
await self.unpunish(user, message, message)
async def _on_weather_button_press(self, message: Message):
await self._accept_button_event(message)
await self.accept_button_event(message)
match message.buttons_info.pressed_text:
case WeatherEmoji.ZOOM_IN.value:
@@ -699,7 +725,7 @@ class FlanaBot(MultiBot, ABC):
- flanautils.cartesian_product_string_matching(original_text_words, multibot_constants.KEYWORDS['date'], min_ratio=0.85).keys()
- flanautils.cartesian_product_string_matching(original_text_words, multibot_constants.KEYWORDS['thanks'], min_ratio=0.85).keys()
- possible_mentioned_ids
- flanautils.CommonWords.all_words
- flanautils.CommonWords.get()
)
if not place_words:
if not message.is_inline:

View File

@@ -21,9 +21,10 @@ HEAT_NAMES = [
'Canal Caliente',
'Canal Olor a Vasco',
'Verano Cordobés al Sol',
'Canal Ardiendo',
'abrid las putas ventanas y traed el extintor',
'Canal INFIERNO'
'Canal Ardiendo',
'Canal INFIERNO',
'🔥🔥🔥🔥🔥🔥🔥'
]
HOT_CHANNEL_ID = 493530483045564417

View File

@@ -85,7 +85,7 @@ INSULTS = (
)
KEYWORDS = {
'choose': ('choose', 'elige'),
'choose': ('choose', 'elige', 'escoge'),
'covid_chart': ('case', 'caso', 'contagiado', 'contagio', 'corona', 'coronavirus', 'covid', 'covid19', 'death',
'disease', 'enfermedad', 'enfermos', 'fallecido', 'incidencia', 'jacovid', 'mascarilla', 'muerte',
'muerto', 'pandemia', 'sick', 'virus'),