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

Commit 93a5d57

Browse files
author
Ari Archer
committed
1.3.0 : anon api
Signed-off-by: Ari Archer <[email protected]>
1 parent daf87cd commit 93a5d57

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

awc/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from . import const, exc, util
1313

14-
__version__: typing.Final[str] = "1.2.4"
14+
__version__: typing.Final[str] = "1.3.0"
1515

1616

1717
class Awc:

awc/api.py

+16
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,19 @@ def applied(awc: Awc) -> bool:
180180
181181
awc: awc.Awc -- the awc.Awc instance to work on"""
182182
return util.resp_to_bool(awc.get(api="applied").text)
183+
184+
185+
def anon(awc: Awc, content: str) -> requests.Response:
186+
"""send message to server anonymously
187+
188+
awc: awc.Awc -- the awc.Awc instance to work on
189+
content: str -- the reason why youre applying
190+
191+
return requests.Response -- the id of the message"""
192+
193+
return awc.post(
194+
api="anon",
195+
data={
196+
"content": util.truncate(content, const.MAX_CONTENT_LEN),
197+
},
198+
)

awc/sql/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ class IpQueue(SQLTable):
137137
content: pypika.Column = t.content # type: ignore
138138

139139

140+
class AnonMsg(SQLTable):
141+
"""anonymous message table"""
142+
143+
tname: str = "anon"
144+
t: pypika.Table = pypika.Table(tname)
145+
146+
cid: pypika.Column = t.cid # type: ignore
147+
content: pypika.Column = t.content # type: ignore
148+
149+
140150
def sql(query: pypika.queries.QueryBuilder) -> str:
141151
"""return an sql query"""
142152
return query.get_sql()

awc/sql/helpers.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pypika.queries # type: ignore
88

99
from .. import const, util
10-
from . import Ban, Comment, IpQueue, IpWhitelist, delete
10+
from . import AnonMsg, Ban, Comment, IpQueue, IpWhitelist, delete
1111

1212

1313
def whitelist(author: str) -> typing.List[pypika.queries.QueryBuilder]:
@@ -100,3 +100,21 @@ def censor_comments(
100100
},
101101
)
102102
]
103+
104+
105+
def get_anon_msg(cid: int) -> typing.List[pypika.queries.QueryBuilder]:
106+
"""get an anonymous message by id
107+
108+
cid: int -- content id
109+
110+
return typing.List[pypika.queries.QueryBuilder] -- the queries"""
111+
return [AnonMsg.select(AnonMsg.cid == cid, AnonMsg.content)] # type: ignore
112+
113+
114+
def del_anon_msg(cid: int) -> typing.List[pypika.queries.QueryBuilder]:
115+
"""delete an anonymous message by id
116+
117+
cid: int -- content id
118+
119+
return typing.List[pypika.queries.QueryBuilder] -- the queries"""
120+
return [delete(AnonMsg.query(AnonMsg.cid == cid))] # type: ignore

examples/main.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ def main() -> int:
131131

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

134+
print(
135+
"anon message with id",
136+
(anon_id := int(awc.api.anon(api, infinput("anonymous message")).text)),
137+
)
138+
139+
print(
140+
"anon msg :",
141+
awc.api.sql(api, awc.sql.multisql(awc.sql.helpers.get_anon_msg(anon_id))),
142+
)
143+
144+
print("deleting the anon msg")
145+
print(awc.api.sql(api, awc.sql.multisql(awc.sql.helpers.del_anon_msg(anon_id))))
146+
134147
print("imma ban you wait")
135148
print(awc.api.sql(api, awc.sql.multisql(awc.sql.helpers.ban(author))))
136149

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

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

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

0 commit comments

Comments
 (0)