Utils

Checks

This module provides basic checks to common procedures.

utils.checks.confirm(author)[source]
Parameters:author – The ctx.author attribute value.
Returns:True if the author matches the context and properly responds, False otherwise.
utils.checks.is_dm(ctx)[source]

Check to see if the message received is a direct message.

Parameters:ctx – The invocation context.
Returns:True if the context is a direct message, False otherwise.
utils.checks.is_number(author)[source]
Parameters:author – The ctx.author attribute value.
Returns:True if the author matches the context and properly responds, False otherwise.
utils.checks.is_registered()[source]

Check to see if the user is registered in database.

Returns:True if the utils.fjclasses.DiscordUser exists.
Raises:utils.fjclasses.UserNotRegisteredError if User is not found in database.

FJClasses

This module contains all classes and models used throughout the bot.

_Abstract

_Base

class utils.fjclasses._Base(id=None, name=None)[source]

A generic class with only id and name attribute.

fetch_info()[source]

Abstract function for fetching object’s attribute values from database.

fill_info(row)[source]

Abstract function for applying object’s attribute values based on query result.

Parameters:row – The SQL result.
id

The object’s unique identifier value.

Type:return
name

The name of the object.

Type:return

_Database

class utils.fjclasses._Database[source]

A generic database handler.

close()[source]

Closes the database connection and cursor. Fails gracefully.

connection

The database connection.

Type:return
cursor

The database cursor.

Type:return
db

The database object (itself).

Type:return
execute(sql, params=None)[source]

Executes query with or without params.

Parameters:
  • sql – The SQL query.
  • params – The parameters for the query.
fetchall()[source]

Grabs all values from query result.

Returns:All query results.
fetchone()[source]

Grabs single value from query result.

Returns:A single query result.
query(sql, params=None)[source]

Executes a query and returns all results in a single call.

Parameters:
  • sql – The SQL query.
  • params – The parameters for the query.
Returns:

All query results.

_User

class utils.fjclasses._User[source]

A generic class used by different user types.

current_bets()[source]

Return the list of currently placed bets.

Returns:Query result of currently placed bets. Error message if none.
fetch_info()[source]

Abstract function to fetch the user info.

fill_info(row)[source]

Applies attributes based on query result.

Parameters:row – The query result.
fjbucks_check(amount)[source]

Checks whether the FJBucks transaction is valid to make.

Parameters:amount – The amount of FJBucks for the transaction.
Returns:Query result with success or failure message.
fjbucks_transaction(amount, note)[source]

Calls stored procedure to create a FJBucks transaction.

Parameters:
  • amount – The amount of FJBucks for the transaction.
  • note – A memo for the transaction.
Returns:

Query result with success or failure message.

fjbucks_wallet()[source]
Returns:The user’s FJBucks wallet info.
is_registered()[source]

Checks if the user is registered.

Returns:True if id and username values exist, False otherwise.
join_royalrumble()[source]

TODO

mention

Abstract function to notify the user inside the chat.

place_bet(match_id, team, bet)[source]

Places a bet for match.

Parameters:
  • match_id – The Match id to bet for.
  • team – The Match team id to bet for.
  • bet – The amount betting.
Returns:

Query result with success or failure message.

rate_match(match_id, rating)[source]

Places a rating for a match.

Parameters:
  • match_id – The Match id to rate for.
  • rating – The rating for the match.
Returns:

Query result with success or failure message.

refresh()[source]

Re-initializes the user’s attribute values.

register()[source]

Abstract function to register the user.

Creates hyperlink to auto-login user to the website.

This creates a randomized token that allows the user to bypass initial login screen.

Important

Do not post this link in a public chat. It must be DMed to the user requesting it only. Once the hyperlink can only be used once and within a short time frame.

Returns:The hyperlink to auto-login a user to the website.

Creates hyperlink to reset the user’s password.

Once called a temporary password is set for the user to bypass their original password.This is required for users that have no yet set up a password for their account; users that registered through the bot and not the website.

Important

Do not post this link in a public chat. It must be DMed to the user requesting it only. Once the hyperlink can only be used once and within a short time frame.

