Data Models

This module contains a compilation of data models.

to_dict()[source]

Convert a Discord object into a Dictionary.

Note

Currently only supports User, Guild, and TextChannel.

Parameters

dc_obj (Union[ discord.User, discord.Guild, discord.TextChannel, discord.Role]) – Discord object to be converted.

Returns

Dictionary of Discord object.

Return type

Dict[str, Any]

exception MethodNotAllowed[source]

Exception raised when a method is not allowed.

class Model[source]

The Base Model Class which has a corresponding Collection in the DB.

Parameters

user (discord.Member) – The user to map the collection to.

uid_fields = <bound method ? of <class 'scripts.base.models.Model'>>
drop()[source]

Deletes all entries in the Collection for the user.

get()[source]

Returns the Model object as a dictionary.

Parameters

param (str) – The attribute to get from the Model.

Returns

The attribute value.

Return type

Any

save()[source]

Saves the Model object to the Collection.

classmethod latest()[source]

Returns the latest douments from the DB for a model.

Parameters

limit (Optional[int]) – The number of documents to return., default 5

Returns

The documents from the DB.

Return type

List[Dict]

classmethod purge()[source]

Deletes all entries in the Collection.

classes = <bound method ? of <class 'scripts.base.models.Model'>>
classmethod censor_uids()[source]

Censors the user IDs in all the collections.

Parameters

user (discord.User) – The user to censor.

Returns

The number of documents censored.

Return type

int

classmethod count()[source]

The number of documents in the collection.

Returns

The number of documents in the collection.

Return type

int

class Blacklist[source]

Wrapper for blacklisted users based DB actions.

Parameters
  • user (discord.Member) – The user to map the collection to.

  • mod (Optional[discord.Member]) – The Admin who used the command.

  • reason (Optional[str]) – The reason for the blacklist.

pardon()[source]

Pardons a blacklisted user.

async save()[source]

Saves the blacklisted user in the table. Also resets their profile.

classmethod is_blacklisted()[source]

Checks if a user is blacklisted.

Parameters

user_id (str) – The ID of the user to check.

Returns

True if blacklisted, False otherwise.

Return type

bool

class CommandData[source]

Wrapper for command based DB actions

Parameters
  • user (discord.Member) – The user to map the collection to.

  • message (Message) – The message which triggered the command.

  • is_interaction (bool) – Whether the command is an interaction.

  • command (str) – The command which was triggered.

  • args (List[str]) – The arguments passed to the command.

  • kwargs (Dict[str, Any]) – The keyword arguments passed to the command.

save()[source]

Override Save to serialize Discord objects in args or kwargs.

classmethod history()[source]

Returns the list of commands used on PG till now.

Parameters

limit (Optional[int]) – The number of documents to return., default 5

Returns

The recorded commands from the DB.

Return type

List[Dict]

classmethod most_active_channel()[source]

Returns the most active channel.

Returns

The most active channel.

Return type

Dict

classmethod most_used_command()[source]

Returns the most used command.

Returns

The most used command.

Return type

Dict

classmethod most_active_user()[source]

Returns the most active user.

Returns

The most active user.

Return type

Dict

classmethod num_user_cmds()[source]

Returns the number of commands used by a user.

Parameters

user_id (str) – The ID of the user.

Returns

The number of commands used by the user.

Return type

int

classmethod clean_guild()[source]

Replaces the given guild ID in all commands with “REDACTED”.

Parameters

guild_id (str) – The ID of the guild.

Returns

The number of removed commands.

Return type

int

classmethod trend()[source]

Returns the number of commands used on PG per day.

Parameters
  • include_os (bool) – Whether to include commands used on the Official Server.

  • start_time (Optional[datetime]) – The start time of the period.

  • end_time (Optional[datetime]) – The end time of the period.

Returns

The number of commands used on PG.

Return type

Iterable[Dict[str, Union[int, datetime]]]

class DuelActionsModel[source]

Wrapper for duel actions based DB actions

Parameters
  • user (discord.Member) – The user to map the collection to.

  • action (Optional[str]) – An action which can be used in a duel.

  • level (Optional[str]) – The level of the action.

classmethod get_actions()[source]

Get Duel Actions from the DB.

Parameters

user_id (Optional[str]) – An optional user_id to get the actions for.

Returns

The list of duel actions.

Return type

List[Dict]

class Exchanges[source]

Wrapper for currency exchanges based DB actions.

Parameters
  • user (discord.Member) – The user to map the collection to.

  • admin (Optional[discord.Member]) – The Admin who performed the exchange.

  • pokebot (Optional[discord.Member]) – The Pokemon themed bot.

  • chips (Optional[int]) – The amount of chips exchanged.

  • mode (Optional[str]) – The mode of the exchange., default is Deposit.

get_daily_exchanges()[source]

Gets the list of exchanges made by the user today.

Parameters

mode (str) – The mode of the exchange.

Returns

The number of chips exchanged.

Return type

int

classmethod exchanges()[source]

Find all completed exchanges based on the provided filters.

Parameters

kwargs (Dict) – The filters to use in the query.

