add booru image search
This commit is contained in:
parent
2a98b55b8d
commit
f8051314cc
17 changed files with 1161 additions and 75 deletions
46
tgbot/shit/hentai.py
Normal file
46
tgbot/shit/hentai.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
import re
|
||||
|
||||
|
||||
def combine_whitespaces(s: str) -> str:
|
||||
return re.compile(r"\s+").sub(" ", s).strip()
|
||||
|
||||
|
||||
class QueryParams:
|
||||
def __init__(self, booru: str, tags: list[str], random: bool = True, limit: int = 10):
|
||||
self.booru = booru
|
||||
self.tags = tags
|
||||
self.random = random
|
||||
self.limit = limit
|
||||
|
||||
@classmethod
|
||||
def from_query_str(cls, query: str):
|
||||
query = query.replace("hentai ", "")
|
||||
|
||||
query = combine_whitespaces(query)
|
||||
|
||||
list_ = query.split(" ")
|
||||
|
||||
booru = list_[0]
|
||||
|
||||
list_.remove(booru)
|
||||
|
||||
tags = []
|
||||
random = False
|
||||
limit = 10
|
||||
|
||||
for e in list_:
|
||||
if "random=" in e: # this is 'random' argument
|
||||
random = e.replace("random=", "").lower() == "true"
|
||||
continue
|
||||
|
||||
if "limit=" in e: # this is 'limit' argument
|
||||
limit = int(e.replace("limit=", ""))
|
||||
continue
|
||||
|
||||
tags.append(e)
|
||||
|
||||
return cls(booru, tags, random, limit)
|
||||
|
||||
def __str__(self):
|
||||
return "QueryParams(booru=" + self.booru + ", tags=" + str(self.tags) + ", random=" + str(self.random) + \
|
||||
", limit=" + str(self.limit) + ")"
|
Loading…
Add table
Add a link
Reference in a new issue