Skip to content

Quest

tibiawikisql.models.quest

Classes:

Name Description
ItemReward

An item awarded in the quest.

QuestReward

Represents an item obtained in the quest.

QuestCreature

Represents a creature found in the quest.

QuestDanger

Represents a creature found in the quest.

Quest

Represents a quest.

ItemReward pydantic-model

Bases: BaseModel

An item awarded in the quest.

Show JSON schema:
{
  "description": "An item awarded in the quest.",
  "properties": {
    "item_id": {
      "default": 0,
      "title": "Item Id",
      "type": "integer"
    },
    "item_title": {
      "title": "Item Title",
      "type": "string"
    }
  },
  "required": [
    "item_title"
  ],
  "title": "ItemReward",
  "type": "object"
}

Fields:

item_id pydantic-field
item_id: int = 0

The article id of the rewarded item.

item_title pydantic-field
item_title: str

The title of the rewarded item.

QuestReward pydantic-model

Bases: RowModel

Represents an item obtained in the quest.

Show JSON schema:
{
  "description": "Represents an item obtained in the quest.",
  "properties": {
    "quest_id": {
      "title": "Quest Id",
      "type": "integer"
    },
    "quest_title": {
      "title": "Quest Title",
      "type": "string"
    },
    "item_id": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Item Id"
    },
    "item_title": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Item Title"
    }
  },
  "required": [
    "quest_id",
    "quest_title"
  ],
  "title": "QuestReward",
  "type": "object"
}

Fields:

quest_id pydantic-field
quest_id: int

The article id of the quest.

quest_title pydantic-field
quest_title: str

The title of the quest.

item_id pydantic-field
item_id: int | None = None

The article id of the rewarded item.

item_title pydantic-field
item_title: str | None = None

The title of the rewarded item.

insert
insert(conn: Connection | Cursor) -> None

Insert the model into its respective database table.

Parameters:

Name Type Description Default
conn Connection | Cursor

A cursor or connection to the database.

required
Source code in tibiawikisql/models/quest.py
def insert(self, conn: sqlite3.Connection | sqlite3.Cursor) -> None:
    if self.item_id is not None:
        super().insert(conn)
        return
    quest_table = self.table.__table__
    item_table = ItemTable.__table__
    q = (
        Query.into(quest_table)
        .columns(
            "quest_id",
            "item_id",
        )
        .insert(
            Parameter(":quest_id"),
            (
                Query.from_(item_table)
                .select(item_table.article_id)
                .where(item_table.title == Parameter(":item_title"))
            ),
        )
    )

    query_str = q.get_sql()
    with contextlib.suppress(sqlite3.IntegrityError):
        conn.execute(query_str, self.model_dump(mode="json"))

QuestCreature pydantic-model

Bases: BaseModel

Represents a creature found in the quest.

Show JSON schema:
{
  "description": "Represents a creature found in the quest.",
  "properties": {
    "creature_id": {
      "default": 0,
      "title": "Creature Id",
      "type": "integer"
    },
    "creature_title": {
      "title": "Creature Title",
      "type": "string"
    }
  },
  "required": [
    "creature_title"
  ],
  "title": "QuestCreature",
  "type": "object"
}

Fields:

creature_id pydantic-field
creature_id: int = 0

The article id of the found creature.

creature_title pydantic-field
creature_title: str

The title of the found creature.

QuestDanger pydantic-model

Bases: RowModel

Represents a creature found in the quest.

Show JSON schema:
{
  "description": "Represents a creature found in the quest.",
  "properties": {
    "quest_id": {
      "title": "Quest Id",
      "type": "integer"
    },
    "quest_title": {
      "title": "Quest Title",
      "type": "string"
    },
    "creature_id": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Creature Id"
    },
    "creature_title": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Creature Title"
    }
  },
  "required": [
    "quest_id",
    "quest_title"
  ],
  "title": "QuestDanger",
  "type": "object"
}

Fields:

quest_id pydantic-field
quest_id: int

The article id of the quest.

quest_title pydantic-field
quest_title: str

The title of the quest.

creature_id pydantic-field
creature_id: int | None = None

The article id of the found creature.

creature_title pydantic-field
creature_title: str | None = None

The title of the found creature.

insert
insert(conn: Connection | Cursor) -> None

Insert the model into its respective database table.

Parameters:

Name Type Description Default
conn Connection | Cursor

A cursor or connection to the database.

required
Source code in tibiawikisql/models/quest.py
def insert(self, conn: sqlite3.Connection | sqlite3.Cursor) -> None:
    if self.creature_id is not None:
        super().insert(conn)
        return
    quest_table = self.table.__table__
    creature_table = CreatureTable.__table__
    q = (
        Query.into(quest_table)
        .columns(
            "quest_id",
            "creature_id",
        )
        .insert(
            Parameter(":quest_id"),
            (
                Query.from_(creature_table)
                .select(creature_table.article_id)
                .where(creature_table.title == Parameter(":creature_title"))
            ),
        )
    )

    query_str = q.get_sql()
    with contextlib.suppress(sqlite3.IntegrityError):
        conn.execute(query_str, self.model_dump(mode="json"))

Quest pydantic-model

Bases: WikiEntry, WithStatus, WithVersion, RowModel

