from CamelCase to snake_case, update versions info, update configs, reformat imports

This commit is contained in:
Victor Kotlin 2021-09-24 19:10:00 +03:00
parent 22e90ac17e
commit 1edeac3c2b
9 changed files with 96 additions and 58 deletions

View file

@ -1,3 +1,17 @@
"""
Boticord API Wrapper
~~~~~~~~~~~~~~~~~~~
A basic wrapper for the Boticord API.
:copyright: (c) 2021 Grey Cat
:license: MIT, see LICENSE for more details.
"""
__title__ = 'boticordpy'
__author__ = 'Grey Cat'
__license__ = 'MIT'
__copyright__ = 'Copyright 2021 Grey Cat'
__version__ = '2.0.0a'
from .client import BoticordClient from .client import BoticordClient
from .webhook import BoticordWebhook from .webhook import BoticordWebhook
from .types import * from .types import *

View file

@ -1,7 +1,8 @@
from discord.ext import commands from discord.ext import commands
import aiohttp
from typing import Union from typing import Union
import asyncio import asyncio
import aiohttp
from .modules import Bots, Servers, Users from .modules import Bots, Servers, Users
@ -88,7 +89,7 @@ class BoticordClient:
if isinstance(self.bot, commands.AutoShardedBot): if isinstance(self.bot, commands.AutoShardedBot):
data_to_send["shards"] = self.bot.shard_count data_to_send["shards"] = self.bot.shard_count
await self.Bots.postStats(data_to_send) await self.Bots.post_stats(data_to_send)
if sleep_time is None: if sleep_time is None:
sleep_time = 900 sleep_time = 900

View file

@ -1,3 +1,8 @@
from aiohttp import ClientResponse
from typing import Union
import json
from . import exceptions from . import exceptions
from . import types from . import types
@ -17,3 +22,10 @@ class Config:
"delete_bot_comment": types.Comment, "delete_bot_comment": types.Comment,
"new_bot_bump": types.BotVote "new_bot_bump": types.BotVote
} }
async def _json_or_text(response: ClientResponse) -> Union[dict, str]:
text = await response.text()
if response.headers['Content-Type'] == 'application/json; charset=utf-8':
return json.loads(text)
return text

View file

@ -1,18 +1,8 @@
import json
from aiohttp import ClientResponse
from typing import Union
import aiohttp import aiohttp
import asyncio import asyncio
from ..config import Config from ..config import Config, _json_or_text
async def _json_or_text(response: ClientResponse) -> Union[dict, str]:
text = await response.text()
if response.headers['Content-Type'] == 'application/json; charset=utf-8':
return json.loads(text)
return text
class Bots: class Bots:
@ -32,7 +22,7 @@ class Bots:
self.loop = kwargs.get('loop') or asyncio.get_event_loop() self.loop = kwargs.get('loop') or asyncio.get_event_loop()
self.session = kwargs.get('session') or aiohttp.ClientSession(loop=self.loop) self.session = kwargs.get('session') or aiohttp.ClientSession(loop=self.loop)
async def getBotInfo(self, botID: int): async def get_bot_info(self, botID: int):
""" """
Returns information about discord bot with the given ID. Returns information about discord bot with the given ID.
@ -51,7 +41,7 @@ class Bots:
raise status(resp) raise status(resp)
return data return data
async def getBotComments(self, botID: int): async def get_bot_comments(self, botID: int):
""" """
Returns comments of the discord bot with the given ID. Returns comments of the discord bot with the given ID.
@ -69,7 +59,7 @@ class Bots:
raise status(resp) raise status(resp)
return data return data
async def postStats(self, stats: dict): async def post_stats(self, stats: dict):
""" """
Post stats to Boticord API. Post stats to Boticord API.

View file

@ -1,19 +1,9 @@
import json
from aiohttp import ClientResponse
from typing import Union
import aiohttp import aiohttp
import asyncio
import discord import discord
from ..config import Config import asyncio
from ..config import Config, _json_or_text
async def _json_or_text(response: ClientResponse) -> Union[dict, str]:
text = await response.text()
if response.headers['Content-Type'] == 'application/json; charset=utf-8':
return json.loads(text)
return text
class Servers: class Servers:
@ -33,7 +23,7 @@ class Servers:
self.loop = kwargs.get('loop') or asyncio.get_event_loop() self.loop = kwargs.get('loop') or asyncio.get_event_loop()
self.session = kwargs.get('session') or aiohttp.ClientSession(loop=self.loop) self.session = kwargs.get('session') or aiohttp.ClientSession(loop=self.loop)
async def getServerInfo(self, serverID: int): async def get_server_info(self, serverID: int):
""" """
Returns information about discord server with the given ID. Returns information about discord server with the given ID.
@ -51,7 +41,7 @@ class Servers:
raise status(resp) raise status(resp)
return data return data
async def getServerComments(self, serverID: int): async def get_server_comments(self, serverID: int):
""" """
Returns comments of the discord server with the given ID. Returns comments of the discord server with the given ID.
@ -69,7 +59,7 @@ class Servers:
raise status(resp) raise status(resp)
return data return data
async def postServerStats(self, message: discord.Message, custom_stats: dict = None): async def post_server_stats(self, message: discord.Message, custom_stats: dict = None):
""" """
Post server stats to Boticord API. Post server stats to Boticord API.

