2.2.2a version (test docs)

This commit is contained in:
grey-cat-1908 2022-09-10 15:00:26 +03:00
parent 45b04409d4
commit 35dbb2a6b8
14 changed files with 147 additions and 212 deletions

View file

@ -10,7 +10,7 @@ __title__ = "boticordpy"
__author__ = "Marakarka" __author__ = "Marakarka"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright 2022 Marakarka" __copyright__ = "Copyright 2022 Marakarka"
__version__ = "2.2.1" __version__ = "2.2.2a"
from .client import BoticordClient from .client import BoticordClient
from .webhook import Webhook from .webhook import Webhook

View file

@ -11,10 +11,10 @@ class BoticordClient:
.. warning:: .. warning::
In BotiCord API v2 there are some changes with token. In BotiCord API v2 there are some changes with token.
[Read more here](https://docs.boticord.top/topics/v1vsv2/) `Read more here <https://docs.boticord.top/topics/v1vsv2/>`_
Note: Note:
Remember that every http method can return http exception. Remember that every http method can return an http exception.
Args: Args:
token (:obj:`str`) token (:obj:`str`)
@ -111,6 +111,8 @@ class BoticordClient:
async def post_server_stats(self, payload: dict) -> dict: async def post_server_stats(self, payload: dict) -> dict:
"""Post Server's stats. You must be Boticord-Service bot. """Post Server's stats. You must be Boticord-Service bot.
Payload is raw, because if you use it - you know what you are doing.
You can find more information about payload `in BotiCord API Docs <https://docs.boticord.top/methods/servers/>`_
Args: Args:
payload (:obj:`dict`) payload (:obj:`dict`)
@ -183,7 +185,9 @@ class BoticordClient:
else boticord_types.ShortedLink(**response[0]) else boticord_types.ShortedLink(**response[0])
) )
async def create_shorted_link(self, *, code: str, link: str, domain: boticord_types.LinkDomain = 1): async def create_shorted_link(
self, *, code: str, link: str, domain: boticord_types.LinkDomain = 1
):
"""Creates new shorted link """Creates new shorted link
Args: Args:
@ -202,7 +206,9 @@ class BoticordClient:
return boticord_types.ShortedLink(**response) return boticord_types.ShortedLink(**response)
async def delete_shorted_link(self, code: str, domain: boticord_types.LinkDomain = 1): async def delete_shorted_link(
self, code: str, domain: boticord_types.LinkDomain = 1
):
"""Deletes shorted link """Deletes shorted link
Args: Args:
@ -217,7 +223,7 @@ class BoticordClient:
""" """
response = await self.http.delete_shorted_link(code, domain) response = await self.http.delete_shorted_link(code, domain)
return response.get('ok', False) return response.get("ok", False)
def autopost(self) -> AutoPost: def autopost(self) -> AutoPost:
"""Returns a helper instance for auto-posting. """Returns a helper instance for auto-posting.

View file

@ -103,7 +103,9 @@ class HttpClient:
def create_shorted_link(self, code: str, link: str, *, domain: LinkDomain = 1): def create_shorted_link(self, code: str, link: str, *, domain: LinkDomain = 1):
"""Create new shorted link""" """Create new shorted link"""
return self.make_request( return self.make_request(
"POST", "links/create", json={"code": code, "link": link, "domain": int(domain)} "POST",
"links/create",
json={"code": code, "link": link, "domain": int(domain)},
) )
def delete_shorted_link(self, code: str, domain: LinkDomain = 1): def delete_shorted_link(self, code: str, domain: LinkDomain = 1):

View file

@ -348,9 +348,6 @@ class LinkDomain(IntEnum):
BCORD_CC = 1 BCORD_CC = 1
"""``bcord.cc`` domain, default""" """``bcord.cc`` domain, default"""
MYSERVERS_ME = 2
"""``myservers.me`` domain"""
DISCORD_CAMP = 3 DISCORD_CAMP = 3
"""``discord.camp`` domain""" """``discord.camp`` domain"""

View file

@ -1,2 +1,2 @@
sphinx_rtd_theme sphinxawesome_theme
sphinx sphinx

View file

@ -8,8 +8,6 @@ API Reference
API Reference for the boticordpy Module API Reference for the boticordpy Module
Index:
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2

View file

