-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
370 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
FROM python:3.9-slim as base-image | ||
ARG POETRY_VERSION=1.1.7 | ||
WORKDIR /service | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
from chatushka.bot import Chatushka | ||
from chatushka.core.bot import ChatushkaBot | ||
|
||
__all__ = ( | ||
"Chatushka", | ||
) | ||
__all__ = ("ChatushkaBot",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,5 @@ | ||
from asyncio import run | ||
from logging import DEBUG, INFO, WARNING, basicConfig, getLogger | ||
|
||
from chatushka import Chatushka | ||
from chatushka.matchers import CommandsMatcher, RegexMatcher | ||
from chatushka.samples.handlers.eight_ball import eight_ball_answer_handler, eight_ball_handler | ||
from chatushka.samples.handlers.helpers import mute_handler, suicide_handler | ||
from chatushka.samples.handlers.id import user_id_handler | ||
from chatushka.samples.handlers.jokes import jokes_handler | ||
from chatushka.samples.matchers.heroes.matchers import add_heroes_matchers | ||
from chatushka.services.mongodb.wrapper import MongoDBWrapper | ||
from chatushka.settings import get_settings | ||
|
||
logger = getLogger() | ||
settings = get_settings() | ||
|
||
|
||
def make_regex_matcher(): | ||
matcher = RegexMatcher() | ||
matcher.add_handler(r"\?", eight_ball_answer_handler) | ||
return matcher | ||
|
||
|
||
def make_commands_matcher(): | ||
matcher = CommandsMatcher( | ||
prefixes=settings.command_prefixes, | ||
postfixes=settings.command_postfixes, | ||
allow_raw=True, | ||
) | ||
matcher.add_handler("id", user_id_handler) | ||
matcher.add_handler("joke", jokes_handler) | ||
matcher.add_handler(("8ball", "ball8", "b8", "8b"), eight_ball_handler) | ||
return matcher | ||
|
||
|
||
def make_sensitive_matcher(): | ||
matcher = CommandsMatcher( | ||
prefixes=settings.command_prefixes, | ||
postfixes=settings.command_postfixes, | ||
) | ||
matcher.add_handler(("suicide", "wtf"), suicide_handler) | ||
return matcher | ||
|
||
|
||
def make_privilege_matcher(): | ||
matcher = CommandsMatcher( | ||
prefixes=settings.command_prefixes, | ||
postfixes=settings.command_postfixes, | ||
) | ||
matcher.add_handler("mute", mute_handler) | ||
return matcher | ||
|
||
|
||
def make_bot() -> Chatushka: | ||
instance = Chatushka(token=settings.token, debug=settings.debug) | ||
wrapper = MongoDBWrapper() | ||
wrapper.add_event_handlers(instance) | ||
add_heroes_matchers(instance) | ||
instance.add_matchers( | ||
make_commands_matcher(), | ||
make_sensitive_matcher(), | ||
make_privilege_matcher(), | ||
make_regex_matcher(), | ||
) | ||
return instance | ||
|
||
|
||
def main(): | ||
basicConfig(level=DEBUG if settings.debug else INFO) | ||
logger.debug("Debug mode is on".upper()) | ||
getLogger("httpx").setLevel(WARNING) | ||
bot = make_bot() | ||
run(bot.serve()) | ||
|
||
from chatushka.bot.main import cli_main | ||
|
||
# pylint: disable=no-value-for-parameter | ||
if __name__ == "__main__": | ||
main() | ||
cli_main() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from asyncio import run | ||
from logging import DEBUG, INFO, WARNING, basicConfig, getLogger | ||
|
||
from click import command, option | ||
|
||
from chatushka import ChatushkaBot | ||
from chatushka.bot.matchers import eight_ball_matchers, helpers_matcher, heroes_matchers, jokes_matcher, suicide_matcher | ||
from chatushka.bot.settings import get_settings | ||
from chatushka.core.services.mongodb.wrapper import MongoDBWrapper | ||
|
||
logger = getLogger() | ||
settings = get_settings() | ||
|
||
|
||
def make_bot( | ||
token: str, | ||
debug: bool, | ||
) -> ChatushkaBot: | ||
instance = ChatushkaBot(token=token, debug=debug) | ||
wrapper = MongoDBWrapper() | ||
wrapper.add_event_handlers(instance) | ||
|
||
instance.add_matchers( | ||
jokes_matcher, | ||
*eight_ball_matchers, | ||
helpers_matcher, | ||
*heroes_matchers, | ||
suicide_matcher, | ||
) | ||
|
||
instance.add_matchers() | ||
return instance | ||
|
||
|
||
@command() | ||
@option( | ||
"--token", | ||
"-t", | ||
required=True, | ||
) | ||
@option( | ||
"--debug/--no-debug", | ||
is_flag=True, | ||
) | ||
def cli_main( | ||
token: str, | ||
debug: bool, | ||
) -> None: | ||
basicConfig(level=DEBUG if debug else INFO) | ||
getLogger("httpx").setLevel(WARNING) | ||
logger.debug("Debug mode is on".upper()) | ||
bot = make_bot(token, debug) | ||
run(bot.serve()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from chatushka.bot.matchers.bobuk_jokes import jokes_matcher | ||
from chatushka.bot.matchers.eight_ball import eight_ball_matchers | ||
from chatushka.bot.matchers.helpers import helpers_matcher | ||
from chatushka.bot.matchers.heroes import heroes_matchers | ||
from chatushka.bot.matchers.suicide import suicide_matcher | ||
|
||
__all__ = ( | ||
"jokes_matcher", | ||
"eight_ball_matchers", | ||
"helpers_matcher", | ||
"heroes_matchers", | ||
"suicide_matcher", | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from chatushka.bot.settings import get_settings | ||
from chatushka.core.matchers import CommandsMatcher | ||
|
||
settings = get_settings() | ||
admin_matcher = CommandsMatcher( | ||
prefixes=settings.command_prefixes, | ||
postfixes=settings.command_postfixes, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 11 additions & 2 deletions
13
chatushka/samples/handlers/jokes.py → chatushka/bot/matchers/bobuk_jokes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.