Skip to content

Commit

Permalink
moved defining module help to the parent Module class
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Bagiński committed Jun 28, 2023
1 parent ed47cba commit 2424165
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 27 deletions.
2 changes: 0 additions & 2 deletions modules/HelpModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from textwrap import dedent

from modules.module import IntegrationTest, Module, Response
from utilities.help_utils import ModuleHelp
from utilities.serviceutils import ServiceMessage


Expand All @@ -29,7 +28,6 @@ class HelpModule(Module):

def __init__(self):
super().__init__()
self.help = ModuleHelp.from_docstring(self.class_name, __doc__)
self.re_help = re.compile(r"help \w+", re.I)

def process_message(self, message: ServiceMessage) -> Response:
Expand Down
16 changes: 3 additions & 13 deletions modules/module.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass, field
import inspect
import re
import random
from typing import Callable, Iterable, Literal, Optional, TypedDict, Union
Expand Down Expand Up @@ -130,23 +131,12 @@ class Module:
we show it to each module and ask if it can process the message,
then give it to the module that's most confident"""

# def make_module_help(
# self,
# descr: Optional[str] = None,
# capabilities: Optional[CapabilitiesDict] = None,
# ) -> ModuleHelp:
# return ModuleHelp(
# module_name=self.class_name,
# descr=descr,
# capabilities=capabilities or {},
# docstring=__doc__,
# )

def __init__(self):
self.utils = Utilities.get_instance()
self.log = get_logger()
self.re_replace = re.compile(r".*?({{.+?}})")
self.help = ModuleHelp.from_docstring(self.class_name, __doc__)
module_docstring = inspect.getmodule(self).__doc__
self.help = ModuleHelp.from_docstring(self.class_name, module_docstring)

def process_message(self, message: ServiceMessage) -> Response:
"""Handle the message, return a string which is your response.
Expand Down
2 changes: 0 additions & 2 deletions modules/question_setter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
from config import ENVIRONMENT_TYPE, coda_api_token
from modules.module import IntegrationTest, Module, Response
from utilities.discordutils import DiscordChannel
from utilities.help_utils import ModuleHelp
from utilities.serviceutils import ServiceMessage
from utilities.utilities import (
has_permissions,
Expand Down Expand Up @@ -96,7 +95,6 @@ def __init__(self) -> None:
raise Exception(exc_msg)

super().__init__()
self.help = ModuleHelp.from_docstring(self.class_name, __doc__)
self.coda_api = CodaAPI.get_instance()

self.msg_id2gdoc_links: dict[str, list[str]] = {}
Expand Down
2 changes: 0 additions & 2 deletions modules/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
meta_editing_channel_id,
)
from modules.module import Module, Response
from utilities.help_utils import ModuleHelp
from utilities.utilities import (
has_permissions,
is_in_testing_mode,
Expand Down Expand Up @@ -87,7 +86,6 @@ def __init__(self) -> None:
raise Exception(exc_msg)

super().__init__()
self.help = ModuleHelp.from_docstring(self.class_name, __doc__)
self.coda_api = CodaAPI.get_instance()

###################
Expand Down
2 changes: 0 additions & 2 deletions modules/testModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from modules.module import IntegrationTest, Module, Response
from servicemodules.serviceConstants import Services
from utilities import get_question_id, is_test_response
from utilities.help_utils import ModuleHelp
from utilities.serviceutils import ServiceMessage
from utilities.utilities import is_bot_dev

Expand All @@ -65,7 +64,6 @@ class TestModule(Module):

def __init__(self):
super().__init__()
self.help = ModuleHelp.from_docstring(self.class_name, __doc__)
self.sent_test: list[IntegrationTest] = []

def process_message(self, message: ServiceMessage) -> Response:
Expand Down
6 changes: 0 additions & 6 deletions utilities/help_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ class ModuleHelp:
The **main segment** contains an obligatory short module description (`descr`) and an optional, longer module description (`longdescr`).
The main segment is followed by one or more **command segments**, each describing one specific command or a set of related commands:
what they do and how to use them. A detailed specification of command segments can be found in the docstring of the `CommandHelp` class.
### How to add `help` to `Module`
```py
self.help = ModuleHelp.from_docstring(self.class_name, __doc__)
```
"""

module_name: str
Expand Down

0 comments on commit 2424165

Please sign in to comment.