Browse Source

Configurable tinydb path

master
Giuseppe Guerra 4 months ago
parent
commit
da366ab731
4 changed files with 12 additions and 7 deletions
  1. +2
    -1
      fokabot.py
  2. +4
    -4
      plugins/faq.py
  3. +4
    -2
      singletons/bot.py
  4. +2
    -0
      singletons/config.py

+ 2
- 1
fokabot.py View File

@@ -67,7 +67,8 @@ def main() -> None:
redis_port=Config()["REDIS_PORT"],
redis_database=Config()["REDIS_DATABASE"],
redis_password=Config()["REDIS_PASSWORD"],
redis_pool_size=Config()["REDIS_POOL_SIZE"]
redis_pool_size=Config()["REDIS_POOL_SIZE"],
tinydb_path=Config()["TINYDB_PATH"],
)
# Register all events
import events


+ 4
- 4
plugins/faq.py View File

@@ -20,7 +20,7 @@ async def faq(topic: str) -> str:
:param topic: FAQ topic name. Will get it from FokaBot's tinydb
:return: the topic content, if it exists, or an error message
"""
async with AIOTinyDB(".db.json") as db:
async with AIOTinyDB(bot.tinydb_path) as db:
results = db.table("faq").search(where("topic") == topic)
if results:
return results[0]["response"]
@@ -43,7 +43,7 @@ async def mod_faq(topic: str, new_response: str) -> str:
:param new_response: the new response
:return: success message
"""
async with AIOTinyDB(".db.json") as db:
async with AIOTinyDB(bot.tinydb_path) as db:
db.table("faq").upsert({"topic": topic, "response": new_response}, where("topic") == topic)
return f"FAQ topic '{topic}' updated!"

@@ -56,7 +56,7 @@ async def ls_faq() -> str:

:return: A list of all available FAQ topics
"""
async with AIOTinyDB(".db.json") as db:
async with AIOTinyDB(bot.tinydb_path) as db:
return f"Available FAQ topics: {', '.join(x['topic'] for x in db.table('faq').all())}"


@@ -71,6 +71,6 @@ async def del_faq(topic: str) -> str:
:param topic: the name of the topic to delete
:return: a success message
"""
async with AIOTinyDB(".db.json") as db:
async with AIOTinyDB(bot.tinydb_path) as db:
db.table("faq").remove(where("topic") == topic)
return f"FAQ topic '{topic}' deleted!"

+ 4
- 2
singletons/bot.py View File

@@ -34,7 +34,7 @@ from constants.api_privileges import APIPrivileges

@singleton.singleton
class Bot:
VERSION: str = "2.2.1"
VERSION: str = "2.2.2"

def __init__(
self, *, nickname: str = "FokaBot", wss: bool = True,
@@ -48,7 +48,7 @@ class Bot:
http_host: str = None, http_port: int = None,
redis_host: str = "127.0.0.1", redis_port: int = 6379,
redis_database: int = 0, redis_password: Optional[str] = None,
redis_pool_size: int = 8,
redis_pool_size: int = 8, tinydb_path: str = None,
):
self.ready = False
self.nickname = nickname
@@ -94,6 +94,8 @@ class Bot:
self._pubsub_task: Optional[asyncio.Task] = None
self.pubsub_binding_manager: PubSubBindingManager = PubSubBindingManager()

self.tinydb_path = tinydb_path

self.login_channels_left: Set[str] = set()
self.joined_channels: Set[str] = set()
self.match_delayed_start_tasks: Dict[int, asyncio.Task] = {}


+ 2
- 0
singletons/config.py View File

@@ -46,6 +46,8 @@ class Config:
"REDIS_DATABASE": config("REDIS_DATABASE", default="0", cast=int),
"REDIS_PASSWORD": config("REDIS_PASSWORD", default=None),
"REDIS_POOL_SIZE": config("REDIS_POOL_SIZE", default="8", cast=int),

"TINYDB_PATH": config("TINYDB_PATH", default=".db.json"),
}

def __getitem__(self, item: str) -> Any:


Loading…
Cancel
Save