Returns

The list of completed exchanges.

Return type

List[Dict]

class Inventory[source]

Wrapper for Inventory based DB operations.

Parameters

user (discord.Member) – The user to map the collection to.

delete()[source]

Deletes an Item from user’s Inventory. Input can either be a name or List of itemids. If item name is given, a quantity can be provided. If quantity is -1, all items of the name will be removed.

Parameters
  • item_inp (Union[str, List[str]]) – The name or list of item ids to delete.

  • quantity (int) – The quantity of items to delete., default is -1.

  • is_name (bool) – Whether the input is a name or list of item ids.

Returns

The number of items deleted.

Return type

int

from_id()[source]

Gets an item using ItemID if it exists in user’s inventory.

Parameters

itemid (str) – The ItemID of the item.

Returns

The Item object.

Return type

Item

from_name()[source]

Returns a list of ItemIDs if they exist in user’s Inventory.

Parameters

name (str) – The name of the item.

Returns

The list of ItemIDs.

Return type

List[str]

get()[source]

Returns a list of items in user’s Inventory and the net worth.

Note

These items are not included for calculating the net worth:

Parameters

category (Optional[str]) – The category to filter by.

Returns

The list of items and the net worth of the inventory.

Return type

Tuple[Dict[str, List], int]

save()[source]

Saves an item to a player’s inventory.

Parameters

itemid (str) – The ItemID of the item.

bulk_insert()[source]

Inserts a list of items to a player’s inventory.

Parameters

items (List[str]) – The list of item ids to insert.

class Matches[source]

Wrapper for Gamble matches based DB actions

Parameters
  • user (discord.Member) – The user to map the collection to.

  • started_by (Optional[discord.Member]) – The user who started the match.

  • participants (Optional[List[discord.Member]]) – The list of participants.

  • winner (discord.Member) – The user who won.

  • deal_cost (int) – The fee of the gamble match., deafult is 50.

  • lower_wins (bool) – Was the lower_wins rule in place?

  • by_joker (bool) – Did the match end due to a joker?

property num_matches: int

Returns number of gamble matches played.

Returns

Number of matches played.

Return type

int

property num_wins: int

Returns number of gamble matches won.

Returns

Number of matches won.

Return type

int

get_stats()[source]

Get Match num_matches() and num_wins() as a Tuple.

Returns

Tuple of num_matches and num_wins.

Return type

Tuple[int, int]

classmethod get_matches()[source]

Get the recently played gamble matches.

Parameters

limit (Optional[int]) – The maximum number of matches to return., default 10

Returns

List of recent matches.

Return type

List[Dict]

class Trades[source]

Wrapper for trades based DB actions.

Parameters
  • user (discord.Member) – The user to map the collection to.

  • traded_to (discord.Member) – The user with whom the trade happened.

  • given_chips (int) – The number of pokechips given to user.

  • taken_chips (int) – The number of pokechips taken from user.

  • given_items (List[str]) – The list of items given to user.

  • taken_items (List[str]) – The list of items taken from user.

class Transactions[source]

Wrapper for webshop transactions based DB actions.

Parameters
  • user (discord.Member) – The user to map the collection to.

  • created_on (datetime) – The date and time of the transaction.

  • tx_id (str) – The transaction ID.

  • gateway (str) – The gateway used for the transaction.

  • webitem_id (str) – The ID of the webitem.

  • quantity (int) – The quantity of the webitem purchased.

  • total_price (float) – The total price of the transaction.

  • redeemed (bool) – Was the webitem redeemed?

get()[source]

Get all transactions for the user.

Returns

List of transactions.

Return type

List[Transactions]

from_tx_id()[source]

Get the transaction with the given ID.

Parameters

tx_id (str) – The transaction ID.

Returns

The transaction.

Return type

Transactions

redeem()[source]

Redeem the transaction.

Returns

The transaction.

Return type

Transactions

class Minigame[source]

Base class for Minigames.

property num_plays: int

Returns number of minigames (of specified type) played.

Returns

Number of minigames played.

Return type

int

property num_wins

Returns number of minigames (of specified type) won.

Returns

Number of minigames won.

Return type

int

get_lb()[source]

Returns leaderboard for the specified minigame.

Returns

The leaderboard for the minigame.

Return type

List[Dict]

get_plays()[source]

Returns list of minigames (of specified type) played.

Parameters

wins (bool) – Whether to include only wins or all plays.

Returns

List of minigames played.

Return type

List[Dict]

save()[source]

Saves the Model object to the Collection.

class UnlockedModel[source]

The Base Unlocked Model class which can be modified after creation.

Parameters

user (discord.Member) – The user to map the collection to.

pk_field: str = 'user_id'

The name of the primary key.

reset()[source]

Resets a model for a particular user.

save()[source]

Saves the Model object to the Collection.

update()[source]

Updates an existing unfrozen model.

class UnboundModel[source]

A special subset of Models which don’t have a user associated with them.

Parameters

pk_value (Optional[Any]) – The value of the primary key.

pk_field: str = '_id'

The name of the primary key.