Returns:The hyperlink to reset the user’s password for the website.
royalrumble_info()[source]

TODO

stats(season)[source]

Return user’s stats for the Matches season.

Parameters:season – The Match season to fetch stats for.
Returns:The user stats for the Matches season.
username

The user’s username.

Type:return
validate_bet(match_id, team, bet)[source]

Checks to see if user is able to place the bet through a stored procedure.

Parameters:
  • match_id – The Match id to bet for.
  • team – The Match team id to bet for.
  • bet – The amount betting.
Returns:

Query result with success or failure message.

_Exceptions

GuildNotOriginError

class utils.fjclasses.GuildNotOriginError(message=None, *args)[source]

Custom exception class. Thrown when command requires origin guild.

UserNotRegisteredError

class utils.fjclasses.UserNotRegisteredError(message=None, *args)[source]

Custom exception class. Thrown when command requires registered user.

ChatangoUser

class utils.fjclasses.ChatangoUser(author)[source]

This class is used to refer to individual Chatango authors.

chatango

The author. (itself)

Type:return
fetch_info()[source]

Fetches attribute values from database using current Chatango author unique identifier (name).

Note

If no results are found with id, no attributes are set.

join_royalrumble()[source]

TODO

mention

The author’s mention.

Type:return
name

The author’s name.

Type:return
register()[source]

Inserts the author as a User in the database using Discord profile.

Returns:Query result with success or failure message.
royalrumble_info()[source]

TODO

stats_text(season)[source]

Formats the user’s stats for the season as plain text.

Parameters:season – The season id.
Returns:Formatted text message.

DbHelper

class utils.fjclasses.DbHelper[source]

This class handles the most common and generic queries.

add_chatroom_command(command, response)[source]

TODO

Parameters:
  • command – The chatroom command to insert.
  • response – The response for the chatroom command.
chatroom_command(command)[source]

Fetches response to a quick chatroom command.

Parameters:command – The command to fetch the response for.
Returns:The query result if found, False otherwise.
chatroom_command_list()[source]

Fetches the complete list of available chatroom commands.

Returns:The query result of chatroom commands ordered by alpha.
chatroom_scheduler_list()[source]

Fetches list of weekly alert scheduler.

Returns:The query result for the weekly schedule.
future_events(ppv_check=0)[source]

Fetches list of upcoming PPV events.

Parameters:ppv_check – The PPV flag check. Default is 0.
Returns:The query result of upcoming events.
guild_info(guild_id)[source]

Fetches Discord guild information by id.

Parameters:guild_id – The guild id.
Returns:The command prefix for the guild, False otherwise.
leaderboard(season)[source]

Fetches the leaderboard for the season.

Parameters:season – The season id.
Returns:Query result of User stats ordered by total points for the season.
search_match_by_current()[source]

Fetches info for the current Match.

Returns:A list of :class:’utils.fjclasses._Base’.
search_match_by_id(id)[source]

Fetches Match info by id.

Parameters:id – The Match id.
Returns:A list of :class:’utils.fjclasses._Base’.
search_match_by_open_bets()[source]

Fetches info for Matches that are available to bet on.

Returns:A list of :class:’utils.fjclasses._Base’.
search_match_by_open_bets_and_superstar_name(name)[source]

Fetches info for Matches that are available to bet on and contain the Superstar.

Parameters:name – The Superstar name.
Returns:A list of :class:’utils.fjclasses._Base’.
search_match_by_recent_completed()[source]

Fetches info for the most recently completed Match.

Returns:A list of :class:’utils.fjclasses._Base’.
search_superstar_by_name(name)[source]

Fetches Superstar info by name.

Parameters:name – The Superstar’s name to query for.
Returns:A list of :class:’utils.fjclasses._Base’.
search_user_by_name(name)[source]

Fetches User info by name.

Parameters:name – The User’s name to query for.
Returns:A list of :class:’utils.fjclasses._Base’.
superstar_birthday_upcoming()[source]

Fetches Superstar info who’s birthday is coming up.

