コード例 #1
0
ファイル: element.py プロジェクト: TWoolhouse/WebServer
 async def e_text(self) -> str:
     elm = (await self.dbc.select(self.dbc["Text"],
                                  db.Condition(self.eid)))()
     link = (await self.dbc.select(self.dbc["ElmTypeLink"],
                                   db.Condition(elm[0])))(0)
     text = elm[2]
     if link:
         for count, l in enumerate(link):
             text = text.replace(
                 l[2],
                 f"""<a class="link txt" href="{{{count}}}">{{{count}}}</a>""",
                 1)
         text = text.format(*map(lambda x: x[2], link))
     return text
コード例 #2
0
ファイル: element.py プロジェクト: TWoolhouse/WebServer
 async def out_text(self) -> str:
     text = (await self.dbi.select(self.dbi["Text"],
                                   db.Condition(self.eid)))()
     links = (await self.dbi.select(self.dbi["ElmTypeLink"],
                                    db.Condition(text[0])))(0)
     text = text[2]
     if links:
         links = [l[2] for l in links]
         for count, link in enumerate(links):
             text = text.replace(
                 link,
                 f"""<a class="link txt" href="{{{count}}}">{{{count}}}</a>""",
                 1)
         text = text.format(*links)
     return text
コード例 #3
0
ファイル: element.py プロジェクト: TWoolhouse/WebServer
 async def e_share(self) -> str:
     try:
         author, code, stype, msg = (await self.dbc.select(
             self.dbc["ElmTypeShare"],
             db.Condition(self.eid),
             cols=(2, 3, 4, 5)))()
         uid, uname = (await self.dbc.select(self.dbc["User"],
                                             author,
                                             cols=(1, 2)))()
         if stype == "p":
             if msg:
                 text = msg
                 index = text.index("\n") if "\n" in text else 80
                 text = [text[:index], text[index:].replace("\n", "\\n")
                         ] if len(text) > index else [text, False]
                 main, hidden = text[
                     0], f"<p class=\"show_more\" onclick=\"chat.msg.shr_more(this, \'{text[1]}\')\"> more</p>" if text[
                         1] else ""
                 msg = f"""
                 <div class="txt"><p>{main}</p>{hidden}</div>
                 """
             else:
                 msg = ""
             return f"""
             <div class="usr">
                 <img class=\"onload\" onload=\"chat.ext.mda(this, {uid}, 'p')\" src="/img/instagram/default_user.png">
                 {self.link_user(uname)}
             </div>
             <a class="link pst" href="https://instagram.com/p/{code}/">
                 <img class="post" src="https://instagram.com/p/{code}/media/?size=l" alt="This Post is Private" onerror="chat.ext.mda_err(this)">
             </a>{msg}"""
     except Exception as e:
         traceback.print_exception(e, e, e.__traceback__)
         return await self.e_error()
コード例 #4
0
    async def handle(self):
        if "s" in self.client.query:
            eid = int(self.client.query["elm"])
            if not (await self.dbi.select(self.dbi["elm save"],
                                          db.Condition(eid)))():
                await self.dbi.insert(self.dbi["elm save"], eid)
            return

        return self.client.buffer << website.buffer.Python(
            f"{website.path}page/instagram/save.html", self)
コード例 #5
0
ファイル: element.py プロジェクト: TWoolhouse/WebServer
 async def e_action(self) -> str:
     elm = (await self.dbc.select(self.dbc["ElmTypeAction"],
                                  db.Condition(self.eid)))()
     stype = elm[2]
     msg = elm[3]
     if stype == "c":  # Call
         msg = "Started" if msg == "s" else "Ended"
         return f"<p>{msg}</p><p class=\"head\"> Video Call</p>"
     elif stype == "n":  # Renaming the Group Chat
         return f"<p class=\"head\">Name:</p><p> {msg}</p>"
     elif stype in ("a", "r"):  # Add/Remove User
         stype = "Add" if stype == "a" else "Remove"
         try:
             uid = int(msg)
             u = (await self.dbc.select(self.dbc["User"],
                                        db.Condition(uid)))()
             if u:
                 msg = u[2]
         except ValueError:
             pass
         return f"<p class=\"head\">{stype} User:</p><p> {self.link_user(msg)}</p>"
コード例 #6
0
 async def likes(self) -> str:
     users = [(await self.dbi.select(self.dbi["User"], u[2]))()
              for u in (await self.dbi.select(
                  self.dbi["Like"], db.Condition(self.elm.eid)))(0)]
     images = []
     for user in users:
         images.append(
             f"""<a class="link" href="https://www.instagram.com/{user[2]}/">
         <img class="like" src="{await self.elm.profile_pic(user[1])}">
         </a>
         """)
     return "".join(images)