drop()[source]

Overriden Drop method to disable it.

save()[source]

Overriden Save method to pop the user field.

class TaskModel[source]

A special subset of UnboundModels representing automated tasks.

class Boosts[source]

Wrapper for Permanent Boosts based DB actions.

Parameters

user (discord.Member) – The user to map the collection to.

classmethod reset_all()[source]

Resets the Boosts collection.

class Loots[source]

Wrapper for Loots based DB actions.

Parameters

user (discord.Member) – The user to map the collection to.

classmethod reset_all()[source]

Resets the Loots collection.

class Profiles[source]

Wrapper for Profiles based DB actions.

Parameters

user (discord.Member) – The user to map the collection to.

property full_info: Dict

Get the full/consolidated info for the user.

Returns

The full info for the user.

Return type

Dict

credit()[source]

Shorthand method to credit user’s balance and won_chips.

Parameters
  • amount (int) – The amount to credit to the balance.

  • bonds (bool) – Currency type is Pokebonds?

debit()[source]

Shorthand method to debit user’s balance and won_chips.

Parameters
  • amount (int) – The amount to debit from the balance.

  • bonds (bool) – Currency type is Pokebonds?

get_badges()[source]

Computes the Badges unlocked by the user.

Returns

The list of badges unlocked by the user.

Return type

List[str]

get_rank()[source]

Get the user’s rank in the leaderboard.

Returns

The user’s rank in the leaderboard.

Return type

int

classmethod get_all()[source]

DB query to get all whitelisted profiles.

Parameters

ids_only (bool) – Return only the user IDs?

Returns

The list of whitelisted profiles.

Return type

List[Dict]

classmethod get_leaderboard()[source]

Get the global leaderboard of PokeGambler.

Parameters

sort_by (List[str]) – The fields to sort the leaderboard by.

Returns

The leaderboard.

Return type

List[Dict]

classmethod reset_all()[source]

Resets all the Profiles.

class Votes[source]

Wrapper for Votes based DB actions.

Parameters

user (discord.Member) – The user to map the collection to.

classmethod most_active_voter()[source]

Get the most active voter.

Returns

The most active voter.

Return type

Dict

classmethod reset_all()[source]

Resets the Votes collection.

votes_count = <bound method ? of <class 'scripts.base.models.Votes'>>
class Webshop[source]

Wrapper for Webshop Model.

Parameters
  • name (str) – The name of the item.

  • description (str) – The description of the item.

  • image (str) – The image of the item.

  • price (float) – The price of the item.

  • offer_price (float) – Any special offer price for the item.

  • reward_pokechips (int) – The amount of Pokechips held by the item.

  • reward_pokebonds (int) – The amount of Pokebonds held by the item.

  • reward_items (List[Item]) – The ingame Items held by the item.

  • meta (Dict[str, bool]) – Metadata Dictionary

class Duels[source]

Wrapper for duels based DB actions

Parameters
  • user (discord.Member) – The user to map the collection to.

  • gladiator (Optional[str]) – The gladiator used by the user.

  • opponent (Optional[discord.Member]) – The opponent for the Duel.

  • opponent_gladiator (Optional[str]) – The gladiator of the opponent.

  • won (Optional[str]) – The ID of the winner of the Duel.

  • cost (Optional[int]) – The cost of the Duel., default is 50.

get_plays()[source]

Returns list of duels played/won by the user.

Parameters

wins (bool) – Whether to get the list of wins or plays.

Returns

The list of plays.

Return type

List[Dict]

class Flips[source]

Wrapper for Quickflips based DB actions.

Parameters
  • user (discord.Member) – The user to map the collection to.

  • cost (int) – The cost of the flip.

  • won (bool) – Did the user win the flip?

class Moles[source]

Wrapper for Whackamole based DB actions.

Parameters
  • user (discord.Member) – The user to map the collection to.

  • cost (int) – The cost of the mole.

  • level (int) – The level of the mole.

  • won (bool) – Did the user win the mole?

class Checkpoints[source]

Wrapper for Daily Checkpoints Model.

Parameters

ctx (bot.PokeGambler) – The PokeGambler client.

num_profiles

The number of profiles created till this checkpoint.

num_guilds

The number of guilds the bot is in.

num_commands

The number of commands used till this checkpoint.

num_votes

The number of votes received till this checkpoint.

classmethod get_checkpoints()[source]

Get the checkpoints between the given times.

Parameters
  • start_time (datetime) – The start time of the checkpoints.

  • end_time (datetime) – The end time of the checkpoints.

Returns

The checkpoints.

Return type

List[Dict]

class Nitro[source]

Wrapper for Nitro Reward records.

Parameters
  • boosters (List[discord.Member]) – The list of the nitro boosters.

  • rewardboxes (List[str]) – The list of IDs of nitro reward boxes.

classmethod get_last_rewarded()[source]

Returns the last time the users were rewarded.

Returns

Last time the users were rewarded.

Return type

datetime.datetime

@expire_cache[source]

Decorator to reset User cache.

Parameters

func (Callable) – Function which requires cache to be cleared.