Returns:The query result of Superstars.
update_chatroom_command(command, response)[source]

TODO

Parameters:
  • command – The chatroom command to update.
  • response – The updated response for the chatroom command.
update_guild_info(guild, prefix)[source]

Updates the Discord guild’s information and command prefix.

Note

If an entry for the guild does not exist, a new entry for the guild is inserted.

Parameters:
  • guild – The guild object.
  • prefix – The guild’s command prefix to update to.
Returns:

TODO

DiscordUser

class utils.fjclasses.DiscordUser(author)[source]

This class is used to refer to individual Discord authors.

discord

The author object. (itself)

Type:return
fetch_info()[source]

Fetches attribute values from database using current Discord author unique identifier (id).

Note

If no results are found with id, no attributes are set.

fjbucks_wallet_embed()[source]

Creates rich content of the User’s FJBucks wallet.

Returns:Rich content.
join_royalrumble()[source]

TODO

mention

The author’s mention value.

Type:return
name

The author’s name value.

Type:return
register()[source]

Inserts the author as a User in the database using Discord profile.

Returns:Query result with success or failure message.
royalrumble_info()[source]

TODO

stats_embed(season)[source]

Creates rich content of the User’s stats for the season.

Parameters:season – The season id.
Returns:Rich content.

Match

class utils.fjclasses.Match(id=None)[source]

The class is used to refer to individual Matches.

contains_contestant(name)[source]

Checks if Superstar is a Match contestant.

Parameters:name – The Superstar name.
Returns:True if the Superstar is a contestant, False otherwise.
contestants_by_team(team_id)[source]

Returns the list of Superstars in the Match based on the team id.

Parameters:team_id – The team id.
Returns:The list Superstars in the team, False otherwise.
fetch_info()[source]

Fetches attribute values from database using current Match unique identifier (id).

Note

If no results are found with id, no attributes are set.

fill_info(row)[source]

Applies attributes based on query result.

Parameters:row – The query result.
info_embed()[source]

Creates rich content of the Match’s info.

Returns:Rich content.
info_text()[source]

Formatted text of a Match’s info. (long version)

Returns:Formatted text.
info_text_short()[source]

Formatted text of a Match’s info. (short version)

Returns:Formatted text.
set_teams(rows)[source]

Initializes teams attribute with query result.

Parameters:rows – The list of contestants in the Match.
team_by_contestant(name)[source]

Returns the team id of Superstar in the Match based on the Superstar’s name.

Parameters:name – The Superstar’s name.
Returns:The Superstar’s team, False otherwise.

Superstar

class utils.fjclasses.Superstar(id=None)[source]

This class is used to refer to individual Superstars.

fetch_info()[source]

Fetches attribute values from database using current Chatango author unique identifier (id).

Note

If no results are found with id, no attributes are set.

fill_info(row)[source]

Applies attributes based on query result.

Parameters:row – The query result.
info_embed()[source]

Creates rich content of the Superstar’s info.

Returns:Rich content.

QuickEmbed

This module provides a quick way to personalize messages back to the user.

Instead of flat text messages or going through all the steps to setup and personalize rich content, this module is used.

utils.quickembed.error(desc, user=None)[source]

Styles the rich content for a failed response. Colored red.

Parameters:
Returns:

The personalized rich content.

utils.quickembed.filler(embed, desc, user)[source]

Creates the rich content and fills in all user info.

Parameters:
Returns:

The personalized rich content.

utils.quickembed.general(desc, user=None)[source]

Styles the rich content for a generic response. Colored blue.

Parameters:
Returns:

The personalized rich content.

utils.quickembed.info(desc, user=None)[source]

Styles the rich content for a informative response. Colored white.

Parameters:
Returns:

The personalized rich content.

utils.quickembed.question(desc, user=None)[source]

Styles the rich content for a question response. Colored yellow.

Parameters:
Returns:

The personalized rich content.

utils.quickembed.success(desc, user=None)[source]

Styles the rich content for a successful response. Colored green.

Parameters:
Returns:

The personalized rich content.