Skip to content

Commit

Permalink
chore(format): ruff lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
HsiangNianian committed Jun 16, 2024
1 parent e914584 commit dfec9f9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
2 changes: 0 additions & 2 deletions examples/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@

if __name__ == "__main__":
bot.run()


8 changes: 7 additions & 1 deletion hydro_roll/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
if TYPE_CHECKING:
from .typing import *


class Atien(object):
parser = argparse.ArgumentParser(description="水系终端脚手架")

Expand Down Expand Up @@ -85,7 +86,12 @@ async def _extract_package(self, data, package_name):
print(f"下载包时出错:{package_name}")

def build_template(self):
template = input("请选择应用模板(输入数字):\n" "1. 创建轻量应用\n" "2. 创建标准应用\n" "3. 创建开发应用\n")
template = input(
"请选择应用模板(输入数字):\n"
"1. 创建轻量应用\n"
"2. 创建标准应用\n"
"3. 创建开发应用\n"
)

if template == "1":
print("选择了轻量应用模板")
Expand Down
15 changes: 7 additions & 8 deletions hydro_roll/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,14 @@ def __init__(self, _path: str) -> None:
self.current_path = _path

def get_dice_dir_list(self, _prefix: str) -> list:

return [
os.path.join(self.current_path, f'{_prefix}', *dirs)
os.path.join(self.current_path, f"{_prefix}", *dirs)
for dirs in [
['config'],
['data'],
['rules'],
['scripts'],
['web', 'frontend'],
['web', 'backend'],
["config"],
["data"],
["rules"],
["scripts"],
["web", "frontend"],
["web", "backend"],
]
]
3 changes: 2 additions & 1 deletion hydro_roll/models/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import difflib
import pickle


def find_max_similarity(input_string, string_list):
max_similarity = 0
max_string = ""
Expand All @@ -11,4 +12,4 @@ def find_max_similarity(input_string, string_list):
max_similarity = similarity
max_string = string

return max_string, max_similarity
return max_string, max_similarity
2 changes: 1 addition & 1 deletion hydro_roll/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
T_Config = TypeVar("T_Config", bound="ConfigModel")

T_BotHook = Callable[["Bot"], Awaitable[NoReturn]]
T_EventHook = Callable[[T_Event], Awaitable[NoReturn]]
T_EventHook = Callable[[T_Event], Awaitable[NoReturn]]
56 changes: 35 additions & 21 deletions tests/test_sqlite3.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,78 @@
import sqlite3


class BottlePlugin:
def __init__(self):
self.conn = sqlite3.connect('bottles.db')
self.conn = sqlite3.connect("bottles.db")
self.cursor = self.conn.cursor()
self.create_table()

def create_table(self):
self.cursor.execute('''
self.cursor.execute("""
CREATE TABLE IF NOT EXISTS bottles (
id INTEGER PRIMARY KEY AUTOINCREMENT,
message TEXT NOT NULL,
sender TEXT NOT NULL,
receiver TEXT NOT NULL,
status INTEGER DEFAULT 0
);
''')
self.cursor.execute('''
""")
self.cursor.execute("""
CREATE TABLE IF NOT EXISTS comments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
bottle_id INTEGER NOT NULL,
comment TEXT NOT NULL
);
''')
self.cursor.execute('''
""")
self.cursor.execute("""
CREATE TABLE IF NOT EXISTS likes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
bottle_id INTEGER NOT NULL,
user TEXT NOT NULL
);
''')
""")
self.conn.commit()

def throw_bottle(self, message, sender):
self.cursor.execute("INSERT INTO bottles (message, sender, receiver) VALUES (?, ?, '')", (message, sender))
self.cursor.execute(
"INSERT INTO bottles (message, sender, receiver) VALUES (?, ?, '')",
(message, sender),
)
self.conn.commit()

def pick_bottle(self, receiver):
self.cursor.execute("SELECT id, message, sender FROM bottles WHERE receiver='' OR receiver=? ORDER BY RANDOM() LIMIT 1", (receiver,))
self.cursor.execute(
"SELECT id, message, sender FROM bottles WHERE receiver='' OR receiver=? ORDER BY RANDOM() LIMIT 1",
(receiver,),
)
row = self.cursor.fetchone()
if row is None:
return None
bottle_id, message, sender = row
self.cursor.execute("UPDATE bottles SET receiver=? WHERE id=?", (receiver, bottle_id))
self.cursor.execute(
"UPDATE bottles SET receiver=? WHERE id=?", (receiver, bottle_id)
)
self.conn.commit()
return {'id': bottle_id, 'message': message, 'sender': sender}
return {"id": bottle_id, "message": message, "sender": sender}

def add_comment(self, bottle_id, comment):
self.cursor.execute("INSERT INTO comments (bottle_id, comment) VALUES (?, ?)", (bottle_id, comment))
self.cursor.execute(
"INSERT INTO comments (bottle_id, comment) VALUES (?, ?)",
(bottle_id, comment),
)
self.conn.commit()

def get_comments(self, bottle_id):
self.cursor.execute("SELECT comment FROM comments WHERE bottle_id=?", (bottle_id,))
self.cursor.execute(
"SELECT comment FROM comments WHERE bottle_id=?", (bottle_id,)
)
rows = self.cursor.fetchall()
return [row[0] for row in rows]

def like_bottle(self, bottle_id, user):
self.cursor.execute("INSERT INTO likes (bottle_id, user) VALUES (?, ?)", (bottle_id, user))
self.cursor.execute(
"INSERT INTO likes (bottle_id, user) VALUES (?, ?)", (bottle_id, user)
)
self.conn.commit()

def get_likes(self, bottle_id):
Expand All @@ -71,27 +87,25 @@ def clear_bottles(self):
self.conn.commit()




plugin = BottlePlugin()

# 扔一个漂流瓶
plugin.throw_bottle('Hello, world!', 'Alice')
plugin.throw_bottle("Hello, world!", "Alice")

# 捡一个漂流瓶
bottle = plugin.pick_bottle('Bob')
bottle = plugin.pick_bottle("Bob")
if bottle is not None:
print(bottle)

# 添加评论
plugin.add_comment(1, 'Nice message!')
plugin.add_comment(1, "Nice message!")
comments = plugin.get_comments(1)
print(comments)

# 点赞
plugin.like_bottle(1, 'Charlie')
plugin.like_bottle(1, "Charlie")
likes = plugin.get_likes(1)
print(likes)

# 清空漂流瓶
# plugin.clear_bottles()
# plugin.clear_bottles()

0 comments on commit dfec9f9

Please sign in to comment.