@ -2,5 +2,7 @@
Models API Reference Models API Reference
#################### ####################
We recommend you to read the `boticordpy/types.py <https://github.com/boticord/boticordpy/blob/master/boticordpy/types.py>`_ file, because it is much easier to read than here.
.. automodule:: boticordpy.types .. automodule:: boticordpy.types
:members: :members:

View file

@ -22,12 +22,12 @@ import os
sys.path.insert(0, os.path.abspath("../..")) sys.path.insert(0, os.path.abspath("../.."))
project = 'BoticordPY' project = "BoticordPY"
copyright = '2022, Victor Kotlin (Marakarka)' copyright = "2022, Victor Kotlin (Marakarka)"
author = 'Victor Kotlin (Marakarka)' author = "Victor Kotlin (Marakarka)"
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = '2.0.0' release = "2.2.2a"
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
@ -44,7 +44,7 @@ extensions = [
] ]
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ["_templates"]
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
@ -62,17 +62,15 @@ intersphinx_mapping = {
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
# #
html_theme = "sphinx_rtd_theme" html_theme = "sphinxawesome_theme"
html_theme_options = { html_theme_options = {}
}
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
# so a file named "custom.css" will overwrite the builtin "custom.css". # so a file named "custom.css" will overwrite the builtin "custom.css".
html_static_path = ['_static'] html_static_path = ["_static"]
def setup(app): def setup(app):
app.add_css_file('custom.css') app.add_css_file("custom.css")

View file

@ -9,25 +9,22 @@ Other Information
Listeners Listeners
########## ##########
List of listeners for webhooks When you work with BotiCord Webhooks you may receive a lot of events.
To make it easier to handle them there is a list of the events you can receive:
+------------------------+----------------------------------+ .. csv-table::
| Boticord Events | Meaning | :header: "BotiCord Events", "Meaning"
+========================+==================================+ :widths: 20, 20
| new_bot_comment | On new bot comment |
+------------------------+----------------------------------+ "test_webhook_message", "Test message."
| edit_bot_comment | On bot comment edit | "new_bot_comment", "On new bot comment"
+------------------------+----------------------------------+ "edit_bot_comment", "On bot comment edit"
| delete_bot_comment | On bot comment delete | "delete_bot_comment", "On bot comment delete"
+------------------------+----------------------------------+ "new_bot_bump", "On new bot bump"
| new_bot_bump | On new bot bump | "new_server_comment", "On new server comment"
+------------------------+----------------------------------+ "edit_server_comment", "On server comment edit"
| new_server_comment | On new server comment | "delete_server_comment", "On server comment delete"
+------------------------+----------------------------------+ "new_server_bump", "On new server bump"
| edit_server_comment | On server comment edit |
+------------------------+----------------------------------+
| delete_server_comment | On server comment delete |
+------------------------+----------------------------------+
################## ##################

View file

@ -5,7 +5,7 @@
Quickstart Quickstart
========== ==========
**For more examples or information about other features check Github-Repo.** **For some examples or information about other features check our Github-Repo.**
Installation Installation
------------ ------------
@ -24,63 +24,3 @@ Enter one of these commands to install the library:
Or just clone the repo: https://github.com/boticord/boticordpy Or just clone the repo: https://github.com/boticord/boticordpy
Examples
-------------------------
**Discord.py Autopost example**
::
from discord.ext import commands
from boticordpy import BoticordClient
bot = commands.Bot(command_prefix="!")
async def get_stats():
return {"servers": len(bot.guilds), "shards": 0, "users": len(bot.users)}
async def on_success_posting():
print("stats posting successfully")
boticord_client = BoticordClient("your_api_token")
autopost = (
boticord_client.autopost()
.init_stats(get_stats)
.on_success(on_success_posting)
.start()
)
bot.run("bot token")
..
**Discord.py Webhooks example**
::
from discord.ext import commands
from boticordpy import webhook
bot = commands.Bot(command_prefix="!")
async def edit_bot_comment(data):
print(data.comment.new)
boticord_webhook = webhook.Webhook("x-hook-key", "bot").register_listener("edit_bot_comment", edit_bot_comment)
boticord_webhook.start(5000)
bot.run("bot token")
..

View file

@ -1,21 +1,24 @@
# You can use disnake or nextcord or something like this. # You can use any library to interact with the Discord API.
# (THIS EXAMPLE IS NOT TESTED. IF YOU HAVE ANY PROBLEMS - ASK DEVELOPER PLEASE) # This example uses discord.py.
# You can install it with `pip install discord.py`.
from discord.ext import commands from discord.ext import commands
from boticordpy import BoticordClient from boticordpy import BoticordClient
bot = commands.Bot(command_prefix="!") bot = commands.Bot(command_prefix="!")
# Function that will return the current bot's stats.
async def get_stats(): async def get_stats():
return {"servers": len(bot.guilds), "shards": 0, "users": len(bot.users)} return {"servers": len(bot.guilds), "shards": 0, "users": len(bot.users)}
# Function that will be called if stats are posted successfully.
async def on_success_posting(): async def on_success_posting():
print("stats posting successfully") print("stats posting successfully")
boticord_client = BoticordClient("your_api_token")
boticord_client = BoticordClient("your_api_token", version=2)
autopost = ( autopost = (
boticord_client.autopost() boticord_client.autopost()
.init_stats(get_stats) .init_stats(get_stats)

View file

@ -1,7 +1,8 @@
# You can use disnake or nextcord or something like this. # You can use any library to interact with the Discord API.
# This example uses discord.py.
# You can install it with `pip install discord.py`.
from discord.ext import commands from discord.ext import commands
from boticordpy import webhook from boticordpy import webhook
bot = commands.Bot(command_prefix="!") bot = commands.Bot(command_prefix="!")
@ -10,7 +11,10 @@ bot = commands.Bot(command_prefix="!")
async def edit_bot_comment(data): async def edit_bot_comment(data):
print(data.comment.new) print(data.comment.new)
boticord_webhook = webhook.Webhook("x-hook-key", "bot").register_listener("edit_bot_comment", edit_bot_comment)
boticord_webhook = webhook.Webhook("x-hook-key", "bot").register_listener(
"edit_bot_comment", edit_bot_comment
)
boticord_webhook.start(5000) boticord_webhook.start(5000)
bot.run("bot token") bot.run("bot_token")

View file

@ -5,24 +5,32 @@ import re
HERE = pathlib.Path(__file__).parent HERE = pathlib.Path(__file__).parent
with open('boticordpy/__init__.py') as f: with open("boticordpy/__init__.py") as f:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1) version = re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE
).group(1)
if version.endswith(('a', 'b', 'rc')): if version.endswith(("a", "b", "rc")):
# append version identifier based on commit count # append version identifier based on commit count
try: try:
import subprocess import subprocess
p = subprocess.Popen(['git', 'rev-list', '--count', 'HEAD'], p = subprocess.Popen(
stdout=subprocess.PIPE, stderr=subprocess.PIPE) ["git", "rev-list", "--count", "HEAD"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out, err = p.communicate() out, err = p.communicate()
if out: if out:
version += out.decode('utf-8').strip() version += out.decode("utf-8").strip()
p = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], p = subprocess.Popen(
stdout=subprocess.PIPE, stderr=subprocess.PIPE) ["git", "rev-parse", "--short", "HEAD"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out, err = p.communicate() out, err = p.communicate()
if out: if out:
version += '+g' + out.decode('utf-8').strip() version += "+g" + out.decode("utf-8").strip()
except Exception: except Exception:
pass pass

View file

@ -7,111 +7,91 @@ single_comment_dict = {
"text": "aboba", "text": "aboba",
"vote": 1, "vote": 1,
"isUpdated": False, "isUpdated": False,
"createdAt": 1644388399 "createdAt": 1644388399,
} }
bot_data_dict = { bot_data_dict = {
"id": "724663360934772797", "id": "724663360934772797",
"shortCode": "kerdoku", "shortCode": "kerdoku",
"links": ["https://boticord.top/bot/724663360934772797", "links": [
"https://bcord.cc/b/724663360934772797", "https://boticord.top/bot/724663360934772797",
"https://myservers.me/b/724663360934772797", "https://bcord.cc/b/724663360934772797",
"https://boticord.top/bot/kerdoku", "https://myservers.me/b/724663360934772797",
"https://bcord.cc/b/kerdoku", "https://boticord.top/bot/kerdoku",
"https://myservers.me/b/kerdoku"], "https://bcord.cc/b/kerdoku",
"server": { "https://myservers.me/b/kerdoku",
"id": "724668798874943529", ],
"approved": True "server": {"id": "724668798874943529", "approved": True},
}, "information": {
"information": { "bumps": 37,
"bumps": 37, "added": 1091,
"added": 1091, "prefix": "?",
"prefix": "?", "permissions": 1544023111,
"permissions": 1544023111, "tags": ["комбайн", "экономика", "модерация", "приветствия"],
"tags": [ "developers": ["585766846268047370"],
"комбайн", "links": {"discord": "5qXgJvr", "github": None, "site": "https://kerdoku.top"},
"экономика", "library": "discordpy",
"модерация", "shortDescription": "Удобный и дружелюбный бот, который имеет крутой функционал!",
"приветствия" "longDescription": "wow",
], "badge": None,
"developers": ["585766846268047370"], "stats": {"servers": 2558, "shards": 3, "users": 348986},
"links": { "status": "APPROVED",
"discord": "5qXgJvr", },
"github": None,
"site": "https://kerdoku.top"
},
"library": "discordpy",
"shortDescription": "Удобный и дружелюбный бот, который имеет крутой функционал!",
"longDescription": "wow",
"badge": None,
"stats": {
"servers": 2558,
"shards": 3,
"users": 348986
},
"status": "APPROVED"
}
} }
server_data_dict = { server_data_dict = {
"id": "722424773233213460", "id": "722424773233213460",
"shortCode": "boticord", "shortCode": "boticord",
"status": "ACCEPT_MEMBERS", "status": "ACCEPT_MEMBERS",
"links": [ "links": [
"https://boticord.top/server/722424773233213460", "https://boticord.top/server/722424773233213460",
"https://bcord.cc/s/722424773233213460", "https://bcord.cc/s/722424773233213460",
"https://myservers.me/s/722424773233213460", "https://myservers.me/s/722424773233213460",
"https://boticord.top/server/boticord", "https://boticord.top/server/boticord",
"https://bcord.cc/s/boticord", "https://bcord.cc/s/boticord",
"https://myservers.me/s/boticord" "https://myservers.me/s/boticord",
], ],
"bot": { "bot": {"id": None, "approved": False},
"id": None, "information": {
"approved": False "name": "BotiCord Community",
}, "avatar": "https://cdn.discordapp.com/icons/722424773233213460/060188f770836697846710b109272e4c.webp",
"information": { "members": [438, 0],
"name": "BotiCord Community", "bumps": 62,
"avatar": "https://cdn.discordapp.com/icons/722424773233213460/060188f770836697846710b109272e4c.webp", "tags": [
"members": [ "аниме",
438, "игры",
0 "поддержка",
], "комьюнити",
"bumps": 62, "сообщество",
"tags": [ "discord",
"аниме", "дискорд сервера",
"игры", "дискорд боты",
"поддержка", ],
"комьюнити", "links": {
"сообщество", "invite": "hkHjW8a",
"discord", "site": "https://boticord.top/",
"дискорд сервера", "youtube": None,
"дискорд боты" "twitch": None,
], "steam": None,
"links": { "vk": None,
"invite": "hkHjW8a", },
"site": "https://boticord.top/", "shortDescription": "short text",
"youtube": None, "longDescription": "long text",
"twitch": None, "badge": "STAFF",
"steam": None, },
"vk": None
},
"shortDescription": "short text",
"longDescription": "long text",
"badge": "STAFF"
}
} }
user_profile_dict = { user_profile_dict = {
"id": '178404926869733376', "id": "178404926869733376",
"status": '"Если вы не разделяете мою точку зрения, поздравляю — вам больше достанется." © Артемий Лебедев', "status": '"Если вы не разделяете мою точку зрения, поздравляю — вам больше достанется." © Артемий Лебедев',
"badge": 'STAFF', "badge": "STAFF",
"shortCode": 'cipherka', "shortCode": "cipherka",
"site": 'https://sqdsh.top/', "site": "https://sqdsh.top/",
"vk": None, "vk": None,
"steam": 'sadlycipherka', "steam": "sadlycipherka",
"youtube": None, "youtube": None,
"twitch": None, "twitch": None,
"git": 'https://git.sqdsh.top/me' "git": "https://git.sqdsh.top/me",
} }