Giter VIP home page Giter VIP logo

shad-api's Introduction

Shadpy
Shad API Framework for Python
Homepage Documentation Releases

Shad Api

Elegant, modern and asynchronous Shad API framework in Python for users and bots

Accounts

WebSocket Handler:

from shadapi import Client

app = Client('my_account_auth')

@app.handler
async def my_bot(bot, message):
    await message.reply('``Hello`` __from__ **Shad Api**!')

Messages Update Handler:

from shadapi import Client

app = Client('my_account_auth')

@app.updateHandler
async def my_bot(bot, message):
    await message.reply('``Hello`` __from__ **Shad Api**!')

OR

from shadapi import Client

app = Client('my_account_auth')

update_delay = 5 # in seconds

@app.updateHandler(update_delay)
async def my_bot(bot, message):
    await message.reply('``Hello`` __from__ **Shad Api**!')

Another example:

from shadapi import Client

app = Client("my_account_auth")

async def my_bot(bot):
    await bot.sendText('object_guid', '``Hello`` __from__ **Shad Api**!')

app.run(my_bot)

Bots Examples (ONLY FOR SPECIAL MEMBERS) (NOT TESTED)

from shadapi import Bot

app = Bot('token')

async def my_bot(bot):
    me = await bot.getMe()
    print(me)

app.run(my_bot)

OR

from shadapi import Bot

app = Bot('token')

async def my_bot(bot):
    me = await bot.sendMessage('chat_id', 'text')
    print(me)

app.run(my_bot)

Shad-Api is a modern, elegant and asynchronous framework. It enables you to easily interact with the main Shad API through a user account (custom client) or a bot identity (bot API alternative) using Python.

Key Features

  • Ready: Install Shad-Api with pip and start building your applications right away.
  • Easy: Makes the Shad API simple and intuitive, while still allowing advanced usages.
  • Elegant: Low-level details are abstracted and re-presented in a more convenient way.
  • Fast: Boosted up by pycryptodome, a high-performance cryptography library written in C.
  • Async: Fully asynchronous (also usable synchronously if wanted, for convenience).
  • Powerful: Full access to Shad's API to execute any official client action and more.

Setup

Installation

pip3 install shadapi

Obtaining the User token

(Note: this process has to be done in a pc)

  1. Enter Web Shad
  2. After logging in, press F12 or Ctrl-Shift-I to enter the devtools
  3. Open the "Network" tab
  4. Open a chat or send a message to log it in devtools
  5. Select a request from the list which it's domain starts with "shadmessenger"
  6. Inside the "Request" tab, there is a part called "auth" which stores your token in a string type

Notes

broken message handler

when using this library for fethcing messages from a chat, the library will start a WebSocket channel with the server, and because of the present lag in the server, some of the messages will not be sent by the server and wont be processed by the client (this is not an issue with the library, it's from the server! this problem also do exist in the Android and Web versions of Shad) we can kindof fix this problem by loading every last message every once in a while to ensure that the client have recived every message, but this would make the bot use more internet (around 277MB per day for maden requests every 2 seconds). the problem with this bypass is that the server would consider that as "request spam" (aka DDOS) and will refuse to response to most of the requests, and this would make the bot pretty much slower! i did implement this functionality in the library and with the addition of "request delay", but until shad devs fix the main issue inside the server or until i find an actuall bypass solution, this are the only ways to handle messages in this library.

Request method advantages disadvantage
WebSocket syncing instant trigger ignores most messages
getChatUpdates request triggers on every message slow trigger

Thanks to:

shayanheidari01

he did an awesome job at making a rubika library which helped alot to make this project! https://github.com/shayanheidari01/rubika

shad-api's People

Contributors

hoseanrc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

shad-api's Issues

NotRegistered Error

Hello
I am using this package for the first time, when I insert my auth token and run my project, I get "shadapi.exceptions.NotRegistered:" error.

`from shadapi import Client

app = Client("******************************")

async def my_bot(bot):
await bot.sendText('object_guid', 'Hello from Shad Api!')

app.run(my_bot)`

Error:

(venv) C:\Users\MHany\Desktop\AdabBot>c:/Users/MHany/Desktop/AdabBot/venv/Scripts/python.exe c:/Users/MHany/Desktop/AdabBot/test.py Traceback (most recent call last): File "c:\Users\MHany\Desktop\AdabBot\test.py", line 8, in <module> app.run(my_bot) File "c:\Users\MHany\Desktop\AdabBot\venv\Lib\site-packages\shadapi\accounts\_client.py", line 439, in run RUN(runner()) File "C:\Program Files\Python311\Lib\asyncio\runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Program Files\Python311\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "c:\Users\MHany\Desktop\AdabBot\venv\Lib\site-packages\shadapi\accounts\_client.py", line 438, in runner await func(methods) File "c:\Users\MHany\Desktop\AdabBot\test.py", line 6, in my_bot await bot.sendText('object_guid', '``Hello`` __from__ **Shad Api**!') File "c:\Users\MHany\Desktop\AdabBot\venv\Lib\site-packages\shadapi\accounts\methods\__init__.py", line 140, in sendText data = await self.make.request( ^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\MHany\Desktop\AdabBot\venv\Lib\site-packages\shadapi\accounts\methods\__init__.py", line 55, in request raise NotRegistered('Your AUTH is incorrect') shadapi.exceptions.NotRegistered: Your AUTH is incorrect

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.