Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
1.3.0 : anon api
Browse files Browse the repository at this point in the history
Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
  • Loading branch information
Ari Archer committed May 6, 2023
1 parent daf87cd commit 93a5d57
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion awc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from . import const, exc, util

__version__: typing.Final[str] = "1.2.4"
__version__: typing.Final[str] = "1.3.0"


class Awc:
Expand Down
16 changes: 16 additions & 0 deletions awc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,19 @@ def applied(awc: Awc) -> bool:
awc: awc.Awc -- the awc.Awc instance to work on"""
return util.resp_to_bool(awc.get(api="applied").text)


def anon(awc: Awc, content: str) -> requests.Response:
"""send message to server anonymously
awc: awc.Awc -- the awc.Awc instance to work on
content: str -- the reason why youre applying
return requests.Response -- the id of the message"""

return awc.post(
api="anon",
data={
"content": util.truncate(content, const.MAX_CONTENT_LEN),
},
)
10 changes: 10 additions & 0 deletions awc/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ class IpQueue(SQLTable):
content: pypika.Column = t.content # type: ignore


class AnonMsg(SQLTable):
"""anonymous message table"""

tname: str = "anon"
t: pypika.Table = pypika.Table(tname)

cid: pypika.Column = t.cid # type: ignore
content: pypika.Column = t.content # type: ignore


def sql(query: pypika.queries.QueryBuilder) -> str:
"""return an sql query"""
return query.get_sql()
Expand Down
20 changes: 19 additions & 1 deletion awc/sql/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pypika.queries # type: ignore

from .. import const, util
from . import Ban, Comment, IpQueue, IpWhitelist, delete
from . import AnonMsg, Ban, Comment, IpQueue, IpWhitelist, delete


def whitelist(author: str) -> typing.List[pypika.queries.QueryBuilder]:
Expand Down Expand Up @@ -100,3 +100,21 @@ def censor_comments(
},
)
]


def get_anon_msg(cid: int) -> typing.List[pypika.queries.QueryBuilder]:
"""get an anonymous message by id
cid: int -- content id
return typing.List[pypika.queries.QueryBuilder] -- the queries"""
return [AnonMsg.select(AnonMsg.cid == cid, AnonMsg.content)] # type: ignore


def del_anon_msg(cid: int) -> typing.List[pypika.queries.QueryBuilder]:
"""delete an anonymous message by id
cid: int -- content id
return typing.List[pypika.queries.QueryBuilder] -- the queries"""
return [delete(AnonMsg.query(AnonMsg.cid == cid))] # type: ignore
17 changes: 16 additions & 1 deletion examples/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ def main() -> int:

print("whoami api returned", (author := awc.api.whoami(api)))

print(
"anon message with id",
(anon_id := int(awc.api.anon(api, infinput("anonymous message")).text)),
)

print(
"anon msg :",
awc.api.sql(api, awc.sql.multisql(awc.sql.helpers.get_anon_msg(anon_id))),
)

print("deleting the anon msg")
print(awc.api.sql(api, awc.sql.multisql(awc.sql.helpers.del_anon_msg(anon_id))))

print("imma ban you wait")
print(awc.api.sql(api, awc.sql.multisql(awc.sql.helpers.ban(author))))

Expand All @@ -139,7 +152,9 @@ def main() -> int:

# dw you can whitelist too
print("lol okok wait, ill unban you :) ( i wont whitelist you bc i said so !! )")
print(awc.api.sql(api, awc.sql.multisql(awc.sql.helpers.unban(author))))
# nvm u need to unban by ip lol
# print(awc.api.sql(api, awc.sql.multisql(awc.sql.helpers.unban(author))))
print(awc.api.sql(api, "DELETE FROM bans"))

# close the connection and stuff
api.end() # note : you can also use a `with` context manager
Expand Down

0 comments on commit 93a5d57

Please sign in to comment.