Skip to content

Commit

Permalink
Bugfixes + new features (#42)
Browse files Browse the repository at this point in the history
* better formatting

* op variable in classes

to be able to replay events in the future

* Update client.py

* inline added to add_field

* bugfixes + version tag added to user-agent.
  • Loading branch information
erik-thorsell authored Jun 29, 2023
1 parent 960362c commit ef17132
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions nextguild/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
from .classes import Data
from .embed import Embed

version = '1.2.8'

class Client:
def __init__(self, token: str) -> None:
self.token = token
self.headers = {
'Authorization': f'Bearer {self.token}',
'User-Agent': 'NextGuild/1.0',
'User-Agent': f'NextGuild/{version}',
'Content-type': 'application/json',
'Accept': 'application/json'
}
Expand Down Expand Up @@ -117,7 +118,7 @@ def send_message(
url=f'{self.base_url}/channels/{channel_id}/messages',
json=payload
)
return Data(response)
return response

def edit_message(
self,
Expand Down Expand Up @@ -166,7 +167,7 @@ def get_message(
'GET',
f'{self.base_url}/channels/{channel_id}/messages/{message_id}'
)
return Data(response)
return response

def get_channel_messages(
self,
Expand Down
14 changes: 8 additions & 6 deletions nextguild/embed.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
class EmbedField:
def __init__(self, name: str, value: str):
def __init__(self, name: str, value: str, inline: bool = False):
super().__init__()
self.name = name
self.value = value
self.inline = inline


class Embed:
Expand Down Expand Up @@ -41,9 +42,9 @@ def __init__(
if fields:
for field in fields:
if isinstance(field, EmbedField):
self.add_field(field.name, field.value)
self.add_field(field.name, field.value, field.inline)
elif isinstance(field, dict):
self.add_field(field.get('name'), field.get('value'))
self.add_field(field.get('name'), field.get('value'), field.get('inline'))

@property
def to_dict(self) -> dict:
Expand Down Expand Up @@ -84,7 +85,7 @@ def to_dict(self) -> dict:

fields_list = []
for field in self.__fields:
fields_list.append({'name': field.name, 'value': field.value})
fields_list.append({'name': field.name, 'value': field.value, 'inline': field.inline})
embed.update({'fields': fields_list})

return embed
Expand All @@ -93,8 +94,9 @@ def to_dict(self) -> dict:
def fields(self) -> list:
return self.__fields

def add_field(self, name: str, value: str) -> None:
self.__fields.append(EmbedField(name, value))
def add_field(self, name: str, value: str, inline: bool = False) -> None:
inline = str(inline).lower()
self.__fields.append(EmbedField(name, value, inline))

def remove_field(self, index: int) -> None:
self.__fields.pop(index)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "nextguild"
version = "1.2.7"
version = "1.2.8"
authors = [
{ name="Arjun Sharda", email="[email protected]" },
{ name="Erik Thorsell", email="[email protected]" },
Expand Down

0 comments on commit ef17132

Please sign in to comment.