View file

@ -1,18 +1,8 @@
import json
from aiohttp import ClientResponse
from typing import Union
import aiohttp import aiohttp
import asyncio import asyncio
from ..config import Config from ..config import Config, _json_or_text
async def _json_or_text(response: ClientResponse) -> Union[dict, str]:
text = await response.text()
if response.headers['Content-Type'] == 'application/json; charset=utf-8':
return json.loads(text)
return text
class Users: class Users:
@ -26,7 +16,7 @@ class Users:
self.loop = kwargs.get('loop') or asyncio.get_event_loop() self.loop = kwargs.get('loop') or asyncio.get_event_loop()
self.session = kwargs.get('session') or aiohttp.ClientSession(loop=self.loop) self.session = kwargs.get('session') or aiohttp.ClientSession(loop=self.loop)
async def getUserInfo(self, userID: int): async def get_user(self, userID: int):
""" """
Returns information about discord user with the given ID. Returns information about discord user with the given ID.
@ -44,7 +34,7 @@ class Users:
raise status(resp) raise status(resp)
return data return data
async def getUserComments(self, userID: int): async def get_user_comments(self, userID: int):
""" """
Returns comments of discord user with the given ID. Returns comments of discord user with the given ID.
@ -62,7 +52,7 @@ class Users:
raise status(resp) raise status(resp)
return data return data
async def getUserBots(self, userID: int): async def get_user_bots(self, userID: int):
""" """
Returns bots of discord user with the given ID. Returns bots of discord user with the given ID.

View file

@ -1,6 +1,7 @@
from discord.ext.commands import Bot, AutoShardedBot
from aiohttp.web_urldispatcher import _WebHandler
from aiohttp import web from aiohttp import web
import aiohttp import aiohttp
from discord.ext.commands import Bot, AutoShardedBot
import sys import sys
@ -9,7 +10,6 @@ if sys.version_info >= (3, 8):
else: else:
from typing_extensions import TypedDict from typing_extensions import TypedDict
from aiohttp.web_urldispatcher import _WebHandler
from typing import Dict, Union from typing import Dict, Union
from . import BoticordClient from . import BoticordClient

View file

@ -12,6 +12,8 @@
# #
import os import os
import sys import sys
import re
sys.path.insert(0, os.path.abspath('..')) sys.path.insert(0, os.path.abspath('..'))
@ -21,8 +23,14 @@ project = 'BoticordPY'
copyright = '2021, Grey Cat' copyright = '2021, Grey Cat'
author = 'Grey Cat' author = 'Grey Cat'
# The full version, including alpha/beta/rc tags with open('../discord/__init__.py') as f:
release = '1.5' version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1)
# The full version, including alpha/beta/rc tags.
release = version
# This assumes a tag is available for final releases
branch = 'master' if version.endswith('a') else 'v' + version
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------

View file

@ -1,19 +1,52 @@
import pathlib import pathlib
from setuptools import setup from setuptools import setup
import re
# The directory containing this file
HERE = pathlib.Path(__file__).parent HERE = pathlib.Path(__file__).parent
# The text of the README file requirements = []
with open('requirements.txt') as f:
requirements = f.read().splitlines()
version = ''
with open('boticordpy/__init__.py') as f:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1)
if version.endswith(('a', 'b', 'rc')):
# append version identifier based on commit count
try:
import subprocess
p = subprocess.Popen(['git', 'rev-list', '--count', 'HEAD'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if out:
version += out.decode('utf-8').strip()
p = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if out:
version += '+g' + out.decode('utf-8').strip()
except Exception:
pass
README = (HERE / "README.md").read_text(encoding="utf8") README = (HERE / "README.md").read_text(encoding="utf8")
# This call to setup() does all the work packages = [
'boticordpy',
'boticordpy.modules'
]
setup( setup(
name="boticordpy", name="boticordpy",
packages = ['boticordpy', 'boticordpy.modules'], project_urls={
version="1.5", "Documentation": "https://py.boticord.top/en/latest/r",
description="Simple Python Module for boticord api", "Issue tracker": "https://github.com/boticord/boticordpy/issues",
},
packages=packages,
version=version,
description="A Python wrapper for Boticord api",
long_description=README, long_description=README,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",
url="https://github.com/grey-cat-1908/boticordpy", url="https://github.com/grey-cat-1908/boticordpy",
@ -25,5 +58,5 @@ setup(
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.7",
], ],
install_requires=["discord.py", "aiohttp"], install_requires=requirements,
) )