Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
449df672b5 | ||
|
|
d3b8c4f821 | ||
|
|
acbd0e5ad1 | ||
|
|
a0c693f5eb | ||
|
|
5a500e71e3 | ||
|
|
d6cdc1436f | ||
|
|
b9e61b296d |
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
FROM flanaganvaquero/flanawright
|
||||||
|
|
||||||
|
WORKDIR /application
|
||||||
|
|
||||||
|
COPY flanabot flanabot
|
||||||
|
COPY venv/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
|
||||||
|
|
||||||
|
ENV PYTHONPATH=/application
|
||||||
|
|
||||||
|
CMD python3.10 flanabot/main.py
|
||||||
17
docker-compose.yaml
Normal file
17
docker-compose.yaml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
services:
|
||||||
|
flanabot:
|
||||||
|
image: flanaganvaquero/flanabot
|
||||||
|
build: .
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
|
||||||
|
mongodb:
|
||||||
|
image: mongo
|
||||||
|
environment:
|
||||||
|
- MONGO_INITDB_ROOT_USERNAME=${MONGO_USER}
|
||||||
|
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD}
|
||||||
|
volumes:
|
||||||
|
- mongodata:/data/db
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mongodata:
|
||||||
@@ -3,7 +3,7 @@ import datetime
|
|||||||
import itertools
|
import itertools
|
||||||
import pprint
|
import pprint
|
||||||
import random
|
import random
|
||||||
import time
|
import time as time_module
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
from asyncio import Future
|
from asyncio import Future
|
||||||
from typing import Iterable, Iterator, Type
|
from typing import Iterable, Iterator, Type
|
||||||
@@ -36,7 +36,7 @@ class FlanaBot(MultiBot, ABC):
|
|||||||
def _add_handlers(self):
|
def _add_handlers(self):
|
||||||
super()._add_handlers()
|
super()._add_handlers()
|
||||||
|
|
||||||
self.register(self._on_bye, constants.KEYWORDS['bye'], min_ratio=1)
|
self.register(self._on_bye, constants.KEYWORDS['bye'])
|
||||||
|
|
||||||
self.register(self._on_config_list_show, constants.KEYWORDS['config'])
|
self.register(self._on_config_list_show, constants.KEYWORDS['config'])
|
||||||
self.register(self._on_config_list_show, constants.KEYWORDS['help'])
|
self.register(self._on_config_list_show, constants.KEYWORDS['help'])
|
||||||
@@ -87,6 +87,7 @@ class FlanaBot(MultiBot, ABC):
|
|||||||
self.register(self._on_hello, constants.KEYWORDS['hello'])
|
self.register(self._on_hello, constants.KEYWORDS['hello'])
|
||||||
|
|
||||||
self.register(self._on_mute, constants.KEYWORDS['mute'])
|
self.register(self._on_mute, constants.KEYWORDS['mute'])
|
||||||
|
self.register(self._on_mute, (('haz', 'se'), constants.KEYWORDS['mute']))
|
||||||
self.register(self._on_mute, (constants.KEYWORDS['deactivate'], constants.KEYWORDS['unmute']))
|
self.register(self._on_mute, (constants.KEYWORDS['deactivate'], constants.KEYWORDS['unmute']))
|
||||||
self.register(self._on_mute, (constants.KEYWORDS['deactivate'], constants.KEYWORDS['sound']))
|
self.register(self._on_mute, (constants.KEYWORDS['deactivate'], constants.KEYWORDS['sound']))
|
||||||
|
|
||||||
@@ -303,7 +304,7 @@ class FlanaBot(MultiBot, ABC):
|
|||||||
|
|
||||||
async def _search_medias(self, message: Message) -> OrderedSet[Media]:
|
async def _search_medias(self, message: Message) -> OrderedSet[Media]:
|
||||||
bot_state_message: Message | None = None
|
bot_state_message: Message | None = None
|
||||||
start_time = time.perf_counter()
|
start_time = time_module.perf_counter()
|
||||||
|
|
||||||
results: Future = asyncio.gather(
|
results: Future = asyncio.gather(
|
||||||
twitter.get_medias(message.text),
|
twitter.get_medias(message.text),
|
||||||
@@ -314,7 +315,7 @@ class FlanaBot(MultiBot, ABC):
|
|||||||
|
|
||||||
if not message.is_inline and (self.is_bot_mentioned(message) or not message.chat.is_group):
|
if not message.is_inline and (self.is_bot_mentioned(message) or not message.chat.is_group):
|
||||||
while not results.done():
|
while not results.done():
|
||||||
if constants.SCRAPING_MESSAGE_WAITING_TIME <= time.perf_counter() - start_time:
|
if constants.SCRAPING_MESSAGE_WAITING_TIME <= time_module.perf_counter() - start_time:
|
||||||
bot_state_message = await self.send(random.choice(constants.SCRAPING_PHRASES), message)
|
bot_state_message = await self.send(random.choice(constants.SCRAPING_PHRASES), message)
|
||||||
break
|
break
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
@@ -573,10 +574,10 @@ class FlanaBot(MultiBot, ABC):
|
|||||||
).split()
|
).split()
|
||||||
place_words = (
|
place_words = (
|
||||||
OrderedSet(original_text_words)
|
OrderedSet(original_text_words)
|
||||||
- flanautils.cartesian_product_string_matching(original_text_words, constants.KEYWORDS['show'], min_ratio=0.8).keys()
|
- flanautils.cartesian_product_string_matching(original_text_words, constants.KEYWORDS['show'], min_ratio=0.85).keys()
|
||||||
- flanautils.cartesian_product_string_matching(original_text_words, constants.KEYWORDS['weather_chart'], min_ratio=0.8).keys()
|
- flanautils.cartesian_product_string_matching(original_text_words, constants.KEYWORDS['weather_chart'], min_ratio=0.85).keys()
|
||||||
- flanautils.cartesian_product_string_matching(original_text_words, constants.KEYWORDS['date'], min_ratio=0.8).keys()
|
- flanautils.cartesian_product_string_matching(original_text_words, constants.KEYWORDS['date'], min_ratio=0.85).keys()
|
||||||
- flanautils.cartesian_product_string_matching(original_text_words, constants.KEYWORDS['thanks'], min_ratio=0.8).keys()
|
- flanautils.cartesian_product_string_matching(original_text_words, constants.KEYWORDS['thanks'], min_ratio=0.85).keys()
|
||||||
- user_names_with_at_sign
|
- user_names_with_at_sign
|
||||||
- user_names_without_at_sign
|
- user_names_without_at_sign
|
||||||
- flanautils.CommonWords.words
|
- flanautils.CommonWords.words
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ HELLO_PHRASES = ('alo', 'aloh', 'buenas', 'Hola.', 'hello', 'hey', 'hi', 'hola',
|
|||||||
KEYWORDS = {
|
KEYWORDS = {
|
||||||
'activate': ('activa', 'activar', 'activate', 'deja', 'dejale', 'devuelve', 'devuelvele', 'enable', 'encender',
|
'activate': ('activa', 'activar', 'activate', 'deja', 'dejale', 'devuelve', 'devuelvele', 'enable', 'encender',
|
||||||
'enciende', 'habilita', 'habilitar'),
|
'enciende', 'habilita', 'habilitar'),
|
||||||
'bye': ('adieu', 'adio', 'adiooooo', 'adios', 'agur', 'buenas', 'bye', 'cama', 'chao', 'dias', 'farewell',
|
'bye': ('adieu', 'adio', 'adiooooo', 'adios', 'agur', 'buenas', 'bye', 'cama', 'chao', 'farewell', 'goodbye',
|
||||||
'goodbye', 'hasta', 'luego', 'noches', 'pronto', 'taluego', 'taluegorl', 'tenga', 'vemos', 'vista', 'voy'),
|
'hasta', 'luego', 'noches', 'pronto', 'taluego', 'taluegorl', 'tenga', 'vemos', 'vista', 'voy'),
|
||||||
'change': ('alter', 'alternar', 'alternate', 'cambiar', 'change', 'default', 'defecto', 'edit', 'editar',
|
'change': ('alter', 'alternar', 'alternate', 'cambiar', 'change', 'default', 'defecto', 'edit', 'editar',
|
||||||
'exchange', 'modificar', 'modify', 'permutar', 'predeterminado', 'shift', 'swap', 'switch', 'turn',
|
'exchange', 'modificar', 'modify', 'permutar', 'predeterminado', 'shift', 'swap', 'switch', 'turn',
|
||||||
'vary'),
|
'vary'),
|
||||||
@@ -96,8 +96,8 @@ KEYWORDS = {
|
|||||||
'cloudless', 'cloudy', 'cold', 'congelar', 'congelado', 'denbora', 'despejado', 'diluvio', 'frio',
|
'cloudless', 'cloudy', 'cold', 'congelar', 'congelado', 'denbora', 'despejado', 'diluvio', 'frio',
|
||||||
'frost', 'hielo', 'humedad', 'llover', 'llueva', 'llueve', 'lluvia', 'nevada', 'nieva', 'nieve',
|
'frost', 'hielo', 'humedad', 'llover', 'llueva', 'llueve', 'lluvia', 'nevada', 'nieva', 'nieve',
|
||||||
'nube', 'nubes', 'nublado', 'meteorologia', 'rain', 'snow', 'snowfall', 'snowstorm', 'sol',
|
'nube', 'nubes', 'nublado', 'meteorologia', 'rain', 'snow', 'snowfall', 'snowstorm', 'sol',
|
||||||
'solano', 'storm', 'sun', 'temperatura', 'tempo', 'tiempo', 'tormenta', 've', 'ventisca',
|
'solano', 'storm', 'sun', 'temperatura', 'tempo', 'tiempo', 'tormenta', 'ventisca', 'weather',
|
||||||
'weather', 'wetter')
|
'wetter')
|
||||||
}
|
}
|
||||||
|
|
||||||
RECOVER_PHRASES = (
|
RECOVER_PHRASES = (
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ asgiref==3.4.1
|
|||||||
async-generator==1.10
|
async-generator==1.10
|
||||||
async-timeout==3.0.1
|
async-timeout==3.0.1
|
||||||
attrs==21.4.0
|
attrs==21.4.0
|
||||||
|
beautifulsoup4==4.10.0
|
||||||
certifi==2021.10.8
|
certifi==2021.10.8
|
||||||
cffi==1.15.0
|
cffi==1.15.0
|
||||||
chardet==4.0.0
|
chardet==4.0.0
|
||||||
@@ -23,6 +24,7 @@ h11==0.12.0
|
|||||||
hachoir==3.1.2
|
hachoir==3.1.2
|
||||||
idna==3.3
|
idna==3.3
|
||||||
iso8601==1.0.2
|
iso8601==1.0.2
|
||||||
|
jellyfish==0.9.0
|
||||||
kaleido==0.2.1
|
kaleido==0.2.1
|
||||||
mpmath==1.2.1
|
mpmath==1.2.1
|
||||||
multibot
|
multibot
|
||||||
|
|||||||
0
tests/unit/__init__.py
Normal file
0
tests/unit/__init__.py
Normal file
@@ -1,16 +1,21 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import flanautils
|
||||||
|
|
||||||
|
os.environ |= flanautils.find_environment_variables('../.env')
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
from flanabot import constants
|
from multibot import constants as multibot_constants
|
||||||
import flanautils
|
from flanabot.bots.flana_tele_bot import FlanaTeleBot
|
||||||
from flanabot.bots.flana_bots.flana_tele_bot import FlanaTeleBot
|
|
||||||
|
|
||||||
|
|
||||||
class TestParseCallbacks(unittest.TestCase):
|
class TestParseCallbacks(unittest.TestCase):
|
||||||
def _test_no_always_callbacks(self, phrases: Iterable[str], callback: callable):
|
def _test_no_always_callbacks(self, phrases: Iterable[str], callback: callable):
|
||||||
for i, phrase in enumerate(phrases):
|
for i, phrase in enumerate(phrases):
|
||||||
with self.subTest(phrase):
|
with self.subTest(phrase):
|
||||||
callbacks = [registered_callback.callback for registered_callback in self.flana_tele_bot._parse_callbacks(phrase, constants.RATIO_REWARD_EXPONENT, constants.KEYWORDS_LENGHT_PENALTY, constants.MINIMUM_RATIO_TO_MATCH)
|
callbacks = [registered_callback.callback for registered_callback in self.flana_tele_bot._parse_callbacks(phrase, multibot_constants.RATIO_REWARD_EXPONENT, multibot_constants.KEYWORDS_LENGHT_PENALTY, multibot_constants.MINIMUM_RATIO_TO_MATCH)
|
||||||
if not registered_callback.always]
|
if not registered_callback.always]
|
||||||
self.assertEqual(1, len(callbacks))
|
self.assertEqual(1, len(callbacks))
|
||||||
self.assertEqual(callback, callbacks[0], f'\n\nExpected: {callback.__name__}\nActual: {callbacks[0].__name__}')
|
self.assertEqual(callback, callbacks[0], f'\n\nExpected: {callback.__name__}\nActual: {callbacks[0].__name__}')
|
||||||
@@ -111,9 +116,9 @@ class TestParseCallbacks(unittest.TestCase):
|
|||||||
|
|
||||||
def test_on_mute(self):
|
def test_on_mute(self):
|
||||||
phrases = [
|
phrases = [
|
||||||
'silencia',
|
# 'silencia',
|
||||||
'silencia al pavo ese',
|
# 'silencia al pavo ese',
|
||||||
'calla a ese pesao',
|
# 'calla a ese pesao',
|
||||||
'haz que se calle',
|
'haz que se calle',
|
||||||
'quitale el microfono a ese',
|
'quitale el microfono a ese',
|
||||||
'quitale el micro',
|
'quitale el micro',
|
||||||
@@ -124,13 +129,6 @@ class TestParseCallbacks(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
self._test_no_always_callbacks(phrases, self.flana_tele_bot._on_mute)
|
self._test_no_always_callbacks(phrases, self.flana_tele_bot._on_mute)
|
||||||
|
|
||||||
def test_on_new_message(self):
|
|
||||||
for i in range(10):
|
|
||||||
phrase = flanautils.random_string(0, 30, n_spaces=20)
|
|
||||||
with self.subTest(phrase):
|
|
||||||
callbacks = [registered_callback.callback for registered_callback in self.flana_tele_bot._parse_callbacks(phrase)]
|
|
||||||
self.assertIn(self.flana_tele_bot._on_new_message, callbacks, f'\n\nExpected: {self.flana_tele_bot._on_new_message.__name__} in {callbacks}')
|
|
||||||
|
|
||||||
def test_on_new_message_default(self):
|
def test_on_new_message_default(self):
|
||||||
phrases = [
|
phrases = [
|
||||||
'asdqwergf',
|
'asdqwergf',
|
||||||
@@ -157,7 +155,6 @@ class TestParseCallbacks(unittest.TestCase):
|
|||||||
|
|
||||||
def test_on_punish(self):
|
def test_on_punish(self):
|
||||||
phrases = [
|
phrases = [
|
||||||
'acabo con el',
|
|
||||||
'acaba con el',
|
'acaba con el',
|
||||||
'destrozalo',
|
'destrozalo',
|
||||||
'ataca',
|
'ataca',
|
||||||
@@ -169,8 +166,6 @@ class TestParseCallbacks(unittest.TestCase):
|
|||||||
'castigalo',
|
'castigalo',
|
||||||
'castiga a',
|
'castiga a',
|
||||||
'castiga',
|
'castiga',
|
||||||
'banealo',
|
|
||||||
'banea',
|
|
||||||
'enseña quien manda'
|
'enseña quien manda'
|
||||||
]
|
]
|
||||||
self._test_no_always_callbacks(phrases, self.flana_tele_bot._on_punish)
|
self._test_no_always_callbacks(phrases, self.flana_tele_bot._on_punish)
|
||||||
@@ -249,8 +244,7 @@ class TestParseCallbacks(unittest.TestCase):
|
|||||||
'perdona a',
|
'perdona a',
|
||||||
'illo quitale a @flanagan el castigo',
|
'illo quitale a @flanagan el castigo',
|
||||||
'quita castigo',
|
'quita castigo',
|
||||||
'devuelve los permisos',
|
'devuelve los permisos'
|
||||||
'desbanea'
|
|
||||||
]
|
]
|
||||||
self._test_no_always_callbacks(phrases, self.flana_tele_bot._on_unpunish)
|
self._test_no_always_callbacks(phrases, self.flana_tele_bot._on_unpunish)
|
||||||
|
|
||||||
@@ -265,6 +259,8 @@ class TestParseCallbacks(unittest.TestCase):
|
|||||||
'sol',
|
'sol',
|
||||||
'temperatura',
|
'temperatura',
|
||||||
'humedad',
|
'humedad',
|
||||||
|
'que tiempo hara mañana',
|
||||||
|
'que tiempo hara manana',
|
||||||
'que tiempo hace en malaga',
|
'que tiempo hace en malaga',
|
||||||
'que tiempo hace en calle larios',
|
'que tiempo hace en calle larios',
|
||||||
'tiempo rusia',
|
'tiempo rusia',
|
||||||
|
|||||||
Reference in New Issue
Block a user