added cooldown ratio to rhymes
This commit is contained in:
parent
45b6b52d10
commit
3b2633f780
15
database.py
15
database.py
@ -18,6 +18,7 @@ def ensure_db() -> None:
|
||||
guild_id TEXT PRIMARY KEY,
|
||||
guild_name TEXT NOT NULL DEFAULT '',
|
||||
cooldown_until TEXT NOT NULL DEFAULT '1970-01-01T00:00:00',
|
||||
cooldown_ratio REAL NOT NULL DEFAULT 1.0,
|
||||
self_control REAL NOT NULL DEFAULT 1.0,
|
||||
last_updated TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
)
|
||||
@ -49,7 +50,7 @@ def get_guild_state(guild_id: str) -> Dict[str, Any]:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT guild_id, guild_name, cooldown_until, self_control, last_updated
|
||||
SELECT guild_id, guild_name, cooldown_until, cooldown_ratio, self_control, last_updated
|
||||
FROM guild_state WHERE guild_id = ?
|
||||
""",
|
||||
(guild_id,),
|
||||
@ -61,6 +62,7 @@ def get_guild_state(guild_id: str) -> Dict[str, Any]:
|
||||
"guild_id": row["guild_id"],
|
||||
"guild_name": row["guild_name"],
|
||||
"cooldown_until": row["cooldown_until"],
|
||||
"cooldown_ratio": row["cooldown_ratio"],
|
||||
"self_control": row["self_control"],
|
||||
"last_updated": row["last_updated"],
|
||||
}
|
||||
@ -69,26 +71,28 @@ def get_guild_state(guild_id: str) -> Dict[str, Any]:
|
||||
"guild_id": guild_id,
|
||||
"guild_name": "",
|
||||
"cooldown_until": "1970-01-01T00:00:00",
|
||||
"cooldown_ratio": 1.0,
|
||||
"self_control": 1.0,
|
||||
"last_updated": datetime.now().isoformat(),
|
||||
}
|
||||
|
||||
|
||||
def update_guild_state(
|
||||
guild_id: str, guild_name: str, cooldown_until: str, self_control: float
|
||||
guild_id: str, guild_name: str, cooldown_until: str, cooldown_ratio: float, self_control: float
|
||||
) -> None:
|
||||
"""Update guild state in database."""
|
||||
with get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
INSERT OR REPLACE INTO guild_state (guild_id, guild_name, cooldown_until, self_control, last_updated)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
INSERT OR REPLACE INTO guild_state (guild_id, guild_name, cooldown_until, cooldown_ratio, self_control, last_updated)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
guild_id,
|
||||
guild_name,
|
||||
cooldown_until,
|
||||
cooldown_ratio,
|
||||
self_control,
|
||||
datetime.now().isoformat(),
|
||||
),
|
||||
@ -110,12 +114,13 @@ def get_all_guild_states() -> Dict[str, Dict[str, Any]]:
|
||||
with get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT guild_id, guild_name, cooldown_until, self_control, last_updated FROM guild_state"
|
||||
"SELECT guild_id, guild_name, cooldown_until, cooldown_ratio, self_control, last_updated FROM guild_state"
|
||||
)
|
||||
return {
|
||||
row["guild_id"]: {
|
||||
"guild_name": row["guild_name"],
|
||||
"cooldown_until": row["cooldown_until"],
|
||||
"cooldown_ratio": row["cooldown_ratio"],
|
||||
"self_control": row["self_control"],
|
||||
"last_updated": row["last_updated"],
|
||||
}
|
||||
|
||||
@ -84,21 +84,9 @@
|
||||
"Poil au genou."
|
||||
]
|
||||
},
|
||||
{
|
||||
"sound": "OTTE",
|
||||
"blacklist": ["glotte"],
|
||||
"keys": [
|
||||
" bot",
|
||||
"otte",
|
||||
"ott"
|
||||
],
|
||||
"rhymes": [
|
||||
"Poil à la glotte."
|
||||
]
|
||||
},
|
||||
{
|
||||
"sound": "O",
|
||||
"blacklist": ["dos"],
|
||||
"blacklist": ["dos", "bot"],
|
||||
"keys": [
|
||||
"au",
|
||||
"aux",
|
||||
@ -113,6 +101,17 @@
|
||||
"Poil au dos."
|
||||
]
|
||||
},
|
||||
{
|
||||
"sound": "OTTE",
|
||||
"blacklist": ["glotte"],
|
||||
"keys": [
|
||||
"otte",
|
||||
"ott"
|
||||
],
|
||||
"rhymes": [
|
||||
"Poil à la glotte."
|
||||
]
|
||||
},
|
||||
{
|
||||
"sound": "OUL",
|
||||
"blacklist": ["moule", "moules", "boule", "boules", "alcool"],
|
||||
|
||||
@ -89,6 +89,7 @@ async def handle_debug_commands(message, client) -> bool:
|
||||
sleeping_time = "{:.2f} s".format(time_remaining)
|
||||
dump[channel_name] = {
|
||||
"cooldown_until": state["cooldown_until"],
|
||||
"cooldown_ratio": state["cooldown_ratio"],
|
||||
"cooldown_remaining": sleeping_time,
|
||||
"self-control": state["self_control"],
|
||||
"last_updated": state["last_updated"],
|
||||
@ -129,6 +130,7 @@ async def handle_debug_commands(message, client) -> bool:
|
||||
str(message.guild.id),
|
||||
guild_name=message.guild.name,
|
||||
cooldown_until=cooldown_date.isoformat(),
|
||||
cooldown_ratio=1.0,
|
||||
self_control=2.0,
|
||||
)
|
||||
await message.channel.send("ok :'(")
|
||||
@ -156,6 +158,7 @@ async def handle_rhyme_logic(message, client) -> bool:
|
||||
guild_id,
|
||||
guild_name=guild_name,
|
||||
cooldown_until=guild_state["cooldown_until"],
|
||||
cooldown_ratio=guild_state["cooldown_ratio"],
|
||||
self_control=guild_state["self_control"],
|
||||
)
|
||||
|
||||
@ -173,6 +176,7 @@ async def handle_rhyme_logic(message, client) -> bool:
|
||||
guild_id,
|
||||
guild_name=guild_name,
|
||||
cooldown_until=now_dt.isoformat(),
|
||||
cooldown_ratio=1.0,
|
||||
self_control=new_self_control,
|
||||
)
|
||||
return False
|
||||
@ -188,6 +192,7 @@ async def handle_rhyme_logic(message, client) -> bool:
|
||||
guild_id,
|
||||
guild_name=guild_name,
|
||||
cooldown_until=new_cooldown_dt.isoformat(),
|
||||
cooldown_ratio=1.0,
|
||||
self_control=self_control + 1.0,
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user