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