コード例 #7
0
ファイル: element.py プロジェクト: TWoolhouse/WebServer
 async def e_placeholder(self) -> str:
     elm = (await self.dbc.select(self.dbc["ElmTypePlaceholder"],
                                  db.Condition(self.eid)))()
     if elm[2] == "s":
         stype = "Story"
         msg = "Expired"
     else:
         stype = {"p": "Post", "i": "Image", "v": "Video"}[elm[2]]
         if " deleted" in elm[3]:
             msg = "Deleted"
         elif " private" in elm[3]:
             sta = elm[3].find("@")
             end = elm[3].find(" has")
             acc = elm[3][sta + 1:end]
             msg = f"Private {self.link_user(acc, True)}"
         else:
             msg = "Unavailable"
     return f"{stype} {msg}"
コード例 #8
0
    async def perform_search(self, user: str, text: str, date: str):
        if user:
            u = f"{user}%"
            tbla, tblb = self.dbi["User"], self.dbi["User Active"]
            await self.dbi.select(db.Join(tbla, tblb[1]),
                                  db.Condition(u, tbla[2], db.op.LIKE),
                                  db.op.OR,
                                  db.Condition(u, tbla[3], db.op.LIKE),
                                  cols=(tbla[0], ))
            user = self.dbi.fetch()
            if not user:
                self.client.session.search["err"] = f"User does not exist"
                return False
            else:
                user = user[0]

        tbla, tblb = self.dbi["Element"], self.dbi["Text"]
        cond = []
        if user:
            cond.append(db.Condition(user, tbla["user"]))
        if date:
            cond.append(db.Condition(f"{date}%", tbla["time"], db.op.LIKE))
        if text:
            if text.startswith("!"):
                etype, ename = (await self.dbi.select(
                    self.dbi["Element Type"],
                    db.Condition(f"%{text.split(' ')[0][1:].split('!')[0]}%",
                                 1,
                                 op=db.op.LIKE)))()
                tblb = self.dbi[ename]
            else:
                etype = 1
                cond.append(db.Condition(f"%{text}%", tblb["text"],
                                         db.op.LIKE))
        else:
            etype = 1
        await self.dbi.select(db.Join(tbla, tblb[1]), *cond, cols=(tbla[0], ))
        res = self.dbi.fetch(0)
        if not res:
            self.client.session.search["err"] = "No results"
            return False
        self.client.session.search["data"] = [i[0] for i in res]
        self.client.session.search["size"] = len(
            self.client.session.search["data"])
        self.client.session.search[
            "pages"] = self.client.session.search["size"] // self.BLOCK - (
                not self.client.session.search["size"] % self.BLOCK)
        return True
コード例 #9
0
ファイル: db.py プロジェクト: TWoolhouse/NEA
    async def score_list(self, type: str = "all", data=None):
        dbi = self._db("get_score")
        tu, tg, ta, ts = self._db["User"], self._db["Game"], self._db[
            "AI"], self._db["Score"]
        if type in ("user", "game", "ai"):
            tb = {"user": tu, "game": tg, "ai": ta}
            await dbi.select(
                (ts, ta, tg, tu),
                db.Condition(tb[type]["id"], data),
                cols=(tu["name"], tg["name"], ta["name"], ts["value"]),
                order=(ts["value"], -1))
        else:  # All
            await dbi.select(
                (ts, ta, tg, tu),
                cols=(tu["name"], tg["name"], ta["name"], ts["value"]),
                order=(ts["value"], -1))

        SIZE = 10
        while True:
            res = dbi.fetch(SIZE)
            yield res
            if len(res) < SIZE:
                break
コード例 #10
0
ファイル: element.py プロジェクト: TWoolhouse/WebServer
 async def e_media(self) -> str:
     elm = (await self.dbc.select(self.dbc["ElmTypeMedia"],
                                  db.Condition(self.eid)))()
     return f"""<p class="igdata onload" onload="chat.ext.mda(this, {self.eid}, 'm')" alt="Failed to Load IG Data">Loading IG Data...</p>"""
コード例 #11
0
ファイル: db.py プロジェクト: TWoolhouse/NEA
 async def ai_list(self, game: int) -> list[tuple[int, str]]:
     return (await self._db().select(self._db["Ai"],
                                     db.Condition(game, "gid"),
                                     cols=["id", "name"]))(None)
コード例 #12
0
ファイル: db.py プロジェクト: TWoolhouse/NEA
 async def user_exists(self, username: str) -> bool:
     return (await self._db().select(self._db["User"],
                                     db.Condition(username, "name"),
                                     cols=["id"]))(1)
コード例 #13
0
ファイル: db.py プロジェクト: TWoolhouse/NEA
 async def login(self, username: str, password: str) -> int:
     return (await self._db().select(self._db["User"],
                                     db.Condition(username, "name"),
                                     db.Condition(password, "password"),
                                     cols=["id"]))(1)[0]