-
-
Notifications
You must be signed in to change notification settings - Fork 15
Scripts
Ghost features a scripting system which allows you to add your own features to Ghost via python code. Custom scripts use Python code allowing you to do anything you want with Ghost. As an example, you will create a simple command that responds with what you give it.
To create this script we will utilize discord.py-self's command method.
@ghost.command(name="example", description="Respond with what you want", usage="[text]", aliases=["examplecommand"])
async def example(ctx, *, text: str = "Hello World"):
await ctx.send(text)To install a custom script, open the GUI and go to the scripts page. Here you can open the scripts folder with the button next to the search bar. This is where you can put your script file. If you have any files the script uses put them in this folder too. Once you're done, restart Ghost and if the script has been setup correctly you should be able to use your command!
Ghost has a few custom variables that will allow you to interact with the config and a few other bits.
This is Ghost's config class, below are the more important classes documented, if you would like to see all classes please refer to the source code. This class allows you to interact with the config.json file!
check()
Checks the config to ensure all default keys exist and theme values are complete. Missing values are filled in with defaults.
save(notify=True)
Saves the current config to disk. Also writes tokens and notifies any subscribed components if
notifyisTrue.
get(key)
Gets the value of the given key.
Supports nested keys using dot notation, e.g."message_settings.auto_delete_delay"
set(key, value, save=True)
Sets the value of a config key and optionally saves it to disk.
Supports nested keys using dot notation.
get_theme_file(theme)
Loads and returns the raw JSON theme file by name.
save_theme_file(theme_name, new_obj)
Saves a modified theme dictionary as a theme JSON file.
get_theme(theme_name)
Returns a
Themeobject from a saved file or falls back to default if it doesn’t exist.
set_theme(theme_name, save=True)
Sets the active theme and optionally saves the config.
delete_theme(theme_name)
Deletes a saved theme. Automatically switches to the default
"ghost"theme if the deleted one was active.
get_themes()
Returns a list of all available themes as
Themeobjects.
create_theme(theme_name)
Creates a new theme using the default template. Returns a
Themeobject orFalseif it already exists.
get_sniper(sniper)
Gets a specific sniper’s settings as a
Sniperobject from the config.
get_snipers()
Returns a list of all configured snipers as
Sniperobjects.
get_rich_presence()
Returns a
RichPresenceobject configured from the current config.
get_session_spoofing()
Returns a tuple of
(enabled, device)indicating the current spoofing settings.
set_session_spoofing(enabled, device)
Sets spoofing status and device type, then saves the config.
add_command_history(command_string)
Appends a command with a timestamp to the history log file.
get_command_history()
Returns a list of all previously executed commands with timestamps.
get_scripts()
Returns a list of all
.pyfiles in thescriptsdirectory.
patch_identify(new_os)
Patches the WebSocket
identifymethod withnew_methodand sets the target platform.
OS options: (mobile,desktop,web, orembedded)
This is the bot controller, if you want to restart the bot or interact with the GUI you will use methods here.
check_token()
Checks the given token to ensure its valid or not.
start()
This starts the bot without the GUI.
stop()
This stops the bot safely.
Warning
This method does not interact with the GUI so some components may break!
restart()
This restarts the bot safely.
Warning
This method does not interact with the GUI so some components may break!
await setup_webhooks(checks=True)
This creates a dedicated server for webhooks and creates channels and webhooks.
You must setchecksto False to run this!
restart_gui()
This will safely restart the bot and GUI.
get_user_from_id(user_id)
This will return a discord.User object from the given ID.
get_avatar_from_url(url, size=50, radius=5)
This will return an ImageTK image of the given url with the set size and radius.
get_avatar(size=50, radius=5)
This will get the bot account's avatar using
get_avatar_from_urlwhich can be used in the GUI.
get_user()
Returns the bot account user object.
get_friends()
Returns the bot account's friends.
get_guilds()
Returns the bot account's guilds.
get_uptime()
Returns the bot's uptime.
get_latency()
Returns the bot's latency.
This method is used for printing to the terminal/console.
print_cmd(text)
Logs a command with prefix CMD
print_info(text)
Logs info with prefix INFO
print_success(text)
Logs success with prefix SUCCESS
print_error(text)
Logs error with prefix ERROR
print_warning(text)
Logs warning with prefix WARNING
print_cli(text)
Logs cli with prefix CLI
print_rpc(text)
Logs rpc with prefix RPC
print_sniper(sniper, title, description, success=True)
Logs sniper specific information
Success is whether or not the sniper succeeded
This method is a general helper for commands.
format_time(seconds, short_form=True)
Formats seconds into a more human readable time form.
remove_emojis(text)
Removes emojis, symbols etc.
generate_help_pages(bot, cog_name)
Generates a help page for a specific cog.
await rich_embed(ctx, embed)
This sends an embed to the rich embed webhook set in config and automatically forwards the message to the context channel.
await send_message(ctx, embed_obj: dict, extra_title="", extra_message="", delete_after=None)
This is used instead of
ctx.sendand takes an embed object and sends it either with codeblocks, images or rich embeds depending on whats set in the config.
extra_titleis put in the same codeblock next to the title
extra_messageis sent as a regular plain text message after everything
delete_afterdeletes the message after a set number of seconds. If set toNoneit uses the default auto delete delay, if set toFalseits disabled.
await send_error_message(ctx, error_text)
Uses
send_messagewith preset for error messages.
This method is used to interact with the data files used by Ghost.
resource_path(relative_path)
Use this when accessing resources that are going to be compiled with Ghost.
get_application_support()
Returns the application support/appdata/.config path.
get_data_path()
Returns the
data/folder path.
get_cache_path()
Returns the
cache/folder path.
get_themes_path()
Returns the
themes/folder path.
get_scripts_path()
Returns the
scripts/folder path.
get_config_path()
Returns the
config.jsonfile path.
get_theme_path(theme_name)
Returns the file path to the given theme_name.
open_path_in_explorer(path)
Opens a given path in the default file explorer.
open_file_in_editor(file_path)
Opens a given file in the default text editor.