From f808f0cff98ae5ff7f093c1b87b630184138464b Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 12 Dec 2020 23:54:17 +0100 Subject: core: move initial commands in a separate files (improve core.py SNR) --- poezio/core/command_defs.py | 442 ++++++++++++++++++++++++++++++++++++++++++++ poezio/core/commands.py | 8 + poezio/core/core.py | 324 +------------------------------- poezio/core/structs.py | 6 +- 4 files changed, 459 insertions(+), 321 deletions(-) create mode 100644 poezio/core/command_defs.py (limited to 'poezio') diff --git a/poezio/core/command_defs.py b/poezio/core/command_defs.py new file mode 100644 index 00000000..643e2289 --- /dev/null +++ b/poezio/core/command_defs.py @@ -0,0 +1,442 @@ +from poezio.core.commands import CommandCore +from poezio.core.completions import CompletionCore +from poezio.plugin_manager import PluginManager + +from typing import TypedDict, Callable, List + +CommandDict = TypedDict( + "CommandDict", + { + "name": str, + "func": Callable, + "shortdesc": str, + "desc": str, + "completion": Callable, + }, + total=False, +) + + +def get_commands(commands: CommandCore, completions: CompletionCore, plugin_manager: PluginManager) -> List[CommandDict]: + """ + Get the set of default poezio commands. + """ + return [ + { + "name": "help", + "func": commands.help, + "usage": "[command]", + "shortdesc": "\\_o< KOIN KOIN KOIN", + "completion": completions.help, + }, + { + "name": "join", + "func": commands.join, + "usage": "[room_name][@server][/nick] [password]", + "desc": ( + "Join the specified room. You can specify a nickname " + "after a slash (/). If no nickname is specified, you will" + " use the default_nick in the configuration file. You can" + " omit the room name: you will then join the room you're" + " looking at (useful if you were kicked). You can also " + "provide a room_name without specifying a server, the " + "server of the room you're currently in will be used. You" + " can also provide a password to join the room.\nExamples" + ":\n/join room@server.tld\n/join room@server.tld/John\n" + "/join room2\n/join /me_again\n/join\n/join room@server" + ".tld/my_nick password\n/join / password" + ), + "shortdesc": "Join a room", + "completion": completions.join, + }, + { + "name": "exit", + "func": commands.quit, + "desc": "Just disconnect from the server and exit poezio.", + "shortdesc": "Exit poezio.", + }, + { + "name": "quit", + "func": commands.quit, + "desc": "Just disconnect from the server and exit poezio.", + "shortdesc": "Exit poezio.", + }, + { + "name": "next", + "func": commands.rotate_rooms_right, + "shortdesc": "Go to the next room.", + }, + { + "name": "prev", + "func": commands.rotate_rooms_left, + "shortdesc": "Go to the previous room.", + }, + { + "name": "win", + "func": commands.win, + "usage": "", + "shortdesc": "Go to the specified room", + "completion": completions.win, + }, + { + "name": "w", + "func": commands.win, + "usage": "", + "shortdesc": "Go to the specified room", + "completion": completions.win, + }, + { + "name": "wup", + "func": commands.wup, + "usage": "", + "shortdesc": "Go to the tab whose name uniquely starts with prefix", + "completion": completions.win, + }, + { + "name": "move_tab", + "func": commands.move_tab, + "usage": " ", + "desc": ( + "Insert the tab at the position of " + ". This will make the following tabs shift in" + " some cases (refer to the documentation). A tab can be " + "designated by its number or by the beginning of its " + 'address. You can use "." as a shortcut for the current ' + "tab." + ), + "shortdesc": "Move a tab.", + "completion": completions.move_tab, + }, + { + "name": "destroy_room", + "func": commands.destroy_room, + "usage": "[room JID]", + "desc": ( + "Try to destroy the room [room JID], or the current" + " tab if it is a multi-user chat and [room JID] is " + "not given." + ), + "shortdesc": "Destroy a room.", + "completion": None, + }, + { + "name": "status", + "func": commands.status, + "usage": " [status message]", + "desc": ( + "Sets your availability and (optionally) your status " + 'message. The argument is one of "available' + ', chat, away, afk, dnd, busy, xa" and the optional ' + "[status message] argument will be your status message." + ), + "shortdesc": "Change your availability.", + "completion": completions.status, + }, + { + "name": "show", + "func": commands.status, + "usage": " [status message]", + "desc": ( + "Sets your availability and (optionally) your status " + 'message. The argument is one of "available' + ', chat, away, afk, dnd, busy, xa" and the optional ' + "[status message] argument will be your status message." + ), + "shortdesc": "Change your availability.", + "completion": completions.status, + }, + { + "name": "bookmark_local", + "func": commands.bookmark_local, + "usage": "[roomname][/nick] [password]", + "desc": ( + "Bookmark Local: Bookmark locally the specified room " + "(you will then auto-join it on each poezio start). This" + " commands uses almost the same syntaxe as /join. Type " + "/help join for syntax examples. Note that when typing " + '"/bookmark" on its own, the room will be bookmarked ' + "with the nickname you're currently using in this room " + "(instead of default_nick)" + ), + "shortdesc": "Bookmark a room locally.", + "completion": completions.bookmark_local, + }, + { + "name": "bookmark", + "func": commands.bookmark, + "usage": "[roomname][/nick] [autojoin] [password]", + "desc": ( + "Bookmark: Bookmark online the specified room (you " + "will then auto-join it on each poezio start if autojoin" + " is specified and is 'true'). This commands uses almost" + " the same syntax as /join. Type /help join for syntax " + 'examples. Note that when typing "/bookmark" alone, the' + " room will be bookmarked with the nickname you're " + "currently using in this room (instead of default_nick)." + ), + "shortdesc": "Bookmark a room online.", + "completion": completions.bookmark, + }, + { + "name": "accept", + "func": commands.accept, + "usage": "[jid]", + "desc": ( + "Allow the provided JID (or the selected contact " + "in your roster), to see your presence." + ), + "shortdesc": "Allow a user your presence.", + "completion": completions.roster_barejids, + }, + { + "name": "add", + "func": commands.add, + "usage": "", + "desc": ( + "Add the specified JID to your roster, ask them to" + " allow you to see his presence, and allow them to" + " see your presence." + ), + "shortdesc": "Add a user to your roster.", + }, + { + "name": "deny", + "func": commands.deny, + "usage": "[jid]", + "desc": ( + "Deny your presence to the provided JID (or the " + "selected contact in your roster), who is asking" + "you to be in their roster." + ), + "shortdesc": "Deny a user your presence.", + "completion": completions.roster_barejids, + }, + { + "name": "remove", + "func": commands.remove, + "usage": "[jid]", + "desc": ( + "Remove the specified JID from your roster. This " + "will unsubscribe you from its presence, cancel " + "its subscription to yours, and remove the item " + "from your roster." + ), + "shortdesc": "Remove a user from your roster.", + "completion": completions.remove, + }, + { + "name": "reconnect", + "func": commands.command_reconnect, + "usage": "[reconnect]", + "desc": ( + "Disconnect from the remote server if you are " + "currently connected and then connect to it again." + ), + "shortdesc": "Disconnect and reconnect to the server.", + }, + { + "name": "set", + "func": commands.set, + "usage": "[plugin|][section]