Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesigned for plugins and aliases support #19

Merged
merged 14 commits into from
Feb 27, 2023
Merged

Conversation

kolayne
Copy link
Owner

@kolayne kolayne commented Jan 17, 2023

Decomposed Rimokon code into core and plugins. Introduced aliases.

Resolves #13

- Invalidate most of the readme
- Update the filetree to match the upcoming updates
- Minor updates to the files to preserve the bot functioning
The core part of the bot does not handle it in a proper plugin manner
(yet), but it's going to be fixed in the next commit(s)
Implemented the action lookup function that will be used to find the
action function corresponding to received commands.
Added terminology.txt (temp file) that states the differences between
plugin, action, and command.
Implemented the run-rawrun-shell functionality as a plugin, represented
key/type actions through that plugin implementation and made use of them
in the main file, dropping their previous implementations;

Added plugin helpers, which currently contain decorators for notifying
of action execution;

Removed dangling stuff from Rimokon/__main__.py and Rimokon/__util__.py.
Fixed a missing import; fixed bugs in `cmd_get_*`, extended
`cmd_get_rest` to preserve whitespace when requested.
In import_config.py implemented importing config and canonicalizing
actions and aliases defined in it.
The long description at config.py.example are going to be moved to
Wikis (#18)
One more step on the way to #15
@kolayne kolayne self-assigned this Jan 17, 2023
@kolayne
Copy link
Owner Author

kolayne commented Jan 17, 2023

Oops, forgot about the README and the /help command

+ removed the temporary terminology.txt
Generate help message from the enabled actions and aliases.

Modified and moved /start message, fixed #16
@kolayne kolayne force-pushed the redesgin_for_plugins branch from 610a93e to ce2056d Compare January 17, 2023 16:22
Pylint reports unexpected keyword argument "notify"
Copy link
Owner Author

@kolayne kolayne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are things to fix

Rimokon/util.py Outdated

def cmd_get_rest(s: str, cut_first_whitespace: bool = True) -> str:
"""
Cut the first word of the string and (optionally, default) the first whitespace symbol after it.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cut the first word of the string and (optionally, default) the first whitespace symbol after it.
Cut the first word of the string and, optionally, the first whitespace symbol after it (default).

README.md Outdated
[@myidbot](https://t.me/myidbot).
- Copy `Rimokon/config.py.example` to `Rimokon/config.py` and modify it according to your use case.
Optionally, install `xdotool`/`ydotool` or a similar utility for graphics interaction.
Use [@BotFather
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?..



# Decorator that prevents the actions when executed by a non-admin user.
# Must be specified UNDER the `@bot.*_handler` decorator (must be applied before it)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Must be specified UNDER the `@bot.*_handler` decorator (must be applied before it)
# Must be specified UNDER the `@bot.*_handler` decorator (that is, be applied before it)

# It is an array of arrays of strings. Second-level arrays represent lines of keyboard (top-to-bottom),
# strings in them are the commands for the keyboard.
#
# `quick_access_cmds` can be empty (or completely omitted in the config), but its subarrays and the strings
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be omitted any longer, can it?

Comment on lines 26 to 27
# TODO: use logger object
logger.critical(*args)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO: use logger object
logger.critical(*args)
logger.critical(*args)

Rimokon/import_config.py Show resolved Hide resolved
Comment on lines 99 to 102
if k in updated_aliases.keys():
die('Attempt to redefine alias %s (in `config.aliases`)', repr(k))
if k in updated_actions.keys():
die('Alias %s attempts to overwrite an existing action', repr(k_))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this error messages look more similar

if k in updated_actions.keys():
die('Alias %s attempts to overwrite an existing action', repr(k_))
if isinstance(v_, str):
base_plugin = cmd_get_action_name(v_)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • base_action_name?

Rimokon/import_config.py Show resolved Hide resolved

Modifes an action function (which accepts `telebot.TeleBot` and `telebot.Message` as its
first position arguments) such that an additional kw-only argument `notify` is added to
the function. If it is `True` (default), the behavior is the same with `notify_of_execution`;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
the function. If it is `True` (default), the behavior is the same with `notify_of_execution`;
the function. If it is `True` (default), the behavior is the same as with `notify_of_execution`;

But maybe it's better to elaborate on the behavior instead of referring to another function

aliases = {
# A "simple alias" (or "string alias") just expands the given action name in the beginning of the
# received commands to the value. Notice that it is interpreted just like other action names,
# i.e. letters lower/upper case or trailing slashes do not matter.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# i.e. letters lower/upper case or trailing slashes do not matter.
# i.e. letters lower/upper case or leading slashes do not matter.

else:
die('The alias %s specifies neither a string nor a callable object', repr(k_))
# Note: the above checks are not comprehensive, as the function isn't ensured to
# accept the correct set of parameters.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's unclear what function we are talking about

@kolayne kolayne force-pushed the redesgin_for_plugins branch from 0eef5f0 to 3e92662 Compare February 27, 2023 14:24
@kolayne kolayne merged commit 461cf05 into master Feb 27, 2023
@kolayne kolayne deleted the redesgin_for_plugins branch February 27, 2023 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command aliases
1 participant