Skip to main content

DisCloud API Async Wrapper

Project description

Installing

pip install discloud

Dev installing

Note: need https://git-scm.com to download

pip install git+https://github.com/discloud/python-discloud-status@master

Usage

Get Started

First of all, you need to get your Discloud API-Token. You can create a new one by typing .api in the Discloud Server. If you're in trouble on getting your Discloud API-Token, you can DM the Ticket bot (DisCloud ModMail#6424) in the server. The supporters will be glad on helping you

Understanding the returns

Action

All methods that doesn't get information(e.g. start app/change ram/add mod) returns an Action. It has .status attribute, which is either "ok" when no issues happened, or "error" when something happened. It also contains .message attribute which is always returned when an error ocurrs, and is given on almost all actions.

Backup

Backup has a .url attribute that gives the application's backup link.

Logs

Logs has a .small attribute which returns the last ~1800 chars of your app logs, and a .full attribute that gives the complete logs

User

WIP

Application

WIP

Creating a client

import discloud
client = discloud.Client("API-Token")

Userinfo

user = await client.user_info()
print(f"ID: '{user.id}'")
plan = user.plan
print(f"Plan '{plan}'")
print(f"Expire date '{plan.expire_date}'")
print(f"Ends in '{plan.expires_in}'")
print(f"Used ram '{user.using_ram}'")
print(f"Total ram '{user.total_ram}'")
print(f"Locale '{user.locale}'")

Application

Info

bot = await client.app_info(target="APP_ID")
print(f"ID '{bot.id}'")
print(f"Status '{bot.status}'")
print(f"CPU '{bot.cpu}'")
print(f"Memory '{bot.memory}'")
print(f"Memory available '{bot.memory.available}'")
print(f"Using memory '{bot.memory.using}'")
print(f"Mem usada '{bot.memory.using}'")
print(f"SSD '{bot.ssd}'")
print(f"Download '{bot.net_info.download}'")
print(f"Upload '{bot.net_info.upload}'")
print(f"Online since '{bot.online_since}'")
print(f"Started at '{bot.start_date}'")

Logs

Client.app_logs() returns a Logs. The.logs attribute will give you the full logs content, .small_logs will give the last 1800 characters

logs = await client.logs(target="APP_ID")

print(logs.full) # complete logs
print(logs.small) # around last 1800 characters of your logs

Start/Restart/Stop

Client.start()/Client.restart()/Client.stop() returns an Action.

# note: don't expect to get the results there if you use inside of your bot since its going to get shutdown
start_result = await client.start(target="APP_ID")
restart_result = await client.restart(target="APP_ID")
stop_result = await client.stop(target="APP_ID")

print(start_result) # See if the start was successful
print(restart_result) # See if the restart was successful
print(stop_result) # See if the stop was successful

Commit

Client.commit() returns an Action.

# note: this always restart your bot so you won't get a result if its inside of your bot
file = discloud.File("eggs.zip") # Must be .zip
result = await client.commit(app_id="APP_ID", file=file)

print(result.message) # See if the commit was successful

Backup

Client.backup() returns a Backup. The .url attribute will give you the link

backup = await client.backup(target="APP_ID")
print(backup.url) # Get backup url

Update Ram

Client.ram() returns an Action.

result = await client.ram(app_id="APP_ID", NEW_RAM)
print(result.message) # See if ram memory was updated

Upload

Client.upload_app() returns an Action. Note: the .zip must have a discloud.config file, more info at documentation

result = await client.upload_app(file=discloud.File("my_bot.zip"))
print(result.message) # See if the app was successfully added

Delete

Client.delete_app() returns an Action.

result = await client.delete_app(app_id="APP_ID")
print(result.message) # See if the app was successfully deleted

Mods System

First you need to setup a specific client to manage bot mods or manage a bot as mod.

import discloud

client = discloud.Client("API-Token")
mod_client = discloud.ModManager(client, "APP_ID")

Second, be aware of what mods can currently do, actually they can have one or more of these permissions: "start_app", "stop_app", "restart_app", "logs_app", "commit_app", "edit_ram", "backup_app", "status_app"

Application Owners

To add a moderator to your app you must first have a Gold Plan or above.

Adding a moderator

ModManager.add_mod()

permissions = ["start_app"]
await mod_client.add_mod(mod_id="MOD_ID", permissions)
Removing a moderator

ModManager.remove_mod()

await mod_client.remove_mod(mod_id="MOD_ID")
Changing moderator permissions

ModManager.edit_mod_perms()

new_permissions = ["start_app", "restart_app"] # note: this remove existing perms if they are not there
await mod_client.edit_mod_perms(mod_id="MOD_ID", new_permissions)
Getting all moderators

ModManager.get_mods()

mods = await mod_client.get_mods()
print(mods) # 

Application moderators

For each command you can do you will need the respective permission as mentioned above Commands: ModManager.start(), ModManager.restart(), ModManager.stop(), ModManager.commit(), ModManager.backup(), ModManager.logs(), ModManager.ram(), ModManager.status(),

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discloud-1.0.1.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

discloud-1.0.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file discloud-1.0.1.tar.gz.

File metadata

  • Download URL: discloud-1.0.1.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for discloud-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c2ad0d24a053b4e990952fc09a84953417515c8f77216ec1e70f53b6b8a3e479
MD5 9d3b4a5f35d3b0229549899e007212ec
BLAKE2b-256 f216f2dd8961de654104aaef2cf647c3bffaabd5d7eed17b16a2fb3ea6027711

See more details on using hashes here.

File details

Details for the file discloud-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: discloud-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for discloud-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2fbf27925b5ac990a33c5da3f6a59ef5ed58bfafb5487a2a8925083380729a4
MD5 c5d57f1ba1eee11d5f809c5d49881cde
BLAKE2b-256 c8dafc6bb16764b683dd34d306819a0342b335cc8c12c355a43db4b29a9f980f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page