Represents a quest.

Show JSON schema:
{
  "$defs": {
    "ItemReward": {
      "description": "An item awarded in the quest.",
      "properties": {
        "item_id": {
          "default": 0,
          "title": "Item Id",
          "type": "integer"
        },
        "item_title": {
          "title": "Item Title",
          "type": "string"
        }
      },
      "required": [
        "item_title"
      ],
      "title": "ItemReward",
      "type": "object"
    },
    "QuestCreature": {
      "description": "Represents a creature found in the quest.",
      "properties": {
        "creature_id": {
          "default": 0,
          "title": "Creature Id",
          "type": "integer"
        },
        "creature_title": {
          "title": "Creature Title",
          "type": "string"
        }
      },
      "required": [
        "creature_title"
      ],
      "title": "QuestCreature",
      "type": "object"
    }
  },
  "description": "Represents a quest.",
  "properties": {
    "version": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Version"
    },
    "status": {
      "title": "Status",
      "type": "string"
    },
    "article_id": {
      "title": "Article Id",
      "type": "integer"
    },
    "title": {
      "title": "Title",
      "type": "string"
    },
    "timestamp": {
      "format": "date-time",
      "title": "Timestamp",
      "type": "string"
    },
    "name": {
      "title": "Name",
      "type": "string"
    },
    "location": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Location"
    },
    "is_rookgaard_quest": {
      "title": "Is Rookgaard Quest",
      "type": "boolean"
    },
    "is_premium": {
      "title": "Is Premium",
      "type": "boolean"
    },
    "type": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Type"
    },
    "quest_log": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "title": "Quest Log"
    },
    "legend": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Legend"
    },
    "level_required": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Level Required"
    },
    "level_recommended": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Level Recommended"
    },
    "active_time": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Active Time"
    },
    "estimated_time": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Estimated Time"
    },
    "dangers": {
      "items": {
        "$ref": "#/$defs/QuestCreature"
      },
      "title": "Dangers",
      "type": "array"
    },
    "rewards": {
      "items": {
        "$ref": "#/$defs/ItemReward"
      },
      "title": "Rewards",
      "type": "array"
    }
  },
  "required": [
    "version",
    "status",
    "article_id",
    "title",
    "timestamp",
    "name",
    "location",
    "is_rookgaard_quest",
    "is_premium",
    "type",
    "quest_log",
    "legend",
    "level_required",
    "level_recommended",
    "active_time",
    "estimated_time"
  ],
  "title": "Quest",
  "type": "object"
}

Fields:

name pydantic-field
name: str

The name of the quest.

location pydantic-field
location: str | None

The location of the quest.

is_rookgaard_quest pydantic-field
is_rookgaard_quest: bool

Whether this quest is in Rookgaard or not.

is_premium pydantic-field
is_premium: bool

Whether this quest requires a Premium account or not.

type pydantic-field
type: str | None

The type of quest.

quest_log pydantic-field
quest_log: bool | None

Whether this quest is registered in the quest log or not.

legend pydantic-field
legend: str | None

The legend of the quest.

level_required pydantic-field
level_required: int | None

The level required to finish the quest.

level_recommended: int | None

The recommended level to finish the quest.

active_time pydantic-field
active_time: str | None

Times of the year when this quest is active.

estimated_time pydantic-field
estimated_time: str | None

Estimated time to finish this quest.

dangers pydantic-field
dangers: list[QuestCreature]

Creatures found in the quest.

rewards pydantic-field
rewards: list[ItemReward]

Items rewarded in the quest.

insert
insert(conn: Connection | Cursor) -> None

Insert the model into its respective database table.

Parameters:

Name Type Description Default
conn Connection | Cursor

A cursor or connection to the database.

required
Source code in tibiawikisql/models/quest.py
def insert(self, conn: sqlite3.Connection | sqlite3.Cursor) -> None:
    super().insert(conn)
    for reward in self.rewards:
        reward.insert(conn, self.article_id)
    for danger in self.dangers:
        danger.insert(conn, self.article_id)
get_one_by_field classmethod
get_one_by_field(
    conn: Connection | Cursor,
    field: str,
    value: Any,
    use_like: bool = False,
) -> Self | None

Get a single element matching the field's value.

Parameters:

Name Type Description Default
conn Connection | Cursor

A connection or cursor of the database.

required
field str

The field to filter with.

required
value Any

The value to look for.

required
use_like bool

Whether to use LIKE as a comparator instead of =.

False

Returns:

Type Description
Self | None

The object found, or None if no entries match.

Raises:

Type Description
ValueError

The specified field doesn't exist in the table.

Source code in tibiawikisql/models/quest.py
@classmethod
def get_one_by_field(cls, conn: Connection | Cursor, field: str, value: Any, use_like: bool = False) -> Self | None:
    quest: Self = super().get_one_by_field(conn, field, value, use_like)
    if quest is None:
        return None
    quest.rewards = [ItemReward(**dict(r)) for r in QuestRewardTable.get_list_by_quest_id(conn, quest.article_id)]
    quest.dangers = [QuestCreature(**dict(r)) for r in QuestDangerTable.get_list_by_quest_id(conn, quest.article_id)]
    return quest